rdblue commented on a change in pull request #3421:
URL: https://github.com/apache/iceberg/pull/3421#discussion_r739885228



##########
File path: 
spark/v3.0/spark/src/test/java/org/apache/iceberg/spark/sql/TestCreateTableAsSelect.java
##########
@@ -311,4 +314,54 @@ public void testDataFrameV2CreateOrReplace() {
     Assert.assertEquals("Table should have expected snapshots",
         2, Iterables.size(rtasTable.snapshots()));
   }
+
+  @Test
+  public void testCreateRTASWithPartitionSpecChanging() throws 
NoSuchTableException, ParseException {
+    sql("CREATE OR REPLACE TABLE %s USING iceberg PARTITIONED BY (part) AS " +
+            "SELECT id, data, CASE WHEN (id %% 2) = 0 THEN 'even' ELSE 'odd' 
END AS part " +
+            "FROM %s ORDER BY 3, 1", tableName, sourceName);
+
+    Table table  = Spark3Util.loadIcebergTable(spark, tableName);
+
+    assertEquals("Should have rows matching the source table",
+            sql("SELECT id, data, CASE WHEN (id %% 2) = 0 THEN 'even' ELSE 
'odd' END AS part " +
+                    "FROM %s ORDER BY id", sourceName),
+            sql("SELECT * FROM %s ORDER BY id", tableName));
+
+    // Change the partitioning of the table
+    table.updateSpec().removeField("part").commit(); // Spec 1
+    table.updateSpec().addField("id").commit(); // Spec 2
+
+    sql("CREATE OR REPLACE TABLE %s USING iceberg PARTITIONED BY (part, id) AS 
" +
+            "SELECT 2 * id as id, data, CASE WHEN ((2 * id) %% 2) = 0 THEN 
'even' ELSE 'odd' END AS part " +
+            "FROM %s ORDER BY 3, 1", tableName, sourceName);
+
+    Schema expectedSchema = new Schema(
+            Types.NestedField.optional(1, "id", Types.LongType.get()),
+            Types.NestedField.optional(2, "data", Types.StringType.get()),
+            Types.NestedField.optional(3, "part", Types.StringType.get())
+    );
+
+    PartitionSpec expectedSpec = PartitionSpec.builderFor(expectedSchema)
+            .identity("part")

Review comment:
       Why not `alwaysNull` here?




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

Reply via email to