Quanlong Huang has posted comments on this change. ( 
http://gerrit.cloudera.org:8080/24211 )

Change subject: IMPALA-14909: Calcite planner: Fix validation for views with 
column list
......................................................................


Patch Set 6:

(8 comments)

http://gerrit.cloudera.org:8080/#/c/24211/5/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/24211/5/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteAnalysisDriver.java@281
PS5, Line 281:       validator.startValidatingView();
> Ah, I see what you mean.  Heh, yeah, I didn't think the HMS solution was vi
That makes sense. Most of the views won't have the issue so not changing the 
original code path has less impacts.


http://gerrit.cloudera.org:8080/#/c/24211/6/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/24211/6/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/CalciteAnalysisDriver.java@288
PS6, Line 288:         parsedSqlNode = validator.validate(parsedSqlNode);
> That's a good question.  It's not quite obvious, eh? This response is gonna
That makes sense. Thanks for the explanation!


http://gerrit.cloudera.org:8080/#/c/24211/6/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/ViewAliasCorrector.java
File 
java/calcite-planner/src/main/java/org/apache/impala/calcite/service/ViewAliasCorrector.java:

http://gerrit.cloudera.org:8080/#/c/24211/6/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/ViewAliasCorrector.java@37
PS6, Line 37: Impala
nit: using "Hive" might be better. I think originally it's Hive that creates 
the view in this way. Impala is just a victim that has to be consistent with 
Hive. If we create the view in Hive, the View Expanded Text has the same issue.


http://gerrit.cloudera.org:8080/#/c/24211/6/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/ViewAliasCorrector.java@55
PS6, Line 55: The
nit: "the"


http://gerrit.cloudera.org:8080/#/c/24211/6/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/ViewAliasCorrector.java@130
PS6, Line 130:         return itemsWithAliasIssue;
nit: Let's return Collections.emptySet() to avoid creating a new object. We can 
also move the declaration of itemsWithAliasIssue down to L138.


http://gerrit.cloudera.org:8080/#/c/24211/6/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/ViewAliasCorrector.java@133
PS6, Line 133:       // The alias issue only happens when the columns are all 
selected out (see top
             :       // level comment), so if the sizes are different, there is 
no issue.
             :       if (topLevelSqlNodes_.size() != 
secondLevelSqlNodes_.size()) {
             :         return itemsWithAliasIssue;
             :       }
I found that stars (*) are not expanded at this point. So a view created with 
star could have different sizes here. E.g.

 create view dim_view (a1, a2, a3, rn) as
 select *, row_number() over(order by id) from functional.dimtbl;

 select rn from dim_view;
 AnalysisException: From line 1, column 68 to line 1, column 72: Column '_c1' 
not found in table 'DIM_VIEW'
 CAUSED BY: SqlValidatorException: Column '_c1' not found in table 'DIM_VIEW'

The original planner expands stars while analyzing the SelectStmt:
https://github.com/apache/impala/blob/c8ec628c5ddc32b68842b8038522c587f313f277/fe/src/main/java/org/apache/impala/analysis/SelectStmt.java#L338
I think the calcite-planner should do this before validating the alias. We can 
do this in a separate patch if it needs fundamental changes.


http://gerrit.cloudera.org:8080/#/c/24211/6/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/ViewAliasCorrector.java@151
PS6, Line 151: topLevelIdentifier.names.get(1)
Could this be null?


http://gerrit.cloudera.org:8080/#/c/24211/6/java/calcite-planner/src/main/java/org/apache/impala/calcite/service/ViewAliasCorrector.java@194
PS6, Line 194: get(1)
nit: I'm new to Calcite so these indexes always confused me. It might be more 
readable if we add a comment or extract this as a variable originalAlias, e.g.

        SqlNode originalAlias = call.getOperandList().get(1);
        SqlNode asNode =
            SqlStdOperatorTable.AS.createCall(
                newIdentifier.getParserPosition(),
                newIdentifier,
                originalAlias);



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

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: I0d0229c8907f69e648034d12fe375d9d9a384e25
Gerrit-Change-Number: 24211
Gerrit-PatchSet: 6
Gerrit-Owner: Steve Carlin <[email protected]>
Gerrit-Reviewer: Aman Sinha <[email protected]>
Gerrit-Reviewer: Csaba Ringhofer <[email protected]>
Gerrit-Reviewer: Fang-Yu Rao <[email protected]>
Gerrit-Reviewer: Impala Public Jenkins <[email protected]>
Gerrit-Reviewer: Jason Fehr <[email protected]>
Gerrit-Reviewer: Joe McDonnell <[email protected]>
Gerrit-Reviewer: Michael Smith <[email protected]>
Gerrit-Reviewer: Quanlong Huang <[email protected]>
Gerrit-Reviewer: Steve Carlin <[email protected]>
Gerrit-Comment-Date: Sun, 14 Jun 2026 14:10:50 +0000
Gerrit-HasComments: Yes

Reply via email to