use of org.apache.iceberg.data.Record in project hive by apache.
the class TestHiveIcebergV2 method testReadAndWriteFormatV2Partitioned_PosDelete_RowNotSupplied.
@Test
public void testReadAndWriteFormatV2Partitioned_PosDelete_RowNotSupplied() throws IOException {
Assume.assumeFalse("Reading V2 tables with delete files are only supported currently in " + "non-vectorized mode and only Parquet/Avro", isVectorized || fileFormat == FileFormat.ORC);
PartitionSpec spec = PartitionSpec.builderFor(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA).identity("customer_id").build();
Table tbl = testTables.createTable(shell, "customers", HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, spec, fileFormat, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS, 2);
// add some more data to the same partition
shell.executeStatement("insert into customers values (0, 'Laura', 'Yellow'), (0, 'John', 'Green'), " + "(0, 'Blake', 'Blue')");
tbl.refresh();
// delete the first and third rows from the newly-added data file - with row supplied
DataFile dataFile = StreamSupport.stream(tbl.currentSnapshot().addedFiles().spliterator(), false).filter(file -> file.partition().get(0, Long.class) == 0L).filter(file -> file.recordCount() == 3).findAny().orElseThrow(() -> new RuntimeException("Did not find the desired data file in the test table"));
List<PositionDelete<Record>> deletes = ImmutableList.of(positionDelete(dataFile.path(), 0L, null), positionDelete(dataFile.path(), 2L, null));
DeleteFile deleteFile = HiveIcebergTestUtils.createPositionalDeleteFile(tbl, "dummyPath", fileFormat, ImmutableMap.of("customer_id", 0L), deletes);
tbl.newRowDelta().addDeletes(deleteFile).commit();
List<Object[]> objects = shell.executeStatement("SELECT * FROM customers ORDER BY customer_id, first_name");
Assert.assertEquals(4, objects.size());
Assert.assertArrayEquals(new Object[] { 0L, "Alice", "Brown" }, objects.get(0));
Assert.assertArrayEquals(new Object[] { 0L, "John", "Green" }, objects.get(1));
Assert.assertArrayEquals(new Object[] { 1L, "Bob", "Green" }, objects.get(2));
Assert.assertArrayEquals(new Object[] { 2L, "Trudy", "Pink" }, objects.get(3));
}
use of org.apache.iceberg.data.Record in project hive by apache.
the class TestHiveIcebergV2 method testReadAndWriteFormatV2Partitioned_EqDelete_AllColumnsSupplied.
@Test
public void testReadAndWriteFormatV2Partitioned_EqDelete_AllColumnsSupplied() throws IOException {
Assume.assumeFalse("Reading V2 tables with delete files are only supported currently in " + "non-vectorized mode and only Parquet/Avro", isVectorized || fileFormat == FileFormat.ORC);
PartitionSpec spec = PartitionSpec.builderFor(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA).identity("customer_id").build();
Table tbl = testTables.createTable(shell, "customers", HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA, spec, fileFormat, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS, 2);
// add one more row to the same partition
shell.executeStatement("insert into customers values (1, 'Bob', 'Hoover')");
// delete all rows with id=1 and first_name=Bob
List<Record> toDelete = TestHelper.RecordsBuilder.newInstance(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA).add(1L, "Bob", null).build();
DeleteFile deleteFile = HiveIcebergTestUtils.createEqualityDeleteFile(tbl, "dummyPath", ImmutableList.of("customer_id", "first_name"), fileFormat, toDelete);
tbl.newRowDelta().addDeletes(deleteFile).commit();
List<Object[]> objects = shell.executeStatement("SELECT * FROM customers ORDER BY customer_id");
Assert.assertEquals(2, objects.size());
Assert.assertArrayEquals(new Object[] { 0L, "Alice", "Brown" }, objects.get(0));
Assert.assertArrayEquals(new Object[] { 2L, "Trudy", "Pink" }, objects.get(1));
}
use of org.apache.iceberg.data.Record in project hive by apache.
the class TestIcebergInputFormats method testLocality.
@Test
public void testLocality() throws Exception {
helper.createUnpartitionedTable();
List<Record> expectedRecords = helper.generateRandomRecords(1, 0L);
helper.appendToTable(null, expectedRecords);
for (InputSplit split : testInputFormat.create(builder.conf()).getSplits()) {
Assert.assertArrayEquals(IcebergSplit.ANYWHERE, split.getLocations());
}
builder.preferLocality();
for (InputSplit split : testInputFormat.create(builder.conf()).getSplits()) {
Assert.assertArrayEquals(new String[] { "localhost" }, split.getLocations());
}
}
use of org.apache.iceberg.data.Record in project hive by apache.
the class TestIcebergInputFormats method testResiduals.
@Test
public void testResiduals() throws Exception {
helper.createTable();
List<Record> writeRecords = helper.generateRandomRecords(2, 0L);
writeRecords.get(0).set(1, 123L);
writeRecords.get(0).set(2, "2020-03-20");
writeRecords.get(1).set(1, 456L);
writeRecords.get(1).set(2, "2020-03-20");
List<Record> expectedRecords = new ArrayList<>();
expectedRecords.add(writeRecords.get(0));
DataFile dataFile1 = helper.writeFile(Row.of("2020-03-20", 0), writeRecords);
DataFile dataFile2 = helper.writeFile(Row.of("2020-03-21", 0), helper.generateRandomRecords(2, 0L));
helper.appendToTable(dataFile1, dataFile2);
builder.filter(Expressions.and(Expressions.equal("date", "2020-03-20"), Expressions.equal("id", 123)));
testInputFormat.create(builder.conf()).validate(expectedRecords);
// skip residual filtering
builder.skipResidualFiltering();
testInputFormat.create(builder.conf()).validate(writeRecords);
}
use of org.apache.iceberg.data.Record in project hive by apache.
the class TestIcebergInputFormats method validateIdentityPartitionProjections.
private void validateIdentityPartitionProjections(Schema projectedSchema, List<Record> inputRecords) {
builder.project(projectedSchema);
List<Record> actualRecords = testInputFormat.create(builder.conf()).getRecords();
Set<String> fieldNames = TypeUtil.indexByName(projectedSchema.asStruct()).keySet();
for (int pos = 0; pos < inputRecords.size(); pos++) {
Record inputRecord = inputRecords.get(pos);
Record actualRecord = actualRecords.get(pos);
Assert.assertEquals("Projected schema should match", projectedSchema.asStruct(), actualRecord.struct());
for (String name : fieldNames) {
Assert.assertEquals("Projected field " + name + " should match", inputRecord.getField(name), actualRecord.getField(name));
}
}
}
Aggregations