apache / pinot

Apache Pinot - A realtime distributed OLAP datastore
https://pinot.apache.org/
Apache License 2.0
5.26k stars 1.23k forks source link

CalciteSQLParser error even when query executes succesfully #11823

Open timveil opened 8 months ago

timveil commented 8 months ago

When submitting the following query using JDBC an ERROR occurs and is logged but ultimately does not prevent the query from completing.

the query...

SET useMultistageEngine=true;
SELECT stats.* FROM airlineStats stats limit 10

the client side logs...

2023-10-17T11:29:19.472-04:00 ERROR 76108 --- [           main] org.apache.pinot.client.Connection       : Cannot parse table name from query: SET useMultistageEngine=true;
SELECT stats.* FROM airlineStats stats limit 10. Fallback to broker selector default.

java.lang.ClassCastException: class org.apache.calcite.sql.SqlIdentifier cannot be cast to class org.apache.calcite.sql.SqlSelect (org.apache.calcite.sql.SqlIdentifier and org.apache.calcite.sql.SqlSelect are in unnamed module of loader 'app')
    at org.apache.pinot.sql.parsers.CalciteSqlParser.compileSqlNodeToPinotQuery(CalciteSqlParser.java:436) ~[pinot-jdbc-uber-jar-1.1.0-SNAPSHOT.jar:na]
    at org.apache.pinot.sql.parsers.CalciteSqlParser.compileToDataSource(CalciteSqlParser.java:498) ~[pinot-jdbc-uber-jar-1.1.0-SNAPSHOT.jar:na]
    at org.apache.pinot.sql.parsers.CalciteSqlParser.compileSqlNodeToPinotQuery(CalciteSqlParser.java:453) ~[pinot-jdbc-uber-jar-1.1.0-SNAPSHOT.jar:na]
    at org.apache.pinot.client.Connection.resolveTableName(Connection.java:146) ~[pinot-jdbc-uber-jar-1.1.0-SNAPSHOT.jar:na]
    at org.apache.pinot.client.Connection.execute(Connection.java:96) ~[pinot-jdbc-uber-jar-1.1.0-SNAPSHOT.jar:na]
    at org.apache.pinot.client.Connection.execute(Connection.java:83) ~[pinot-jdbc-uber-jar-1.1.0-SNAPSHOT.jar:na]
    at org.apache.pinot.client.PinotStatement.executeQuery(PinotStatement.java:67) ~[pinot-jdbc-uber-jar-1.1.0-SNAPSHOT.jar:na]

because the method Connection.resolveTableName catches/logs this exception, the code executes the query fine using the multi-stage engine. In practice this may result in performance problems because the code is not able to identify the correct broker.

It seems that either Connection.resolveTableName and corresponding method calls need to be reworked to support queries the multi-stage engine supports or this method call should be avoided.

Jackie-Jiang commented 8 months ago

It works because broker is not multi-tenant, and it falls back to picking a random broker. The correct fix should be to make Connection.resolveTableName() work for multi-stage queries. cc @xiangfu0

SnehaHegde24 commented 3 months ago

Hi @Jackie-Jiang ,

Any update on the fix for this issue?

Jackie-Jiang commented 3 months ago

Unfortunately we haven't got a chance to work on this yet