aokolnychyi commented on a change in pull request #2087:
URL: https://github.com/apache/iceberg/pull/2087#discussion_r558408339
##########
File path:
spark3/src/test/java/org/apache/iceberg/actions/TestCreateActions.java
##########
@@ -157,6 +168,105 @@ public void testMigratePartitioned() throws Exception {
assertMigratedFileCount(Actions.migrate(source), source, dest);
}
+ @Test
+ public void testPartitionedTableWithUnRecoveredPartitions() throws Exception
{
+ Assume.assumeTrue("Cannot migrate to a hadoop based catalog",
!type.equals("hadoop"));
+ Assume.assumeTrue("Can only migrate from Spark Session Catalog",
catalog.name().equals("spark_catalog"));
+ String source = sourceName("test_unrecovered_partitions");
+ String dest = source;
+ File location = temp.newFolder();
+ spark.sql(String.format(CREATE_PARTITIONED_PARQUET, source, location));
+ spark.range(5)
+ .selectExpr("id", "cast(id as STRING) as data")
+ .write()
+ .partitionBy("id").mode("overwrite")
+ .parquet(location.toURI().toString());
+ spark.sql(String.format("alter table %s add partition(id=0)", source));
+ assertMigratedFileCount(Actions.migrate(source), source, dest);
+ }
+
+ @Test
+ public void testPartitionedTableWithCustomPartitions() throws Exception {
+ Assume.assumeTrue("Cannot migrate to a hadoop based catalog",
!type.equals("hadoop"));
+ Assume.assumeTrue("Can only migrate from Spark Session Catalog",
catalog.name().equals("spark_catalog"));
+ String source = sourceName("test_custom_parts");
+ String dest = source;
+ File tblLocation = temp.newFolder();
+ File partitionDataLoc = temp.newFolder();
+ spark.sql(String.format(CREATE_PARTITIONED_PARQUET, source, tblLocation));
+ spark.range(10)
+ .selectExpr("cast(id as STRING) as data")
+ .write()
+ .mode("overwrite").parquet(partitionDataLoc.toURI().toString());
+ spark.sql(String.format("alter table %s add partition(id=0) LOCATION
'%s'", source,
+ partitionDataLoc.toURI().toString()));
+ assertMigratedFileCount(Actions.migrate(source), source, dest);
+ }
+
+
+ @Test
+ public void testAddColumnOnMigratedTable() throws Exception {
+ Assume.assumeTrue("Cannot migrate to a hadoop based catalog",
!type.equals("hadoop"));
+ Assume.assumeTrue("Can only migrate from Spark Session Catalog",
catalog.name().equals("spark_catalog"));
+ String source = sourceName("test_add_column_migrated_table");
+ String dest = source;
+ createSourceTable(CREATE_PARQUET, source);
+ Actions.migrate(source).execute();
+ SparkTable sparkTable = loadTable(dest);
+ Table table = sparkTable.table();
+
+ // test column addition on migrated table
+ Schema beforeSchema = table.schema();
+ String colName = "newCol";
+ sparkTable.table().updateSchema().addColumn("newCol",
Types.IntegerType.get()).commit();
+ Schema afterSchema = table.schema();
+ Assert.assertNull(beforeSchema.findField(colName));
+ Assert.assertNotNull(afterSchema.findField(colName));
+ // reads should succeed without any exceptions
+ spark.table(dest).collect();
+
+ colName = "newCol1";
+ spark.sql(String.format("ALTER TABLE %s ADD COLUMN %s INT", dest,
colName)).collect();
+ StructType schema = spark.table(dest).schema();
+ Assert.assertTrue(Arrays.asList(schema.fieldNames()).contains(colName));
+ // reads should succeed without any exceptions
+ spark.table(dest).collect();
Review comment:
Should validate the output too.
----------------------------------------------------------------
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]