Skip to content

Commit

Permalink
Build: Fix ErrorProne NewHashMapInt warnings (apache#3260)
Browse files Browse the repository at this point in the history
This should improve performance by allocating the correct size directly rather than reallocating later.
  • Loading branch information
kbendick authored Oct 10, 2021
1 parent 391c53c commit 6ca31fc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions api/src/main/java/org/apache/iceberg/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
import org.apache.iceberg.util.ByteBuffers;

/**
Expand Down Expand Up @@ -230,7 +230,7 @@ private static Map<Integer, ByteBuffer> readByteBufferMap(ObjectInputStream in)
return null;

} else {
Map<Integer, ByteBuffer> result = new HashMap<>(size);
Map<Integer, ByteBuffer> result = Maps.newHashMapWithExpectedSize(size);

for (int i = 0; i < size; ++i) {
Integer key = (Integer) in.readObject();
Expand Down
4 changes: 2 additions & 2 deletions mr/src/main/java/org/apache/iceberg/mr/Catalogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.apache.iceberg.mr;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
Expand All @@ -39,6 +38,7 @@
import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet;
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
import org.apache.iceberg.relocated.com.google.common.collect.Streams;

/**
Expand Down Expand Up @@ -150,7 +150,7 @@ public static Table createTable(Configuration conf, Properties props) {
String catalogName = props.getProperty(InputFormatConfig.CATALOG_NAME);

// Create a table property map without the controlling properties
Map<String, String> map = new HashMap<>(props.size());
Map<String, String> map = Maps.newHashMapWithExpectedSize(props.size());
for (Object key : props.keySet()) {
if (!PROPERTIES_TO_REMOVE.contains(key)) {
map.put(key.toString(), props.get(key).toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.iceberg.data.GenericRecord;
import org.apache.iceberg.data.Record;
import org.apache.iceberg.mr.hive.serde.objectinspector.WriteObjectInspector;
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
import org.apache.iceberg.schema.SchemaWithPartnerVisitor;
import org.apache.iceberg.types.Type.PrimitiveType;
import org.apache.iceberg.types.Types.ListType;
Expand Down Expand Up @@ -232,7 +233,7 @@ private static class FixNameMappingObjectInspectorPair extends ObjectInspectorPa
FixNameMappingObjectInspectorPair(Schema schema, ObjectInspectorPair pair) {
super(pair.writerInspector(), pair.sourceInspector());

this.sourceNameMap = new HashMap<>(schema.columns().size());
this.sourceNameMap = Maps.newHashMapWithExpectedSize(schema.columns().size());

List<? extends StructField> fields = ((StructObjectInspector) sourceInspector()).getAllStructFieldRefs();
for (int i = 0; i < schema.columns().size(); ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand All @@ -46,6 +45,7 @@
import org.apache.iceberg.mr.InputFormatConfig;
import org.apache.iceberg.mr.hive.serde.objectinspector.IcebergObjectInspector;
import org.apache.iceberg.mr.mapred.Container;
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -55,7 +55,7 @@ public class HiveIcebergSerDe extends AbstractSerDe {

private ObjectInspector inspector;
private Schema tableSchema;
private Map<ObjectInspector, Deserializer> deserializers = new HashMap<>(1);
private Map<ObjectInspector, Deserializer> deserializers = Maps.newHashMapWithExpectedSize(1);
private Container<Record> row = new Container<>();

@Override
Expand Down

0 comments on commit 6ca31fc

Please sign in to comment.