This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new a451e24bc [core][schema] Reassign field id for nested row type (#1643)
a451e24bc is described below

commit a451e24bc16c4b11c5126836badd26a2f3c29901
Author: Shammon FY <[email protected]>
AuthorDate: Tue Jul 25 09:19:21 2023 +0800

    [core][schema] Reassign field id for nested row type (#1643)
---
 .../org/apache/paimon/types/ReassignFieldId.java   |  3 +-
 .../apache/paimon/types/ReassignFieldIdTest.java   | 54 ++++++++++++++++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)

diff --git 
a/paimon-common/src/main/java/org/apache/paimon/types/ReassignFieldId.java 
b/paimon-common/src/main/java/org/apache/paimon/types/ReassignFieldId.java
index b102fa22e..36e4d8607 100644
--- a/paimon-common/src/main/java/org/apache/paimon/types/ReassignFieldId.java
+++ b/paimon-common/src/main/java/org/apache/paimon/types/ReassignFieldId.java
@@ -55,7 +55,8 @@ public class ReassignFieldId extends 
DataTypeDefaultVisitor<DataType> {
     @Override
     public DataType visit(RowType rowType) {
         RowType.Builder builder = RowType.builder(rowType.isNullable(), 
fieldId);
-        rowType.getFields().forEach(f -> builder.field(f.name(), f.type(), 
f.description()));
+        rowType.getFields()
+                .forEach(f -> builder.field(f.name(), f.type().accept(this), 
f.description()));
         return builder.build();
     }
 
diff --git 
a/paimon-common/src/test/java/org/apache/paimon/types/ReassignFieldIdTest.java 
b/paimon-common/src/test/java/org/apache/paimon/types/ReassignFieldIdTest.java
new file mode 100644
index 000000000..194581585
--- /dev/null
+++ 
b/paimon-common/src/test/java/org/apache/paimon/types/ReassignFieldIdTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.paimon.types;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link ReassignFieldId}. */
+public class ReassignFieldIdTest {
+    @Test
+    void testReassignNestRowType() {
+        RowType rowType =
+                RowType.builder()
+                        .field(
+                                "a",
+                                RowType.builder()
+                                        .field(
+                                                "b",
+                                                RowType.builder()
+                                                        .field("c", 
DataTypes.INT())
+                                                        .build())
+                                        .build())
+                        .field("d", DataTypes.INT())
+                        .build();
+        ReassignFieldId reassignFieldId = new ReassignFieldId(new 
AtomicInteger(2));
+        DataType resultDataType = reassignFieldId.visit(rowType);
+
+        Set<Integer> fieldIds = new HashSet<>();
+        resultDataType.collectFieldIds(fieldIds);
+        assertThat(fieldIds).isEqualTo(new HashSet<>(Arrays.asList(3, 4, 5, 
6)));
+    }
+}

Reply via email to