public RelDataType createSqlIntervalType( SqlIntervalQualifier intervalQualifier) { RelDataType newType = new IntervalSqlType(intervalQualifier, false); return canonize(newType); }
/** * Constructs an IntervalSqlType. This should only be called from a factory * method. */ public IntervalSqlType( SqlIntervalQualifier intervalQualifier, boolean isNullable) { super( intervalQualifier.isYearMonth() ? SqlTypeName.INTERVAL_YEAR_MONTH : SqlTypeName.INTERVAL_DAY_TIME, isNullable, null); this.intervalQualifier = intervalQualifier; computeDigest(); }
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); }
if (!intervalType.getIntervalQualifier().isSingleDatetimeField()) {
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); }
IntervalSqlType intervalType = (IntervalSqlType) (isInterval(fromType) ? fromType : toType); if (!intervalType.getIntervalQualifier().isSingleDatetimeField()) {
private RexNode makeCastIntervalToExact(RelDataType toType, RexNode exp) TimeUnit endUnit = intervalType.getIntervalQualifier().getEndUnit(); if (endUnit == null) { endUnit = intervalType.getIntervalQualifier().getStartUnit(); intervalType.getIntervalQualifier() .getFractionalSecondPrecision(), 3); getTypeFactory().createSqlType( SqlTypeName.DECIMAL, scale + intervalType.getPrecision(), scale); value = encodeIntervalOrDecimal(value, decimalType, false);
public RelDataType createSqlIntervalType( SqlIntervalQualifier intervalQualifier) { RelDataType newType = new IntervalSqlType(intervalQualifier, false); return canonize(newType); }
/** * Constructs an IntervalSqlType. This should only be called from a factory * method. */ public IntervalSqlType( SqlIntervalQualifier intervalQualifier, boolean isNullable) { super( intervalQualifier.isYearMonth() ? SqlTypeName.INTERVAL_YEAR_MONTH : SqlTypeName.INTERVAL_DAY_TIME, isNullable, null); this.intervalQualifier = intervalQualifier; computeDigest(); }
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); }
private RelDataType copyIntervalType(RelDataType type, boolean nullable) { return new IntervalSqlType( type.getIntervalQualifier(), nullable); }
private RelDataType copyIntervalType(RelDataType type, boolean nullable) { return new IntervalSqlType( type.getIntervalQualifier(), nullable); }