openinx commented on a change in pull request #3248:
URL: https://github.com/apache/iceberg/pull/3248#discussion_r725863971



##########
File path: spark/src/main/java/org/apache/iceberg/spark/data/SparkOrcWriter.java
##########
@@ -126,30 +127,106 @@ public SparkOrcValueWriter primitive(Type.PrimitiveType 
iPrimitive, TypeDescript
     }
   }
 
-  private static class StructWriter implements SparkOrcValueWriter {
-    private final List<SparkOrcValueWriter> writers;
+  private static class InternalRowWriter extends 
GenericOrcWriter.StructWriter<InternalRow> {
+    private final List<FieldGetter<?>> fieldGetters;
 
-    StructWriter(List<SparkOrcValueWriter> writers) {
-      this.writers = writers;
-    }
+    InternalRowWriter(List<OrcValueWriter<?>> writers, List<TypeDescription> 
orcTypes) {
+      super(writers);
+      this.fieldGetters = Lists.newArrayListWithExpectedSize(orcTypes.size());
 
-    List<SparkOrcValueWriter> writers() {
-      return writers;
+      for (int i = 0; i < orcTypes.size(); i++) {
+        fieldGetters.add(createFieldGetter(orcTypes.get(i)));
+      }
     }
 
     @Override
-    public void nonNullWrite(int rowId, int column, SpecializedGetters data, 
ColumnVector output) {
-      InternalRow value = data.getStruct(column, writers.size());
-      StructColumnVector cv = (StructColumnVector) output;
-      for (int c = 0; c < writers.size(); ++c) {
-        writers.get(c).write(rowId, c, value, cv.fields[c]);
-      }
+    public Class<?> getJavaClass() {
+      return InternalRow.class;
     }
 
     @Override
     public Stream<FieldMetrics<?>> metrics() {
-      return writers.stream().flatMap(SparkOrcValueWriter::metrics);
+      return writers().stream().flatMap(OrcValueWriter::metrics);
+    }
+
+    @Override
+    protected Object get(InternalRow struct, int index) {
+      return fieldGetters.get(index).getFieldOrNull(struct, index);
+    }
+  }
+
+  static FieldGetter<?> createFieldGetter(TypeDescription fieldType) {
+    final FieldGetter<?> fieldGetter;
+    switch (fieldType.getCategory()) {
+      case BOOLEAN:
+        fieldGetter = (row, ordinal) -> row.getBoolean(ordinal);

Review comment:
       Nit:  This lambda could be replaced with method reference : 
   
   ```
    SpecializedGetters::getBoolean
   ```




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