CheneyYin commented on code in PR #7283:
URL: https://github.com/apache/seatunnel/pull/7283#discussion_r1699461739


##########
seatunnel-translation/seatunnel-translation-spark/seatunnel-translation-spark-common/src/main/java/org/apache/seatunnel/translation/spark/serialization/InternalRowConverter.java:
##########
@@ -213,9 +245,27 @@ private static MutableValue 
createMutableValue(SeaTunnelDataType<?> dataType) {
         }
     }
 
+    public SeaTunnelRow unpack(InternalRow engineRow, SeaTunnelRowType 
rowType) throws IOException {
+        RowKind rowKind = RowKind.fromByteValue(engineRow.getByte(0));
+        String tableId = engineRow.getString(1);
+        Object[] fields = new Object[indexes.length];
+        for (int i = 0; i < indexes.length; i++) {
+            fields[i] =
+                    reconvert(
+                            engineRow.get(
+                                    indexes[i] + 2,
+                                    
TypeConverterUtils.convert(rowType.getFieldType(indexes[i]))),
+                            rowType.getFieldType(indexes[i]));
+        }
+        SeaTunnelRow seaTunnelRow = new SeaTunnelRow(fields);
+        seaTunnelRow.setRowKind(rowKind);
+        seaTunnelRow.setTableId(tableId);
+        return seaTunnelRow;
+    }
+
     @Override
     public SeaTunnelRow reconvert(InternalRow engineRow) throws IOException {
-        return (SeaTunnelRow) reconvert(engineRow, dataType);
+        return unpack(engineRow, (SeaTunnelRowType) dataType);
     }

Review Comment:
   ditto



##########
seatunnel-translation/seatunnel-translation-spark/seatunnel-translation-spark-common/src/main/java/org/apache/seatunnel/translation/spark/serialization/InternalRowConverter.java:
##########
@@ -63,17 +64,24 @@
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
+import java.util.stream.IntStream;
 
 public final class InternalRowConverter extends RowConverter<InternalRow> {
+    private final int[] indexes;
 
     public InternalRowConverter(SeaTunnelDataType<?> dataType) {
         super(dataType);
+        indexes = IntStream.range(0, ((SeaTunnelRowType) 
dataType).getTotalFields()).toArray();
+    }
+
+    public InternalRowConverter(SeaTunnelDataType<?> dataType, int[] indexes) {
+        super(dataType);
+        this.indexes = indexes;
     }
 
     @Override
     public InternalRow convert(SeaTunnelRow seaTunnelRow) throws IOException {
-        validate(seaTunnelRow);
-        return (InternalRow) convert(seaTunnelRow, dataType);
+        return parcel(seaTunnelRow, (SeaTunnelRowType) dataType);
     }

Review Comment:
   It might be more reliable to add unit tests for it. It would be best if it 
covers all data types.



##########
seatunnel-translation/seatunnel-translation-spark/seatunnel-translation-spark-common/src/main/java/org/apache/seatunnel/translation/spark/serialization/SeaTunnelRowConverter.java:
##########
@@ -56,11 +57,25 @@ public SeaTunnelRow convert(SeaTunnelRow seaTunnelRow) 
throws IOException {
         validate(seaTunnelRow);
         GenericRowWithSchema rowWithSchema = (GenericRowWithSchema) 
convert(seaTunnelRow, dataType);
         SeaTunnelRow newRow = new SeaTunnelRow(rowWithSchema.values());
-        newRow.setRowKind(seaTunnelRow.getRowKind());
-        newRow.setTableId(seaTunnelRow.getTableId());
         return newRow;
     }
 
+    public GenericRowWithSchema parcel(SeaTunnelRow seaTunnelRow) {

Review Comment:
   ditto



##########
seatunnel-translation/seatunnel-translation-spark/seatunnel-translation-spark-common/src/main/java/org/apache/seatunnel/translation/spark/serialization/SeaTunnelRowConverter.java:
##########
@@ -156,6 +171,20 @@ public SeaTunnelRow reconvert(SeaTunnelRow engineRow) 
throws IOException {
         return (SeaTunnelRow) reconvert(engineRow, dataType);
     }
 
+    public SeaTunnelRow unpack(GenericRowWithSchema engineRow) throws 
IOException {

Review Comment:
   ditto



##########
seatunnel-translation/seatunnel-translation-spark/seatunnel-translation-spark-common/src/main/java/org/apache/seatunnel/translation/spark/utils/SchemaUtil.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.seatunnel.translation.spark.utils;
+
+import org.apache.seatunnel.api.table.catalog.CatalogTable;
+import org.apache.seatunnel.api.table.catalog.CatalogTableUtil;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.translation.spark.execution.ColumnWithIndex;
+import org.apache.seatunnel.translation.spark.execution.IndexQueue;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+public class SchemaUtil {
+
+    public static ColumnWithIndex[] mergeSchema(List<CatalogTable> 
catalogTables) {
+        if (catalogTables.size() == 1) {
+            CatalogTable catalogTable = catalogTables.get(0);
+            return new ColumnWithIndex[] {
+                new ColumnWithIndex(
+                        IntStream.rangeClosed(
+                                        0, 
catalogTable.getSeaTunnelRowType().getTotalFields())
+                                .toArray(),
+                        catalogTable,
+                        null)
+            };
+        }
+        List<String> fieldNames = new ArrayList<>();
+        List<SeaTunnelDataType<?>> fieldTypes = new ArrayList<>();
+        List<ColumnWithIndex> columnWithIndexes = new ArrayList<>();
+        fieldTypes.sort(Comparator.comparingInt(o -> 
o.getSqlType().ordinal()));

Review Comment:
   `fieldTypes` is empty. It's meaningless to sort it.



##########
seatunnel-translation/seatunnel-translation-spark/seatunnel-translation-spark-common/src/main/java/org/apache/seatunnel/translation/spark/utils/SchemaUtil.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.seatunnel.translation.spark.utils;
+
+import org.apache.seatunnel.api.table.catalog.CatalogTable;
+import org.apache.seatunnel.api.table.catalog.CatalogTableUtil;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.translation.spark.execution.ColumnWithIndex;
+import org.apache.seatunnel.translation.spark.execution.IndexQueue;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+public class SchemaUtil {
+
+    public static ColumnWithIndex[] mergeSchema(List<CatalogTable> 
catalogTables) {

Review Comment:
   It would be better to add unit test cases.



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

Reply via email to