lirui-apache commented on a change in pull request #3186:
URL: https://github.com/apache/iceberg/pull/3186#discussion_r725798841



##########
File path: 
spark/src/main/java/org/apache/iceberg/spark/source/BaseDataReader.java
##########
@@ -196,4 +199,71 @@ protected static Object convertConstant(Type type, Object 
value) {
     }
     return value;
   }
+
+  protected void findMoreCompoundConstants(Schema tableSchema, Map<Integer, ?> 
idToConstant) {
+    List<Types.NestedField> columns = tableSchema.columns();
+
+    for (Types.NestedField nestedField : columns) {
+      visitCompoundTypesByDFS(nestedField, (Map<Integer, Object>) 
idToConstant);
+    }
+  }
+
+  protected void visitCompoundTypesByDFS(
+          Types.NestedField nestedField,
+          Map<Integer, Object> idToConstant) {
+    switch (nestedField.type().typeId()) {
+      case STRUCT:
+        List<Types.NestedField> childFieldsInStruct = 
nestedField.type().asStructType().fields();
+        List<Integer> childFieldID = new ArrayList<>();
+        for (Types.NestedField childField : childFieldsInStruct) {
+          visitCompoundTypesByDFS(childField, idToConstant);
+          childFieldID.add(childField.fieldId());
+        }
+        if (idToConstant.keySet().containsAll(childFieldID)) {
+          Object[] objects = new Object[childFieldID.size()];
+          for (int i = 0; i < objects.length; i++) {
+            objects[i] = idToConstant.get(childFieldID.get(i));
+          }
+          idToConstant.put(nestedField.fieldId(), new 
GenericInternalRow(objects));
+        }
+        break;
+      case MAP:
+        int keyId = nestedField.type().asMapType().keyId();
+        int valueId = nestedField.type().asMapType().valueId();
+        Types.NestedField nestedKeyField = 
nestedField.type().asMapType().field(keyId);
+        Types.NestedField nestedValueField = 
nestedField.type().asMapType().field(valueId);
+        List<Integer> kvFieldIds = new ArrayList<>();
+        kvFieldIds.add(nestedKeyField.fieldId());
+        kvFieldIds.add(nestedValueField.fieldId());
+        visitCompoundTypesByDFS(nestedKeyField, idToConstant);
+        visitCompoundTypesByDFS(nestedValueField, idToConstant);
+        if (idToConstant.keySet().containsAll(kvFieldIds)) {
+          Object keyValue = idToConstant.get(keyId);
+          Object valueValue = idToConstant.get(valueId);
+          GenericArrayData keys = new GenericArrayData(new Object[]{keyValue});
+          GenericArrayData values = new GenericArrayData(new 
Object[]{valueValue});
+          idToConstant.put(keyId, keys);
+          idToConstant.put(valueId, values);

Review comment:
       I think we need a `MapData` to represent a constant map value, no?




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to