Skip to content

Commit

Permalink
Add OrcReaderOptions builder
Browse files Browse the repository at this point in the history
  • Loading branch information
sdruzkin authored and ARUNACHALAM THIRUPATHI committed Mar 5, 2022
1 parent 5eae5e5 commit 6e88468
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import io.airlift.units.DataSize;

import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;

public class OrcReaderOptions
Expand Down Expand Up @@ -97,4 +98,90 @@ public boolean appendRowNumber()
{
return appendRowNumber;
}

@Override
public String toString()
{
return toStringHelper(this)
.add("maxMergeDistance", maxMergeDistance)
.add("tinyStripeThreshold", tinyStripeThreshold)
.add("maxBlockSize", maxBlockSize)
.add("zstdJniDecompressionEnabled", zstdJniDecompressionEnabled)
.add("mapNullKeysEnabled", mapNullKeysEnabled)
.add("enableTimestampMicroPrecision", enableTimestampMicroPrecision)
.add("appendRowNumber", appendRowNumber)
.toString();
}

public static Builder builder()
{
return new Builder();
}

public static final class Builder
{
private DataSize maxMergeDistance;
private DataSize tinyStripeThreshold;
private DataSize maxBlockSize;
private boolean zstdJniDecompressionEnabled;
private boolean mapNullKeysEnabled;
private boolean enableTimestampMicroPrecision;
private boolean appendRowNumber;

private Builder() {}

public Builder withMaxMergeDistance(DataSize maxMergeDistance)
{
this.maxMergeDistance = requireNonNull(maxMergeDistance, "maxMergeDistance is null");
return this;
}

public Builder withTinyStripeThreshold(DataSize tinyStripeThreshold)
{
this.tinyStripeThreshold = requireNonNull(tinyStripeThreshold, "tinyStripeThreshold is null");
return this;
}

public Builder withMaxBlockSize(DataSize maxBlockSize)
{
this.maxBlockSize = requireNonNull(maxBlockSize, "maxBlockSize is null");
return this;
}

public Builder withZstdJniDecompressionEnabled(boolean zstdJniDecompressionEnabled)
{
this.zstdJniDecompressionEnabled = zstdJniDecompressionEnabled;
return this;
}

public Builder withMapNullKeysEnabled(boolean mapNullKeysEnabled)
{
this.mapNullKeysEnabled = mapNullKeysEnabled;
return this;
}

public Builder withEnableTimestampMicroPrecision(boolean enableTimestampMicroPrecision)
{
this.enableTimestampMicroPrecision = enableTimestampMicroPrecision;
return this;
}

public Builder withAppendRowNumber(boolean appendRowNumber)
{
this.appendRowNumber = appendRowNumber;
return this;
}

public OrcReaderOptions build()
{
return new OrcReaderOptions(
maxMergeDistance,
tinyStripeThreshold,
maxBlockSize,
zstdJniDecompressionEnabled,
mapNullKeysEnabled,
enableTimestampMicroPrecision,
appendRowNumber);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ public static OrcReaderOptions createDefaultTestConfig()

public static OrcReaderOptions createTestingReaderOptions(boolean zstdJniDecompressionEnabled)
{
return new OrcReaderOptions(
new DataSize(1, MEGABYTE),
new DataSize(1, MEGABYTE),
new DataSize(1, MEGABYTE),
zstdJniDecompressionEnabled);
DataSize dataSize = new DataSize(1, MEGABYTE);
return OrcReaderOptions.builder()
.withMaxMergeDistance(dataSize)
.withTinyStripeThreshold(dataSize)
.withMaxBlockSize(dataSize)
.withZstdJniDecompressionEnabled(zstdJniDecompressionEnabled)
.build();
}
}
54 changes: 25 additions & 29 deletions presto-orc/src/test/java/com/facebook/presto/orc/OrcTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -1474,14 +1474,12 @@ static OrcBatchRecordReader createCustomOrcRecordReader(
orcFileTailSource,
stripeMetadataSource,
NOOP_ORC_AGGREGATED_MEMORY_CONTEXT,
new OrcReaderOptions(
new DataSize(1, MEGABYTE),
new DataSize(1, MEGABYTE),
MAX_BLOCK_SIZE,
false,
mapNullKeysEnabled,
false,
false),
OrcReaderOptions.builder()
.withMaxMergeDistance(new DataSize(1, MEGABYTE))
.withTinyStripeThreshold(new DataSize(1, MEGABYTE))
.withMaxBlockSize(MAX_BLOCK_SIZE)
.withMapNullKeysEnabled(mapNullKeysEnabled)
.build(),
cacheable,
new DwrfEncryptionProvider(new UnsupportedEncryptionLibrary(), new TestingEncryptionLibrary()),
DwrfKeyProvider.of(intermediateEncryptionKeys),
Expand Down Expand Up @@ -1510,14 +1508,12 @@ static OrcReader createCustomOrcReader(
new StorageOrcFileTailSource(),
new StorageStripeMetadataSource(),
NOOP_ORC_AGGREGATED_MEMORY_CONTEXT,
new OrcReaderOptions(
new DataSize(1, MEGABYTE),
new DataSize(1, MEGABYTE),
MAX_BLOCK_SIZE,
false,
mapNullKeysEnabled,
false,
false),
OrcReaderOptions.builder()
.withMaxMergeDistance(new DataSize(1, MEGABYTE))
.withTinyStripeThreshold(new DataSize(1, MEGABYTE))
.withMaxBlockSize(MAX_BLOCK_SIZE)
.withMapNullKeysEnabled(mapNullKeysEnabled)
.build(),
false,
new DwrfEncryptionProvider(new UnsupportedEncryptionLibrary(), new TestingEncryptionLibrary()),
DwrfKeyProvider.of(intermediateEncryptionKeys),
Expand Down Expand Up @@ -1574,11 +1570,12 @@ public static FileMetadata getFileMetadata(File inputFile, OrcEncoding encoding)
new StorageOrcFileTailSource(),
new StorageStripeMetadataSource(),
NOOP_ORC_AGGREGATED_MEMORY_CONTEXT,
new OrcReaderOptions(
dataSize,
dataSize,
dataSize,
zstdJniDecompressionEnabled),
OrcReaderOptions.builder()
.withMaxMergeDistance(dataSize)
.withTinyStripeThreshold(dataSize)
.withMaxBlockSize(dataSize)
.withZstdJniDecompressionEnabled(zstdJniDecompressionEnabled)
.build(),
false,
NO_ENCRYPTION,
DwrfKeyProvider.EMPTY,
Expand Down Expand Up @@ -1698,14 +1695,13 @@ public static OrcSelectiveRecordReader createCustomOrcSelectiveRecordReader(
new StorageOrcFileTailSource(),
new StorageStripeMetadataSource(),
NOOP_ORC_AGGREGATED_MEMORY_CONTEXT,
new OrcReaderOptions(
new DataSize(1, MEGABYTE),
new DataSize(1, MEGABYTE),
MAX_BLOCK_SIZE,
false,
mapNullKeysEnabled,
false,
appendRowNumber),
OrcReaderOptions.builder()
.withMaxMergeDistance(new DataSize(1, MEGABYTE))
.withTinyStripeThreshold(new DataSize(1, MEGABYTE))
.withMaxBlockSize(MAX_BLOCK_SIZE)
.withMapNullKeysEnabled(mapNullKeysEnabled)
.withAppendRowNumber(appendRowNumber)
.build(),
false,
new DwrfEncryptionProvider(new UnsupportedEncryptionLibrary(), new TestingEncryptionLibrary()),
DwrfKeyProvider.of(intermediateEncryptionKeys),
Expand Down
10 changes: 5 additions & 5 deletions presto-orc/src/test/java/com/facebook/presto/orc/TestOrcLz4.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public void testReadLz4()
new StorageOrcFileTailSource(),
new StorageStripeMetadataSource(),
NOOP_ORC_AGGREGATED_MEMORY_CONTEXT,
new OrcReaderOptions(
SIZE,
SIZE,
SIZE,
false),
OrcReaderOptions.builder()
.withMaxMergeDistance(SIZE)
.withTinyStripeThreshold(SIZE)
.withMaxBlockSize(SIZE)
.build(),
false,
NO_ENCRYPTION,
DwrfKeyProvider.EMPTY,
Expand Down

0 comments on commit 6e88468

Please sign in to comment.