rdblue commented on a change in pull request #1103:
URL: https://github.com/apache/iceberg/pull/1103#discussion_r438304950



##########
File path: mr/src/main/java/org/apache/iceberg/mr/mapred/IcebergSerDe.java
##########
@@ -0,0 +1,106 @@
+/*
+ * 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.iceberg.mr.mapred;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+import javax.annotation.Nullable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.serde2.AbstractSerDe;
+import org.apache.hadoop.hive.serde2.SerDeException;
+import org.apache.hadoop.hive.serde2.SerDeStats;
+import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
+import org.apache.hadoop.io.Writable;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.SnapshotsTable;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.types.Types;
+
+public class IcebergSerDe extends AbstractSerDe {
+
+  private Schema schema;
+  private ObjectInspector inspector;
+
+  @Override
+  public void initialize(@Nullable Configuration configuration, Properties 
serDeProperties) throws SerDeException {
+    Table table = null;
+    try {
+      table = TableResolver.resolveTableFromConfiguration(configuration, 
serDeProperties);
+    } catch (IOException e) {
+      throw new UncheckedIOException("Unable to resolve table from 
configuration: ", e);
+    }
+    this.schema = table.schema();
+    if (table instanceof SnapshotsTable) {
+      try {
+        this.inspector = new 
IcebergObjectInspectorGenerator().createObjectInspector(schema);
+      } catch (Exception e) {
+        throw new SerDeException(e);
+      }
+    } else {
+      List<Types.NestedField> columns = new ArrayList<>(schema.columns());
+      columns.add(Types.NestedField.optional(Integer.MAX_VALUE, 
SystemTableUtil.getVirtualColumnName(serDeProperties),
+              Types.LongType.get()));
+      Schema withVirtualColumn = new Schema(columns);
+
+      try {
+        this.inspector = new 
IcebergObjectInspectorGenerator().createObjectInspector(withVirtualColumn);
+      } catch (Exception e) {
+        throw new SerDeException(e);
+      }
+    }
+  }
+
+  @Override
+  public Class<? extends Writable> getSerializedClass() {
+    return null;
+  }
+
+  @Override
+  public Writable serialize(Object o, ObjectInspector objectInspector) {
+    return null;
+  }
+
+  @Override
+  public SerDeStats getSerDeStats() {
+    return null;
+  }
+
+  @Override
+  public Object deserialize(Writable writable) {
+    IcebergWritable icebergWritable = (IcebergWritable) writable;
+    List<Types.NestedField> fields = icebergWritable.getSchema().columns();
+    List<Object> row = new ArrayList<>();

Review comment:
       Does this need to allocate a new ArrayList every time or can it reuse 
one?
   
   We try to make the code called for every row in a tight loop (like this 
method) as small as possible for performance reasons. Ideally, we would be able 
to reuse this storage, have the list of columns already prepared, and access 
field values by column position instead of by name. Something like this:
   
   ```java
   public Object deserialize(Writable writable) {
     Record record = ((IcebergWritable) writable).record();
     for (int i = 0; i < recordSize; i += 1) {
       reusedArray[i] = record.get(i, Object.class);
     }
     return reusedArrayAsList;
   }
   ```




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

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