use of org.apache.calcite.sql.type.OrdinalReturnTypeInference in project flink by apache.
the class OverConvertRule method createBound.
private RexWindowBound createBound(ConvertContext context, 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) {
RelDataType returnType = context.getTypeFactory().createFieldTypeFromLogicalType(new DecimalType(true, 19, 0));
SqlOperator sqlOperator = new SqlPostfixOperator(sqlKind.name(), sqlKind, 2, new OrdinalReturnTypeInference(0), null, null);
SqlNode[] operands = new SqlNode[] { SqlLiteral.createExactNumeric("1", SqlParserPos.ZERO) };
SqlNode node = new SqlBasicCall(sqlOperator, operands, SqlParserPos.ZERO);
ValueLiteralExpression literalExpr = (ValueLiteralExpression) bound;
RexNode literalRexNode = literalExpr.getValueAs(BigDecimal.class).map(v -> context.getRelBuilder().literal(v)).orElse(context.getRelBuilder().literal(extractValue(literalExpr, Object.class)));
List<RexNode> expressions = new ArrayList<>();
expressions.add(literalRexNode);
RexNode rexNode = context.getRelBuilder().getRexBuilder().makeCall(returnType, sqlOperator, expressions);
return RexWindowBound.create(node, rexNode);
} else {
throw new TableException("Unexpected expression: " + bound);
}
}
Aggregations