beyond1920 commented on a change in pull request #8977:
[FLINK-13071][table-planner-blink] QueryOperationConverter in Blink planner
support add kinds of QueryOperations.
URL: https://github.com/apache/flink/pull/8977#discussion_r300522940
##########
File path:
flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/expressions/RexNodeConverter.java
##########
@@ -344,4 +875,125 @@ private RexNode
visitResolvedDistinctKeyReference(ResolvedDistinctKeyReference r
typeFactory.createFieldTypeFromLogicalType(type),
type);
}
+
+ private RexNode visit(UnresolvedCallExpression call) {
+ FunctionDefinition func = call.getFunctionDefinition();
+ switch (func.getKind()) {
+ case SCALAR:
+ if (func instanceof ScalarFunctionDefinition) {
+ ScalarFunction scalaFunc =
((ScalarFunctionDefinition) func).getScalarFunction();
+ List<RexNode> child =
convertCallChildren(call.getChildren());
+ SqlFunction sqlFunction =
UserDefinedFunctionUtils.createScalarSqlFunction(
+
scalaFunc.functionIdentifier(),
+ scalaFunc.toString(),
+ scalaFunc,
+ typeFactory);
+ return relBuilder.call(sqlFunction,
child);
+ } else {
+ FunctionDefinition def =
call.getFunctionDefinition();
+ if
(conversionsOfBuiltInFunc.containsKey(def)) {
+ RexNodeConversion conversion =
conversionsOfBuiltInFunc.get(def);
+ return conversion.convert(call);
+ } else {
+ throw new
UnsupportedOperationException(def.toString());
+ }
+ }
+
+ default:
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ private RexNode createCollation(RexNode node,
RelFieldCollation.Direction direction,
+ RelFieldCollation.NullDirection nullDirection,
Set<SqlKind> kinds) {
+ switch (node.getKind()) {
+ case DESCENDING:
+ kinds.add(node.getKind());
+ return createCollation(((RexCall)
node).getOperands().get(0), RelFieldCollation.Direction.DESCENDING,
+ nullDirection, kinds);
+ case NULLS_FIRST:
+ kinds.add(node.getKind());
+ return createCollation(((RexCall)
node).getOperands().get(0), direction,
+
RelFieldCollation.NullDirection.FIRST, kinds);
+ case NULLS_LAST:
+ kinds.add(node.getKind());
+ return createCollation(((RexCall)
node).getOperands().get(0), direction,
+
RelFieldCollation.NullDirection.LAST, kinds);
+ default:
+ if (nullDirection == null) {
+ // Set the null direction if not
specified.
+ // Consistent with
HIVE/SPARK/MYSQL/BLINK-RUNTIME.
+ if
(FlinkPlannerImpl.defaultNullCollation()
+
.last(direction.equals(RelFieldCollation.Direction.DESCENDING))) {
+ kinds.add(SqlKind.NULLS_LAST);
+ } else {
+ kinds.add(SqlKind.NULLS_FIRST);
+ }
+ }
+ return node;
+ }
+ }
+
+ private RexWindowBound createBound(Expression bound, SqlKind sqlKind) {
+ if (bound instanceof CallExpression) {
+ CallExpression callExpr = (CallExpression) bound;
+ FunctionDefinition func =
callExpr.getFunctionDefinition();
+ if
(BuiltInFunctionDefinitions.UNBOUNDED_ROW.equals(func) ||
BuiltInFunctionDefinitions.UNBOUNDED_RANGE
+ .equals(func)) {
+ SqlNode unbounded =
sqlKind.equals(SqlKind.PRECEDING) ? SqlWindow
+
.createUnboundedPreceding(SqlParserPos.ZERO) :
+
SqlWindow.createUnboundedFollowing(SqlParserPos.ZERO);
+ return RexWindowBound.create(unbounded, null);
+ } else if
(BuiltInFunctionDefinitions.CURRENT_ROW.equals(func) ||
BuiltInFunctionDefinitions.CURRENT_RANGE
+ .equals(func)) {
+ SqlNode currentRow =
SqlWindow.createCurrentRow(SqlParserPos.ZERO);
+ return RexWindowBound.create(currentRow, null);
+ } else {
+ throw new IllegalArgumentException("Unexpected
expression: " + bound);
+ }
+ } else if (bound instanceof ValueLiteralExpression) {
+ int DECIMAL_PRECISION_NEEDED_FOR_LONG = 19;
Review comment:
@sunjincheng121 Those two compile error in this pr already fix in
https://github.com/apache/flink/pull/8689, which is merged already. Could you
try again ?
I'm sorry for the inconvenience.
----------------------------------------------------------------
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