use of org.apache.flink.table.expressions.CallExpression in project flink by apache.
the class JsonObjectConverter method convert.
@Override
public RexNode convert(CallExpression call, CallExpressionConvertRule.ConvertContext context) {
checkArgument(call, (call.getChildren().size() - 1) % 2 == 0);
final List<RexNode> operands = new LinkedList<>();
final SqlJsonConstructorNullClause onNull = JsonConverterUtil.getOnNullArgument(call, 0);
operands.add(context.getRelBuilder().getRexBuilder().makeFlag(onNull));
for (int i = 1; i < call.getChildren().size(); i++) {
final Expression operand = call.getChildren().get(i);
if (i % 2 == 1 && !(operand instanceof ValueLiteralExpression)) {
throw new TableException(String.format("Argument at position %s must be a string literal.", i));
}
operands.add(context.toRexNode(operand));
}
return context.getRelBuilder().getRexBuilder().makeCall(FlinkSqlOperatorTable.JSON_OBJECT, operands);
}
use of org.apache.flink.table.expressions.CallExpression in project flink by apache.
the class FilterUtils method isRetainedAfterApplyingFilterPredicates.
public static boolean isRetainedAfterApplyingFilterPredicates(List<ResolvedExpression> predicates, Function<String, Comparable<?>> getter) {
for (ResolvedExpression predicate : predicates) {
if (predicate instanceof CallExpression) {
FunctionDefinition definition = ((CallExpression) predicate).getFunctionDefinition();
boolean result = false;
if (definition.equals(BuiltInFunctionDefinitions.OR)) {
// nested filter, such as (key1 > 2 or key2 > 3)
for (Expression expr : predicate.getChildren()) {
if (!(expr instanceof CallExpression && expr.getChildren().size() == 2)) {
throw new TableException(expr + " not supported!");
}
result = binaryFilterApplies((CallExpression) expr, getter);
if (result) {
break;
}
}
} else if (predicate.getChildren().size() == 2) {
result = binaryFilterApplies((CallExpression) predicate, getter);
} else {
throw new UnsupportedOperationException(String.format("Unsupported expr: %s.", predicate));
}
if (!result) {
return false;
}
} else {
throw new UnsupportedOperationException(String.format("Unsupported expr: %s.", predicate));
}
}
return true;
}
use of org.apache.flink.table.expressions.CallExpression in project flink by apache.
the class FilterUtils method binaryFilterApplies.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static boolean binaryFilterApplies(CallExpression binExpr, Function<String, Comparable<?>> getter) {
List<Expression> children = binExpr.getChildren();
Preconditions.checkArgument(children.size() == 2);
Comparable lhsValue = getValue(children.get(0), getter);
Comparable rhsValue = getValue(children.get(1), getter);
FunctionDefinition functionDefinition = binExpr.getFunctionDefinition();
if (BuiltInFunctionDefinitions.GREATER_THAN.equals(functionDefinition)) {
return lhsValue.compareTo(rhsValue) > 0;
} else if (BuiltInFunctionDefinitions.LESS_THAN.equals(functionDefinition)) {
return lhsValue.compareTo(rhsValue) < 0;
} else if (BuiltInFunctionDefinitions.GREATER_THAN_OR_EQUAL.equals(functionDefinition)) {
return lhsValue.compareTo(rhsValue) >= 0;
} else if (BuiltInFunctionDefinitions.LESS_THAN_OR_EQUAL.equals(functionDefinition)) {
return lhsValue.compareTo(rhsValue) <= 0;
} else if (BuiltInFunctionDefinitions.EQUALS.equals(functionDefinition)) {
return lhsValue.compareTo(rhsValue) == 0;
} else if (BuiltInFunctionDefinitions.NOT_EQUALS.equals(functionDefinition)) {
return lhsValue.compareTo(rhsValue) != 0;
} else {
throw new UnsupportedOperationException("Unsupported operator: " + functionDefinition);
}
}
Aggregations