use of org.apache.iceberg.Table in project hive by apache.
the class TestHiveIcebergComplexTypeWrites method testComplexTypeWrite.
private void testComplexTypeWrite(Schema schema, List<Record> records) throws IOException {
String tableName = "complex_table";
Table table = testTables.createTable(shell, "complex_table", schema, fileFormat, ImmutableList.of());
String dummyTableName = "dummy";
shell.executeStatement("CREATE TABLE default." + dummyTableName + "(a int)");
shell.executeStatement("INSERT INTO TABLE default." + dummyTableName + " VALUES(1)");
records.forEach(r -> shell.executeStatement(insertQueryForComplexType(tableName, dummyTableName, schema, r)));
HiveIcebergTestUtils.validateData(table, records, 0);
}
use of org.apache.iceberg.Table in project hive by apache.
the class TestHiveIcebergInserts method testInsert.
@Test
public void testInsert() throws IOException {
Table table = testTables.createTable(shell, "customers", HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, fileFormat, ImmutableList.of());
// The expected query is like
// INSERT INTO customers VALUES (0, 'Alice'), (1, 'Bob'), (2, 'Trudy')
StringBuilder query = new StringBuilder().append("INSERT INTO customers VALUES ");
HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS.forEach(record -> query.append("(").append(record.get(0)).append(",'").append(record.get(1)).append("','").append(record.get(2)).append("'),"));
query.setLength(query.length() - 1);
shell.executeStatement(query.toString());
HiveIcebergTestUtils.validateData(table, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS, 0);
}
use of org.apache.iceberg.Table in project hive by apache.
the class TestHiveIcebergInserts method testInsertUsingSourceTableWithSharedColumnsNames.
@Test
public void testInsertUsingSourceTableWithSharedColumnsNames() throws IOException {
List<Record> records = HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS;
PartitionSpec spec = PartitionSpec.builderFor(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA).identity("last_name").build();
testTables.createTable(shell, "source_customers", HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, spec, fileFormat, records);
Table table = testTables.createTable(shell, "target_customers", HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, spec, fileFormat, ImmutableList.of());
// Below select from source table should produce: "hive.io.file.readcolumn.names=customer_id,last_name".
// Inserting into the target table should not fail because first_name is not selected from the source table
shell.executeStatement("INSERT INTO target_customers SELECT customer_id, 'Sam', last_name FROM source_customers");
List<Record> expected = Lists.newArrayListWithExpectedSize(records.size());
records.forEach(r -> {
Record copy = r.copy();
copy.setField("first_name", "Sam");
expected.add(copy);
});
HiveIcebergTestUtils.validateData(table, expected, 0);
}
use of org.apache.iceberg.Table in project hive by apache.
the class TestHiveIcebergInserts method testInsertFromSelectWithOrderBy.
/**
* Testing map-reduce inserts.
* @throws IOException If there is an underlying IOException
*/
@Test
public void testInsertFromSelectWithOrderBy() throws IOException {
Table table = testTables.createTable(shell, "customers", HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, fileFormat, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS);
// We expect that there will be Mappers and Reducers here
shell.executeStatement("INSERT INTO customers SELECT * FROM customers ORDER BY customer_id");
// Check that everything is duplicated as expected
List<Record> records = new ArrayList<>(HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS);
records.addAll(HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS);
HiveIcebergTestUtils.validateData(table, records, 0);
}
use of org.apache.iceberg.Table in project hive by apache.
the class TestHiveIcebergInserts method testInsertFromJoiningTwoIcebergTables.
@Test
public void testInsertFromJoiningTwoIcebergTables() throws IOException {
PartitionSpec spec = PartitionSpec.builderFor(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA).identity("last_name").build();
testTables.createTable(shell, "source_customers_1", HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, spec, fileFormat, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS);
testTables.createTable(shell, "source_customers_2", HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, spec, fileFormat, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS);
Table table = testTables.createTable(shell, "target_customers", HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, spec, fileFormat, ImmutableList.of());
shell.executeStatement("INSERT INTO target_customers SELECT a.customer_id, b.first_name, a.last_name FROM " + "source_customers_1 a JOIN source_customers_2 b ON a.last_name = b.last_name");
HiveIcebergTestUtils.validateData(table, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS, 0);
}
Aggregations