soumyakanti3578 commented on code in PR #4478:
URL: https://github.com/apache/hive/pull/4478#discussion_r1266987369
##########
ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java:
##########
@@ -2631,6 +2631,21 @@ private RelNode genJoinRelNode(RelNode leftRel, String
leftTableAlias, RelNode r
unparseTranslator.addIdentifierTranslation((ASTNode) child);
}
namedColumns.add(columnName);
+
+ // if leftTableAlias is null, set it to the last tableAlias that
contains the
+ // column columnName
+ if (leftTableAlias == null) {
+ Map<String, Map<String, ColumnInfo>> leftRslvMap =
leftRR.getRslvMap();
+ for (String tableAlias: leftRR.getTableNames()) {
+ if (!leftRslvMap.containsKey(tableAlias)) {
+ continue;
+ }
+ if (leftRslvMap.get(tableAlias).containsKey(columnName)) {
+ leftTableAlias = tableAlias;
Review Comment:
Yes, it is a valid query. I don't think we have test cases for it now, but I
will add them. Currently `leftTableAlias` gets assigned `tableAlias` multiple
times, starting from the left most table in the join. So at the end of the for
loop, `leftTableAlias` will be assigned the right most valid (table containing
using column) table alias. For example, if `leftRR.getTableNames()` returns
`t1` and `t2` in that order, it'll first search for `columnName` in `t1`. If
it's there, `leftTableAlias` gets assigned `t1`. Next it searches for the
column in `t2`. If it's not there, then after coming out of the loop
`leftTableAlias` is still assigned to `t1`, which is not the right most table
in the join, but the right most table containing `columnName`.
I think if we don't find the alias at all, then we should probably throw an
Exception. I will update the patch.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]