use of org.apache.iceberg.data.GenericRecord in project hive by apache.
the class TestHiveIcebergTypes method testStructOfMapsInTable.
@Test
public void testStructOfMapsInTable() throws IOException {
Schema schema = new Schema(required(1, "structofmaps", Types.StructType.of(required(2, "map1", Types.MapType.ofRequired(3, 4, Types.StringType.get(), Types.StringType.get())), required(5, "map2", Types.MapType.ofRequired(6, 7, Types.StringType.get(), Types.IntegerType.get())))));
List<Record> records = testTables.createTableWithGeneratedRecords(shell, "structtable", schema, fileFormat, 1);
// access a map entry inside a struct
for (int i = 0; i < records.size(); i++) {
GenericRecord expectedStruct = (GenericRecord) records.get(i).getField("structofmaps");
Map<?, ?> expectedMap = (Map<?, ?>) expectedStruct.getField("map1");
for (Map.Entry<?, ?> entry : expectedMap.entrySet()) {
List<Object[]> queryResult = shell.executeStatement(String.format("SELECT structofmaps.map1[\"%s\"] from default.structtable LIMIT 1 OFFSET %d", entry.getKey(), i));
Assert.assertEquals(entry.getValue(), queryResult.get(0)[0]);
}
expectedMap = (Map<?, ?>) expectedStruct.getField("map2");
for (Map.Entry<?, ?> entry : expectedMap.entrySet()) {
List<Object[]> queryResult = shell.executeStatement(String.format("SELECT structofmaps.map2[\"%s\"] from default.structtable LIMIT 1 OFFSET %d", entry.getKey(), i));
Assert.assertEquals(entry.getValue(), queryResult.get(0)[0]);
}
}
}
use of org.apache.iceberg.data.GenericRecord in project hive by apache.
the class TestHiveIcebergTypes method testStructOfStructsInTable.
@Test
public void testStructOfStructsInTable() throws IOException {
Schema schema = new Schema(required(1, "structofstructs", Types.StructType.of(required(2, "struct1", Types.StructType.of(required(3, "key", Types.StringType.get()), required(4, "value", Types.IntegerType.get()))))));
List<Record> records = testTables.createTableWithGeneratedRecords(shell, "structtable", schema, fileFormat, 1);
// access a struct element inside a struct
for (int i = 0; i < records.size(); i++) {
GenericRecord expectedStruct = (GenericRecord) records.get(i).getField("structofstructs");
GenericRecord expectedInnerStruct = (GenericRecord) expectedStruct.getField("struct1");
List<Object[]> queryResult = shell.executeStatement(String.format("SELECT structofstructs.struct1.key, structofstructs.struct1.value FROM default.structtable " + "LIMIT 1 OFFSET %d", i));
Assert.assertEquals(expectedInnerStruct.getField("key"), queryResult.get(0)[0]);
Assert.assertEquals(expectedInnerStruct.getField("value"), queryResult.get(0)[1]);
}
}
Aggregations