@Test public void testLong() { long num = testRandom.nextLong(); ByteBuffer buffer = ByteBuffer.allocate(8); buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putLong(num); Bucket<Long> bucketFunc = Bucket.get(Types.LongType.get(), 100); Assert.assertEquals("Long hash should match hash of little-endian bytes", hashBytes(buffer.array()), bucketFunc.hash(num)); }
@Test public void testIntegerTypePromotion() { Bucket<Integer> bucketInts = Bucket.get(Types.IntegerType.get(), 100); Bucket<Long> bucketLongs = Bucket.get(Types.LongType.get(), 100); int r = testRandom.nextInt(); Assert.assertEquals("Integer and Long bucket results should match", bucketInts.apply(r), bucketLongs.apply((long) r)); }
@Test(expected = CommitFailedException.class) public void testFailure() throws TException { com.netflix.iceberg.Table icebergTable = new HiveTables(hiveConf).load(DB_NAME, TABLE_NAME); final Table table = metastoreClient.getTable(DB_NAME, TABLE_NAME); final String dummyLocation = "dummylocation"; table.getParameters().put(METADATA_LOCATION_PROP, dummyLocation); metastoreClient.alter_table(DB_NAME, TABLE_NAME, table); icebergTable.updateSchema() .addColumn("data", Types.LongType.get()) .commit(); } }
@Test public void testMapOfStructs() throws IOException { Schema schema = new Schema( required(0, "id", LongType.get()), optional(1, "data", MapType.ofOptional(2, 3, Types.StringType.get(), SUPPORTED_PRIMITIVES))); writeAndValidate(schema); }
@Test public void testNullHumanString() { Types.LongType longType = Types.LongType.get(); Transform<Long, Long> identity = Transforms.identity(longType); Assert.assertEquals("Should produce \"null\" for null", "null", identity.toHumanString(null)); }
@Test public void testArray() throws IOException { Schema schema = new Schema( required(0, "id", LongType.get()), optional(1, "data", ListType.ofOptional(2, Types.StringType.get()))); writeAndValidate(schema); }
@Test public void testComplexMapKey() throws IOException { Schema schema = new Schema( required(0, "id", LongType.get()), optional(1, "data", MapType.ofOptional(2, 3, Types.StructType.of( required(4, "i", Types.IntegerType.get()), optional(5, "s", Types.StringType.get())), Types.StringType.get()))); writeAndValidate(schema); }
@Test public void testMap() throws IOException { Schema schema = new Schema( required(0, "id", LongType.get()), optional(1, "data", MapType.ofOptional(2, 3, Types.StringType.get(), Types.StringType.get()))); writeAndValidate(schema); }
@Test public void testArrayOfStructs() throws IOException { Schema schema = new Schema( required(0, "id", LongType.get()), optional(1, "data", ListType.ofOptional(2, SUPPORTED_PRIMITIVES))); writeAndValidate(schema); }
@Test public void testArrayOfStructs() throws IOException { Schema schema = new Schema( required(0, "id", LongType.get()), optional(1, "data", ListType.ofOptional(2, SUPPORTED_PRIMITIVES))); writeAndValidate(schema); }
@Test public void testArray() throws IOException { Schema schema = new Schema( required(0, "id", LongType.get()), optional(1, "data", ListType.ofOptional(2, Types.StringType.get()))); writeAndValidate(schema); }
@Test public void testMapOfStructs() throws IOException { Schema schema = new Schema( required(0, "id", LongType.get()), optional(1, "data", MapType.ofOptional(2, 3, Types.StringType.get(), SUPPORTED_PRIMITIVES))); writeAndValidate(schema); }
@Test public void testMap() throws IOException { Schema schema = new Schema( required(0, "id", LongType.get()), optional(1, "data", MapType.ofOptional(2, 3, Types.StringType.get(), Types.StringType.get()))); writeAndValidate(schema); }
@Test public void testLongInBag() throws IOException { Schema icebergSchema = new Schema( optional( 1, "nested_list", MapType.ofOptional( 2, 3, StringType.get(), ListType.ofRequired(5, LongType.get())))); SchemaUtil.convert(icebergSchema); }
@Test public void testMap() throws IOException { Schema schema = new Schema( required(0, "id", LongType.get()), optional(1, "data", MapType.ofOptional(2, 3, Types.StringType.get(), Types.StringType.get()))); writeAndValidate(schema); }
@Test public void testComplexMapKey() throws IOException { Schema schema = new Schema( required(0, "id", LongType.get()), optional(1, "data", MapType.ofOptional(2, 3, StructType.of( required(4, "i", Types.IntegerType.get()), optional(5, "s", Types.StringType.get())), Types.StringType.get()))); writeAndValidate(schema); }
@Test public void testMapOfLongToBytes() { Type map = Types.MapType.ofRequired(33, 34, Types.LongType.get(), Types.BinaryType.get()); Schema schema = AvroSchemaUtil.createMap( 33, Schema.create(Schema.Type.LONG), 34, Schema.create(Schema.Type.BYTES)); Assert.assertEquals("Avro schema to map", map, AvroSchemaUtil.convert(schema)); Assert.assertEquals("Map to Avro schema", schema, AvroSchemaUtil.convert(map)); }
private static Schema wrapFileSchema(StructType fileStruct) { // ids for top-level columns are assigned from 1000 return new Schema( required(0, "status", IntegerType.get()), required(1, "snapshot_id", LongType.get()), required(2, "data_file", fileStruct)); }
@Test public void testUpdateDeleteConflict() { AssertHelpers.assertThrows("Should reject update then delete", IllegalArgumentException.class, "column that has updates: id", () -> { UpdateSchema update = new SchemaUpdate(SCHEMA, SCHEMA_LAST_COLUMN_ID); update.updateColumn("id", Types.LongType.get()).deleteColumn("id"); } ); }