marton-bod commented on a change in pull request #2243:
URL: https://github.com/apache/hive/pull/2243#discussion_r635166430



##########
File path: 
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergStorageHandlerWithEngine.java
##########
@@ -514,6 +519,75 @@ public void testInsertOverwritePartitionedTable() throws 
IOException {
     HiveIcebergTestUtils.validateData(table, expected, 0);
   }
 
+  @Test
+  public void testCTASFromHiveTable() {
+    Assume.assumeTrue("CTAS target table is supported only for HiveCatalog 
tables",
+        testTableType == TestTables.TestTableType.HIVE_CATALOG);
+
+    shell.executeStatement("CREATE TABLE source (id bigint, name string) 
PARTITIONED BY (dept string) STORED AS ORC");
+    shell.executeStatement("INSERT INTO source VALUES (1, 'Mike', 'HR'), (2, 
'Linda', 'Finance')");
+
+    shell.executeStatement(String.format(
+        "CREATE TABLE target STORED BY '%s' %s TBLPROPERTIES ('%s'='%s') AS 
SELECT * FROM source",
+        HiveIcebergStorageHandler.class.getName(),
+        testTables.locationForCreateTableSQL(TableIdentifier.of("default", 
"target")),
+        TableProperties.DEFAULT_FILE_FORMAT, fileFormat));
+
+    List<Object[]> objects = shell.executeStatement("SELECT * FROM target 
ORDER BY id");
+    Assert.assertEquals(2, objects.size());
+    Assert.assertArrayEquals(new Object[]{1L, "Mike", "HR"}, objects.get(0));
+    Assert.assertArrayEquals(new Object[]{2L, "Linda", "Finance"}, 
objects.get(1));
+  }
+
+  @Test
+  public void testCTASFromDifferentIcebergCatalog() {
+    Assume.assumeTrue("CTAS target table is supported only for HiveCatalog 
tables",
+        testTableType == TestTables.TestTableType.HIVE_CATALOG);
+
+    // get source data from a different catalog
+    shell.executeStatement(String.format(
+        "CREATE TABLE source STORED BY '%s' LOCATION '%s' TBLPROPERTIES 
('%s'='%s', '%s'='%s')",
+        HiveIcebergStorageHandler.class.getName(),
+        temp.getRoot().getPath() + "/default/source/",
+        InputFormatConfig.CATALOG_NAME, Catalogs.ICEBERG_HADOOP_TABLE_NAME,
+        InputFormatConfig.TABLE_SCHEMA, 
SchemaParser.toJson(HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA)));
+    shell.executeStatement("INSERT INTO source VALUES (1, 'Mike', 'Roger'), 
(2, 'Linda', 'Albright')");
+
+    // CTAS into a new HiveCatalog table
+    shell.executeStatement(String.format(
+        "CREATE TABLE target STORED BY '%s' TBLPROPERTIES ('%s'='%s') AS 
SELECT * FROM source",
+        HiveIcebergStorageHandler.class.getName(),
+        TableProperties.DEFAULT_FILE_FORMAT, fileFormat));
+
+    List<Object[]> objects = shell.executeStatement("SELECT * FROM target 
ORDER BY customer_id");
+    Assert.assertEquals(2, objects.size());
+    Assert.assertArrayEquals(new Object[]{1L, "Mike", "Roger"}, 
objects.get(0));
+    Assert.assertArrayEquals(new Object[]{2L, "Linda", "Albright"}, 
objects.get(1));
+  }
+
+  @Test
+  public void testCTASFailureRollback() throws IOException {

Review comment:
       Sure!




-- 
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]

Reply via email to