Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Not ready for review) Use builder pattern for ParquetReader #18633

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -595,4 +595,106 @@ private List<OffsetRange> concatRanges(List<OffsetRange> offsetRanges)
}
return pageRanges;
}

public static Builder builder(
MessageColumnIO messageColumnIO,
List<BlockMetaData> block,
ParquetDataSource dataSource,
AggregatedMemoryContext systemMemoryContext)
{
return new Builder(messageColumnIO, block, dataSource, systemMemoryContext);
}

public static class Builder
{
private final MessageColumnIO messageColumnIO;
private final List<BlockMetaData> blocks;
protected final ParquetDataSource dataSource;
private final AggregatedMemoryContext systemMemoryContext;
private Optional<List<Long>> firstRowsOfBlocks = Optional.empty();
private DataSize maxReadBlockSize;
private boolean batchReadEnabled;
private boolean enableVerification;
private Predicate parquetPredicate;
private List<ColumnIndexStore> blockIndexStores;
private boolean columnIndexFilterEnabled;
private Optional<InternalFileDecryptor> fileDecryptor = Optional.empty();

private Builder(
MessageColumnIO messageColumnIO,
List<BlockMetaData> block,
ParquetDataSource dataSource,
AggregatedMemoryContext systemMemoryContext)
{
this.messageColumnIO = messageColumnIO;
this.blocks = block;
this.dataSource = dataSource;
this.systemMemoryContext = systemMemoryContext;
}

public Builder withFirstRowOfBlocks(Optional<List<Long>> firstRowsOfBlocks)
{
this.firstRowsOfBlocks = firstRowsOfBlocks;
return this;
}

public Builder withMaxReadBlockSize(DataSize maxReadBlockSize)
{
this.maxReadBlockSize = maxReadBlockSize;
return this;
}

public Builder withBatchReadEnabled(boolean batchReadEnabled)
{
this.batchReadEnabled = batchReadEnabled;
return this;
}

public Builder withEnableVerification(boolean enableVerification)
{
this.enableVerification = enableVerification;
return this;
}

public Builder withPredicate(Predicate parquetPredicate)
{
this.parquetPredicate = parquetPredicate;
return this;
}

public Builder withBlockIndexStores(List<ColumnIndexStore> blockIndexStores)
{
this.blockIndexStores = blockIndexStores;
return this;
}

public Builder withColumnIndexEnabled(boolean columnIndexFilterEnabled)
{
this.columnIndexFilterEnabled = columnIndexFilterEnabled;
return this;
}

public Builder withFileDecryptor(Optional<InternalFileDecryptor> fileDecryptor)
{
this.fileDecryptor = fileDecryptor;
return this;
}

public ParquetReader build()
{
return new ParquetReader(
this.messageColumnIO,
this.blocks,
this.firstRowsOfBlocks,
this.dataSource,
this.systemMemoryContext,
this.maxReadBlockSize,
this.batchReadEnabled,
this.enableVerification,
this.parquetPredicate,
this.blockIndexStores,
this.columnIndexFilterEnabled,
this.fileDecryptor);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -432,19 +432,16 @@ private ParquetReader createParquetReader(ParquetMetadata parquetMetadata,
nextStart += block.getRowCount();
}

return new ParquetReader(
messageColumn,
blocks.build(),
Optional.empty(),
dataSource,
com.facebook.presto.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext(),
new DataSize(100000, DataSize.Unit.BYTE),
false,
false,
null,
null,
false,
fileDecryptor);
return ParquetReader.builder(messageColumn, blocks.build(), dataSource, com.facebook.presto.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext())
.withFirstRowOfBlocks(Optional.empty())
.withMaxReadBlockSize(new DataSize(100000, DataSize.Unit.BYTE))
.withBatchReadEnabled(false)
.withEnableVerification(false)
.withPredicate(null)
.withBlockIndexStores(null)
.withColumnIndexEnabled(false)
.withFileDecryptor(fileDecryptor)
.build();
}

private void validateFile(ParquetReader parquetReader, MessageColumnIO messageColumn, EncryptionTestFile inputFile)
Expand Down