jackye1995 commented on a change in pull request #3455:
URL: https://github.com/apache/iceberg/pull/3455#discussion_r743307652
##########
File path:
spark/v3.0/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestAddFilesProcedure.java
##########
@@ -692,6 +692,61 @@ public void addOrcFileWithDoubleAndFloatColumns() throws
Exception {
expectedRecordCount, actualRecordCount);
}
+ @Test
+ public void emptyPathAndTableBasedImportsDoNotThrow() {
+
+ String createIceberg =
+ "CREATE TABLE %s (id Integer, name String, dept String, subdept
String) USING iceberg";
+ sql(createIceberg, tableName);
+
+ // Empty path based import
+ Object pathResult = scalarSql("CALL %s.system.add_files('%s',
'`parquet`.`%s`')",
+ catalogName, tableName, fileTableDir.getAbsolutePath());
+ Assert.assertEquals(0L, pathResult);
+ assertEquals("Iceberg table contains no added data when importing from an
empty path",
+ emptyQueryResult,
+ sql("SELECT * FROM %s ORDER BY id", tableName));
+
+ // Empty table based import
+ String createHive = "CREATE TABLE %s (id Integer, name String, dept
String, subdept String) STORED AS parquet";
+ sql(createHive, sourceTableName);
+
+ Object tableResult = scalarSql("CALL %s.system.add_files('%s', '%s')",
+ catalogName, tableName, sourceTableName);
+ Assert.assertEquals(0L, tableResult);
+ assertEquals("Iceberg table contains no added data when importing from an
empty table",
+ emptyQueryResult,
+ sql("SELECT * FROM %s ORDER BY id", tableName));
+ }
+
+ @Test
+ public void partitionedImportFromEmptyPartitionDoesNotThrow() {
+ createPartitionedHiveTable();
+
+ final int emptyPartitionId = 999;
+ // Add an empty partition to the hive table
+ sql("ALTER TABLE %s ADD PARTITION (id = '%d') LOCATION '%d'",
sourceTableName,
+ emptyPartitionId, emptyPartitionId);
+
+ String createIceberg =
+ "CREATE TABLE %s (id Integer, name String, dept String, subdept
String) USING iceberg PARTITIONED BY (id)";
+
+ sql(createIceberg, tableName);
+
+ Object tableResult = scalarSql("CALL %s.system.add_files(" +
+ "table => '%s', " +
+ "source_table => '%s', " +
+ "partition_filter => map('id', %d))",
+ catalogName, tableName, sourceTableName, emptyPartitionId);
+
+ Assert.assertEquals(0L, tableResult);
+ assertEquals("Iceberg table contains no added data when importing from an
empty table",
+ emptyQueryResult,
+ sql("SELECT * FROM %s ORDER BY id", tableName));
+ }
+
+ private static final List<Object[]> emptyQueryResult = Lists.newArrayList();
Review comment:
nit: static variables should be at the top of class. (things below
should technically also be moved to the top, but don't need to be in this PR)
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]