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 2024/04/30 10:26:43 UTC

[PR] Core: Assign fresh IDs to view schema [iceberg]

nastra opened a new pull request, #10253:
URL: https://github.com/apache/iceberg/pull/10253

   (no comment)


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


Re: [PR] Core: Assign fresh IDs to view schema [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #10253:
URL: https://github.com/apache/iceberg/pull/10253#discussion_r1877468569


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -1341,6 +1343,8 @@ public View create() {
       Preconditions.checkState(
           null != defaultNamespace, "Cannot create view without specifying a default namespace");
 
+      this.schema = TypeUtil.assignFreshIds(schema, new AtomicInteger(0)::incrementAndGet);

Review Comment:
   yes you're right. One of the issues was that there wasn't a straightforward way inside `ViewMetadata` of detecting  whether `ViewMetadata` is created the first time or replaced. I think we can actually use the `history` field (or alternatively introduce a new field) to detect whether the view is created/replaced. I've updated the code so that no additional changes outside of `ViewMetadata` are required (and also moved the tests now into `TestViewMetadata`



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


Re: [PR] Core: Assign fresh IDs to view schema [iceberg]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10253:
URL: https://github.com/apache/iceberg/pull/10253#issuecomment-2452745478

   This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.


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


Re: [PR] Core: Assign fresh IDs to view schema [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra closed pull request #10253: Core: Assign fresh IDs to view schema
URL: https://github.com/apache/iceberg/pull/10253


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


Re: [PR] Core: Assign fresh IDs to view schema [iceberg]

Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #10253:
URL: https://github.com/apache/iceberg/pull/10253#discussion_r1875107084


##########
spark/v3.5/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestViews.java:
##########
@@ -1798,8 +1798,9 @@ public void createOrReplaceViewKeepsViewHistory() {
     assertThat(view.schema().asStruct())
         .isEqualTo(
             new Schema(
-                    Types.NestedField.optional(0, "new_id", Types.IntegerType.get(), "some ID"),
-                    Types.NestedField.optional(1, "new_data", Types.StringType.get(), "some data"))
+                    0,
+                    Types.NestedField.optional(1, "new_id", Types.IntegerType.get(), "some ID"),
+                    Types.NestedField.optional(2, "new_data", Types.StringType.get(), "some data"))

Review Comment:
   So the first field ID changed to 1 because `highestFieldId` is set to 0 and then incremented when assigning the new IDs? This should be fine and aligns with whatever we do for tables. It also does not impact existing views because we're assigning the fresh IDs from a higher field ID 



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


Re: [PR] Core: Assign fresh IDs to view schema [iceberg]

Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #10253:
URL: https://github.com/apache/iceberg/pull/10253#discussion_r1876428234


##########
core/src/test/java/org/apache/iceberg/view/TestViewUtil.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.view;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.Test;
+
+public class TestViewUtil {
+
+  @Test
+  public void assignFreshSchemaIdWhereNewSchemasFieldIdIsSmallerThanHighestFieldId() {
+    Schema schemaOne = new Schema(Types.NestedField.required(1, "x", Types.LongType.get()));
+    Schema schemaTwo = new Schema(Types.NestedField.required(2, "y", Types.LongType.get()));
+    Schema schemaThree = new Schema(Types.NestedField.required(3, "z", Types.LongType.get()));
+    Schema newSchema = new Schema(Types.NestedField.required(1, "a", Types.LongType.get()));
+
+    ViewMetadata metadata =
+        ViewMetadata.builder()
+            .setLocation("custom-location")
+            .addSchema(schemaOne)
+            .addSchema(schemaTwo)
+            .addSchema(schemaThree)
+            .setCurrentVersion(
+                ImmutableViewVersion.builder()
+                    .versionId(1)
+                    .schemaId(0)
+                    .timestampMillis(System.currentTimeMillis())
+                    .defaultNamespace(Namespace.empty())
+                    .build(),
+                schemaOne)
+            .build();
+
+    newSchema = ViewUtil.assignFreshIds(metadata, newSchema);

Review Comment:
   This test demonstrates the problem that I pointed out above. It is necessary to construct a fake `ViewMetadata` to test the method.



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


Re: [PR] Core: Assign fresh IDs to view schema [iceberg]

Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #10253:
URL: https://github.com/apache/iceberg/pull/10253#discussion_r1876379535


##########
core/src/main/java/org/apache/iceberg/view/ViewUtil.java:
##########
@@ -18,12 +18,34 @@
  */
 package org.apache.iceberg.view;
 
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.iceberg.Schema;
 import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.types.TypeUtil;
 
 public class ViewUtil {
   private ViewUtil() {}
 
   public static String fullViewName(String catalog, TableIdentifier ident) {
     return catalog + "." + ident;
   }
+
+  public static Schema assignFreshIds(ViewMetadata base, Schema newSchema) {

Review Comment:
   I think that the current arguments to this method pass too much state. Utility methods should require a minimal amount of information so it is clear what they depend on when called. Rather than passing the entire `ViewMetadata`, this method should accept `newSchema`, the base schema, and the highest field ID.
   
   I'm also not sure that it makes sense to have a util method that just calls another util method, `TypeUtil.assignFreshIds`. I think once you apply the principle of passing minimal state, you basically end up with a wrapper around the `TypeUtil` method that creates an atomic integer.



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


Re: [PR] Core: Assign fresh IDs to view schema [iceberg]

Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #10253:
URL: https://github.com/apache/iceberg/pull/10253#discussion_r1876380842


##########
core/src/main/java/org/apache/iceberg/view/ViewUtil.java:
##########
@@ -18,12 +18,34 @@
  */
 package org.apache.iceberg.view;
 
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.iceberg.Schema;
 import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.types.TypeUtil;
 
 public class ViewUtil {
   private ViewUtil() {}
 
   public static String fullViewName(String catalog, TableIdentifier ident) {
     return catalog + "." + ident;
   }
+
+  public static Schema assignFreshIds(ViewMetadata base, Schema newSchema) {
+    return TypeUtil.assignFreshIds(
+        newSchema,
+        base.schema(),
+        new AtomicInteger(highestFieldId(base.schemas()))::incrementAndGet);
+  }
+
+  public static int maxVersionId(ViewMetadata metadata) {

Review Comment:
   This method has the same issue. Instead of passing `ViewMetadata`, it should accept `Collection<ViewVersion>`.



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


Re: [PR] Core: Assign fresh IDs to view schema [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #10253:
URL: https://github.com/apache/iceberg/pull/10253#discussion_r1584840748


##########
core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java:
##########
@@ -52,8 +52,27 @@ public abstract class ViewCatalogTests<C extends ViewCatalog & SupportsNamespace
           required(3, "id", Types.IntegerType.get(), "unique ID"),
           required(4, "data", Types.StringType.get()));
 
+  // actual schema for the view, with column IDs reassigned
+  protected static final Schema VIEW_SCHEMA =
+      new Schema(
+          0,
+          required(1, "id", Types.IntegerType.get(), "unique ID"),
+          required(2, "data", Types.StringType.get()));
+
   private static final Schema OTHER_SCHEMA =
-      new Schema(7, required(1, "some_id", Types.IntegerType.get()));
+      new Schema(

Review Comment:
   changing this to show that the new column get's a re-assigned column ID



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


Re: [PR] Core: Assign fresh IDs to view schema [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #10253:
URL: https://github.com/apache/iceberg/pull/10253#discussion_r1875960542


##########
spark/v3.5/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestViews.java:
##########
@@ -1798,8 +1798,9 @@ public void createOrReplaceViewKeepsViewHistory() {
     assertThat(view.schema().asStruct())
         .isEqualTo(
             new Schema(
-                    Types.NestedField.optional(0, "new_id", Types.IntegerType.get(), "some ID"),
-                    Types.NestedField.optional(1, "new_data", Types.StringType.get(), "some data"))
+                    0,
+                    Types.NestedField.optional(1, "new_id", Types.IntegerType.get(), "some ID"),
+                    Types.NestedField.optional(2, "new_data", Types.StringType.get(), "some data"))

Review Comment:
   yes correct, that's exactly how it is done



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


Re: [PR] Core: Assign fresh IDs to view schema [iceberg]

Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #10253:
URL: https://github.com/apache/iceberg/pull/10253#discussion_r1877460844


##########
core/src/main/java/org/apache/iceberg/view/ViewUtil.java:
##########
@@ -18,12 +18,34 @@
  */
 package org.apache.iceberg.view;
 
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.iceberg.Schema;
 import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.types.TypeUtil;
 
 public class ViewUtil {
   private ViewUtil() {}
 
   public static String fullViewName(String catalog, TableIdentifier ident) {
     return catalog + "." + ident;
   }
+
+  public static Schema assignFreshIds(ViewMetadata base, Schema newSchema) {
+    return TypeUtil.assignFreshIds(
+        newSchema,
+        base.schema(),
+        new AtomicInteger(highestFieldId(base.schemas()))::incrementAndGet);
+  }
+
+  public static int maxVersionId(ViewMetadata metadata) {

Review Comment:
   I've removed this refactoring around `maxVersionId` for now since assigning fresh ids moved into `ViewMetadata` and it didn't seem appropriate anymore to include this refactoring (I'll open a separate PR for this)



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


Re: [PR] Core: Assign fresh IDs to view schema [iceberg]

Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #10253:
URL: https://github.com/apache/iceberg/pull/10253#discussion_r1876425086


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -1341,6 +1343,8 @@ public View create() {
       Preconditions.checkState(
           null != defaultNamespace, "Cannot create view without specifying a default namespace");
 
+      this.schema = TypeUtil.assignFreshIds(schema, new AtomicInteger(0)::incrementAndGet);

Review Comment:
   It looks like this is being done in the wrong place because we need to assign fresh IDs in both the REST catalog here and in `BaseMetastoreViewCatalog`. We don't want to create a situation where implementations need to know to assign fresh IDs.
   
   For tables, the initial assignment is done in `TableMetadata.newTableMetadata` and the reassignment for replace happens in `TableMetadata.buildReplacement`. Views should have a similar approach, where creating a replacement `ViewMetadata` automatically handles the reassignment so callers don't need to know and do it manually.



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