amaliujia commented on a change in pull request #10946:
URL: https://github.com/apache/beam/pull/10946#discussion_r422351792



##########
File path: 
sdks/java/extensions/sql/zetasql/src/main/java/org/apache/beam/sdk/extensions/sql/zetasql/translation/ExpressionConverter.java
##########
@@ -551,6 +561,60 @@ public RexNode convertResolvedLiteral(ResolvedLiteral 
resolvedLiteral) {
     return ret;
   }
 
+  public RexCall convertTableValuedFunction(
+      RelNode input,
+      TableValuedFunction tvf,
+      List<ResolvedNodes.ResolvedTVFArgument> argumentList,
+      List<ResolvedColumn> inputTableColumns) {
+    switch (tvf.getName()) {
+      case "TUMBLE":
+        // TUMBLE tvf's second argument is descriptor.
+        ResolvedColumn wmCol =
+            
extractWatermarkColumnFromDescriptor(argumentList.get(1).getDescriptorArg());
+        if (wmCol.getType().getKind() != TYPE_TIMESTAMP) {
+          throw new IllegalArgumentException(
+              "Watermarked column should be TIMESTAMP type: "
+                  + extractWatermarkColumnNameFromDescriptor(
+                      argumentList.get(1).getDescriptorArg()));
+        }
+        return (RexCall)
+            rexBuilder()
+                .makeCall(
+                    new SqlWindowTableFunction(SqlKind.TUMBLE.name()),
+                    convertRelNodeToRexRangeRef(input),
+                    convertWatermarkedResolvedColumnToRexInputRef(wmCol, 
inputTableColumns),
+                    convertIntervalToRexIntervalLiteral(
+                        (ResolvedLiteral) argumentList.get(2).getExpr()));
+      default:
+        throw new UnsupportedOperationException(
+            "Does not support table-valued function: " + tvf.getName());
+    }
+  }
+
+  private RexInputRef convertWatermarkedResolvedColumnToRexInputRef(
+      ResolvedColumn wmCol, List<ResolvedColumn> inputTableColumns) {
+    for (int i = 0; i < inputTableColumns.size(); i++) {
+      if (inputTableColumns.get(i).equals(wmCol)) {
+        return rexBuilder()
+            .makeInputRef(TypeUtils.toRelDataType(rexBuilder(), 
wmCol.getType(), false), i);
+      }
+    }
+
+    // ZetaSQL parser guarantees that wmCol can be found from 
inputTableColumns.
+    // so it shouldn't reach here.
+    throw new IllegalArgumentException();

Review comment:
       I moved comments here to exception as the exception message. I don't 
have a concert description for in which normal case it will reach this step. It 
could reach this step when ZetaSQL has bugs, but putting something like 
"ZetaSQL has bugs to make you reach this exception" sounds not useful neither.




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