xiangfu0 commented on code in PR #9263: URL: https://github.com/apache/pinot/pull/9263#discussion_r951989943
########## pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/Connection.java: ########## @@ -105,6 +108,38 @@ public ResultSetGroup execute(Request request) return execute(null, request); } + /** + * Extract tableName from the given query + * @param query + * @return tableName + * @throws PinotClientException + */ + public String getTableNameFromQuery(String query) { + PinotQuery pinotQuery; + + try { + pinotQuery = CalciteSqlParser.compileToPinotQuery(query); + } catch (Exception e) { + LOGGER.info("Caught exception while compiling SQL request: {}, {}", query, e.getMessage()); + throw new PinotClientException("Caught exception while compiling SQL request"); Review Comment: Add e to the PinotClientException. ########## pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/Connection.java: ########## @@ -105,6 +108,38 @@ public ResultSetGroup execute(Request request) return execute(null, request); } + /** + * Extract tableName from the given query + * @param query + * @return tableName + * @throws PinotClientException + */ + public String getTableNameFromQuery(String query) { + PinotQuery pinotQuery; + + try { + pinotQuery = CalciteSqlParser.compileToPinotQuery(query); + } catch (Exception e) { + LOGGER.info("Caught exception while compiling SQL request: {}, {}", query, e.getMessage()); + throw new PinotClientException("Caught exception while compiling SQL request"); + } + + DataSource dataSource; + + try { + dataSource = pinotQuery.getDataSource(); + } catch (Exception e) { + throw new PinotClientException("Caught exception while extracting DataSource from PinotQuery. DataSource is null."); + } + + String tableName = dataSource.getTableName(); + + if(tableName == null) { Review Comment: If tableName is null, then return null. I'm thinking of the case like `select 1` which is a valid SQL and should be executed by any pinot broker. ########## pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/Connection.java: ########## @@ -105,6 +108,38 @@ public ResultSetGroup execute(Request request) return execute(null, request); } + /** + * Extract tableName from the given query + * @param query + * @return tableName + * @throws PinotClientException + */ + public String getTableNameFromQuery(String query) { + PinotQuery pinotQuery; + + try { + pinotQuery = CalciteSqlParser.compileToPinotQuery(query); + } catch (Exception e) { + LOGGER.info("Caught exception while compiling SQL request: {}, {}", query, e.getMessage()); Review Comment: LOGGER.error ########## pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/Connection.java: ########## @@ -105,6 +108,38 @@ public ResultSetGroup execute(Request request) return execute(null, request); } + /** + * Extract tableName from the given query + * @param query + * @return tableName + * @throws PinotClientException + */ + public String getTableNameFromQuery(String query) { + PinotQuery pinotQuery; + + try { + pinotQuery = CalciteSqlParser.compileToPinotQuery(query); + } catch (Exception e) { + LOGGER.info("Caught exception while compiling SQL request: {}, {}", query, e.getMessage()); + throw new PinotClientException("Caught exception while compiling SQL request"); + } + + DataSource dataSource; + + try { + dataSource = pinotQuery.getDataSource(); Review Comment: When this will throw an exception? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org