Search in sources :

Example 1 with CallExpression

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);
    }
}
Also used : CallExpression(org.apache.flink.table.expressions.CallExpression) Expression(org.apache.flink.table.expressions.Expression) FieldReferenceExpression(org.apache.flink.table.expressions.FieldReferenceExpression) ValueLiteralExpression(org.apache.flink.table.expressions.ValueLiteralExpression)

Example 2 with CallExpression

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);
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) ValueLiteralExpression(org.apache.flink.table.expressions.ValueLiteralExpression) SqlOperator(org.apache.calcite.sql.SqlOperator) RelDataType(org.apache.calcite.rel.type.RelDataType) BigDecimal(java.math.BigDecimal) SqlBasicCall(org.apache.calcite.sql.SqlBasicCall) SqlPostfixOperator(org.apache.calcite.sql.SqlPostfixOperator) OrdinalReturnTypeInference(org.apache.calcite.sql.type.OrdinalReturnTypeInference) DecimalType(org.apache.flink.table.types.logical.DecimalType) FunctionDefinition(org.apache.flink.table.functions.FunctionDefinition) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) CallExpression(org.apache.flink.table.expressions.CallExpression) SqlNode(org.apache.calcite.sql.SqlNode) RexNode(org.apache.calcite.rex.RexNode)

Example 3 with CallExpression

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);
}
Also used : CallExpression(org.apache.flink.table.expressions.CallExpression) Expression(org.apache.flink.table.expressions.Expression) RelDataType(org.apache.calcite.rel.type.RelDataType) RexNode(org.apache.calcite.rex.RexNode)

Example 4 with CallExpression

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;
}
Also used : CallExpression(org.apache.flink.table.expressions.CallExpression) Expression(org.apache.flink.table.expressions.Expression) ValueLiteralExpression(org.apache.flink.table.expressions.ValueLiteralExpression) ArrayList(java.util.ArrayList) SqlJsonValueEmptyOrErrorBehavior(org.apache.calcite.sql.SqlJsonValueEmptyOrErrorBehavior) RexNode(org.apache.calcite.rex.RexNode)

Example 5 with CallExpression

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);
}
Also used : ValueLiteralExpression(org.apache.flink.table.expressions.ValueLiteralExpression) CallExpression(org.apache.flink.table.expressions.CallExpression) Expression(org.apache.flink.table.expressions.Expression) ValueLiteralExpression(org.apache.flink.table.expressions.ValueLiteralExpression) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

CallExpression (org.apache.flink.table.expressions.CallExpression)13 ValueLiteralExpression (org.apache.flink.table.expressions.ValueLiteralExpression)11 Expression (org.apache.flink.table.expressions.Expression)9 RexNode (org.apache.calcite.rex.RexNode)7 FunctionDefinition (org.apache.flink.table.functions.FunctionDefinition)6 FieldReferenceExpression (org.apache.flink.table.expressions.FieldReferenceExpression)5 ArrayList (java.util.ArrayList)4 TableException (org.apache.flink.table.api.TableException)4 ResolvedExpression (org.apache.flink.table.expressions.ResolvedExpression)4 RelDataType (org.apache.calcite.rel.type.RelDataType)3 ImmutableList (com.google.common.collect.ImmutableList)2 BigDecimal (java.math.BigDecimal)2 List (java.util.List)2 SqlBasicCall (org.apache.calcite.sql.SqlBasicCall)2 SqlNode (org.apache.calcite.sql.SqlNode)2 SqlOperator (org.apache.calcite.sql.SqlOperator)2 SqlPostfixOperator (org.apache.calcite.sql.SqlPostfixOperator)2 OrdinalReturnTypeInference (org.apache.calcite.sql.type.OrdinalReturnTypeInference)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1