Jackie-Jiang commented on code in PR #14918: URL: https://github.com/apache/pinot/pull/14918#discussion_r1931093052
########## pinot-query-planner/src/main/java/org/apache/pinot/query/parser/utils/ParserUtils.java: ########## @@ -53,95 +54,87 @@ public static boolean canCompileWithMultiStageEngine(String query, String databa } /** - * Tries to fill an empty or not properly filled schema when no rows have been returned. + * Tries to fill an empty or not properly filled {@link DataSchema} when no row has been returned. + * + * Response data schema can be inaccurate or incomplete in several forms: + * 1. No result table at all (when all segments have been pruned on broker). + * 2. Data schema has all columns set to default type (STRING) (when all segments pruned on server). * * Priority is: - * - Types in schema provided by V2 validation for the given query. - * - Types in schema provided by V1 for the given table (only appliable to selection fields). - * - Types in response provided by V1 server (no action). + * - Types from multi-stage engine validation for the given query. + * - Types from schema for the given table (only applicable to selection fields). + * - Types from single-stage engine response (no action). + * + * Multi-stage engine schema will be available only if query compiles. */ - public static void fillEmptyResponseSchema( - BrokerResponse response, TableCache tableCache, Schema schema, String database, String query - ) { - if (response == null || response.getNumRowsResultSet() > 0) { - return; - } + public static void fillEmptyResponseSchema(BrokerResponse response, TableCache tableCache, Schema schema, + String database, String query) { + assert response.getNumRowsResultSet() == 0; - QueryEnvironment queryEnvironment = new QueryEnvironment(database, tableCache, null); - RelRoot node = queryEnvironment.getRelRootIfCanCompile(query); - DataSchema.ColumnDataType resolved; + DataSchema dataSchema = response.getResultTable() != null ? response.getResultTable().getDataSchema() : null; - // V1 schema info for the response can be inaccurate or incomplete in several forms: - // 1) No schema provided at all (when no segments have been even pruned). - // 2) Schema provided but all columns set to default type (STRING) (when no segments have been matched). - // V2 schema will be available only if query compiles. + List<RelDataTypeField> dataTypeFields = null; + try { + QueryEnvironment queryEnvironment = new QueryEnvironment(database, tableCache, null); + RelRoot node = queryEnvironment.getRelRootIfCanCompile(query); + if (node != null && node.validatedRowType != null) { + dataTypeFields = node.validatedRowType.getFieldList(); + } + } catch (Exception ignored) { Review Comment: QueryEnvironment initialization is doing a lot of things, and we don't want to break the query when say v2 is not enabled on the broker -- 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