You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/02/12 23:51:21 UTC

[GitHub] [beam] ibzib commented on a change in pull request #13912: [BEAM-11747] Reject the mixed Java UDF and ZetaSQL builtin operator cases

ibzib commented on a change in pull request #13912:
URL: https://github.com/apache/beam/pull/13912#discussion_r575577010



##########
File path: sdks/java/extensions/sql/zetasql/src/main/java/org/apache/beam/sdk/extensions/sql/zetasql/ZetaSQLQueryPlanner.java
##########
@@ -116,8 +116,43 @@ public QueryPlanner createPlanner(
     return modifyRuleSetsForZetaSql(BeamRuleSets.getRuleSets());
   }
 
-  /** Returns true if the argument contains any user-defined Java functions. */
-  static boolean hasUdfInProjects(RelOptRuleCall x) {
+  /**
+   * Returns true if the arguments only contain any user-defined Java functions, otherwise returns

Review comment:
       We should add a few more sentences explaining exactly what this means too. It's kind of confusing right now because not all instances of `SqlUserDefinedFunction` are actually user defined, but someone who reads this code might not realize that unless we clarify.
   
   ```suggestion
      * Returns true if the arguments only contain user-defined Java functions, otherwise returns
   ```

##########
File path: sdks/java/extensions/sql/zetasql/src/main/java/org/apache/beam/sdk/extensions/sql/zetasql/ZetaSQLQueryPlanner.java
##########
@@ -116,8 +116,43 @@ public QueryPlanner createPlanner(
     return modifyRuleSetsForZetaSql(BeamRuleSets.getRuleSets());
   }
 
-  /** Returns true if the argument contains any user-defined Java functions. */
-  static boolean hasUdfInProjects(RelOptRuleCall x) {
+  /**
+   * Returns true if the arguments only contain any user-defined Java functions, otherwise returns
+   * false.
+   */
+  static boolean hasOnlyJavaUdfInProjects(RelOptRuleCall x) {
+    List<RelNode> resList = x.getRelList();
+    for (RelNode relNode : resList) {
+      if (relNode instanceof LogicalCalc) {
+        LogicalCalc logicalCalc = (LogicalCalc) relNode;
+        for (RexNode rexNode : logicalCalc.getProgram().getExprList()) {
+          if (rexNode instanceof RexCall) {
+            RexCall call = (RexCall) rexNode;
+            if (call.getOperator() instanceof SqlUserDefinedFunction) {
+              SqlUserDefinedFunction udf = (SqlUserDefinedFunction) call.op;
+              if (udf.function instanceof ZetaSqlScalarFunctionImpl) {
+                ZetaSqlScalarFunctionImpl scalarFunction = (ZetaSqlScalarFunctionImpl) udf.function;
+                if (!scalarFunction.functionGroup.equals(
+                    SqlAnalyzer.USER_DEFINED_JAVA_SCALAR_FUNCTIONS)) {
+                  return false;
+                }
+              } else {
+                return false;
+              }
+            } else {
+              return false;
+            }
+          }
+        }
+      }
+    }
+    return true;
+  }
+
+  /**
+   * Returns false if the argument contains any user-defined Java functions, otherwise returns true.
+   */
+  static boolean hasNoJavaUdfInProjects(RelOptRuleCall x) {

Review comment:
       Nit: positive phrasing avoids double negatives and makes the logic easier to follow, so consider inverting this (and renaming to something like `hasJavaUdfInProjects` or `hasAnyJavaUdfInProjects`)




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org