org.apache.iceberg.types.Types.TimestampType Java Examples

The following examples show how to use org.apache.iceberg.types.Types.TimestampType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArrowSchemaUtilTest.java    From iceberg with Apache License 2.0 6 votes vote down vote up
@Test
public void convertPrimitive() {
  Schema iceberg = new Schema(
      Types.NestedField.optional(0, INTEGER_FIELD, IntegerType.get()),
      Types.NestedField.optional(1, BOOLEAN_FIELD, BooleanType.get()),
      Types.NestedField.required(2, DOUBLE_FIELD, DoubleType.get()),
      Types.NestedField.required(3, STRING_FIELD, StringType.get()),
      Types.NestedField.optional(4, DATE_FIELD, DateType.get()),
      Types.NestedField.optional(5, TIMESTAMP_FIELD, TimestampType.withZone()),
      Types.NestedField.optional(6, LONG_FIELD, LongType.get()),
      Types.NestedField.optional(7, FLOAT_FIELD, FloatType.get()),
      Types.NestedField.optional(8, TIME_FIELD, TimeType.get()),
      Types.NestedField.optional(9, BINARY_FIELD, Types.BinaryType.get()),
      Types.NestedField.optional(10, DECIMAL_FIELD, Types.DecimalType.of(1, 1)),
      Types.NestedField.optional(12, LIST_FIELD, Types.ListType.ofOptional(13, Types.IntegerType.get())),
      Types.NestedField.required(14, MAP_FIELD, Types.MapType.ofOptional(15, 16,
          StringType.get(), IntegerType.get())),
      Types.NestedField.optional(17, FIXED_WIDTH_BINARY_FIELD, Types.FixedType.ofLength(10)));

  org.apache.arrow.vector.types.pojo.Schema arrow = ArrowSchemaUtil.convert(iceberg);

  validate(iceberg, arrow);
}
 
Example #2
Source File: TestPartitionTransforms.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testToStringMatchesSpecification()
{
    assertEquals(Transforms.identity(StringType.get()).toString(), "identity");
    assertEquals(Transforms.bucket(StringType.get(), 13).toString(), "bucket[13]");
    assertEquals(Transforms.truncate(StringType.get(), 19).toString(), "truncate[19]");
    assertEquals(Transforms.year(DateType.get()).toString(), "year");
    assertEquals(Transforms.month(DateType.get()).toString(), "month");
    assertEquals(Transforms.day(DateType.get()).toString(), "day");
    assertEquals(Transforms.hour(TimestampType.withoutZone()).toString(), "hour");
}
 
Example #3
Source File: TestPartitionFields.java    From presto with Apache License 2.0 5 votes vote down vote up
private static PartitionSpec partitionSpec(Consumer<PartitionSpec.Builder> consumer)
{
    Schema schema = new Schema(
            NestedField.required(1, "order_key", LongType.get()),
            NestedField.required(2, "ts", TimestampType.withoutZone()),
            NestedField.required(3, "price", DoubleType.get()),
            NestedField.optional(4, "comment", StringType.get()),
            NestedField.optional(5, "notes", ListType.ofRequired(6, StringType.get())));

    PartitionSpec.Builder builder = PartitionSpec.builderFor(schema);
    consumer.accept(builder);
    return builder.build();
}
 
Example #4
Source File: ArrowSchemaUtilTest.java    From iceberg with Apache License 2.0 5 votes vote down vote up
@Test
public void convertComplex() {
  Schema iceberg = new Schema(
      Types.NestedField.optional(0, "m", MapType.ofOptional(
          1, 2, StringType.get(),
          LongType.get())
      ),
      Types.NestedField.required(3, "m2", MapType.ofOptional(
          4, 5, StringType.get(),
          ListType.ofOptional(6, TimestampType.withoutZone()))
      )
  );
  org.apache.arrow.vector.types.pojo.Schema arrow = ArrowSchemaUtil.convert(iceberg);
  Assert.assertEquals(iceberg.columns().size(), arrow.getFields().size());
}
 
Example #5
Source File: MessageTypeToType.java    From iceberg with Apache License 2.0 4 votes vote down vote up
@Override
public Optional<Type> visit(LogicalTypeAnnotation.TimestampLogicalTypeAnnotation timestampType) {
  return Optional.of(timestampType.isAdjustedToUTC() ? TimestampType.withZone() : TimestampType.withoutZone());
}
 
Example #6
Source File: SchemaConverter.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static CompleteType fromIcebergPrimitiveType(PrimitiveType type) {
  switch (type.typeId()) {
    case BOOLEAN:
      return CompleteType.BIT;
    case INTEGER:
      return CompleteType.INT;
    case LONG:
      return CompleteType.BIGINT;
    case FLOAT:
      return CompleteType.FLOAT;
    case DOUBLE:
      return CompleteType.DOUBLE;
    case STRING:
      return CompleteType.VARCHAR;
    case BINARY:
      return CompleteType.VARBINARY;
    case UUID:
      return new CompleteType(new FixedSizeBinary(16));
    case DATE:
      return CompleteType.DATE;
    case TIME:
      // TODO: When we support Time and Timestamp MICROS, this needs to be changed  to use
      // the existing schema definition for older tables, and to use MICROS for newer tables
      return CompleteType.TIME;
    case TIMESTAMP:
      {
        if (((TimestampType) type.asPrimitiveType()).shouldAdjustToUTC()) {
          return CompleteType.TIMESTAMP;
        } else {
          throw new UnsupportedOperationException("iceberg timestamp type without zone not supported");
        }
      }
    case FIXED:
      return new CompleteType(new FixedSizeBinary(((FixedType)type).length()));
    case DECIMAL:
      DecimalType decimalType = (DecimalType)type;
      return new CompleteType(new Decimal(decimalType.precision(), decimalType.scale()));
    default:
      throw new UnsupportedOperationException("Unsupported iceberg type : " + type);
  }
}