use of org.apache.iceberg.catalog.TableIdentifier in project hive by apache.
the class TestHiveIcebergStorageHandlerNoScan method testCreateTableWithColumnSpecificationHierarchy.
@Test
public void testCreateTableWithColumnSpecificationHierarchy() {
TableIdentifier identifier = TableIdentifier.of("default", "customers");
shell.executeStatement("CREATE EXTERNAL TABLE customers (" + "id BIGINT, name STRING, " + "employee_info STRUCT < employer: STRING, id: BIGINT, address: STRING >, " + "places_lived ARRAY < STRUCT <street: STRING, city: STRING, country: STRING >>, " + "memorable_moments MAP < STRING, STRUCT < year: INT, place: STRING, details: STRING >>, " + "current_address STRUCT < street_address: STRUCT " + "<street_number: INT, street_name: STRING, street_type: STRING>, country: STRING, postal_code: STRING >) " + "STORED BY ICEBERG " + testTables.locationForCreateTableSQL(identifier) + testTables.propertiesForCreateTableSQL(ImmutableMap.of()));
// Check the Iceberg table data
org.apache.iceberg.Table icebergTable = testTables.loadTable(identifier);
Assert.assertEquals(COMPLEX_SCHEMA.asStruct(), icebergTable.schema().asStruct());
}
use of org.apache.iceberg.catalog.TableIdentifier in project hive by apache.
the class TestHiveIcebergInserts method testInsertOverwritePartitionedTable.
@Test
public void testInsertOverwritePartitionedTable() throws IOException {
TableIdentifier target = TableIdentifier.of("default", "target");
PartitionSpec spec = PartitionSpec.builderFor(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA).identity("last_name").build();
Table table = testTables.createTable(shell, target.name(), HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, spec, fileFormat, ImmutableList.of());
// IOW into empty target table -> whole source result set is inserted
List<Record> expected = new ArrayList<>(HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS);
expected.add(TestHelper.RecordsBuilder.newInstance(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA).add(8L, "Sue", "Green").build().get(// add one more to 'Green' so we have a partition w/ multiple records
0));
shell.executeStatement(testTables.getInsertQuery(expected, target, true));
HiveIcebergTestUtils.validateData(table, expected, 0);
// IOW into non-empty target table -> only the affected partitions are overwritten
List<Record> newRecords = TestHelper.RecordsBuilder.newInstance(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA).add(0L, "Mike", // overwritten
"Brown").add(1L, "Christy", // overwritten (partition has this single record now)
"Green").add(3L, "Bill", // appended (new partition)
"Purple").build();
shell.executeStatement(testTables.getInsertQuery(newRecords, target, true));
expected = new ArrayList<>(newRecords);
// existing, untouched partition ('Pink')
expected.add(HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS.get(2));
HiveIcebergTestUtils.validateData(table, expected, 0);
// IOW empty source result set -> has no effect on partitioned table
shell.executeStatement("INSERT OVERWRITE TABLE target SELECT * FROM target WHERE FALSE");
HiveIcebergTestUtils.validateData(table, expected, 0);
}
use of org.apache.iceberg.catalog.TableIdentifier in project hive by apache.
the class TestHiveIcebergInserts method testInsertOverwriteNonPartitionedTable.
@Test
public void testInsertOverwriteNonPartitionedTable() throws IOException {
TableIdentifier target = TableIdentifier.of("default", "target");
Table table = testTables.createTable(shell, target.name(), HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, fileFormat, ImmutableList.of());
// IOW overwrites the whole table (empty target table)
testTables.createTable(shell, "source", HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, fileFormat, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS);
shell.executeStatement("INSERT OVERWRITE TABLE target SELECT * FROM source");
HiveIcebergTestUtils.validateData(table, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS, 0);
// IOW overwrites the whole table (non-empty target table)
List<Record> newRecords = TestHelper.RecordsBuilder.newInstance(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA).add(0L, "Mike", "Taylor").add(1L, "Christy", "Hubert").build();
shell.executeStatement(testTables.getInsertQuery(newRecords, target, true));
HiveIcebergTestUtils.validateData(table, newRecords, 0);
// IOW empty result set -> clears the target table
shell.executeStatement("INSERT OVERWRITE TABLE target SELECT * FROM source WHERE FALSE");
HiveIcebergTestUtils.validateData(table, ImmutableList.of(), 0);
}
use of org.apache.iceberg.catalog.TableIdentifier in project hive by apache.
the class TestHiveIcebergStorageHandlerLocalScan method testCreateTableWithColumnSpecification.
@Test
public void testCreateTableWithColumnSpecification() throws IOException {
TableIdentifier identifier = TableIdentifier.of("default", "customers");
Map<StructLike, List<Record>> data = new HashMap<>(1);
data.put(null, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS);
String createSql = "CREATE EXTERNAL TABLE " + identifier + " (customer_id BIGINT, first_name STRING COMMENT 'This is first name', " + "last_name STRING COMMENT 'This is last name')" + " STORED BY ICEBERG " + testTables.locationForCreateTableSQL(identifier) + testTables.propertiesForCreateTableSQL(ImmutableMap.of());
runCreateAndReadTest(identifier, createSql, HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, PartitionSpec.unpartitioned(), data);
}
use of org.apache.iceberg.catalog.TableIdentifier in project hive by apache.
the class TestHiveIcebergStorageHandlerLocalScan method testCreatePartitionedTableByProperty.
@Test
public void testCreatePartitionedTableByProperty() throws IOException {
TableIdentifier identifier = TableIdentifier.of("default", "customers");
PartitionSpec spec = PartitionSpec.builderFor(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA).identity("last_name").build();
Map<StructLike, List<Record>> data = ImmutableMap.of(Row.of("Brown"), Collections.singletonList(HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS.get(0)), Row.of("Green"), Collections.singletonList(HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS.get(1)), Row.of("Pink"), Collections.singletonList(HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS.get(2)));
String createSql = "CREATE EXTERNAL TABLE " + identifier + " STORED BY ICEBERG " + testTables.locationForCreateTableSQL(identifier) + "TBLPROPERTIES ('" + InputFormatConfig.PARTITION_SPEC + "'='" + PartitionSpecParser.toJson(spec) + "', " + "'" + InputFormatConfig.TABLE_SCHEMA + "'='" + SchemaParser.toJson(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA) + "', " + "'" + InputFormatConfig.CATALOG_NAME + "'='" + testTables.catalogName() + "')";
runCreateAndReadTest(identifier, createSql, HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, spec, data);
}
Aggregations