apilloud commented on a change in pull request #14241:
URL: https://github.com/apache/beam/pull/14241#discussion_r605243389



##########
File path: 
sdks/java/extensions/sql/zetasql/src/main/java/org/apache/beam/sdk/extensions/sql/zetasql/BeamJavaUdfCalcRule.java
##########
@@ -36,9 +47,63 @@ private BeamJavaUdfCalcRule() {
         LogicalCalc.class, Convention.NONE, BeamLogicalConvention.INSTANCE, 
"BeamJavaUdfCalcRule");
   }
 
+  /**
+   * Returns true if all the following are true: All RexCalls can be 
implemented by codegen, All
+   * RexCalls only contain ZetaSQL user-defined Java functions, All 
RexLiterals pass ZetaSQL
+   * compliance tests, All RexInputRefs pass ZetaSQL compliance tests, No 
other RexNode types
+   * Otherwise returns false. ZetaSQL user-defined Java functions are in the 
category whose function
+   * group is equal to {@code SqlAnalyzer.USER_DEFINED_JAVA_SCALAR_FUNCTIONS}
+   */
   @Override
   public boolean matches(RelOptRuleCall x) {
-    return ZetaSQLQueryPlanner.hasOnlyJavaUdfInProjects(x);

Review comment:
       Thank you for moving this!

##########
File path: 
sdks/java/extensions/sql/zetasql/src/main/java/org/apache/beam/sdk/extensions/sql/zetasql/BeamJavaUdfCalcRule.java
##########
@@ -52,4 +117,57 @@ public RelNode convert(RelNode rel) {
         RelOptRule.convert(input, 
input.getTraitSet().replace(BeamLogicalConvention.INSTANCE)),
         calc.getProgram());
   }
+
+  /**
+   * Returns true only if the literal can be correctly implemented by {@link
+   * org.apache.beam.sdk.extensions.sql.impl.rel.BeamCalcRel} in ZetaSQL.
+   */
+  private static boolean udfSupportsLiteral(RexLiteral rexLiteral) {
+    switch (rexLiteral.getType().getSqlTypeName()) {
+      case BIGINT:
+      case BOOLEAN:
+      case DECIMAL:
+      case DOUBLE:
+      case TIME:
+      case TIMESTAMP:
+      case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
+      case VARBINARY:
+      case VARCHAR:
+        return true;
+      case DATE: // BEAM-11990
+      default:
+        return false;
+    }
+  }
+
+  /**
+   * Returns true only if the input ref can be correctly implemented by {@link
+   * org.apache.beam.sdk.extensions.sql.impl.rel.BeamCalcRel} in ZetaSQL.
+   */
+  private static boolean udfSupportsInput(RexInputRef rexInputRef) {

Review comment:
       nit: I'm not sure this function adds value, consider just calling 
`udfSupportsInputType` directly?

##########
File path: 
sdks/java/extensions/sql/zetasql/src/main/java/org/apache/beam/sdk/extensions/sql/zetasql/BeamJavaUdfCalcRule.java
##########
@@ -52,4 +117,57 @@ public RelNode convert(RelNode rel) {
         RelOptRule.convert(input, 
input.getTraitSet().replace(BeamLogicalConvention.INSTANCE)),
         calc.getProgram());
   }
+
+  /**
+   * Returns true only if the literal can be correctly implemented by {@link
+   * org.apache.beam.sdk.extensions.sql.impl.rel.BeamCalcRel} in ZetaSQL.
+   */
+  private static boolean udfSupportsLiteral(RexLiteral rexLiteral) {
+    switch (rexLiteral.getType().getSqlTypeName()) {
+      case BIGINT:
+      case BOOLEAN:
+      case DECIMAL:
+      case DOUBLE:
+      case TIME:
+      case TIMESTAMP:
+      case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
+      case VARBINARY:

Review comment:
       I think we had a previous discussion on this CL about `CHAR`, `BINARY`, 
and `NULL`... They are all missing here.




-- 
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:
[email protected]


Reply via email to