You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/02/17 10:38:28 UTC

[GitHub] [incubator-inlong] ifndef-SleePy commented on a change in pull request #2556: [INLONG-2554][Sort] Support array and map data structures in ORC writer

ifndef-SleePy commented on a change in pull request #2556:
URL: https://github.com/apache/incubator-inlong/pull/2556#discussion_r808856345



##########
File path: inlong-sort/sort-connectors/src/main/java/org/apache/inlong/sort/flink/hive/formats/orc/RowVectorizer.java
##########
@@ -150,9 +158,141 @@ private static void setColumn(int rowId, ColumnVector column, LogicalType type,
                 vector.set(rowId, timestamp);
                 break;
             }
-            // TODO: support MAP type
+            case ARRAY: {
+                Object[] inputArray = (Object[]) field;
+                ColumnVector innerVector = constructColumnVectorFromArray(inputArray);
+                ListColumnVector tempListVector = new ListColumnVector(1, innerVector);
+                tempListVector.lengths[0] = inputArray.length;
+                ListColumnVector vector = (ListColumnVector) column;
+                vector.setElement(rowId, 0, tempListVector);
+                break;
+            }
+            case MAP: {
+                Map<?, ?> mapField = (Map<?, ?>) field;
+                int mapEleSize = mapField.size();
+                Object[] keys = new Object[mapEleSize];
+                Object[] values = new Object[mapEleSize];
+                int i = 0;
+                for (Map.Entry<?, ?> entry : mapField.entrySet()) {
+                    keys[i] = entry.getKey();
+                    values[i] = entry.getValue();
+                    ++i;
+                }
+
+                ColumnVector keysVector = constructColumnVectorFromArray(keys);
+                ColumnVector valuesVector = constructColumnVectorFromArray(values);
+                MapColumnVector tempMapVector = new MapColumnVector(1, keysVector, valuesVector);
+                tempMapVector.lengths[0] = mapEleSize;
+
+                MapColumnVector vector = (MapColumnVector) column;
+                vector.setElement(rowId, 0, tempMapVector);
+                break;
+            }
             default:
                 throw new UnsupportedOperationException("Unsupported type: " + type);
         }
     }
+
+    @VisibleForTesting
+    static ColumnVector constructColumnVectorFromArray(Object[] inputArray) {
+        int length = inputArray.length;
+        checkState(length > 0);

Review comment:
       Why it can not be an empty array? Is it right to construct vector from column content?

##########
File path: inlong-sort/sort-connectors/src/main/java/org/apache/inlong/sort/flink/hive/formats/orc/RowVectorizer.java
##########
@@ -150,9 +158,141 @@ private static void setColumn(int rowId, ColumnVector column, LogicalType type,
                 vector.set(rowId, timestamp);
                 break;
             }
-            // TODO: support MAP type
+            case ARRAY: {
+                Object[] inputArray = (Object[]) field;
+                ColumnVector innerVector = constructColumnVectorFromArray(inputArray);
+                ListColumnVector tempListVector = new ListColumnVector(1, innerVector);
+                tempListVector.lengths[0] = inputArray.length;
+                ListColumnVector vector = (ListColumnVector) column;
+                vector.setElement(rowId, 0, tempListVector);
+                break;
+            }
+            case MAP: {
+                Map<?, ?> mapField = (Map<?, ?>) field;
+                int mapEleSize = mapField.size();
+                Object[] keys = new Object[mapEleSize];
+                Object[] values = new Object[mapEleSize];
+                int i = 0;
+                for (Map.Entry<?, ?> entry : mapField.entrySet()) {
+                    keys[i] = entry.getKey();
+                    values[i] = entry.getValue();
+                    ++i;
+                }
+
+                ColumnVector keysVector = constructColumnVectorFromArray(keys);
+                ColumnVector valuesVector = constructColumnVectorFromArray(values);
+                MapColumnVector tempMapVector = new MapColumnVector(1, keysVector, valuesVector);
+                tempMapVector.lengths[0] = mapEleSize;
+
+                MapColumnVector vector = (MapColumnVector) column;
+                vector.setElement(rowId, 0, tempMapVector);
+                break;
+            }
             default:
                 throw new UnsupportedOperationException("Unsupported type: " + type);
         }
     }
+
+    @VisibleForTesting
+    static ColumnVector constructColumnVectorFromArray(Object[] inputArray) {

Review comment:
       Do not get ColumnVector from like this. Could you infer child type from schema provided from manager?




-- 
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: commits-unsubscribe@inlong.apache.org

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