Fang-Yu Rao has posted comments on this change. ( 
http://gerrit.cloudera.org:8080/25144 )

Change subject: IMPALA-14944: Throw UnsupportedFeatureException for some 
Calcite planner queries
......................................................................


Patch Set 2:

(9 comments)

I left more comments on the rest of patch set 2 that I did not read earlier. 
The exception handling logic is complicated to me. But I think it would be 
helpful if we could add more code comments describing why we would encounter a 
specific exception in some scenarios.

http://gerrit.cloudera.org:8080/#/c/25144/2/fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java
File fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java:

http://gerrit.cloudera.org:8080/#/c/25144/2/fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java@529
PS2, Line 529: analysisResult_.shouldFallbackBecauseOfException()
Would it be okay too to pass 'analysisException' at 
https://gerrit.cloudera.org/c/25144/2/fe/src/main/java/org/apache/impala/analysis/AnalysisContext.java#511
 to shouldFallbackBecauseOfException() instead of calling getException() again 
in the overridden method at 
https://gerrit.cloudera.org/c/25144/2/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteAnalysisResult.java#75?

Or, we could just evaluate "analysisException instanceof 
UnsupportedFeatureException" here?


http://gerrit.cloudera.org:8080/#/c/25144/2/fe/src/main/java/org/apache/impala/service/Frontend.java
File fe/src/main/java/org/apache/impala/service/Frontend.java:

http://gerrit.cloudera.org:8080/#/c/25144/2/fe/src/main/java/org/apache/impala/service/Frontend.java@2521
PS2, Line 2521: // If there is any kind of exception from the first planner, we 
hit this code.
I know it's not added in this patch. But would it be a bit more informative if 
we give an example of how this could be reached, e.g., by setting the query 
option of 'disable_hdfs_num_rows_estimate' to true which would make the 
condition at  
https://gerrit.cloudera.org/c/25144/2/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteCompilerFactory.java#99
 evaluate to true?


http://gerrit.cloudera.org:8080/#/c/25144/2/fe/src/main/java/org/apache/impala/service/Frontend.java@2540
PS2, Line 2540:     if (error instanceof InconsistentMetadataFetchException) {
              :       throw (InconsistentMetadataFetchException) error;
              :     }
I am a bit confused by this. I thought when error is an 
InconsistentMetadataFetchException, Frontend should have already retried.   In 
the commit message we have the following, which seems to imply by throwing this 
InconsistentMetadataFetchException, we could make the Calcite planner retry 
again?

 If an InconsistentMetadataFetchException is thrown, this is because there
 was some metadata that changed after a fetch. This exception is now passed
 through to the top level and the query will be retried in Calcite again.

Specifically, I took a quick look at the code, and found that in 
Frontend#getTExecRequest() at 
https://github.com/apache/impala/blob/266d7ed/fe/src/main/java/org/apache/impala/service/Frontend.java#L2674-L2678
 we already take care of the query retry. Note that this method 
(getTExecRequestWithFallback()) calls getTExecRequest().

        try {
          req = doCreateExecRequest(compilerFactory, planCtx, warnings, 
timeline);
          markTimelineRetries(attempt, retryMsg, timeline);
          break;
        } catch (InconsistentMetadataFetchException e) {
          if (attempt++ == INCONSISTENT_METADATA_NUM_RETRIES) {
            markTimelineRetries(attempt, e.getMessage(), timeline);
            throw e;
          }
          ...
         }


http://gerrit.cloudera.org:8080/#/c/25144/2/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteAnalysisDriver.java
File 
java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteAnalysisDriver.java:

http://gerrit.cloudera.org:8080/#/c/25144/2/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteAnalysisDriver.java@151
PS2, Line 151:         
ComplexTableDetector.checkForComplexTables(parsedStmt_.getParsedSqlNode(),
             :             queryCtx_, ctx_);
Would it make sense to add the following check to return earlier (v.s. calling 
checkForComplexTables() unconditionally) if the ImpalaException caught is an 
UnsupportedFeatureException? For instance, this could happen in the following 
cases:

- if we throw such an exception at 
https://github.com/apache/impala/blob/af7786a/java/calcite-planner/src/main/java/org/apache/impala/calcite/schema/CalciteDb.java#L90-L93
 when calling dbBuilder.addTable() in 
CalciteMetadataHandler#populateCalciteSchema().
- when 'stmtTableCache_.needsAnyTableMasksInQuery_' is true.
- when we try to load a table 'iceberg_uuid_test' with a column whose type is 
uuid (as in the query "SELECT id, uuid_col, name FROM iceberg_uuid_test ORDER 
BY id" in 
https://github.com/apache/impala/blob/master/testdata/workloads/functional-query/queries/QueryTest/iceberg-uuid-type.test).


 if (e instanceof UnsupportedFeatureException) {
   return new CalciteAnalysisResult(this, e);
 }

In addition, would it make the exception handling logic a bit easier to 
understand if we add a short code comment listing the possible cases that would 
trigger an ImpalaException? In the future, when the Calcite planner supports a 
currently unsupported feature, it'd also be easier to know whether we could 
remove some catch blocks.


http://gerrit.cloudera.org:8080/#/c/25144/2/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteQueryParser.java
File 
java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteQueryParser.java:

http://gerrit.cloudera.org:8080/#/c/25144/2/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteQueryParser.java@46
PS2, Line 46: ParseException
nit: Could we remove this since ParseException is also an ImpalaException?


http://gerrit.cloudera.org:8080/#/c/25144/2/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteSingleNodePlanner.java
File 
java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteSingleNodePlanner.java:

http://gerrit.cloudera.org:8080/#/c/25144/2/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteSingleNodePlanner.java@94
PS2, Line 94: e instanceof InconsistentMetadataFetchException
Would it make the code easier to understand if we add a code comment describing 
when the exception could be an InconsistentMetadataFetchException? For 
instance, when the call to physPlanCreator.create() at 
https://gerrit.cloudera.org/c/25144/2/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteSingleNodePlanner.java#87
 could result in a call to HdfsPartitionPruner#prunePartitions(), which in turn 
call getPartitionIds() or loadPartitions() of a LocalFsTable that could throw 
an InconsistentMetadataFetchException.


http://gerrit.cloudera.org:8080/#/c/25144/2/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/ComplexTableDetector.java
File 
java/calcite-planner/src/main/java/org/apache/impala/calcite/service/ComplexTableDetector.java:

http://gerrit.cloudera.org:8080/#/c/25144/2/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/ComplexTableDetector.java@121
PS2, Line 121: throw new UnsupportedFeatureException("Complex table " + 
detector.complexTable_ +
             :           " not supported.")
> Well...
Thanks for the explanation Steve! There is no need to change this part of the 
code. I raised this question only for my own understanding. :-)


http://gerrit.cloudera.org:8080/#/c/25144/2/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/ImpalaSqlValidatorImpl.java
File 
java/calcite-planner/src/main/java/org/apache/impala/calcite/service/ImpalaSqlValidatorImpl.java:

http://gerrit.cloudera.org:8080/#/c/25144/2/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/ImpalaSqlValidatorImpl.java@103
PS2, Line 103: if (spec.getTypeName().names.get(0).toLowerCase().equals("uuid"))
Would it be clearer if we add a short code comment giving an example that would 
make the conditional evaluate to true, e.g., "SELECT 
CAST('12345678-1234-5678-1234-567812345678' AS UUID)"?


http://gerrit.cloudera.org:8080/#/c/25144/2/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/ImpalaSqlValidatorImpl.java@181
PS2, Line 181: SqlNodeList columnList = withItem.columnList;
             :     if (columnList != null) {
             :       final RelDataType rowType = 
getValidatedNodeType(withItem.query);
             :       final int fieldCount = rowType.getFieldCount();
             :       if (columnList.size() != fieldCount) {
             :         throw new CalciteContextException("", new 
UnsupportedFeatureException(
             :             "Number of columns in with clause must match number 
of query columns"));
             :       }
             :     }
Would it be clearer if we add a code comment saying that it's the same as the 
check done in super.validateWithItem(withItem) when 'columnList' is not null, 
since the implementation of the overridden method is outside of Apache Impala?



--
To view, visit http://gerrit.cloudera.org:8080/25144
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I037d636064c4c99131598b7424dd99e4ad56d30f
Gerrit-Change-Number: 25144
Gerrit-PatchSet: 2
Gerrit-Owner: Steve Carlin <[email protected]>
Gerrit-Reviewer: Aleksandr Efimov <[email protected]>
Gerrit-Reviewer: Aman Sinha <[email protected]>
Gerrit-Reviewer: Fang-Yu Rao <[email protected]>
Gerrit-Reviewer: Impala Public Jenkins <[email protected]>
Gerrit-Reviewer: Joe McDonnell <[email protected]>
Gerrit-Reviewer: Michael Smith <[email protected]>
Gerrit-Reviewer: Steve Carlin <[email protected]>
Gerrit-Comment-Date: Fri, 23 Oct 2026 22:51:58 +0000
Gerrit-HasComments: Yes

Reply via email to