use of org.apache.flink.table.expressions.CallExpression in project flink by apache.
the class OrcFilters method convertOr.
private static Predicate convertOr(CallExpression callExp) {
if (callExp.getChildren().size() < 2) {
return null;
}
Expression left = callExp.getChildren().get(0);
Expression right = callExp.getChildren().get(1);
Predicate c1 = toOrcPredicate(left);
Predicate c2 = toOrcPredicate(right);
if (c1 == null || c2 == null) {
return null;
} else {
return new Or(c1, c2);
}
}
use of org.apache.flink.table.expressions.CallExpression 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);
}
}
use of org.apache.flink.table.expressions.CallExpression in project flink by apache.
the class MapConverter method convert.
@Override
public RexNode convert(CallExpression call, CallExpressionConvertRule.ConvertContext context) {
List<Expression> children = call.getChildren();
checkArgument(call, !children.isEmpty() && children.size() % 2 == 0);
List<RexNode> childrenRexNode = toRexNodes(context, children);
RelDataType mapType = context.getTypeFactory().createFieldTypeFromLogicalType(call.getOutputDataType().getLogicalType());
return context.getRelBuilder().getRexBuilder().makeCall(mapType, FlinkSqlOperatorTable.MAP_VALUE_CONSTRUCTOR, childrenRexNode);
}
use of org.apache.flink.table.expressions.CallExpression in project flink by apache.
the class JsonValueConverter method getBehaviorOperands.
private List<RexNode> getBehaviorOperands(CallExpression call, CallExpressionConvertRule.ConvertContext context, SqlJsonEmptyOrError mode) {
final int idx = getArgumentIndexForBehavior(mode);
final SqlJsonValueEmptyOrErrorBehavior behavior = getBehavior(call, idx);
final Expression defaultExpression = call.getChildren().get(idx + 1);
final List<RexNode> operands = new ArrayList<>();
operands.add(context.getRelBuilder().getRexBuilder().makeFlag(behavior));
if (behavior == SqlJsonValueEmptyOrErrorBehavior.DEFAULT) {
operands.add(context.toRexNode(defaultExpression));
}
operands.add(context.getRelBuilder().getRexBuilder().makeFlag(mode));
return operands;
}
use of org.apache.flink.table.expressions.CallExpression in project flink by apache.
the class TrimConverter method convert.
@Override
public RexNode convert(CallExpression call, CallExpressionConvertRule.ConvertContext context) {
checkArgumentNumber(call, 4);
List<Expression> children = call.getChildren();
ValueLiteralExpression removeLeadingExpr = (ValueLiteralExpression) children.get(0);
Boolean removeLeading = extractValue(removeLeadingExpr, Boolean.class);
ValueLiteralExpression removeTrailingExpr = (ValueLiteralExpression) children.get(1);
Boolean removeTrailing = extractValue(removeTrailingExpr, Boolean.class);
RexNode trimString = context.toRexNode(children.get(2));
RexNode str = context.toRexNode(children.get(3));
Enum trimMode;
if (removeLeading && removeTrailing) {
trimMode = SqlTrimFunction.Flag.BOTH;
} else if (removeLeading) {
trimMode = SqlTrimFunction.Flag.LEADING;
} else if (removeTrailing) {
trimMode = SqlTrimFunction.Flag.TRAILING;
} else {
throw new IllegalArgumentException("Unsupported trim mode.");
}
return context.getRelBuilder().call(FlinkSqlOperatorTable.TRIM, context.getRelBuilder().getRexBuilder().makeFlag(trimMode), trimString, str);
}
Aggregations