/** * Retrieves a decimal node's integer representation * * @param decimalNode the decimal value as an opaque type * @return an integer representation of the decimal value */ protected RexNode decodeValue(RexNode decimalNode) { assert SqlTypeUtil.isDecimal(decimalNode.getType()); return builder.decodeIntervalOrDecimal(decimalNode); }
/** * Retrieves a decimal node's integer representation * * @param decimalNode the decimal value as an opaque type * * @return an integer representation of the decimal value */ protected RexNode decodeValue(RexNode decimalNode) { assert (SqlTypeUtil.isDecimal(decimalNode.getType())); return builder.decodeIntervalOrDecimal(decimalNode); }
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); }
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.multiplyOperator, value, makeExactLiteral(multiplier)); } return encodeIntervalOrDecimal(value, toType, false); }
private RexNode makeCastIntervalToExact(RelDataType toType, RexNode exp) { IntervalSqlType intervalType = (IntervalSqlType) exp.getType(); 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)); RexNode value = decodeIntervalOrDecimal(exp); if (multiplier.longValue() != 1) { value = makeCall( SqlStdOperatorTable.DIVIDE_INTEGER, value, makeBigintLiteral(multiplier)); } if (scale > 0) { RelDataType decimalType = getTypeFactory().createSqlType( SqlTypeName.DECIMAL, scale + intervalType.getPrecision(), scale); value = encodeIntervalOrDecimal(value, decimalType, false); } return ensureType(toType, value, false); }
RexNode value = decodeIntervalOrDecimal(exp); if (multiplier.longValue() != 1) { value = makeCall(