amaliujia commented on a change in pull request #13912:
URL: https://github.com/apache/beam/pull/13912#discussion_r576547245
##########
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:
I agreed this might be better. But I think it's bit tricky to implement
the positive version of `hasNoJavaUdfInProjects `. The `hasNoJavaUdfInProjects
` is more error prone at this moment (we only need to consider java udf).
----------------------------------------------------------------
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]