openinx commented on a change in pull request #4218:
URL: https://github.com/apache/iceberg/pull/4218#discussion_r817498679
##########
File path: mr/src/main/java/org/apache/iceberg/mr/hive/Deserializer.java
##########
@@ -125,13 +125,14 @@ public FieldDeserializer primitive(PrimitiveType type,
ObjectInspectorPair pair)
@Override
public FieldDeserializer struct(StructType type, ObjectInspectorPair pair,
List<FieldDeserializer> deserializers) {
+ GenericRecord template = type != null ? GenericRecord.create(type) :
null;
return o -> {
if (o == null) {
return null;
}
List<Object> data = ((StructObjectInspector)
pair.sourceInspector()).getStructFieldsDataAsList(o);
- Record result = GenericRecord.create(type);
+ Record result = template.copy();
Review comment:
Indeed, the `type` should never be null here because the
`SchemaWithPartnerVistor` guarantee it. See:
https://github.com/apache/iceberg/blob/90225d6c9413016d611e2ce5eff37db1bc1b4fc5/core/src/main/java/org/apache/iceberg/schema/SchemaWithPartnerVisitor.java#L52-L61
I think we can just add a `Precondition.checkNotNull` in the line128 instead
of checking the null case in a `if-else` block.
##########
File path: data/src/jmh/java/org/apache/iceberg/ReaderBenchmark.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.io.IOException;
+import org.apache.iceberg.data.RandomGenericData;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.io.FileAppender;
+import org.apache.iceberg.types.Types;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.TearDown;
+import org.openjdk.jmh.annotations.Threads;
+import org.openjdk.jmh.annotations.Warmup;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.apache.iceberg.types.Types.NestedField.required;
+
+@Fork(1)
+@State(Scope.Benchmark)
+@Warmup(iterations = 3)
+@Measurement(iterations = 20)
+@BenchmarkMode(Mode.SingleShotTime)
+public abstract class ReaderBenchmark {
+ private static final Logger LOG =
LoggerFactory.getLogger(ReaderBenchmark.class);
+
+ private static final Schema TEST_SCHEMA = new Schema(
+ required(1, "longCol", Types.LongType.get()),
+ required(2, "intCol", Types.IntegerType.get()),
+ required(3, "floatCol", Types.FloatType.get()),
+ optional(4, "doubleCol", Types.DoubleType.get()),
+ optional(5, "decimalCol", Types.DecimalType.of(20, 5)),
+ optional(6, "dateCol", Types.DateType.get()),
+ optional(7, "timestampCol", Types.TimestampType.withZone()),
+ optional(8, "stringCol", Types.StringType.get()));
+
+ private static final int NUM_ROWS = 2500000;
+ private static final int SEED = -1;
+
+ private File testFile;
+
+ @Setup
+ public void setupBenchmark() throws IOException {
+ testFile = java.nio.file.Files.createTempFile("perf-bench", null).toFile();
Review comment:
Nit: Could we import this as a package, instead of using the full
qualifier name here ?
##########
File path: mr/src/main/java/org/apache/iceberg/mr/hive/Deserializer.java
##########
@@ -125,13 +125,14 @@ public FieldDeserializer primitive(PrimitiveType type,
ObjectInspectorPair pair)
@Override
public FieldDeserializer struct(StructType type, ObjectInspectorPair pair,
List<FieldDeserializer> deserializers) {
+ GenericRecord template = type != null ? GenericRecord.create(type) :
null;
return o -> {
if (o == null) {
return null;
}
List<Object> data = ((StructObjectInspector)
pair.sourceInspector()).getStructFieldsDataAsList(o);
- Record result = GenericRecord.create(type);
+ Record result = template.copy();
Review comment:
So here we use `GenericRecord(GenericRecord toCopy)` constructor rather
than `GenericRecord(StructType struct)` to eliminate the access to
`NAME_MAP_CACHE` ? I'm afraid the further PR will easily fallback to use the
other because this tiny different is hard for the next developer and reviewer
to notice. Is possible to add few doc ?
--
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]