thomasrebele commented on code in PR #6103:
URL: https://github.com/apache/hive/pull/6103#discussion_r2416196958


##########
ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java:
##########
@@ -4918,15 +4920,16 @@ private RelNode genLogicalPlan(QB qb, boolean 
outerMostQB,
 
         aliasToRel.put(subqAlias, relNode);
         if (qb.getViewToTabSchema().containsKey(subqAlias)) {
-          if (relNode instanceof HiveProject) {
-            if (this.viewProjectToTableSchema == null) {
-              this.viewProjectToTableSchema = new LinkedHashMap<>();
-            }
-            viewProjectToTableSchema.put((HiveProject) relNode, 
qb.getViewToTabSchema().get(subqAlias));
-          } else {
-            throw new SemanticException("View " + subqAlias + " is 
corresponding to "
-                + relNode.toString() + ", rather than a HiveProject.");
+          HiveProject project = switch (Objects.requireNonNull(relNode)) {
+            case HiveProject hiveProject -> hiveProject;

Review Comment:
   Minor: Sonar warns about wrong indentation for the `case`s.



##########
ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java:
##########
@@ -4918,15 +4920,16 @@ private RelNode genLogicalPlan(QB qb, boolean 
outerMostQB,
 
         aliasToRel.put(subqAlias, relNode);
         if (qb.getViewToTabSchema().containsKey(subqAlias)) {
-          if (relNode instanceof HiveProject) {
-            if (this.viewProjectToTableSchema == null) {
-              this.viewProjectToTableSchema = new LinkedHashMap<>();
-            }
-            viewProjectToTableSchema.put((HiveProject) relNode, 
qb.getViewToTabSchema().get(subqAlias));
-          } else {
-            throw new SemanticException("View " + subqAlias + " is 
corresponding to "
-                + relNode.toString() + ", rather than a HiveProject.");
+          HiveProject project = switch (Objects.requireNonNull(relNode)) {
+            case HiveProject hiveProject -> hiveProject;
+            case SingleRel singleRel when singleRel.getInput() instanceof 
HiveProject hiveProject -> hiveProject;

Review Comment:
   Would it make sense to descend into `SingleRel`s recursively, until a 
HiveProject can be found? Maybe the view definition could have, e.g., a 
`Sort(Filter(Project(...))`?



##########
ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java:
##########
@@ -4918,15 +4920,16 @@ private RelNode genLogicalPlan(QB qb, boolean 
outerMostQB,
 
         aliasToRel.put(subqAlias, relNode);
         if (qb.getViewToTabSchema().containsKey(subqAlias)) {
-          if (relNode instanceof HiveProject) {
-            if (this.viewProjectToTableSchema == null) {
-              this.viewProjectToTableSchema = new LinkedHashMap<>();
-            }
-            viewProjectToTableSchema.put((HiveProject) relNode, 
qb.getViewToTabSchema().get(subqAlias));
-          } else {
-            throw new SemanticException("View " + subqAlias + " is 
corresponding to "
-                + relNode.toString() + ", rather than a HiveProject.");
+          HiveProject project = switch (Objects.requireNonNull(relNode)) {
+            case HiveProject hiveProject -> hiveProject;
+            case SingleRel singleRel when singleRel.getInput() instanceof 
HiveProject hiveProject -> hiveProject;
+            default -> throw new SemanticException("View " + subqAlias + " is 
corresponding to "
+                + relNode + ", rather than a HiveProject or a SingleRel with 
HiveProject as its child.");

Review Comment:
   Could you make the error message clearer? Maybe something like `"Could not 
obtain a HiveProject from " + relNode`.



-- 
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]

Reply via email to