You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "nastra (via GitHub)" <gi...@apache.org> on 2023/03/02 14:26:52 UTC

[GitHub] [iceberg] nastra commented on a diff in pull request #6984: Core: Allow dropping columns referenced in old sort orders

nastra commented on code in PR #6984:
URL: https://github.com/apache/iceberg/pull/6984#discussion_r1123158985


##########
spark/v3.3/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestAlterSortOrder.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.spark.extensions;
+
+import java.util.Map;
+import org.apache.iceberg.Table;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestAlterSortOrder extends SparkExtensionsTestBase {
+  public TestAlterSortOrder(String catalogName, String implementation, Map<String, String> config) {
+    super(catalogName, implementation, config);
+  }
+
+  @After
+  public void removeTable() {
+    sql("DROP TABLE IF EXISTS %s", tableName);
+  }
+
+  @Test
+  public void testDeleteColumnFromOldSortOrder() {
+    sql(
+        "CREATE TABLE %s (id bigint NOT NULL, category string, ts timestamp, data string) USING iceberg",
+        tableName);
+    Table table = validationCatalog.loadTable(tableIdent);
+
+    Assert.assertTrue("Table should start unsorted", table.sortOrder().isUnsorted());
+
+    sql("ALTER TABLE %s WRITE ORDERED BY ts", tableName);
+
+    table.refresh();
+
+    Assert.assertEquals("Should have two sort orders", 2, table.sortOrders().size());
+    Assert.assertEquals(
+        "Expected identity sort order on ts",
+        "[\n" + "  identity(3) ASC NULLS FIRST\n" + "]",
+        table.sortOrders().get(1).toString());
+
+    sql("ALTER TABLE %s WRITE ORDERED BY id", tableName);
+
+    table.refresh();
+
+    Assert.assertEquals("Should have three sort orders", 3, table.sortOrders().size());
+    Assert.assertEquals(
+        "Expected identity sort order on id",
+        "[\n" + "  identity(1) ASC NULLS FIRST\n" + "]",
+        table.sortOrders().get(2).toString());
+
+    sql("ALTER TABLE %s DROP COLUMN ts", tableName);
+
+    table.refresh();

Review Comment:
   this one is probably not needed



##########
core/src/test/java/org/apache/iceberg/util/TestSortOrderUtil.java:
##########
@@ -303,4 +305,35 @@ public void testSortOrderClusteringWithRedundantPartitionFieldsMissing() {
         expected,
         SortOrderUtil.buildSortOrder(table.schema(), updatedSpec, order));
   }
+
+  @Test
+  public void testDropColumnFromDefaultSortOrder() {

Review Comment:
   btw, both tests are passing for me without the fix



##########
core/src/test/java/org/apache/iceberg/util/TestSortOrderUtil.java:
##########
@@ -303,4 +305,35 @@ public void testSortOrderClusteringWithRedundantPartitionFieldsMissing() {
         expected,
         SortOrderUtil.buildSortOrder(table.schema(), updatedSpec, order));
   }
+
+  @Test
+  public void testDropColumnFromDefaultSortOrder() {
+    TestTables.TestTable table =
+        TestTables.create(
+            tableDir, "test", SCHEMA, PartitionSpec.unpartitioned(), SortOrder.unsorted(), 1);
+    table.replaceSortOrder().asc("ts").commit();
+
+    AssertHelpers.assertThrows(

Review Comment:
   nit: I've been trying to steer people away from using `AssertHelpers` (https://github.com/apache/iceberg/pull/6977), so this could be rewritten as
   ```
   Assertions.assertThatThrownBy(() -> table.updateSchema().deleteColumn("ts").commit())
           .isInstanceOf(ValidationException.class)
           .hasMessage("Cannot find source column for sort field: identity(3) ASC NULLS FIRST");
   ```



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org