You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by om...@apache.org on 2021/02/23 23:50:02 UTC
[orc] branch master updated: ORC-754: Code cleanup (#646)
This is an automated email from the ASF dual-hosted git repository.
omalley pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/orc.git
The following commit(s) were added to refs/heads/master by this push:
new caf2dcf ORC-754: Code cleanup (#646)
caf2dcf is described below
commit caf2dcfc810aaf2f1d0d39ada253d3a577d8ff14
Author: Pavan Lanka <pl...@apple.com>
AuthorDate: Tue Feb 23 15:49:51 2021 -0800
ORC-754: Code cleanup (#646)
* Replaced Charset.forName with StandardCharsets
* Final on some variables
* Removed final on a private method
* Simplified some conditions
* Removed redundant casts
* Removed duplicate condition branches
* Removed the maven compiler config setting in bench
---
java/bench/core/pom.xml | 1 -
.../src/java/org/apache/orc/impl/OrcAcidUtils.java | 3 +-
.../src/java/org/apache/orc/impl/ReaderImpl.java | 2 +-
.../java/org/apache/orc/impl/RecordReaderImpl.java | 33 ++++++++--------------
.../org/apache/orc/impl/RecordReaderUtils.java | 2 +-
.../org/apache/orc/impl/TreeReaderFactory.java | 15 +++++-----
.../org/apache/orc/impl/reader/StripePlanner.java | 2 +-
7 files changed, 25 insertions(+), 33 deletions(-)
diff --git a/java/bench/core/pom.xml b/java/bench/core/pom.xml
index 15d9a4d..47dbf76 100644
--- a/java/bench/core/pom.xml
+++ b/java/bench/core/pom.xml
@@ -23,7 +23,6 @@
<relativePath>..</relativePath>
</parent>
- <groupId>org.apache.orc</groupId>
<artifactId>orc-benchmarks-core</artifactId>
<version>1.7.0-SNAPSHOT</version>
<packaging>jar</packaging>
diff --git a/java/core/src/java/org/apache/orc/impl/OrcAcidUtils.java b/java/core/src/java/org/apache/orc/impl/OrcAcidUtils.java
index 7ca9e1d..7ddf328 100644
--- a/java/core/src/java/org/apache/orc/impl/OrcAcidUtils.java
+++ b/java/core/src/java/org/apache/orc/impl/OrcAcidUtils.java
@@ -28,6 +28,7 @@ import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
+import java.nio.charset.StandardCharsets;
public class OrcAcidUtils {
public static final String ACID_STATS = "hive.acid.stats";
@@ -68,7 +69,7 @@ public class OrcAcidUtils {
}
}
- private static final Charset utf8 = Charset.forName("UTF-8");
+ private static final Charset utf8 = StandardCharsets.UTF_8;
private static final CharsetDecoder utf8Decoder = utf8.newDecoder();
public static AcidStats parseAcidStats(Reader reader) {
diff --git a/java/core/src/java/org/apache/orc/impl/ReaderImpl.java b/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
index 76132f4..1257945 100644
--- a/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
+++ b/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
@@ -74,7 +74,7 @@ public class ReaderImpl implements Reader {
protected List<OrcProto.StripeStatistics> stripeStatistics;
private final int metadataSize;
protected final List<OrcProto.Type> types;
- private TypeDescription schema;
+ private final TypeDescription schema;
private final List<OrcProto.UserMetadataItem> userMetadata;
private final List<OrcProto.ColumnStatistics> fileStats;
private final List<StripeInformation> stripes;
diff --git a/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java b/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java
index 508ca65..873b65e 100644
--- a/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java
+++ b/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java
@@ -611,14 +611,11 @@ public class RecordReaderImpl implements RecordReader {
// 1) Bloom filter is available
// 2) Min/Max evaluation yield YES or MAYBE
// 3) Predicate is EQUALS or IN list
- if (bloomFilter != null
- && result != TruthValue.NO_NULL && result != TruthValue.NO
- && (predicate.getOperator().equals(PredicateLeaf.Operator.EQUALS)
- || predicate.getOperator().equals(PredicateLeaf.Operator.NULL_SAFE_EQUALS)
- || predicate.getOperator().equals(PredicateLeaf.Operator.IN))) {
- return true;
- }
- return false;
+ return bloomFilter != null
+ && result != TruthValue.NO_NULL && result != TruthValue.NO
+ && (predicate.getOperator().equals(PredicateLeaf.Operator.EQUALS)
+ || predicate.getOperator().equals(PredicateLeaf.Operator.NULL_SAFE_EQUALS)
+ || predicate.getOperator().equals(PredicateLeaf.Operator.IN));
}
private static TruthValue evaluatePredicateMinMax(PredicateLeaf predicate,
@@ -748,11 +745,11 @@ public class RecordReaderImpl implements RecordReader {
TruthValue result = hasNull ? TruthValue.NO_NULL : TruthValue.NO;
if (predObj instanceof Long) {
- if (bf.testLong(((Long) predObj).longValue())) {
+ if (bf.testLong((Long) predObj)) {
result = TruthValue.YES_NO_NULL;
}
} else if (predObj instanceof Double) {
- if (bf.testDouble(((Double) predObj).doubleValue())) {
+ if (bf.testDouble((Double) predObj)) {
result = TruthValue.YES_NO_NULL;
}
} else if (predObj instanceof String || predObj instanceof Text ||
@@ -836,10 +833,10 @@ public class RecordReaderImpl implements RecordReader {
break;
case DECIMAL:
if (obj instanceof Boolean) {
- return new HiveDecimalWritable(((Boolean) obj).booleanValue() ?
+ return new HiveDecimalWritable((Boolean) obj ?
HiveDecimal.ONE : HiveDecimal.ZERO);
} else if (obj instanceof Integer) {
- return new HiveDecimalWritable(((Integer) obj).intValue());
+ return new HiveDecimalWritable((Integer) obj);
} else if (obj instanceof Long) {
return new HiveDecimalWritable(((Long) obj));
} else if (obj instanceof Float || obj instanceof Double ||
@@ -866,10 +863,6 @@ public class RecordReaderImpl implements RecordReader {
return Double.valueOf(obj.toString());
} else if (obj instanceof Timestamp) {
return TimestampUtils.getDouble((Timestamp) obj);
- } else if (obj instanceof HiveDecimal) {
- return ((HiveDecimal) obj).doubleValue();
- } else if (obj instanceof BigDecimal) {
- return ((BigDecimal) obj).doubleValue();
}
break;
case LONG:
@@ -897,7 +890,7 @@ public class RecordReaderImpl implements RecordReader {
} else if (obj instanceof Float) {
return TimestampUtils.doubleToTimestamp(((Float) obj).doubleValue());
} else if (obj instanceof Double) {
- return TimestampUtils.doubleToTimestamp(((Double) obj).doubleValue());
+ return TimestampUtils.doubleToTimestamp((Double) obj);
} else if (obj instanceof HiveDecimal) {
return TimestampUtils.decimalToTimestamp((HiveDecimal) obj);
} else if (obj instanceof HiveDecimalWritable) {
@@ -933,7 +926,7 @@ public class RecordReaderImpl implements RecordReader {
private final long rowIndexStride;
// same as the above array, but indices are set to true
private final boolean[] sargColumns;
- private SchemaEvolution evolution;
+ private final SchemaEvolution evolution;
private final long[] exceptionCount;
private final boolean useUTCTimestamp;
private final boolean writerUsedProlepticGregorian;
@@ -1264,9 +1257,7 @@ public class RecordReaderImpl implements RecordReader {
endRowGroup += 1;
}
- final long markerPosition =
- (endRowGroup * rowIndexStride) < rowCountInStripe ? (endRowGroup * rowIndexStride)
- : rowCountInStripe;
+ final long markerPosition = Math.min((endRowGroup * rowIndexStride), rowCountInStripe);
batchSize = (int) Math.min(targetBatchSize, (markerPosition - rowInStripe));
if (isLogDebugEnabled && batchSize < targetBatchSize) {
diff --git a/java/core/src/java/org/apache/orc/impl/RecordReaderUtils.java b/java/core/src/java/org/apache/orc/impl/RecordReaderUtils.java
index 400a47f..a9c87b0 100644
--- a/java/core/src/java/org/apache/orc/impl/RecordReaderUtils.java
+++ b/java/core/src/java/org/apache/orc/impl/RecordReaderUtils.java
@@ -545,7 +545,7 @@ public class RecordReaderUtils {
private long currentGeneration = 0;
- private final TreeMap<Key, ByteBuffer> getBufferTree(boolean direct) {
+ private TreeMap<Key, ByteBuffer> getBufferTree(boolean direct) {
return direct ? directBuffers : buffers;
}
diff --git a/java/core/src/java/org/apache/orc/impl/TreeReaderFactory.java b/java/core/src/java/org/apache/orc/impl/TreeReaderFactory.java
index cfe1603..6d27508 100644
--- a/java/core/src/java/org/apache/orc/impl/TreeReaderFactory.java
+++ b/java/core/src/java/org/apache/orc/impl/TreeReaderFactory.java
@@ -245,7 +245,8 @@ public class TreeReaderFactory {
switch (kind) {
case DIRECT_V2:
case DICTIONARY_V2:
- return new RunLengthIntegerReaderV2(in, signed, context == null ? false : context.isSkipCorrupt());
+ return new RunLengthIntegerReaderV2(in, signed,
+ context != null && context.isSkipCorrupt());
case DIRECT:
case DICTIONARY:
return new RunLengthIntegerReader(in, signed);
@@ -1098,13 +1099,13 @@ public class TreeReaderFactory {
public static class TimestampTreeReader extends TreeReader {
protected IntegerReader data = null;
protected IntegerReader nanos = null;
- private Map<String, Long> baseTimestampMap;
+ private final Map<String, Long> baseTimestampMap;
protected long base_timestamp;
private final TimeZone readerTimeZone;
private final boolean instantType;
private TimeZone writerTimeZone;
private boolean hasSameTZRules;
- private ThreadLocal<DateFormat> threadLocalDateFormat;
+ private final ThreadLocal<DateFormat> threadLocalDateFormat;
private final boolean useProleptic;
private final boolean fileUsesProleptic;
@@ -1416,7 +1417,7 @@ public class TreeReaderFactory {
protected InStream valueStream;
protected IntegerReader scaleReader = null;
private int[] scratchScaleVector;
- private byte[] scratchBytes;
+ private final byte[] scratchBytes;
DecimalTreeReader(int columnId,
int precision,
@@ -1953,7 +1954,7 @@ public class TreeReaderFactory {
final int batchSize) throws IOException {
if (result.noNulls || !(result.isRepeating && result.isNull[0])) {
byte[] allBytes =
- commonReadByteArrays(stream, lengths, scratchlcv, result, (int) batchSize);
+ commonReadByteArrays(stream, lengths, scratchlcv, result, batchSize);
// Too expensive to figure out 'repeating' by comparisons.
result.isRepeating = false;
@@ -2213,7 +2214,7 @@ public class TreeReaderFactory {
scratchlcv.isRepeating = result.isRepeating;
scratchlcv.noNulls = result.noNulls;
scratchlcv.isNull = result.isNull;
- scratchlcv.ensureSize((int) batchSize, false);
+ scratchlcv.ensureSize(batchSize, false);
reader.nextVector(scratchlcv, scratchlcv.vector, batchSize);
if (!scratchlcv.isRepeating) {
// The vector has non-repeating strings. Iterate thru the batch
@@ -2572,7 +2573,7 @@ public class TreeReaderFactory {
}
}
- private static FilterContext NULL_FILTER = new FilterContext() {
+ private static final FilterContext NULL_FILTER = new FilterContext() {
@Override
public void reset() {
}
diff --git a/java/core/src/java/org/apache/orc/impl/reader/StripePlanner.java b/java/core/src/java/org/apache/orc/impl/reader/StripePlanner.java
index d8d08fb..f4dabe8 100644
--- a/java/core/src/java/org/apache/orc/impl/reader/StripePlanner.java
+++ b/java/core/src/java/org/apache/orc/impl/reader/StripePlanner.java
@@ -68,7 +68,7 @@ public class StripePlanner {
private String writerTimezone;
private long currentStripeId;
private long originalStripeId;
- private Map<StreamName, StreamInformation> streams = new HashMap<>();
+ private final Map<StreamName, StreamInformation> streams = new HashMap<>();
// the index streams sorted by offset
private final List<StreamInformation> indexStreams = new ArrayList<>();
// the data streams sorted by offset