(RexNode) rexBuilder.makeExactLiteral(BigDecimal.ZERO)); preNames = Collections.singletonList(null);
/** * Makes an exact, non-nullable literal of Bigint type */ protected RexNode makeExactLiteral(long l) { BigDecimal bd = BigDecimal.valueOf(l); return builder.makeExactLiteral(bd, int8); }
/** * Makes an exact, non-nullable literal of Bigint type */ protected RexNode makeExactLiteral(long l) { BigDecimal bd = BigDecimal.valueOf(l); return builder.makeExactLiteral(bd, int8); }
rexBuilder.makeExactLiteral(BigDecimal.ZERO, longType); final RexLiteral trueLiteral = rexBuilder.makeLiteral(true); final RexLiteral falseLiteral = rexBuilder.makeLiteral(false);
(BigDecimal) value, type.getScale()); return rexBuilder.makeExactLiteral( roundedValue, type);
private RexNode mod(RexBuilder rexBuilder, RelDataType resType, RexNode res, long val) { if (val == 1L) { return res; } return rexBuilder.makeCall(SqlStdOperatorTable.MOD, res, rexBuilder.makeExactLiteral(BigDecimal.valueOf(val), resType)); }
private RexNode divide(RexBuilder rexBuilder, RexNode res, long val) { if (val == 1L) { return res; } return rexBuilder.makeCall(SqlStdOperatorTable.DIVIDE_INTEGER, res, rexBuilder.makeExactLiteral(BigDecimal.valueOf(val))); }
/** * Creates a numeric literal. */ public RexLiteral makeExactLiteral(BigDecimal bd) { RelDataType relType; int scale = bd.scale(); long l = bd.unscaledValue().longValue(); assert (scale >= 0) && (scale <= SqlTypeName.MAX_NUMERIC_SCALE); assert BigDecimal.valueOf(l, scale).equals(bd); if (scale == 0) { if ((l >= Integer.MIN_VALUE) && (l <= Integer.MAX_VALUE)) { relType = typeFactory.createSqlType(SqlTypeName.INTEGER); } else { relType = typeFactory.createSqlType(SqlTypeName.BIGINT); } } else { int precision = bd.unscaledValue().toString().length(); relType = typeFactory.createSqlType( SqlTypeName.DECIMAL, scale, precision); } return makeExactLiteral(bd, relType); }
/** * Creates a numeric literal. */ public RexLiteral makeExactLiteral(BigDecimal bd) { RelDataType relType; int scale = bd.scale(); long l = bd.unscaledValue().longValue(); assert ((scale >= 0) && (scale <= SqlTypeName.MAX_NUMERIC_SCALE)); assert (BigDecimal.valueOf(l, scale).equals(bd)); if (scale == 0) { if ((l >= Integer.MIN_VALUE) && (l <= Integer.MAX_VALUE)) { relType = typeFactory.createSqlType(SqlTypeName.INTEGER); } else { relType = typeFactory.createSqlType(SqlTypeName.BIGINT); } } else { int precision = bd.unscaledValue().toString().length(); relType = typeFactory.createSqlType( SqlTypeName.DECIMAL, scale, precision); } return makeExactLiteral(bd, relType); }
public RelNode convert(RelNode rel) { OneRowRel oneRow = (OneRowRel) rel; RexBuilder rexBuilder = rel.getCluster().getRexBuilder(); return new EnumerableValuesRel( oneRow.getCluster(), oneRow.getRowType(), Collections.singletonList( Collections.singletonList( rexBuilder.makeExactLiteral(BigDecimal.ZERO))), oneRow.getTraitSet().replace(EnumerableConvention.INSTANCE)); } }
@Override public void onMatch(RelOptRuleCall call) { final OneRowRel rel = call.rel(0); call.transformTo( new ValuesRel( rel.getCluster(), rel.getRowType(), Collections.singletonList( Collections.singletonList( rel.getCluster().getRexBuilder().makeExactLiteral( BigDecimal.ZERO))))); }
public void check(RexBuilder rexBuilder, RexExecutorImpl executor) { final List<RexNode> reducedValues = new ArrayList<RexNode>(); final RexLiteral hello = rexBuilder.makeCharLiteral( new NlsString("Hello world!", null, null)); final RexNode plus = rexBuilder.makeCall(SqlStdOperatorTable.PLUS, rexBuilder.makeExactLiteral(BigDecimal.ONE), rexBuilder.makeExactLiteral(BigDecimal.ONE)); RexLiteral four = rexBuilder.makeExactLiteral(BigDecimal.valueOf(4)); final RexNode substring = rexBuilder.makeCall(SqlStdOperatorTable.SUBSTRING, hello, plus, four); executor.reduce(rexBuilder, ImmutableList.of(substring, plus), reducedValues); assertThat(reducedValues.size(), equalTo(2)); assertThat(reducedValues.get(0), instanceOf(RexLiteral.class)); assertThat(((RexLiteral) reducedValues.get(0)).getValue2(), equalTo((Object) "ello")); // substring('Hello world!, 2, 4) assertThat(reducedValues.get(1), instanceOf(RexLiteral.class)); assertThat(((RexLiteral) reducedValues.get(1)).getValue2(), equalTo((Object) 2L)); } });
@Before public void setUp() { // create some reusable fixtures RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(); intType = typeFactory.createSqlType(SqlTypeName.INTEGER); intType = typeFactory.createTypeWithNullability(intType, true); stringType = typeFactory.createSqlType(SqlTypeName.VARCHAR, 20); stringType = typeFactory.createTypeWithNullability(stringType, true); rexBuilder = new RexBuilder(typeFactory); intLiteral7 = rexBuilder.makeExactLiteral( BigDecimal.valueOf(7), intType); intLiteral490 = rexBuilder.makeExactLiteral( BigDecimal.valueOf(490), intType); intLiteral8point5 = rexBuilder.makeExactLiteral( new BigDecimal("8.5"), intType); sargFactory = new SargFactory(rexBuilder); }
private RexNode makeCastBooleanToExact(RelDataType toType, RexNode exp) { final RexNode casted = makeCall( SqlStdOperatorTable.CASE, exp, makeExactLiteral(BigDecimal.ONE, toType), makeZeroLiteral(toType)); if (!exp.getType().isNullable()) { return casted; } return makeCall( toType, SqlStdOperatorTable.CASE, ImmutableList.<RexNode>of( makeCall(SqlStdOperatorTable.IS_NOT_NULL, exp), casted, makeNullLiteral(toType.getSqlTypeName()))); }
private RexNode makeCastBooleanToExact(RelDataType toType, RexNode exp) { final RexNode casted = makeCall( SqlStdOperatorTable.caseOperator, exp, makeExactLiteral(BigDecimal.ONE, toType), makeZeroLiteral(toType)); if (!exp.getType().isNullable()) { return casted; } return makeCall( toType, SqlStdOperatorTable.caseOperator, ImmutableList.<RexNode>of( makeCall(SqlStdOperatorTable.isNotNullOperator, exp), casted, makeNullLiteral(toType.getSqlTypeName()))); }
@Before public void setUp() { // create some reusable fixtures RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(); intType = typeFactory.createSqlType(SqlTypeName.INTEGER); intType = typeFactory.createTypeWithNullability(intType, true); stringType = typeFactory.createSqlType(SqlTypeName.VARCHAR, 20); stringType = typeFactory.createTypeWithNullability(stringType, true); rexBuilder = new RexBuilder(typeFactory); intLiteral7 = rexBuilder.makeExactLiteral( BigDecimal.valueOf(7), intType); intLiteral490 = rexBuilder.makeExactLiteral( BigDecimal.valueOf(490), intType); intLiteral8point5 = rexBuilder.makeExactLiteral( new BigDecimal("8.5"), intType); sargFactory = new SargFactory(rexBuilder); }
private RexNode makeCastExactToInterval(RelDataType toType, RexNode exp) { IntervalSqlType intervalType = (IntervalSqlType) toType; TimeUnit endUnit = intervalType.getIntervalQualifier().getEndUnit(); if (endUnit == null) { endUnit = intervalType.getIntervalQualifier().getStartUnit(); } int scale = 0; if (endUnit == TimeUnit.SECOND) { scale = Math.min( intervalType.getIntervalQualifier() .getFractionalSecondPrecision(), 3); } BigDecimal multiplier = BigDecimal.valueOf(endUnit.multiplier) .divide(BigDecimal.TEN.pow(scale)); RelDataType decimalType = getTypeFactory().createSqlType( SqlTypeName.DECIMAL, scale + intervalType.getPrecision(), scale); RexNode value = decodeIntervalOrDecimal(ensureType(decimalType, exp, true)); if (multiplier.longValue() != 1) { value = makeCall( SqlStdOperatorTable.MULTIPLY, value, makeExactLiteral(multiplier)); } return encodeIntervalOrDecimal(value, toType, false); }
public RexNode visitInputRef(RexInputRef inputRef) { if ((currentRel != null) && (currentRel instanceof CorrelatorRel)) { // if this rel references corVar // and now it needs to be rewritten // it must have been pulled above the CorrelatorRel // replace the input ref to account for the LHS of the // CorrelatorRel int leftInputFieldCount = ((CorrelatorRel) currentRel).getLeft().getRowType() .getFieldCount(); RelDataType newType = inputRef.getType(); if (projectPulledAboveLeftCorrelator) { newType = typeFactory.createTypeWithNullability(newType, true); } int pos = inputRef.getIndex(); RexInputRef newInputRef = new RexInputRef(leftInputFieldCount + pos, newType); if ((isCount != null) && isCount.contains(pos)) { return createCaseExpression( newInputRef, rexBuilder.makeExactLiteral(BigDecimal.ZERO), newInputRef); } else { return newInputRef; } } return inputRef; }
public RexNode visitInputRef(RexInputRef inputRef) { if ((currentRel != null) && (currentRel instanceof CorrelatorRel)) { // if this rel references corVar // and now it needs to be rewritten // it must have been pulled above the CorrelatorRel // replace the input ref to account for the LHS of the // CorrelatorRel int leftInputFieldCount = ((CorrelatorRel) currentRel).getLeft().getRowType() .getFieldCount(); RelDataType newType = inputRef.getType(); if (projectPulledAboveLeftCorrelator) { newType = typeFactory.createTypeWithNullability(newType, true); } int pos = inputRef.getIndex(); RexInputRef newInputRef = new RexInputRef(leftInputFieldCount + pos, newType); if ((isCount != null) && isCount.contains(pos)) { return createCaseExpression( newInputRef, rexBuilder.makeExactLiteral(BigDecimal.ZERO), newInputRef); } else { return newInputRef; } } return inputRef; }
@Ignore @Test /** Tests that we can analyze a program with no inputs that outputs two * constants. */ public void testAnalyzeTwoConstantProgram() { final RelDataTypeFactory typeFactory = new FieldTypeFactory(); final RelDataType inputType = typeFactory.createStructType( new RelDataTypeFactory.FieldInfoBuilder() ); final RexBuilder builder = new RexBuilder( typeFactory ); final RexProgramBuilder programBuilder = new RexProgramBuilder( inputType, builder ); programBuilder.addProject( builder.makeExactLiteral( BigDecimal.ONE ), "x" ); programBuilder.addProject( builder.makeCharLiteral( new NlsString( "foo", null, null ) ), "y" ); final RexProgram program = programBuilder.getProgram(); final ProgramUtil.Analyzed analyze = ProgramUtil.analyze( program ); assertTrue( analyze.hasConstants ); assertFalse( analyze.hasFunctions ); assertNull( analyze.permutation ); assertFalse( analyze.isComplex ); } }