use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class StandardConvertletTable method convertCall.
/**
* Converts a {@link SqlCall} to a {@link RexCall} with a perhaps different
* operator.
*/
private RexNode convertCall(SqlRexContext cx, SqlCall call, SqlOperator op) {
final List<SqlNode> operands = call.getOperandList();
final RexBuilder rexBuilder = cx.getRexBuilder();
final SqlOperandTypeChecker.Consistency consistency = op.getOperandTypeChecker() == null ? SqlOperandTypeChecker.Consistency.NONE : op.getOperandTypeChecker().getConsistency();
final List<RexNode> exprs = convertExpressionList(cx, operands, consistency);
RelDataType type = rexBuilder.deriveReturnType(op, exprs);
return rexBuilder.makeCall(type, op, RexUtil.flatten(exprs, op));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class StandardConvertletTable method convertDatetimeMinus.
public RexNode convertDatetimeMinus(SqlRexContext cx, SqlDatetimeSubtractionOperator op, SqlCall call) {
// Rewrite datetime minus
final RexBuilder rexBuilder = cx.getRexBuilder();
final List<SqlNode> operands = call.getOperandList();
final List<RexNode> exprs = convertExpressionList(cx, operands, SqlOperandTypeChecker.Consistency.NONE);
RelDataType int8Type = cx.getTypeFactory().createSqlType(SqlTypeName.BIGINT);
final RexNode[] casts = new RexNode[2];
casts[0] = rexBuilder.makeCast(cx.getTypeFactory().createTypeWithNullability(int8Type, exprs.get(0).getType().isNullable()), exprs.get(0));
casts[1] = rexBuilder.makeCast(cx.getTypeFactory().createTypeWithNullability(int8Type, exprs.get(1).getType().isNullable()), exprs.get(1));
final RelDataType resType = cx.getValidator().getValidatedNodeType(call);
return rexBuilder.makeCall(resType, op, exprs.subList(0, 2));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class StandardConvertletTable method convertAggregateFunction.
public RexNode convertAggregateFunction(SqlRexContext cx, SqlAggFunction fun, SqlCall call) {
final List<SqlNode> operands = call.getOperandList();
final List<RexNode> exprs;
if (call.isCountStar()) {
exprs = ImmutableList.of();
} else {
exprs = convertExpressionList(cx, operands, SqlOperandTypeChecker.Consistency.NONE);
}
RelDataType returnType = cx.getValidator().getValidatedNodeTypeIfKnown(call);
final int groupCount = cx.getGroupCount();
if (returnType == null) {
RexCallBinding binding = new RexCallBinding(cx.getTypeFactory(), fun, exprs, ImmutableList.<RelCollation>of()) {
@Override
public int getGroupCount() {
return groupCount;
}
};
returnType = fun.inferReturnType(binding);
}
return cx.getRexBuilder().makeCall(returnType, fun, exprs);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class StandardConvertletTable method makeConstructorCall.
private static RexNode makeConstructorCall(SqlRexContext cx, SqlFunction constructor, List<RexNode> exprs) {
final RexBuilder rexBuilder = cx.getRexBuilder();
RelDataType type = rexBuilder.deriveReturnType(constructor, exprs);
int n = type.getFieldCount();
ImmutableList.Builder<RexNode> initializationExprs = ImmutableList.builder();
final InitializerContext initializerContext = new InitializerContext() {
public RexBuilder getRexBuilder() {
return rexBuilder;
}
public RexNode convertExpression(SqlNode e) {
throw new UnsupportedOperationException();
}
};
for (int i = 0; i < n; ++i) {
initializationExprs.add(cx.getInitializerExpressionFactory().newAttributeInitializer(type, constructor, i, exprs, initializerContext));
}
List<RexNode> defaultCasts = RexUtil.generateCastExpressions(rexBuilder, type, initializationExprs.build());
return rexBuilder.makeNewInvocation(type, defaultCasts);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode in project calcite by apache.
the class StandardConvertletTable method convertFunction.
public RexNode convertFunction(SqlRexContext cx, SqlFunction fun, SqlCall call) {
final List<SqlNode> operands = call.getOperandList();
final List<RexNode> exprs = convertExpressionList(cx, operands, SqlOperandTypeChecker.Consistency.NONE);
if (fun.getFunctionType() == SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR) {
return makeConstructorCall(cx, fun, exprs);
}
RelDataType returnType = cx.getValidator().getValidatedNodeTypeIfKnown(call);
if (returnType == null) {
returnType = cx.getRexBuilder().deriveReturnType(fun, exprs);
}
return cx.getRexBuilder().makeCall(returnType, fun, exprs);
}
Aggregations