use of org.apache.iceberg.Schema in project hive by apache.
the class TestHiveIcebergStorageHandlerNoScan method testPartitionEvolution.
@Test
public void testPartitionEvolution() {
Schema schema = new Schema(optional(1, "id", Types.LongType.get()), optional(2, "ts", Types.TimestampType.withZone()));
TableIdentifier identifier = TableIdentifier.of("default", "part_test");
shell.executeStatement("CREATE EXTERNAL TABLE " + identifier + " STORED BY ICEBERG " + testTables.locationForCreateTableSQL(identifier) + " TBLPROPERTIES ('" + InputFormatConfig.TABLE_SCHEMA + "'='" + SchemaParser.toJson(schema) + "', " + "'" + InputFormatConfig.CATALOG_NAME + "'='" + testTables.catalogName() + "')");
shell.executeStatement("ALTER TABLE " + identifier + " SET PARTITION SPEC (month(ts))");
PartitionSpec spec = PartitionSpec.builderFor(schema).withSpecId(1).month("ts").build();
Table table = testTables.loadTable(identifier);
Assert.assertEquals(spec, table.spec());
shell.executeStatement("ALTER TABLE " + identifier + " SET PARTITION SPEC (day(ts))");
spec = PartitionSpec.builderFor(schema).withSpecId(2).alwaysNull("ts", "ts_month").day("ts").build();
table.refresh();
Assert.assertEquals(spec, table.spec());
}
use of org.apache.iceberg.Schema in project hive by apache.
the class TestHiveIcebergStorageHandlerNoScan method testSetPartitionTransformSameField.
@Test
public void testSetPartitionTransformSameField() {
Schema schema = new Schema(optional(1, "id", Types.LongType.get()), optional(2, "truncate_field", Types.StringType.get()), optional(3, "bucket_field", Types.StringType.get()));
TableIdentifier identifier = TableIdentifier.of("default", "part_test");
shell.executeStatement("CREATE EXTERNAL TABLE " + identifier + " PARTITIONED BY SPEC (truncate(2, truncate_field), bucket(2, bucket_field))" + " STORED BY ICEBERG " + testTables.locationForCreateTableSQL(identifier) + "TBLPROPERTIES ('" + InputFormatConfig.TABLE_SCHEMA + "'='" + SchemaParser.toJson(schema) + "', " + "'" + InputFormatConfig.CATALOG_NAME + "'='" + testTables.catalogName() + "')");
PartitionSpec spec = PartitionSpec.builderFor(schema).truncate("truncate_field", 2).bucket("bucket_field", 2).build();
Table table = testTables.loadTable(identifier);
Assert.assertEquals(spec, table.spec());
// Change one, keep one
shell.executeStatement("ALTER TABLE default.part_test " + "SET PARTITION SPEC (truncate(3, truncate_field), bucket(2, bucket_field) )");
spec = PartitionSpec.builderFor(schema).withSpecId(1).alwaysNull("truncate_field", "truncate_field_trunc").bucket("bucket_field", 2).truncate("truncate_field", 3, "truncate_field_trunc_3").build();
table.refresh();
Assert.assertEquals(spec, table.spec());
// Change one again, keep the other one
shell.executeStatement("ALTER TABLE default.part_test " + "SET PARTITION SPEC (truncate(4, truncate_field), bucket(2, bucket_field) )");
spec = PartitionSpec.builderFor(schema).withSpecId(2).alwaysNull("truncate_field", "truncate_field_trunc").bucket("bucket_field", 2).alwaysNull("truncate_field", "truncate_field_trunc_3").truncate("truncate_field", 4, "truncate_field_trunc_4").build();
table.refresh();
Assert.assertEquals(spec, table.spec());
// Keep the already changed, change the other one (change the order of clauses in the spec)
shell.executeStatement("ALTER TABLE default.part_test " + "SET PARTITION SPEC (bucket(3, bucket_field), truncate(4, truncate_field))");
spec = PartitionSpec.builderFor(schema).withSpecId(3).alwaysNull("truncate_field", "truncate_field_trunc").alwaysNull("bucket_field", "bucket_field_bucket").alwaysNull("truncate_field", "truncate_field_trunc_3").truncate("truncate_field", 4, "truncate_field_trunc_4").bucket("bucket_field", 3, "bucket_field_bucket_3").build();
table.refresh();
Assert.assertEquals(spec, table.spec());
}
use of org.apache.iceberg.Schema in project hive by apache.
the class TestHiveIcebergStorageHandlerNoScan method testAlterTableChangeColumnTypeAndComment.
@Test
public void testAlterTableChangeColumnTypeAndComment() throws TException, InterruptedException {
TableIdentifier identifier = TableIdentifier.of("default", "customers");
Schema schema = new Schema(optional(1, "customer_id", Types.IntegerType.get()), optional(2, "last_name", Types.StringType.get(), "This is last name"));
testTables.createTable(shell, identifier.name(), schema, SPEC, FileFormat.PARQUET, ImmutableList.of());
shell.executeStatement("ALTER TABLE default.customers CHANGE COLUMN " + "customer_id customer_id bigint COMMENT 'This is an identifier'");
org.apache.iceberg.Table icebergTable = testTables.loadTable(identifier);
org.apache.hadoop.hive.metastore.api.Table hmsTable = shell.metastore().getTable("default", "customers");
List<FieldSchema> icebergSchema = HiveSchemaUtil.convert(icebergTable.schema());
List<FieldSchema> hmsSchema = hmsTable.getSd().getCols();
List<FieldSchema> expectedSchema = Lists.newArrayList(new FieldSchema("customer_id", "bigint", "This is an identifier"), new FieldSchema("last_name", "string", "This is last name"));
Assert.assertEquals(expectedSchema, icebergSchema);
if (testTableType != TestTables.TestTableType.HIVE_CATALOG) {
expectedSchema.stream().filter(fs -> fs.getComment() == null).forEach(fs -> fs.setComment("from deserializer"));
}
Assert.assertEquals(expectedSchema, hmsSchema);
}
use of org.apache.iceberg.Schema in project hive by apache.
the class TestIcebergInputFormats method testProjection.
@Test
public void testProjection() throws Exception {
helper.createTable();
List<Record> inputRecords = helper.generateRandomRecords(1, 0L);
helper.appendToTable(Row.of("2020-03-20", 0), inputRecords);
Schema projection = TypeUtil.select(SCHEMA, ImmutableSet.of(1));
builder.project(projection);
List<Record> outputRecords = testInputFormat.create(builder.conf()).getRecords();
Assert.assertEquals(inputRecords.size(), outputRecords.size());
Assert.assertEquals(projection.asStruct(), outputRecords.get(0).struct());
}
use of org.apache.iceberg.Schema in project hive by apache.
the class TestHiveIcebergComplexTypeWrites method testWriteMapOfMapsInTable.
@Test
public void testWriteMapOfMapsInTable() throws IOException {
Schema schema = new Schema(required(1, "id", Types.LongType.get()), required(2, "mapofmaps", Types.MapType.ofRequired(3, 4, Types.StringType.get(), Types.MapType.ofRequired(5, 6, Types.StringType.get(), Types.StringType.get()))));
List<Record> records = TestHelper.generateRandomRecords(schema, 5, 0L);
testComplexTypeWrite(schema, records);
}
Aggregations