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

[core] Incremental-between tags should deduplicate records #3338

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public MemorySegmentPool memoryPool() {
return memoryPool;
}

public RowType valueType() {
return valueType;
}

public void setIOManager(IOManager ioManager) {
this.ioManager = ioManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,16 @@ public MergeFileSplitRead withKeyProjection(@Nullable int[][] projectedFields) {
return this;
}

public MergeFileSplitRead withValueProjection(@Nullable int[][] projectedFields) {
public Comparator<InternalRow> keyComparator() {
return keyComparator;
}

public MergeSorter mergeSorter() {
return mergeSorter;
}

@Override
public MergeFileSplitRead withProjection(@Nullable int[][] projectedFields) {
if (projectedFields == null) {
return this;
}
Expand Down Expand Up @@ -160,11 +169,13 @@ public MergeFileSplitRead withValueProjection(@Nullable int[][] projectedFields)
return this;
}

@Override
public MergeFileSplitRead withIOManager(IOManager ioManager) {
this.mergeSorter.setIOManager(ioManager);
return this;
}

@Override
public MergeFileSplitRead forceKeepDelete() {
this.forceKeepDelete = true;
return this;
Expand Down Expand Up @@ -211,75 +222,28 @@ public MergeFileSplitRead withFilter(Predicate predicate) {

@Override
public RecordReader<KeyValue> createReader(DataSplit split) throws IOException {
RecordReader<KeyValue> reader = createReaderWithoutOuterProjection(split);
if (outerProjection != null) {
ProjectedRow projectedRow = ProjectedRow.from(outerProjection);
reader = reader.transform(kv -> kv.replaceValue(projectedRow.replaceRow(kv.value())));
if (!split.beforeFiles().isEmpty()) {
throw new IllegalArgumentException("This read cannot accept split with before files.");
}
return reader;
}

private RecordReader<KeyValue> createReaderWithoutOuterProjection(DataSplit split)
throws IOException {
if (split.beforeFiles().isEmpty()) {
if (split.isStreaming() || split.convertToRawFiles().isPresent()) {
return noMergeRead(
split.partition(),
split.bucket(),
split.dataFiles(),
split.deletionFiles().orElse(null),
split.isStreaming());
} else {
return projectKey(
mergeRead(
split.partition(),
split.bucket(),
split.dataFiles(),
null,
forceKeepDelete));
}
} else if (split.isStreaming()) {
// streaming concat read
return ConcatRecordReader.create(
() ->
new ReverseReader(
noMergeRead(
split.partition(),
split.bucket(),
split.beforeFiles(),
split.beforeDeletionFiles().orElse(null),
true)),
() ->
noMergeRead(
split.partition(),
split.bucket(),
split.dataFiles(),
split.deletionFiles().orElse(null),
true));
if (split.isStreaming()) {
return createNoMergeReader(
split.partition(),
split.bucket(),
split.dataFiles(),
split.deletionFiles().orElse(null),
split.isStreaming());
} else {
// batch diff read
return projectKey(
DiffReader.readDiff(
mergeRead(
split.partition(),
split.bucket(),
split.beforeFiles(),
split.beforeDeletionFiles().orElse(null),
false),
mergeRead(
split.partition(),
split.bucket(),
split.dataFiles(),
split.deletionFiles().orElse(null),
false),
keyComparator,
createUdsComparator(),
mergeSorter,
forceKeepDelete));
return createMergeReader(
split.partition(),
split.bucket(),
split.dataFiles(),
split.deletionFiles().orElse(null),
forceKeepDelete);
}
}

private RecordReader<KeyValue> mergeRead(
public RecordReader<KeyValue> createMergeReader(
BinaryRow partition,
int bucket,
List<DataFileMeta> files,
Expand Down Expand Up @@ -316,10 +280,10 @@ private RecordReader<KeyValue> mergeRead(
reader = new DropDeleteReader(reader);
}

return reader;
return projectOuter(projectKey(reader));
}

private RecordReader<KeyValue> noMergeRead(
public RecordReader<KeyValue> createNoMergeReader(
BinaryRow partition,
int bucket,
List<DataFileMeta> files,
Expand All @@ -344,7 +308,8 @@ private RecordReader<KeyValue> noMergeRead(
file.schemaId(), fileName, file.fileSize(), file.level());
});
}
return ConcatRecordReader.create(suppliers);

return projectOuter(ConcatRecordReader.create(suppliers));
}

private Optional<String> changelogFile(DataFileMeta fileMeta) {
Expand All @@ -365,8 +330,16 @@ private RecordReader<KeyValue> projectKey(RecordReader<KeyValue> reader) {
return reader.transform(kv -> kv.replaceKey(projectedRow.replaceRow(kv.key())));
}

private RecordReader<KeyValue> projectOuter(RecordReader<KeyValue> reader) {
if (outerProjection != null) {
ProjectedRow projectedRow = ProjectedRow.from(outerProjection);
reader = reader.transform(kv -> kv.replaceValue(projectedRow.replaceRow(kv.value())));
}
return reader;
}

@Nullable
private UserDefinedSeqComparator createUdsComparator() {
public UserDefinedSeqComparator createUdsComparator() {
return UserDefinedSeqComparator.create(
readerFactoryBuilder.projectedValueType(), sequenceFields);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.paimon.data.InternalRow;
import org.apache.paimon.deletionvectors.ApplyDeletionVectorReader;
import org.apache.paimon.deletionvectors.DeletionVector;
import org.apache.paimon.disk.IOManager;
import org.apache.paimon.format.FileFormatDiscover;
import org.apache.paimon.format.FormatKey;
import org.apache.paimon.format.FormatReaderContext;
Expand Down Expand Up @@ -98,6 +99,17 @@ public RawFileSplitRead(
this.projection = Projection.range(0, rowType.getFieldCount()).toNestedIndexes();
}

@Override
public SplitRead<InternalRow> forceKeepDelete() {
return this;
}

@Override
public SplitRead<InternalRow> withIOManager(@Nullable IOManager ioManager) {
return this;
}

@Override
public RawFileSplitRead withProjection(int[][] projectedFields) {
if (projectedFields != null) {
projection = projectedFields;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@

package org.apache.paimon.operation;

import org.apache.paimon.disk.IOManager;
import org.apache.paimon.predicate.Predicate;
import org.apache.paimon.reader.RecordReader;
import org.apache.paimon.table.source.DataSplit;
import org.apache.paimon.utils.IOFunction;

import javax.annotation.Nullable;

import java.io.IOException;

Expand All @@ -31,8 +35,48 @@
*/
public interface SplitRead<T> {

SplitRead<T> withFilter(Predicate predicate);
SplitRead<T> forceKeepDelete();

SplitRead<T> withIOManager(@Nullable IOManager ioManager);

SplitRead<T> withProjection(@Nullable int[][] projectedFields);

SplitRead<T> withFilter(@Nullable Predicate predicate);

/** Create a {@link RecordReader} from split. */
RecordReader<T> createReader(DataSplit split) throws IOException;

static <L, R> SplitRead<R> convert(
SplitRead<L> read, IOFunction<DataSplit, RecordReader<R>> convertedFactory) {
return new SplitRead<R>() {
@Override
public SplitRead<R> forceKeepDelete() {
read.forceKeepDelete();
return this;
}

@Override
public SplitRead<R> withIOManager(@Nullable IOManager ioManager) {
read.withIOManager(ioManager);
return this;
}

@Override
public SplitRead<R> withProjection(@Nullable int[][] projectedFields) {
read.withProjection(projectedFields);
return this;
}

@Override
public SplitRead<R> withFilter(@Nullable Predicate predicate) {
read.withFilter(predicate);
return this;
}

@Override
public RecordReader<R> createReader(DataSplit split) throws IOException {
return convertedFactory.apply(split);
}
};
}
}
Loading
Loading