Skip to content
Open
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
6 changes: 6 additions & 0 deletions docs/generated/core_configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,12 @@
<td>Integer</td>
<td>Bucket number for the partitions compacted for the first time in postpone bucket tables.</td>
</tr>
<tr>
<td><h5>postpone.merge-on-read</h5></td>
<td style="word-wrap: break-word;">false</td>
<td>Boolean</td>
<td>Whether to merge records in the postpone bucket with records in real buckets during batch reads. This requires an execution engine capable of routing and shuffling postpone records to their target real buckets.</td>
</tr>
<tr>
<td><h5>postpone.target-row-num-per-bucket</h5></td>
<td style="word-wrap: break-word;">(none)</td>
Expand Down
12 changes: 12 additions & 0 deletions paimon-api/src/main/java/org/apache/paimon/CoreOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2637,6 +2637,14 @@ public String toString() {
.withDescription(
"Whether to write the data into fixed bucket for batch writing a postpone bucket table.");

public static final ConfigOption<Boolean> POSTPONE_MERGE_ON_READ =
key("postpone.merge-on-read")
.booleanType()
.defaultValue(false)
.withDescription(
"Whether to merge records in the postpone bucket with records in real buckets during batch reads. "
+ "This requires an execution engine capable of routing and shuffling postpone records to their target real buckets.");

public static final ConfigOption<Integer> POSTPONE_BATCH_WRITE_FIXED_BUCKET_MAX_PARALLELISM =
key("postpone.batch-write-fixed-bucket.max-parallelism")
.intType()
Expand Down Expand Up @@ -4272,6 +4280,10 @@ public boolean postponeBatchWriteFixedBucket() {
return options.get(POSTPONE_BATCH_WRITE_FIXED_BUCKET);
}

public boolean postponeMergeOnRead() {
return options.get(POSTPONE_MERGE_ON_READ);
}

public int postponeBatchWriteFixedBucketMaxParallelism() {
return options.get(POSTPONE_BATCH_WRITE_FIXED_BUCKET_MAX_PARALLELISM);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.paimon.mergetree.compact.MergeFunction;
import org.apache.paimon.mergetree.compact.ReducerMergeFunctionWrapper;
import org.apache.paimon.options.MemorySize;
import org.apache.paimon.reader.RecordReader;
import org.apache.paimon.sort.BinaryExternalSortBuffer;
import org.apache.paimon.sort.BinaryInMemorySortBuffer;
import org.apache.paimon.sort.SortBuffer;
Expand Down Expand Up @@ -181,6 +182,51 @@ public void forEach(
}
}

/**
* Creates a sorted reader which merges records with the same key.
*
* <p>The returned reader owns this buffer. Closing it clears the buffer and releases spill
* files. No records may be added after this method is called.
*/
public RecordReader<KeyValue> createReader(
Comparator<InternalRow> keyComparator, MergeFunction<KeyValue> mergeFunction)
throws IOException {
MergeIterator mergeIterator =
new MergeIterator(null, buffer.sortedIterator(), keyComparator, mergeFunction);
return new RecordReader<KeyValue>() {

private boolean read;
private boolean closed;

@Nullable
@Override
public RecordIterator<KeyValue> readBatch() {
if (read) {
return null;
}
read = true;
return new RecordIterator<KeyValue>() {
@Nullable
@Override
public KeyValue next() throws IOException {
return mergeIterator.hasNext() ? mergeIterator.next() : null;
}

@Override
public void releaseBatch() {}
};
}

@Override
public void close() {
if (!closed) {
closed = true;
clear();
}
}
};
}

@Override
public void clear() {
buffer.clear();
Expand Down
Loading
Loading