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);
}
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;
}
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;
}
Aggregations