public RexNode convertJdbc( SqlRexContext cx, SqlJdbcFunctionCall op, SqlCall call) { // Yuck!! The function definition contains arguments! // TODO: adopt a more conventional definition/instance structure final SqlCall convertedCall = op.getLookupCall(); return cx.convertExpression(convertedCall); }
public RexNode convertJdbc( SqlRexContext cx, SqlJdbcFunctionCall op, SqlCall call) { // Yuck!! The function definition contains arguments! // TODO: adopt a more conventional definition/instance structure final SqlCall convertedCall = op.getLookupCall(); return cx.convertExpression(convertedCall); }
private RexNode convertIsDistinctFrom( SqlRexContext cx, SqlCall call, boolean neg) { RexNode op0 = cx.convertExpression(call.operand(0)); RexNode op1 = cx.convertExpression(call.operand(1)); return RelOptUtil.isDistinctFrom( cx.getRexBuilder(), op0, op1, neg); }
private RexNode convertIsDistinctFrom( SqlRexContext cx, SqlCall call, boolean neg) { RexNode op0 = cx.convertExpression(call.operand(0)); RexNode op1 = cx.convertExpression(call.operand(1)); return RelOptUtil.isDistinctFrom( cx.getRexBuilder(), op0, op1, neg); }
private static List<RexNode> convertExpressionList(SqlRexContext cx, List<SqlNode> nodes, SqlOperandTypeChecker.Consistency consistency) { final List<RexNode> exprs = Lists.newArrayList(); for (SqlNode node : nodes) { exprs.add(cx.convertExpression(node)); } if (exprs.size() > 1) { final RelDataType type = consistentType(cx, consistency, RexUtil.types(exprs)); if (type != null) { final List<RexNode> oldExprs = Lists.newArrayList(exprs); exprs.clear(); for (RexNode expr : oldExprs) { exprs.add(cx.getRexBuilder().ensureType(type, expr, true)); } } } return exprs; }
private static List<RexNode> convertExpressionList(SqlRexContext cx, List<SqlNode> nodes, SqlOperandTypeChecker.Consistency consistency) { final List<RexNode> exprs = new ArrayList<>(); for (SqlNode node : nodes) { exprs.add(cx.convertExpression(node)); } if (exprs.size() > 1) { final RelDataType type = consistentType(cx, consistency, RexUtil.types(exprs)); if (type != null) { final List<RexNode> oldExprs = Lists.newArrayList(exprs); exprs.clear(); for (RexNode expr : oldExprs) { exprs.add(cx.getRexBuilder().ensureType(type, expr, true)); } } } return exprs; }
private static List<RexNode> convertExpressionList(SqlRexContext cx, List<SqlNode> nodes, SqlOperandTypeChecker.Consistency consistency) { final List<RexNode> exprs = new ArrayList<>(); for (SqlNode node : nodes) { exprs.add(cx.convertExpression(node)); } if (exprs.size() > 1) { final RelDataType type = consistentType(cx, consistency, RexUtil.types(exprs)); if (type != null) { final List<RexNode> oldExprs = Lists.newArrayList(exprs); exprs.clear(); for (RexNode expr : oldExprs) { exprs.add(cx.getRexBuilder().ensureType(type, expr, true)); } } } return exprs; }
/** * Registers that one operator is an alias for another. * * @param alias Operator which is alias * @param target Operator to translate calls to */ protected void addAlias(final SqlOperator alias, final SqlOperator target) { map.put( alias, (SqlRexConvertlet) (cx, call) -> { Preconditions.checkArgument(call.getOperator() == alias, "call to wrong operator"); final SqlCall newCall = target.createCall(SqlParserPos.ZERO, call.getOperandList()); return cx.convertExpression(newCall); }); } }
/** * Registers that one operator is an alias for another. * * @param alias Operator which is alias * @param target Operator to translate calls to */ protected void addAlias(final SqlOperator alias, final SqlOperator target) { map.put( alias, (SqlRexConvertlet) (cx, call) -> { Preconditions.checkArgument(call.getOperator() == alias, "call to wrong operator"); final SqlCall newCall = target.createCall(SqlParserPos.ZERO, call.getOperandList()); return cx.convertExpression(newCall); }); } }
@Override public RexNode convertCall(SqlRexContext cx, SqlCall call) { final List<RexNode> exprs = new LinkedList<>(); for (SqlNode node : call.getOperandList()) { exprs.add(cx.convertExpression(node)); } final RexBuilder rexBuilder = cx.getRexBuilder(); // The result of IS [NOT] DISTINCT FROM is NOT NULL because it can only return TRUE or FALSE. final RelDataType returnType = rexBuilder.getTypeFactory().createSqlType(SqlTypeName.BOOLEAN); return rexBuilder.makeCall(returnType, call.getOperator(), exprs); } }
@Override public RexNode convertCall(SqlRexContext cx, SqlCall call) { final RexBuilder rexBuilder = cx.getRexBuilder(); final SqlLiteral literal = (SqlLiteral) call.getOperandList().get(0); final String value = ((NlsString)literal.getValue()).getValue(); TimeUnitRange range = VALID_PERIODS.get(value.toLowerCase()); Preconditions.checkNotNull(range, "Unhandle range type: %s.", value); List<RexNode> exprs = new ArrayList<>(); exprs.add(rexBuilder.makeFlag(range)); exprs.add(cx.convertExpression(call.getOperandList().get(1))); RelDataTypeFactory typeFactory = cx.getTypeFactory(); final RelDataType returnType = typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), exprs.get(1).getType().isNullable()); return rexBuilder.makeCall(returnType, SqlStdOperatorTable.EXTRACT, exprs); }
public RexNode convertCall(SqlRexContext cx, SqlCall call) { final RexBuilder rexBuilder = cx.getRexBuilder(); final RexNode operand = cx.convertExpression(call.getOperandList().get(0)); return rexBuilder.makeCall(SqlStdOperatorTable.TRIM, rexBuilder.makeFlag(flag), rexBuilder.makeLiteral(" "), operand); } }
public RexNode convertCall(SqlRexContext cx, SqlCall call) { final RexBuilder rexBuilder = cx.getRexBuilder(); final RexNode operand = cx.convertExpression(call.getOperandList().get(0)); return rexBuilder.makeCall(SqlStdOperatorTable.TRIM, rexBuilder.makeFlag(flag), rexBuilder.makeLiteral(" "), operand); } }
@Override public RexNode convertCall(SqlRexContext cx, SqlCall call) { final List<SqlNode> operands = call.getOperandList(); final List<RexNode> exprs = new LinkedList<>(); for (SqlNode node: operands) { exprs.add(cx.convertExpression(node)); } final RelDataType returnType = cx.getRexBuilder().deriveReturnType(call.getOperator(), exprs); return cx.getRexBuilder().makeCall(returnType, call.getOperator(), exprs); } };
private SqlNode expandRegrSzz( final SqlNode arg1, final SqlNode arg2, final RelDataType avgType, final SqlRexContext cx, boolean variance) { final SqlParserPos pos = SqlParserPos.ZERO; final SqlNode count = SqlStdOperatorTable.REGR_COUNT.createCall(pos, arg1, arg2); final SqlNode varPop = expandCovariance(arg1, variance ? arg1 : arg2, arg2, avgType, cx, true); final RexNode varPopRex = cx.convertExpression(varPop); final SqlNode varPopCast; varPopCast = getCastedSqlNode(varPop, avgType, pos, varPopRex); return SqlStdOperatorTable.MULTIPLY.createCall(pos, varPopCast, count); }
private SqlNode expandAvg( final SqlNode arg, final RelDataType avgType, final SqlRexContext cx) { final SqlParserPos pos = SqlParserPos.ZERO; final SqlNode sum = SqlStdOperatorTable.SUM.createCall(pos, arg); final RexNode sumRex = cx.convertExpression(sum); final SqlNode sumCast; sumCast = getCastedSqlNode(sum, avgType, pos, sumRex); final SqlNode count = SqlStdOperatorTable.COUNT.createCall(pos, arg); return SqlStdOperatorTable.DIVIDE.createCall( pos, sumCast, count); }
private SqlNode expandRegrSzz( final SqlNode arg1, final SqlNode arg2, final RelDataType avgType, final SqlRexContext cx, boolean variance) { final SqlParserPos pos = SqlParserPos.ZERO; final SqlNode count = SqlStdOperatorTable.REGR_COUNT.createCall(pos, arg1, arg2); final SqlNode varPop = expandCovariance(arg1, variance ? arg1 : arg2, arg2, avgType, cx, true); final RexNode varPopRex = cx.convertExpression(varPop); final SqlNode varPopCast; varPopCast = getCastedSqlNode(varPop, avgType, pos, varPopRex); return SqlStdOperatorTable.MULTIPLY.createCall(pos, varPopCast, count); }
private SqlNode expandAvg( final SqlNode arg, final RelDataType avgType, final SqlRexContext cx) { final SqlParserPos pos = SqlParserPos.ZERO; final SqlNode sum = SqlStdOperatorTable.SUM.createCall(pos, arg); final RexNode sumRex = cx.convertExpression(sum); final SqlNode sumCast; sumCast = getCastedSqlNode(sum, avgType, pos, sumRex); final SqlNode count = SqlStdOperatorTable.COUNT.createCall(pos, arg); return SqlStdOperatorTable.DIVIDE.createCall( pos, sumCast, count); }
private Pair<RexNode, RexNode> convertOverlapsOperand(SqlRexContext cx, SqlParserPos pos, SqlNode operand) { final SqlNode a0; final SqlNode a1; switch (operand.getKind()) { case ROW: a0 = ((SqlCall) operand).operand(0); final SqlNode a10 = ((SqlCall) operand).operand(1); final RelDataType t1 = cx.getValidator().getValidatedNodeType(a10); if (SqlTypeUtil.isInterval(t1)) { // make t1 = t0 + t1 when t1 is an interval. a1 = plus(pos, a0, a10); } else { a1 = a10; } break; default: a0 = operand; a1 = operand; } final RexNode r0 = cx.convertExpression(a0); final RexNode r1 = cx.convertExpression(a1); return Pair.of(r0, r1); }
@Override public RexNode convertCall(SqlRexContext cx, SqlCall call) { SqlFlattenOperator operator = (SqlFlattenOperator) call.getOperator(); final List<RexNode> exprs = new LinkedList<>(); for (SqlNode node : call.getOperandList()) { exprs.add(cx.convertExpression(node)); } SqlFlattenOperator indexedOperator = operator.withIndex(((SqlValidatorImpl)cx.getValidator()).nextFlattenIndex()); final RexBuilder rexBuilder = cx.getRexBuilder(); // Since we don't have any way of knowing if the output of the flatten is nullable, we should always assume it is. // This is especially important when accelerating a count(column) query, because the normalizer will convert it to // a count(1) if it thinks this column is non-nullable, and then remove the flatten altogether. This is actually a // problem with the fact that flatten is not really a project operator (because it can output more than one row per input). RelDataType type = rexBuilder .getTypeFactory() .createTypeWithNullability( rexBuilder .getTypeFactory() .createSqlType(SqlTypeName.ANY), true ); return rexBuilder.makeCall(type, indexedOperator, exprs); }