use of org.apache.iceberg.data.Record in project hive by apache.
the class TestDeserializer method testMapDeserialize.
@Test
public void testMapDeserialize() {
Schema schema = new Schema(optional(1, "map_type", Types.MapType.ofOptional(2, 3, Types.LongType.get(), Types.StringType.get())));
StructObjectInspector inspector = ObjectInspectorFactory.getStandardStructObjectInspector(Arrays.asList("map_type"), Arrays.asList(ObjectInspectorFactory.getStandardMapObjectInspector(PrimitiveObjectInspectorFactory.writableLongObjectInspector, PrimitiveObjectInspectorFactory.writableStringObjectInspector)));
Deserializer deserializer = new Deserializer.Builder().schema(schema).writerInspector((StructObjectInspector) IcebergObjectInspector.create(schema)).sourceInspector(inspector).build();
Record expected = GenericRecord.create(schema);
expected.set(0, Collections.singletonMap(1L, "Taylor"));
MapWritable map = new MapWritable();
map.put(new LongWritable(1L), new Text("Taylor"));
Object[] data = new Object[] { map };
Record actual = deserializer.deserialize(data);
Assert.assertEquals(expected, actual);
}
use of org.apache.iceberg.data.Record in project hive by apache.
the class TestDeserializer method testNullDeserialize.
@Test
public void testNullDeserialize() {
Deserializer deserializer = new Deserializer.Builder().schema(HiveIcebergTestUtils.FULL_SCHEMA).writerInspector((StructObjectInspector) IcebergObjectInspector.create(HiveIcebergTestUtils.FULL_SCHEMA)).sourceInspector(HiveIcebergTestUtils.FULL_SCHEMA_OBJECT_INSPECTOR).build();
Record expected = HiveIcebergTestUtils.getNullTestRecord();
Object[] nulls = new Object[HiveIcebergTestUtils.FULL_SCHEMA.columns().size()];
Arrays.fill(nulls, null);
Record actual = deserializer.deserialize(nulls);
Assert.assertEquals(expected, actual);
// Check null record as well
Assert.assertNull(deserializer.deserialize(null));
}
use of org.apache.iceberg.data.Record in project hive by apache.
the class TestHiveIcebergPartitions method testHourTransform.
@Test
public void testHourTransform() throws IOException {
Schema schema = new Schema(optional(1, "id", Types.LongType.get()), optional(2, "part_field", Types.TimestampType.withoutZone()));
PartitionSpec spec = PartitionSpec.builderFor(schema).hour("part_field").build();
List<Record> records = TestHelper.RecordsBuilder.newInstance(schema).add(1L, LocalDateTime.of(2019, 2, 22, 9, 44, 54)).add(2L, LocalDateTime.of(2019, 2, 22, 10, 44, 54)).add(3L, LocalDateTime.of(2019, 2, 23, 9, 44, 54)).build();
Table table = testTables.createTable(shell, "part_test", schema, spec, fileFormat, records);
HiveIcebergTestUtils.validateData(table, records, 0);
HiveIcebergTestUtils.validateDataWithSQL(shell, "part_test", records, "id");
}
use of org.apache.iceberg.data.Record in project hive by apache.
the class TestHiveIcebergPartitions method testDayTransform.
@Test
public void testDayTransform() throws IOException {
Schema schema = new Schema(optional(1, "id", Types.LongType.get()), optional(2, "part_field", Types.TimestampType.withoutZone()));
PartitionSpec spec = PartitionSpec.builderFor(schema).day("part_field").build();
List<Record> records = TestHelper.RecordsBuilder.newInstance(schema).add(1L, LocalDateTime.of(2019, 2, 22, 9, 44, 54)).add(2L, LocalDateTime.of(2019, 2, 22, 10, 44, 54)).add(3L, LocalDateTime.of(2019, 2, 23, 9, 44, 54)).build();
Table table = testTables.createTable(shell, "part_test", schema, spec, fileFormat, records);
HiveIcebergTestUtils.validateData(table, records, 0);
HiveIcebergTestUtils.validateDataWithSQL(shell, "part_test", records, "id");
}
use of org.apache.iceberg.data.Record in project hive by apache.
the class TestHiveIcebergPartitions method testPartitionPruning.
@Test
public void testPartitionPruning() throws IOException {
Schema salesSchema = new Schema(required(1, "ss_item_sk", Types.IntegerType.get()), required(2, "ss_sold_date_sk", Types.IntegerType.get()));
PartitionSpec salesSpec = PartitionSpec.builderFor(salesSchema).identity("ss_sold_date_sk").build();
Schema dimSchema = new Schema(required(1, "d_date_sk", Types.IntegerType.get()), required(2, "d_moy", Types.IntegerType.get()));
List<Record> salesRecords = TestHelper.RecordsBuilder.newInstance(salesSchema).add(51, 5).add(61, 6).add(71, 7).add(81, 8).add(91, 9).build();
List<Record> dimRecords = TestHelper.RecordsBuilder.newInstance(salesSchema).add(1, 10).add(2, 20).add(3, 30).add(4, 40).add(5, 50).build();
Table salesTable = testTables.createTable(shell, "x1_store_sales", salesSchema, salesSpec, fileFormat, null);
PartitionKey partitionKey = new PartitionKey(salesSpec, salesSchema);
for (Record r : salesRecords) {
partitionKey.partition(r);
testTables.appendIcebergTable(shell.getHiveConf(), salesTable, fileFormat, partitionKey, ImmutableList.of(r));
}
testTables.createTable(shell, "x1_date_dim", dimSchema, fileFormat, dimRecords);
String query = "select s.ss_item_sk from x1_store_sales s, x1_date_dim d " + "where s.ss_sold_date_sk=d.d_date_sk*2 and d.d_moy=30";
// Check the query results
List<Object[]> rows = shell.executeStatement(query);
Assert.assertEquals(1, rows.size());
Assert.assertArrayEquals(new Object[] { 61 }, rows.get(0));
// Check if Dynamic Partitioning is used
Assert.assertTrue(shell.executeStatement("explain " + query).stream().filter(a -> ((String) a[0]).contains("Dynamic Partitioning Event Operator")).findAny().isPresent());
}
Aggregations