[HUDI-1445] Refactor AbstractHoodieLogRecordScanner to use Builder (#2313)
This commit is contained in:
@@ -105,7 +105,6 @@ public abstract class AbstractHoodieLogRecordScanner {
|
||||
// Progress
|
||||
private float progress = 0.0f;
|
||||
|
||||
// TODO (NA) - Change this to a builder, this constructor is too long
|
||||
public AbstractHoodieLogRecordScanner(FileSystem fs, String basePath, List<String> logFilePaths, Schema readerSchema,
|
||||
String latestInstantTime, boolean readBlocksLazily, boolean reverseReader, int bufferSize) {
|
||||
this.readerSchema = readerSchema;
|
||||
@@ -358,4 +357,28 @@ public abstract class AbstractHoodieLogRecordScanner {
|
||||
public long getTotalCorruptBlocks() {
|
||||
return totalCorruptBlocks.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder used to build {@code AbstractHoodieLogRecordScanner}.
|
||||
*/
|
||||
public abstract static class Builder {
|
||||
|
||||
public abstract Builder withFileSystem(FileSystem fs);
|
||||
|
||||
public abstract Builder withBasePath(String basePath);
|
||||
|
||||
public abstract Builder withLogFilePaths(List<String> logFilePaths);
|
||||
|
||||
public abstract Builder withReaderSchema(Schema schema);
|
||||
|
||||
public abstract Builder withLatestInstantTime(String latestInstantTime);
|
||||
|
||||
public abstract Builder withReadBlocksLazily(boolean readBlocksLazily);
|
||||
|
||||
public abstract Builder withReverseReader(boolean reverseReader);
|
||||
|
||||
public abstract Builder withBufferSize(int bufferSize);
|
||||
|
||||
public abstract AbstractHoodieLogRecordScanner build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +105,13 @@ public class HoodieMergedLogRecordScanner extends AbstractHoodieLogRecordScanner
|
||||
return numMergedRecordsInLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the builder for {@code HoodieMergedLogRecordScanner}.
|
||||
*/
|
||||
public static HoodieMergedLogRecordScanner.Builder newBuilder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processNextRecord(HoodieRecord<? extends HoodieRecordPayload> hoodieRecord) throws IOException {
|
||||
String key = hoodieRecord.getRecordKey();
|
||||
@@ -128,5 +135,79 @@ public class HoodieMergedLogRecordScanner extends AbstractHoodieLogRecordScanner
|
||||
public long getTotalTimeTakenToReadAndMergeBlocks() {
|
||||
return totalTimeTakenToReadAndMergeBlocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder used to build {@code HoodieUnMergedLogRecordScanner}.
|
||||
*/
|
||||
public static class Builder extends AbstractHoodieLogRecordScanner.Builder {
|
||||
private FileSystem fs;
|
||||
private String basePath;
|
||||
private List<String> logFilePaths;
|
||||
private Schema readerSchema;
|
||||
private String latestInstantTime;
|
||||
private boolean readBlocksLazily;
|
||||
private boolean reverseReader;
|
||||
private int bufferSize;
|
||||
// specific configurations
|
||||
private Long maxMemorySizeInBytes;
|
||||
private String spillableMapBasePath;
|
||||
|
||||
public Builder withFileSystem(FileSystem fs) {
|
||||
this.fs = fs;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withLogFilePaths(List<String> logFilePaths) {
|
||||
this.logFilePaths = logFilePaths;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withReaderSchema(Schema schema) {
|
||||
this.readerSchema = schema;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withLatestInstantTime(String latestInstantTime) {
|
||||
this.latestInstantTime = latestInstantTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withReadBlocksLazily(boolean readBlocksLazily) {
|
||||
this.readBlocksLazily = readBlocksLazily;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withReverseReader(boolean reverseReader) {
|
||||
this.reverseReader = reverseReader;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withBufferSize(int bufferSize) {
|
||||
this.bufferSize = bufferSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withMaxMemorySizeInBytes(Long maxMemorySizeInBytes) {
|
||||
this.maxMemorySizeInBytes = maxMemorySizeInBytes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withSpillableMapBasePath(String spillableMapBasePath) {
|
||||
this.spillableMapBasePath = spillableMapBasePath;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HoodieMergedLogRecordScanner build() {
|
||||
return new HoodieMergedLogRecordScanner(fs, basePath, logFilePaths, readerSchema,
|
||||
latestInstantTime, maxMemorySizeInBytes, readBlocksLazily, reverseReader,
|
||||
bufferSize, spillableMapBasePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,13 @@ public class HoodieUnMergedLogRecordScanner extends AbstractHoodieLogRecordScann
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the builder for {@code HoodieUnMergedLogRecordScanner}.
|
||||
*/
|
||||
public static HoodieUnMergedLogRecordScanner.Builder newBuilder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processNextRecord(HoodieRecord<? extends HoodieRecordPayload> hoodieRecord) throws Exception {
|
||||
// Just call callback without merging
|
||||
@@ -60,4 +67,71 @@ public class HoodieUnMergedLogRecordScanner extends AbstractHoodieLogRecordScann
|
||||
|
||||
public void apply(HoodieRecord<? extends HoodieRecordPayload> record) throws Exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder used to build {@code HoodieUnMergedLogRecordScanner}.
|
||||
*/
|
||||
public static class Builder extends AbstractHoodieLogRecordScanner.Builder {
|
||||
private FileSystem fs;
|
||||
private String basePath;
|
||||
private List<String> logFilePaths;
|
||||
private Schema readerSchema;
|
||||
private String latestInstantTime;
|
||||
private boolean readBlocksLazily;
|
||||
private boolean reverseReader;
|
||||
private int bufferSize;
|
||||
// specific configurations
|
||||
private LogRecordScannerCallback callback;
|
||||
|
||||
public Builder withFileSystem(FileSystem fs) {
|
||||
this.fs = fs;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withLogFilePaths(List<String> logFilePaths) {
|
||||
this.logFilePaths = logFilePaths;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withReaderSchema(Schema schema) {
|
||||
this.readerSchema = schema;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withLatestInstantTime(String latestInstantTime) {
|
||||
this.latestInstantTime = latestInstantTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withReadBlocksLazily(boolean readBlocksLazily) {
|
||||
this.readBlocksLazily = readBlocksLazily;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withReverseReader(boolean reverseReader) {
|
||||
this.reverseReader = reverseReader;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withBufferSize(int bufferSize) {
|
||||
this.bufferSize = bufferSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withLogRecordScannerCallback(LogRecordScannerCallback callback) {
|
||||
this.callback = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HoodieUnMergedLogRecordScanner build() {
|
||||
return new HoodieUnMergedLogRecordScanner(fs, basePath, logFilePaths, readerSchema,
|
||||
latestInstantTime, readBlocksLazily, reverseReader, bufferSize, callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user