@Override public String toHumanString(T value) { if (value == null) { return "null"; } switch (type.typeId()) { case DATE: return TransformUtil.humanDay((Integer) value); case TIME: return TransformUtil.humanTime((Long) value); case TIMESTAMP: if (((Types.TimestampType) type).shouldAdjustToUTC()) { return TransformUtil.humanTimestampWithZone((Long) value); } else { return TransformUtil.humanTimestampWithoutZone((Long) value); } case FIXED: case BINARY: if (value instanceof ByteBuffer) { return TransformUtil.base64encode(((ByteBuffer) value).duplicate()); } else if (value instanceof byte[]) { return TransformUtil.base64encode(ByteBuffer.wrap((byte[]) value)); } else { throw new UnsupportedOperationException("Unsupported binary type: " + value.getClass()); } default: return value.toString(); } }
@Override public Type primitive(Type.PrimitiveType primitive) { Class<? extends DataType> expectedType = TYPES.get(primitive.typeId()); Preconditions.checkArgument(expectedType != null && expectedType.isInstance(current), "Cannot project %s to incompatible type: %s", primitive, current); // additional checks based on type switch (primitive.typeId()) { case DECIMAL: Types.DecimalType decimal = (Types.DecimalType) primitive; DecimalType d = (DecimalType) current; Preconditions.checkArgument(d.scale() == decimal.scale(), "Cannot project decimal with incompatible scale: %s != %s", d.scale(), decimal.scale()); Preconditions.checkArgument(d.precision() >= decimal.precision(), "Cannot project decimal with incompatible precision: %s < %s", d.precision(), decimal.precision()); break; case TIMESTAMP: Types.TimestampType timestamp = (Types.TimestampType) primitive; Preconditions.checkArgument(timestamp.shouldAdjustToUTC(), "Cannot project timestamp (without time zone) as timestamptz (with time zone)"); break; default: } return primitive; }
@Override public Type primitive(Type.PrimitiveType primitive) { Class<? extends DataType> expectedType = TYPES.get(primitive.typeId()); Preconditions.checkArgument(expectedType != null && expectedType.isInstance(current), "Cannot project %s to incompatible type: %s", primitive, current); // additional checks based on type switch (primitive.typeId()) { case DECIMAL: Types.DecimalType decimal = (Types.DecimalType) primitive; DecimalType d = (DecimalType) current; Preconditions.checkArgument(d.scale() == decimal.scale(), "Cannot project decimal with incompatible scale: %s != %s", d.scale(), decimal.scale()); Preconditions.checkArgument(d.precision() >= decimal.precision(), "Cannot project decimal with incompatible precision: %s < %s", d.precision(), decimal.precision()); break; case TIMESTAMP: Types.TimestampType timestamp = (Types.TimestampType) primitive; Preconditions.checkArgument(timestamp.shouldAdjustToUTC(), "Cannot project timestamp (without time zone) as timestamptz (with time zone)"); break; default: } return primitive; }
if (ts.shouldAdjustToUTC()) { return EPOCH.plus(random.nextLong() % FIFTY_YEARS_IN_MICROS, MICROS); } else {
case TIMESTAMP_MICROS: TimestampType tsMicrosType = (TimestampType) expected; if (tsMicrosType.shouldAdjustToUTC()) { return new TimestamptzReader(desc); } else { if (tsMillisType.shouldAdjustToUTC()) { return new TimestamptzMillisReader(desc); } else {
break; case TIMESTAMP: if (((Types.TimestampType) primitive).shouldAdjustToUTC()) { primitiveSchema = TIMESTAMPTZ_SCHEMA; } else {
case TIMESTAMP: Types.TimestampType timestamp = (Types.TimestampType) primitive; if (timestamp.shouldAdjustToUTC()) { return TimestampType$.MODULE$;
if (((Types.TimestampType) type).shouldAdjustToUTC()) { long timestampMicros = ChronoUnit.MICROS.between(EPOCH, OffsetDateTime.parse(value(), DateTimeFormatter.ISO_DATE_TIME));
@Override public String toString() { if (shouldAdjustToUTC()) { return "timestamptz"; } else { return "timestamp"; } }