Search in sources :

Example 6 with TimeUnit

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.avatica.util.TimeUnit in project calcite by apache.

the class RexBuilder method makeCastIntervalToExact.

private RexNode makeCastIntervalToExact(RelDataType toType, RexNode exp) {
    final TimeUnit endUnit = exp.getType().getSqlTypeName().getEndUnit();
    final TimeUnit baseUnit = baseUnit(exp.getType().getSqlTypeName());
    final BigDecimal multiplier = baseUnit.multiplier;
    final int scale = 0;
    BigDecimal divider = endUnit.multiplier.scaleByPowerOfTen(-scale);
    RexNode value = multiplyDivide(decodeIntervalOrDecimal(exp), multiplier, divider);
    if (scale > 0) {
        RelDataType decimalType = getTypeFactory().createSqlType(SqlTypeName.DECIMAL, scale + exp.getType().getPrecision(), scale);
        value = encodeIntervalOrDecimal(value, decimalType, false);
    }
    return ensureType(toType, value, false);
}
Also used : TimeUnit(org.apache.calcite.avatica.util.TimeUnit) RelDataType(org.apache.calcite.rel.type.RelDataType) BigDecimal(java.math.BigDecimal)

Example 7 with TimeUnit

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.avatica.util.TimeUnit in project calcite by apache.

the class RexLiteral method getTimeUnits.

/**
 * Returns a list of the time units covered by an interval type such
 * as HOUR TO SECOND. Adds MILLISECOND if the end is SECOND, to deal with
 * fractional seconds.
 */
private static List<TimeUnit> getTimeUnits(SqlTypeName typeName) {
    final TimeUnit start = typeName.getStartUnit();
    final TimeUnit end = typeName.getEndUnit();
    final ImmutableList<TimeUnit> list = TIME_UNITS.subList(start.ordinal(), end.ordinal() + 1);
    if (end == TimeUnit.SECOND) {
        return CompositeList.of(list, ImmutableList.of(TimeUnit.MILLISECOND));
    }
    return list;
}
Also used : TimeUnit(org.apache.calcite.avatica.util.TimeUnit)

Example 8 with TimeUnit

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.avatica.util.TimeUnit in project flink by apache.

the class RexLiteral method getTimeUnits.

/**
 * Returns a list of the time units covered by an interval type such as HOUR TO SECOND. Adds
 * MILLISECOND if the end is SECOND, to deal with fractional seconds.
 */
private static List<TimeUnit> getTimeUnits(SqlTypeName typeName) {
    final TimeUnit start = typeName.getStartUnit();
    final TimeUnit end = typeName.getEndUnit();
    final ImmutableList<TimeUnit> list = TIME_UNITS.subList(start.ordinal(), end.ordinal() + 1);
    if (end == TimeUnit.SECOND) {
        return CompositeList.of(list, ImmutableList.of(TimeUnit.MILLISECOND));
    }
    return list;
}
Also used : TimeUnit(org.apache.calcite.avatica.util.TimeUnit)

Aggregations

TimeUnit (org.apache.calcite.avatica.util.TimeUnit)7 BigDecimal (java.math.BigDecimal)3 RelDataType (org.apache.calcite.rel.type.RelDataType)2 ByteString (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.avatica.util.ByteString)1 TimeUnit (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.avatica.util.TimeUnit)1 DateString (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.DateString)1 TimeString (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.TimeString)1 TimestampString (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.util.TimestampString)1 SqlIntervalQualifier (org.apache.calcite.sql.SqlIntervalQualifier)1 DateString (org.apache.calcite.util.DateString)1 TimeString (org.apache.calcite.util.TimeString)1 TimestampString (org.apache.calcite.util.TimestampString)1