meetjunsu commented on a change in pull request #17542:
URL: https://github.com/apache/flink/pull/17542#discussion_r760999986



##########
File path: 
flink-formats/flink-parquet/src/main/java/org/apache/flink/formats/parquet/row/ParquetRowDataWriter.java
##########
@@ -224,6 +293,176 @@ private TimestampWriter(int precision) {
         public void write(RowData row, int ordinal) {
             
recordConsumer.addBinary(timestampToInt96(row.getTimestamp(ordinal, 
precision)));
         }
+
+        @Override
+        public void write(Object value) {
+            recordConsumer.addBinary(timestampToInt96((TimestampData) value));
+        }
+    }
+
+    private class MapWriter implements FieldWriter {
+
+        private String repeatedGroupName;
+        private String keyName, valueName;
+        private FieldWriter keyWriter, valueWriter;
+        private ArrayData.ElementGetter keyElementGetter, valueElementGetter;
+
+        private MapWriter(LogicalType keyType, LogicalType valueType, 
GroupType groupType) {
+
+            // Get the internal map structure (MAP_KEY_VALUE)
+            GroupType repeatedType = groupType.getType(0).asGroupType();
+            this.repeatedGroupName = repeatedType.getName();
+
+            // Get key element information
+            Type type = repeatedType.getType(0);
+            this.keyName = type.getName();
+            this.keyWriter = createWriter(keyType, type);
+
+            // Get value element information
+            Type valuetype = repeatedType.getType(1);
+            this.valueName = valuetype.getName();
+            this.valueWriter = createWriter(valueType, valuetype);
+
+            this.keyElementGetter = ArrayData.createElementGetter(keyType);
+            this.valueElementGetter = ArrayData.createElementGetter(valueType);
+        }
+
+        @Override
+        public void write(RowData row, int ordinal) {
+            recordConsumer.startGroup();
+
+            MapData mapData = row.getMap(ordinal);
+
+            if (mapData != null && mapData.size() > 0) {
+                recordConsumer.startField(repeatedGroupName, 0);
+
+                ArrayData keyArray = mapData.keyArray();
+                ArrayData valueArray = mapData.valueArray();
+                for (int i = 0; i < keyArray.size(); i++) {
+                    Object key = keyElementGetter.getElementOrNull(keyArray, 
i);
+                    Object value = 
valueElementGetter.getElementOrNull(valueArray, i);
+
+                    recordConsumer.startGroup();
+                    if (key != null) {
+                        // write key element
+                        recordConsumer.startField(keyName, 0);
+                        keyWriter.write(key);
+                        recordConsumer.endField(keyName, 0);
+
+                        // write value element
+                        if (value != null) {
+                            recordConsumer.startField(valueName, 1);
+                            valueWriter.write(value);
+                            recordConsumer.endField(valueName, 1);
+                        }
+                    }
+                    recordConsumer.endGroup();
+                }
+
+                recordConsumer.endField(repeatedGroupName, 0);
+            }
+            recordConsumer.endGroup();
+        }
+
+        @Override
+        public void write(Object value) {}
+    }
+
+    private class ArrayWriter implements FieldWriter {
+
+        private String elementName;
+        private FieldWriter elementWriter;
+        private String repeatedGroupName;
+        private ArrayData.ElementGetter elementGetter;
+
+        private ArrayWriter(LogicalType t, GroupType groupType) {
+
+            // Get the internal array structure
+            GroupType repeatedType = groupType.getType(0).asGroupType();
+            this.repeatedGroupName = repeatedType.getName();
+
+            Type elementType = repeatedType.getType(0);
+            this.elementName = elementType.getName();
+
+            this.elementWriter = createWriter(t, elementType);
+            this.elementGetter = ArrayData.createElementGetter(t);
+        }
+
+        @Override
+        public void write(RowData row, int ordinal) {
+            recordConsumer.startGroup();
+            ArrayData arrayData = row.getArray(ordinal);
+            int listLength = arrayData.size();
+
+            if (listLength > 0) {
+                recordConsumer.startField(repeatedGroupName, 0);
+
+                for (int i = 0; i < listLength; i++) {
+                    Object object = elementGetter.getElementOrNull(arrayData, 
i);
+                    recordConsumer.startGroup();
+                    if (object != null) {
+                        recordConsumer.startField(elementName, 0);
+                        elementWriter.write(object);
+                        recordConsumer.endField(elementName, 0);
+                    }
+                    recordConsumer.endGroup();
+                }
+
+                recordConsumer.endField(repeatedGroupName, 0);
+            }
+            recordConsumer.endGroup();
+        }
+
+        @Override
+        public void write(Object value) {}
+    }
+
+    private class GroupTypeWriter implements FieldWriter {

Review comment:
       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-unsubscr...@flink.apache.org

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


Reply via email to