rdblue commented on a change in pull request #2038:
URL: https://github.com/apache/iceberg/pull/2038#discussion_r559049940
##########
File path:
mr/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergStorageHandlerWithEngine.java
##########
@@ -256,4 +265,293 @@ public void testSelectDistinctFromTable() throws
IOException {
Assert.assertEquals(tableName, size, distinctIds);
}
}
+
+ @Test
+ public void testInsert() throws IOException {
+ Assume.assumeTrue("Tez write is not implemented yet",
executionEngine.equals("mr"));
+
+ 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, new
ArrayList<>(HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS), 0);
+ }
+
+ @Test
+ public void testInsertFromSelect() throws IOException {
+ Assume.assumeTrue("Tez write is not implemented yet",
executionEngine.equals("mr"));
+
+ Table table = testTables.createTable(shell, "customers",
HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA,
+ fileFormat, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS);
+
+ shell.executeStatement("INSERT INTO customers SELECT * FROM customers");
+
+ // 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);
+ }
+
+ @Test
+ public void testInsertFromSelectWithOrderBy() throws IOException {
+ Assume.assumeTrue("Tez write is not implemented yet",
executionEngine.equals("mr"));
+
+ // We expect that there will be Mappers and Reducers here
+ Table table = testTables.createTable(shell, "customers",
HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA,
+ fileFormat, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS);
+
+ 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);
+ }
+
+ @Test
+ public void testWriteArrayOfPrimitivesInTable() throws IOException {
+ Assume.assumeTrue("Tez write is not implemented yet",
executionEngine.equals("mr"));
+ Schema schema = new Schema(required(1, "id", Types.LongType.get()),
+ required(2, "arrayofprimitives",
+ Types.ListType.ofRequired(3, Types.StringType.get())));
+ List<Record> records = TestHelper.generateRandomRecords(schema, 5, 0L);
+ testComplexTypeWrite(schema, records);
+ }
+
+ @Test
+ public void testWriteArrayOfArraysInTable() throws IOException {
+ Assume.assumeTrue("Tez write is not implemented yet",
executionEngine.equals("mr"));
+ Schema schema =
+ new Schema(
+ required(1, "id", Types.LongType.get()),
+ required(2, "arrayofarrays",
+ Types.ListType.ofRequired(3, Types.ListType.ofRequired(4,
Types.StringType.get()))));
+ List<Record> records = TestHelper.generateRandomRecords(schema, 5,
0L).stream()
+ .filter(r -> !((List<String>)
r.get(1)).isEmpty()).collect(Collectors.toList());
+ testComplexTypeWrite(schema, records);
+ }
+
+ @Test
+ public void testWriteArrayOfMapsInTable() throws IOException {
+ Assume.assumeTrue("Tez write is not implemented yet",
executionEngine.equals("mr"));
+ Schema schema =
+ new Schema(required(1, "id", Types.LongType.get()),
+ required(2, "arrayofmaps", Types.ListType
+ .ofRequired(3, Types.MapType.ofRequired(4, 5,
Types.StringType.get(),
+ Types.StringType.get()))));
+ List<Record> records = TestHelper.generateRandomRecords(schema, 5,
0L).stream()
+ .filter(r -> !((List<Map<String, String>>)
r.get(1)).isEmpty()).collect(Collectors.toList());
+ testComplexTypeWrite(schema, records);
+ }
+
+ @Test
+ public void testWriteArrayOfStructsInTable() throws IOException {
+ Assume.assumeTrue("Tez write is not implemented yet",
executionEngine.equals("mr"));
+ Schema schema =
+ new Schema(required(1, "id", Types.LongType.get()),
+ required(2, "arrayofstructs", Types.ListType.ofRequired(3,
Types.StructType
+ .of(required(4, "something", Types.StringType.get()),
required(5, "someone",
+ Types.StringType.get()), required(6, "somewhere",
Types.StringType.get())))));
+ List<Record> records = TestHelper.generateRandomRecords(schema, 5,
0L).stream()
+ .filter(r -> !((List<?>)
r.get(1)).isEmpty()).collect(Collectors.toList());
+ testComplexTypeWrite(schema, records);
+ }
+
+ @Test
+ public void testWriteMapOfPrimitivesInTable() throws IOException {
+ Assume.assumeTrue("Tez write is not implemented yet",
executionEngine.equals("mr"));
+ Schema schema = new Schema(required(1, "id", Types.LongType.get()),
+ required(2, "mapofprimitives", Types.MapType.ofRequired(3, 4,
Types.StringType.get(),
+ Types.StringType.get())));
+ List<Record> records = TestHelper.generateRandomRecords(schema, 5,
0L).stream()
+ .filter(r -> !((Map<String, String>)
r.get(1)).isEmpty()).collect(Collectors.toList());
+ testComplexTypeWrite(schema, records);
+ }
+
+ @Test
+ public void testWriteMapOfArraysInTable() throws IOException {
+ Assume.assumeTrue("Tez write is not implemented yet",
executionEngine.equals("mr"));
+ Schema schema = new Schema(required(1, "id", Types.LongType.get()),
+ required(2, "mapofarrays",
+ Types.MapType.ofRequired(3, 4, Types.StringType.get(),
Types.ListType.ofRequired(5,
+ Types.StringType.get()))));
+ List<Record> records = TestHelper.generateRandomRecords(schema, 5,
0L).stream()
+ .filter(r -> !((Map<String, List<String>>)
r.get(1)).isEmpty()).collect(Collectors.toList());
+ testComplexTypeWrite(schema, records);
+ }
+
+ @Test
+ public void testWriteMapOfMapsInTable() throws IOException {
+ Assume.assumeTrue("Tez write is not implemented yet",
executionEngine.equals("mr"));
+ Schema schema = new Schema(required(1, "id", Types.LongType.get()),
+ required(2, "mapofmaps", Types.MapType.ofRequired(3, 4,
Types.StringType.get(),
+ Types.MapType.ofRequired(5, 6, Types.StringType.get(),
Types.StringType.get()))));
+ List<Record> records = TestHelper.generateRandomRecords(schema, 5,
0L).stream()
+ .filter(r -> !((Map<String, Map<String, String>>)
r.get(1)).isEmpty()).collect(Collectors.toList());
+ testComplexTypeWrite(schema, records);
+ }
+
+ @Test
+ public void testWriteMapOfStructsInTable() throws IOException {
+ Assume.assumeTrue("Tez write is not implemented yet",
executionEngine.equals("mr"));
+ Schema schema = new Schema(required(1, "id", Types.LongType.get()),
+ required(2, "mapofstructs", Types.MapType.ofRequired(3, 4,
Types.StringType.get(),
+ Types.StructType.of(required(5, "something",
Types.StringType.get()),
+ required(6, "someone", Types.StringType.get()),
+ required(7, "somewhere", Types.StringType.get())))));
+ List<Record> records = TestHelper.generateRandomRecords(schema, 5,
0L).stream()
+ .filter(r -> !((Map<String, GenericRecord>)
r.get(1)).isEmpty()).collect(Collectors.toList());
Review comment:
Why are these filters needed in the complex type cases?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]