amaliujia commented on a change in pull request #1587: [CALCITE-3272] Support
TUMBLE as Table Value Function
URL: https://github.com/apache/calcite/pull/1587#discussion_r347158057
##########
File path:
core/src/main/java/org/apache/calcite/adapter/enumerable/RexToLixTranslator.java
##########
@@ -940,6 +956,49 @@ public static Expression translateLiteral(
return list;
}
+ private List<Expression> translateTableFunctionCall(RexCall rexCall, RelNode
input) {
+ if (rexCall.op.getKind() == SqlKind.TUMBLE) {
+ // construct a input ref over watermarked column.
+ // Before DESCRIPTOR is implemented, the second parameter of TUMBLE
+ // is a string, which is one of the column from input.
+ assert rexCall.getOperands().get(1) instanceof RexLiteral;
+ String watermarkedColumnName =
+ ((RexLiteral) rexCall.getOperands().get(1)).getValueAs(String.class);
+ int watermarkedColumnIndex = -1;
+ List<RexNode> schemaForwardInputRefs = new ArrayList<>();
+ for (int i = 0; i < input.getRowType().getFieldCount(); i++) {
+ if
(watermarkedColumnName.equals(input.getRowType().getFieldNames().get(i))) {
+ watermarkedColumnIndex = i;
+ }
+ schemaForwardInputRefs.add(builder.makeInputRef(input, i));
+ }
+ assert watermarkedColumnIndex > -1
+ && watermarkedColumnIndex < input.getRowType().getFieldCount();
+
+ List<Expression> translatedOperands =
translateList(schemaForwardInputRefs);
+
+ // convert the third parameter, which should be a literal for an
interval.
+ assert rexCall.getOperands().get(2) instanceof RexLiteral;
+ Expression intervalExpression = translate(rexCall.getOperands().get(2));
+
+ List<Expression> translatedOperandsForTumble = new ArrayList<>();
+
translatedOperandsForTumble.add(translatedOperands.get(watermarkedColumnIndex));
+ translatedOperandsForTumble.add(intervalExpression);
+ // compute the window_start
+ MethodNameImplementor windowStartMethod = new
MethodNameImplementor("tumbleWindowStart");
Review comment:
I found it was hard to add these to `RexImpTable` because one operator has
two implementor: window_start and window_end.
For TUMBLE and HOP, a workaround is only provide implementor for
window_start and later compute window_end by window_start + window_size.
However, it won't work for `SESSION`.
----------------------------------------------------------------
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]
With regards,
Apache Git Services