Skip to content

Commit

Permalink
PARQUET-1503: Remove Ints Utility Class
Browse files Browse the repository at this point in the history
  • Loading branch information
belugabehr committed Jan 24, 2019
1 parent e7835e0 commit 2bd2ce2
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.io.IOException;

import org.apache.parquet.Ints;
import org.apache.parquet.bytes.BytesInput;
import org.apache.parquet.column.ColumnDescriptor;
import org.apache.parquet.column.Encoding;
Expand Down Expand Up @@ -78,7 +77,7 @@ void writePage(int rowCount, int valueCount, Statistics<?> statistics, ValuesWri
Encoding encoding = values.getEncoding();
pageWriter.writePageV2(
rowCount,
Ints.checkedCast(statistics.getNumNulls()),
Math.toIntExact(statistics.getNumNulls()),
valueCount,
repetitionLevels.getBytes(),
definitionLevels.getBytes(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.util.Optional;

import org.apache.parquet.Ints;
import org.apache.parquet.bytes.BytesInput;
import org.apache.parquet.column.Encoding;
import org.apache.parquet.column.statistics.Statistics;
Expand All @@ -44,7 +43,7 @@ public class DataPageV1 extends DataPage {
* @param valuesEncoding the values encoding for this page
*/
public DataPageV1(BytesInput bytes, int valueCount, int uncompressedSize, Statistics<?> statistics, Encoding rlEncoding, Encoding dlEncoding, Encoding valuesEncoding) {
super(Ints.checkedCast(bytes.size()), uncompressedSize, valueCount);
super(Math.toIntExact(bytes.size()), uncompressedSize, valueCount);
this.bytes = bytes;
this.statistics = statistics;
this.rlEncoding = rlEncoding;
Expand All @@ -66,7 +65,7 @@ public DataPageV1(BytesInput bytes, int valueCount, int uncompressedSize, Statis
*/
public DataPageV1(BytesInput bytes, int valueCount, int uncompressedSize, long firstRowIndex, int rowCount,
Statistics<?> statistics, Encoding rlEncoding, Encoding dlEncoding, Encoding valuesEncoding) {
super(Ints.checkedCast(bytes.size()), uncompressedSize, valueCount, firstRowIndex);
super(Math.toIntExact(bytes.size()), uncompressedSize, valueCount, firstRowIndex);
this.bytes = bytes;
this.statistics = statistics;
this.rlEncoding = rlEncoding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.util.Optional;

import org.apache.parquet.Ints;
import org.apache.parquet.bytes.BytesInput;
import org.apache.parquet.column.Encoding;
import org.apache.parquet.column.statistics.Statistics;
Expand All @@ -47,7 +46,7 @@ public static DataPageV2 uncompressed(
rowCount, nullCount, valueCount,
repetitionLevels, definitionLevels,
dataEncoding, data,
Ints.checkedCast(repetitionLevels.size() + definitionLevels.size() + data.size()),
Math.toIntExact(repetitionLevels.size() + definitionLevels.size() + data.size()),
statistics,
false);
}
Expand All @@ -73,7 +72,7 @@ public static DataPageV2 uncompressed(
rowCount, nullCount, valueCount, firstRowIndex,
repetitionLevels, definitionLevels,
dataEncoding, data,
Ints.checkedCast(repetitionLevels.size() + definitionLevels.size() + data.size()),
Math.toIntExact(repetitionLevels.size() + definitionLevels.size() + data.size()),
statistics,
false);
}
Expand Down Expand Up @@ -121,7 +120,7 @@ public DataPageV2(
int uncompressedSize,
Statistics<?> statistics,
boolean isCompressed) {
super(Ints.checkedCast(repetitionLevels.size() + definitionLevels.size() + data.size()), uncompressedSize, valueCount);
super(Math.toIntExact(repetitionLevels.size() + definitionLevels.size() + data.size()), uncompressedSize, valueCount);
this.rowCount = rowCount;
this.nullCount = nullCount;
this.repetitionLevels = repetitionLevels;
Expand All @@ -139,7 +138,7 @@ private DataPageV2(
int uncompressedSize,
Statistics<?> statistics,
boolean isCompressed) {
super(Ints.checkedCast(repetitionLevels.size() + definitionLevels.size() + data.size()), uncompressedSize,
super(Math.toIntExact(repetitionLevels.size() + definitionLevels.size() + data.size()), uncompressedSize,
valueCount, firstRowIndex);
this.rowCount = rowCount;
this.nullCount = nullCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import java.io.IOException;

import org.apache.parquet.Ints;
import org.apache.parquet.bytes.BytesInput;
import org.apache.parquet.column.Encoding;

Expand Down Expand Up @@ -53,7 +52,7 @@ public DictionaryPage(BytesInput bytes, int dictionarySize, Encoding encoding) {
* @param encoding the encoding used
*/
public DictionaryPage(BytesInput bytes, int uncompressedSize, int dictionarySize, Encoding encoding) {
super(Ints.checkedCast(bytes.size()), uncompressedSize);
super(Math.toIntExact(bytes.size()), uncompressedSize);
this.bytes = checkNotNull(bytes, "bytes");
this.dictionarySize = dictionarySize;
this.encoding = checkNotNull(encoding, "encoding");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Objects;

import org.apache.parquet.bytes.ByteBufferAllocator;
import org.apache.parquet.Ints;
import org.apache.parquet.bytes.BytesInput;
import org.apache.parquet.column.Encoding;
import org.apache.parquet.column.values.ValuesWriter;
Expand Down Expand Up @@ -68,7 +67,7 @@ public BytesInput getBytes() {
try {
// prepend the length of the column
BytesInput rle = encoder.toBytes();
return BytesInput.concat(BytesInput.fromInt(Ints.checkedCast(rle.size())), rle);
return BytesInput.concat(BytesInput.fromInt(Math.toIntExact(rle.size())), rle);
} catch (IOException e) {
throw new ParquetEncodingException(e);
}
Expand Down
2 changes: 2 additions & 0 deletions parquet-common/src/main/java/org/apache/parquet/Ints.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/**
* Utilities for working with ints
*/
@Deprecated
public final class Ints {
private Ints() { }

Expand All @@ -31,6 +32,7 @@ private Ints() { }
* @param value a long to be casted to an int
* @return an int that is == to value
* @throws IllegalArgumentException if value can't be casted to an int
* @deprecated replaced by {@link java.lang.Math#toIntExact(long)}
*/
public static int checkedCast(long value) {
int valueI = (int) value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
*/
package org.apache.parquet.hadoop;

import static org.apache.parquet.Ints.checkedCast;

import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.PrimitiveIterator;
import org.apache.parquet.Ints;
import org.apache.parquet.bytes.BytesInput;
import org.apache.parquet.column.ColumnDescriptor;
import org.apache.parquet.column.page.DataPage;
Expand Down Expand Up @@ -118,7 +115,7 @@ public DataPage visit(DataPageV1 dataPageV1) {
dataPageV1.getValueCount(),
dataPageV1.getUncompressedSize(),
firstRowIndex,
checkedCast(offsetIndex.getLastRowIndex(currentPageIndex, rowCount) - firstRowIndex + 1),
Math.toIntExact(offsetIndex.getLastRowIndex(currentPageIndex, rowCount) - firstRowIndex + 1),
dataPageV1.getStatistics(),
dataPageV1.getRlEncoding(),
dataPageV1.getDlEncoding(),
Expand Down Expand Up @@ -148,7 +145,7 @@ public DataPage visit(DataPageV2 dataPageV2) {
}
}
try {
int uncompressedSize = Ints.checkedCast(
int uncompressedSize = Math.toIntExact(
dataPageV2.getUncompressedSize()
- dataPageV2.getDefinitionLevels().size()
- dataPageV2.getRepetitionLevels().size());
Expand Down

0 comments on commit 2bd2ce2

Please sign in to comment.