return Types.FixedType.ofLength(primitive.getFixedSize()); case BYTES: return Types.BinaryType.get(); case NULL: return null;
return Types.StringType.get(); case BINARY: return Types.BinaryType.get(); case DATE: return Types.DateType.get();
return Types.FixedType.ofLength(primitive.getTypeLength()); case BINARY: return Types.BinaryType.get();
Types.NestedField.required(8, "u", Types.UUIDType.get()), Types.NestedField.required(9, "f", Types.FixedType.ofLength(3)), Types.NestedField.required(10, "b", Types.BinaryType.get()) );
Types.UUIDType.get(), Types.FixedType.ofLength(12), Types.BinaryType.get(), Types.DecimalType.of(9, 4) );
optional(31, "uuid", Types.UUIDType.get()), optional(32, "fixed", Types.FixedType.ofLength(16)), optional(33, "binary", Types.BinaryType.get()), optional(34, "decimal", Types.DecimalType.of(14, 2)) );
((DecimalType) atomic).scale()); } else if (atomic instanceof BinaryType) { return Types.BinaryType.get();
Types.FloatType.get(), Types.DoubleType.get(), Types.DateType.get(), Types.TimeType.get(), Types.TimestampType.withZone(), Types.TimestampType.withoutZone(), Types.StringType.get(), Types.UUIDType.get(), Types.BinaryType.get(), Types.FixedType.ofLength(3), Types.FixedType.ofLength(4), Types.DecimalType.of(9, 2), Types.DecimalType.of(9, 3),
@Test public void testIdentityConversions() { List<Pair<Literal<?>, Type>> pairs = Arrays.asList( Pair.of(Literal.of(true), Types.BooleanType.get()), Pair.of(Literal.of(34), Types.IntegerType.get()), Pair.of(Literal.of(34L), Types.LongType.get()), Pair.of(Literal.of(34.11F), Types.FloatType.get()), Pair.of(Literal.of(34.55D), Types.DoubleType.get()), Pair.of(Literal.of("34.55"), Types.DecimalType.of(9, 2)), Pair.of(Literal.of("2017-08-18"), Types.DateType.get()), Pair.of(Literal.of("14:21:01.919"), Types.TimeType.get()), Pair.of(Literal.of("2017-08-18T14:21:01.919"), Types.TimestampType.withoutZone()), Pair.of(Literal.of("abc"), Types.StringType.get()), Pair.of(Literal.of(UUID.randomUUID()), Types.UUIDType.get()), Pair.of(Literal.of(new byte[] {0, 1, 2}), Types.FixedType.ofLength(3)), Pair.of(Literal.of(ByteBuffer.wrap(new byte[] {0, 1, 2})), Types.BinaryType.get()) ); for (Pair<Literal<?>, Type> pair : pairs) { Literal<?> lit = pair.first(); Type type = pair.second(); // first, convert the literal to the target type (date/times start as strings) Literal<?> expected = lit.to(type); // then check that converting again to the same type results in an identical literal Assert.assertSame("Converting twice should produce identical values", expected, expected.to(type)); } }
static StructType getType(StructType partitionType) { // IDs start at 100 to leave room for changes to ManifestEntry return StructType.of( required(100, "file_path", StringType.get()), required(101, "file_format", StringType.get()), required(102, "partition", partitionType), required(103, "record_count", LongType.get()), required(104, "file_size_in_bytes", LongType.get()), required(105, "block_size_in_bytes", LongType.get()), optional(106, "file_ordinal", IntegerType.get()), optional(107, "sort_columns", ListType.ofRequired(112, IntegerType.get())), optional(108, "column_sizes", MapType.ofRequired(117, 118, IntegerType.get(), LongType.get())), optional(109, "value_counts", MapType.ofRequired(119, 120, IntegerType.get(), LongType.get())), optional(110, "null_value_counts", MapType.ofRequired(121, 122, IntegerType.get(), LongType.get())), optional(125, "lower_bounds", MapType.ofRequired(126, 127, IntegerType.get(), BinaryType.get())), optional(128, "upper_bounds", MapType.ofRequired(129, 130, IntegerType.get(), BinaryType.get())) // NEXT ID TO ASSIGN: 131 ); }
@Test public void testLiterals() throws Exception { Literal[] literals = new Literal[] { Literal.of(false), Literal.of(34), Literal.of(35L), Literal.of(36.75F), Literal.of(8.75D), Literal.of("2017-11-29").to(Types.DateType.get()), Literal.of("11:30:07").to(Types.TimeType.get()), Literal.of("2017-11-29T11:30:07.123").to(Types.TimestampType.withoutZone()), Literal.of("2017-11-29T11:30:07.123+01:00").to(Types.TimestampType.withZone()), Literal.of("abc"), Literal.of(UUID.randomUUID()), Literal.of(new byte[] { 1, 2, 3 }).to(Types.FixedType.ofLength(3)), Literal.of(new byte[] { 3, 4, 5, 6 }).to(Types.BinaryType.get()), Literal.of(new BigDecimal("122.50")), }; for (Literal<?> lit : literals) { checkValue(lit); } }
@Test public void testIdentityTypes() throws Exception { // these types make a strong guarantee than equality, instances are identical Type[] identityPrimitives = new Type[] { Types.BooleanType.get(), Types.IntegerType.get(), Types.LongType.get(), Types.FloatType.get(), Types.DoubleType.get(), Types.DateType.get(), Types.TimeType.get(), Types.TimestampType.withoutZone(), Types.TimestampType.withZone(), Types.StringType.get(), Types.UUIDType.get(), Types.BinaryType.get() }; for (Type type : identityPrimitives) { Assert.assertSame("Serialization result should be identical to starting type", type, TestHelpers.roundTripSerialize(type)); } }
@Test public void testInvalidDecimalConversions() { testInvalidConversions(Literal.of(new BigDecimal("34.11")), Types.BooleanType.get(), Types.IntegerType.get(), Types.LongType.get(), Types.FloatType.get(), Types.DoubleType.get(), Types.DateType.get(), Types.TimeType.get(), Types.TimestampType.withZone(), Types.TimestampType.withoutZone(), Types.DecimalType.of(9, 4), Types.StringType.get(), Types.UUIDType.get(), Types.FixedType.ofLength(1), Types.BinaryType.get() ); }
@Test public void testInvalidTimeConversions() { testInvalidConversions( Literal.of("14:21:01.919").to(Types.TimeType.get()), Types.BooleanType.get(), Types.IntegerType.get(), Types.LongType.get(), Types.FloatType.get(), Types.DoubleType.get(), Types.DateType.get(), Types.TimestampType.withZone(), Types.TimestampType.withoutZone(), Types.DecimalType.of(9, 4), Types.StringType.get(), Types.UUIDType.get(), Types.FixedType.ofLength(1), Types.BinaryType.get() ); }
@Test public void testInvalidDateConversions() { testInvalidConversions(Literal.of("2017-08-18").to(Types.DateType.get()), Types.BooleanType.get(), Types.IntegerType.get(), Types.LongType.get(), Types.FloatType.get(), Types.DoubleType.get(), Types.TimeType.get(), Types.TimestampType.withZone(), Types.TimestampType.withoutZone(), Types.DecimalType.of(9, 4), Types.StringType.get(), Types.UUIDType.get(), Types.FixedType.ofLength(1), Types.BinaryType.get() ); }
@Test public void testInvalidBooleanConversions() { testInvalidConversions(Literal.of(true), Types.IntegerType.get(), Types.LongType.get(), Types.FloatType.get(), Types.DoubleType.get(), Types.DateType.get(), Types.TimeType.get(), Types.TimestampType.withZone(), Types.TimestampType.withoutZone(), Types.DecimalType.of(9, 2), Types.StringType.get(), Types.UUIDType.get(), Types.FixedType.ofLength(1), Types.BinaryType.get() ); }
@Test public void testByteBufferOffHeap() { byte[] bytes = randomBytes(128); ByteBuffer buffer = ByteBuffer.allocateDirect(128); // copy to the middle of the off-heap buffer buffer.position(5); buffer.limit(105); buffer.mark(); buffer.put(bytes, 5, 100); buffer.reset(); Bucket<ByteBuffer> bucketFunc = Bucket.get(Types.BinaryType.get(), 100); Assert.assertEquals( "DirectByteBuffer hash should match hash for correct slice", hashBytes(bytes, 5, 100), bucketFunc.hash(buffer)); // verify that the buffer was not modified Assert.assertEquals("Buffer position should not change", 5, buffer.position()); Assert.assertEquals("Buffer limit should not change", 105, buffer.limit()); }
@Test public void complexNested() throws IOException { convertToPigSchema(new Schema( optional(1,"t", StructType.of( optional(2, "b", ListType.ofOptional(3,StructType.of( optional(4, "i", IntegerType.get()), optional(5,"s", StringType.get()) ))) )), optional(6, "m1", MapType.ofOptional(7,8, StringType.get(), StructType.of( optional(9, "b", ListType.ofOptional(10, BinaryType.get()) ), optional(11, "m2", MapType.ofOptional(12,13, StringType.get(), IntegerType.get())) ))), optional(14, "b1", ListType.ofOptional(15, MapType.ofOptional(16,17, StringType.get(), ListType.ofOptional(18, FloatType.get())))) ), "t:(b:{(i:int,s:chararray)}),m1:[(b:{(bytearray)},m2:[int])],b1:{([{(float)}])}", ""); }
@Test public void testInvalidUUIDConversions() { testInvalidConversions(Literal.of(UUID.randomUUID()), Types.BooleanType.get(), Types.IntegerType.get(), Types.LongType.get(), Types.FloatType.get(), Types.DoubleType.get(), Types.DateType.get(), Types.TimeType.get(), Types.TimestampType.withZone(), Types.TimestampType.withoutZone(), Types.DecimalType.of(9, 2), Types.StringType.get(), Types.FixedType.ofLength(1), Types.BinaryType.get() ); }