Skip to content
Draft
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
25 changes: 25 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 @@ -2458,6 +2458,23 @@ public String toString() {
"For DELETE manifest entry in manifest file, drop stats to reduce memory and storage."
+ " Default value is false only for compatibility of old reader.");

public static final ConfigOption<Boolean> PARTITION_BUCKET_MAPPING_CACHE_ENABLED =
key("partition-bucket-mapping.cache-enabled")
.booleanType()
.defaultValue(false)
.withDescription(
"If true, cache partition bucket mappings in the current JVM when initializing writers."
+ " This avoids repeated manifest scans by multiple writers in the same TaskManager,"
+ " but the cached mapping is shared until the table snapshot changes.");

public static final ConfigOption<Integer> PARTITION_BUCKET_MAPPING_CACHE_MAX_ENTRIES =
key("partition-bucket-mapping.cache-max-entries")
.intType()
.defaultValue(128)
.withDescription(
"Maximum number of partition bucket mappings to cache in the current JVM."
+ " Older snapshots of the same table are invalidated when a newer snapshot mapping is loaded.");

public static final ConfigOption<Boolean> DATA_FILE_THIN_MODE =
key("data-file.thin-mode")
.booleanType()
Expand Down Expand Up @@ -4210,6 +4227,14 @@ public boolean manifestDeleteFileDropStats() {
return options.get(MANIFEST_DELETE_FILE_DROP_STATS);
}

public boolean partitionBucketMappingCacheEnabled() {
return options.get(PARTITION_BUCKET_MAPPING_CACHE_ENABLED);
}

public int partitionBucketMappingCacheMaxEntries() {
return options.get(PARTITION_BUCKET_MAPPING_CACHE_MAX_ENTRIES);
}

public boolean disableNullToNotNull() {
return options.get(DISABLE_ALTER_COLUMN_NULL_TO_NOT_NULL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.apache.paimon.table.sink.DynamicBucketRowKeyExtractor;
import org.apache.paimon.table.sink.FixedBucketRowKeyExtractor;
import org.apache.paimon.table.sink.FixedBucketWriteSelector;
import org.apache.paimon.table.sink.PartitionBucketMapping;
import org.apache.paimon.table.sink.PostponeBucketRowKeyExtractor;
import org.apache.paimon.table.sink.RowKeyExtractor;
import org.apache.paimon.table.sink.RowKindGenerator;
Expand Down Expand Up @@ -265,7 +266,9 @@ public Optional<Statistics> statistics() {
public Optional<WriteSelector> newWriteSelector() {
switch (bucketMode()) {
case HASH_FIXED:
return Optional.of(new FixedBucketWriteSelector(schema()));
return Optional.of(
new FixedBucketWriteSelector(
schema(), PartitionBucketMapping.loadFromTable(this)));
case BUCKET_UNAWARE:
case POSTPONE_MODE:
return Optional.empty();
Expand Down Expand Up @@ -307,7 +310,8 @@ protected RowKeyExtractor createRowKeyExtractor(RowType writeType) {
TableSchema schema = schema().copy(writeType.getFields());
switch (bucketMode()) {
case HASH_FIXED:
return new FixedBucketRowKeyExtractor(schema);
return new FixedBucketRowKeyExtractor(
schema, PartitionBucketMapping.loadFromTable(this));
case HASH_DYNAMIC:
case KEY_DYNAMIC:
return new DynamicBucketRowKeyExtractor(schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.paimon.predicate.Predicate;
import org.apache.paimon.schema.TableSchema;
import org.apache.paimon.table.query.LocalTableQuery;
import org.apache.paimon.table.sink.KeyAndBucketExtractor;
import org.apache.paimon.table.sink.TableWriteImpl;
import org.apache.paimon.table.source.AppendBatchTableScan;
import org.apache.paimon.table.source.AppendOnlySplitGenerator;
Expand All @@ -43,6 +44,7 @@
import org.apache.paimon.table.source.splitread.DataEvolutionSplitReadProvider;
import org.apache.paimon.table.source.splitread.SplitReadConfig;
import org.apache.paimon.table.source.splitread.SplitReadProvider;
import org.apache.paimon.types.RowType;
import org.apache.paimon.utils.Preconditions;
import org.apache.paimon.utils.RowKindFilter;

Expand Down Expand Up @@ -176,11 +178,19 @@ public TableWriteImpl<InternalRow> newWrite(String commitUser) {

@Override
public TableWriteImpl<InternalRow> newWrite(String commitUser, @Nullable Integer writeId) {
return newWrite(commitUser, writeId, this::createRowKeyExtractor);
}

@Override
public TableWriteImpl<InternalRow> newWrite(
String commitUser,
@Nullable Integer writeId,
Function<RowType, KeyAndBucketExtractor<InternalRow>> keyAndBucketExtractorFactory) {
BaseAppendFileStoreWrite writer = store().newWrite(commitUser, writeId);
return new TableWriteImpl<>(
rowType(),
writer,
this::createRowKeyExtractor,
keyAndBucketExtractorFactory,
(record, rowKind) -> {
Preconditions.checkState(
rowKind.isAdd(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.paimon.FileStore;
import org.apache.paimon.Snapshot;
import org.apache.paimon.consumer.ConsumerManager;
import org.apache.paimon.data.InternalRow;
import org.apache.paimon.fs.FileIO;
import org.apache.paimon.fs.Path;
import org.apache.paimon.manifest.IndexManifestEntry;
Expand All @@ -31,6 +32,7 @@
import org.apache.paimon.schema.TableSchema;
import org.apache.paimon.stats.Statistics;
import org.apache.paimon.table.query.LocalTableQuery;
import org.apache.paimon.table.sink.KeyAndBucketExtractor;
import org.apache.paimon.table.sink.RowKeyExtractor;
import org.apache.paimon.table.sink.TableCommitImpl;
import org.apache.paimon.table.sink.TableWriteImpl;
Expand All @@ -40,6 +42,7 @@
import org.apache.paimon.table.source.StreamDataTableScan;
import org.apache.paimon.table.source.snapshot.SnapshotReader;
import org.apache.paimon.tag.TagAutoManager;
import org.apache.paimon.types.RowType;
import org.apache.paimon.utils.BranchManager;
import org.apache.paimon.utils.ChangelogManager;
import org.apache.paimon.utils.DVMetaCache;
Expand All @@ -55,6 +58,7 @@
import java.time.Duration;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;

/** Delegated {@link FileStoreTable}. */
public abstract class DelegatedFileStoreTable implements FileStoreTable {
Expand Down Expand Up @@ -356,6 +360,14 @@ public TableWriteImpl<?> newWrite(String commitUser, @Nullable Integer writeId)
return wrapped.newWrite(commitUser, writeId);
}

@Override
public TableWriteImpl<?> newWrite(
String commitUser,
@Nullable Integer writeId,
Function<RowType, KeyAndBucketExtractor<InternalRow>> keyAndBucketExtractorFactory) {
return wrapped.newWrite(commitUser, writeId, keyAndBucketExtractorFactory);
}

@Override
public TableWriteImpl<?> newPostponeFixedBucketWrite(
String commitUser, @Nullable Integer writeId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.paimon.stats.Statistics;
import org.apache.paimon.table.query.LocalTableQuery;
import org.apache.paimon.table.sink.BatchTableCommit;
import org.apache.paimon.table.sink.KeyAndBucketExtractor;
import org.apache.paimon.table.sink.PostponeFixedBucketWriteBuilder;
import org.apache.paimon.table.sink.RowKeyExtractor;
import org.apache.paimon.table.sink.TableCommitImpl;
Expand All @@ -51,6 +52,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

/**
* An abstraction layer above {@link FileStore} to provide reading and writing of {@link
Expand Down Expand Up @@ -152,6 +154,12 @@ default PostponeFixedBucketWriteBuilder newPostponeFixedBucketWriteBuilder() {

TableWriteImpl<?> newWrite(String commitUser, @Nullable Integer writeId);

/** Creates a new write using the supplied bucket assignment logic. */
TableWriteImpl<?> newWrite(
String commitUser,
@Nullable Integer writeId,
Function<RowType, KeyAndBucketExtractor<InternalRow>> keyAndBucketExtractorFactory);

/** Creates a fixed-bucket merge-tree write for a postpone-bucket batch write. */
default TableWriteImpl<?> newPostponeFixedBucketWrite(
String commitUser, @Nullable Integer writeId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.paimon.table;

import org.apache.paimon.data.InternalRow;
import org.apache.paimon.schema.TableSchema;
import org.apache.paimon.table.sink.FixedBucketRowKeyExtractor;
import org.apache.paimon.table.sink.FixedBucketWriteSelector;
import org.apache.paimon.table.sink.KeyAndBucketExtractor;
import org.apache.paimon.table.sink.PartitionBucketMapping;
import org.apache.paimon.table.sink.RowKeyExtractor;
import org.apache.paimon.table.sink.TableWriteImpl;
import org.apache.paimon.table.sink.WriteSelector;
import org.apache.paimon.types.RowType;

import javax.annotation.Nullable;

import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

/**
* A table wrapper for overwrite operations which routes rows using the target schema bucket count.
* Existing per-partition bucket mappings must not be used while rewriting a partition to a new
* bucket count.
*/
public class OverwriteFileStoreTable extends DelegatedFileStoreTable {

public OverwriteFileStoreTable(FileStoreTable wrapped) {
super(wrapped);
}

private PartitionBucketMapping targetBucketMapping() {
return new PartitionBucketMapping(schema().numBuckets());
}

@Override
public Optional<WriteSelector> newWriteSelector() {
return Optional.of(new FixedBucketWriteSelector(schema(), targetBucketMapping()));
}

@Override
public RowKeyExtractor createRowKeyExtractor() {
return new FixedBucketRowKeyExtractor(schema(), targetBucketMapping());
}

@Override
public TableWriteImpl<?> newWrite(String commitUser) {
return newWrite(commitUser, null);
}

@Override
public TableWriteImpl<?> newWrite(String commitUser, @Nullable Integer writeId) {
return wrapped()
.newWrite(
commitUser,
writeId,
writeType ->
new FixedBucketRowKeyExtractor(
schema().copy(writeType.getFields()),
targetBucketMapping()));
}

@Override
public TableWriteImpl<?> newWrite(
String commitUser,
@Nullable Integer writeId,
Function<RowType, KeyAndBucketExtractor<InternalRow>> keyAndBucketExtractorFactory) {
return wrapped().newWrite(commitUser, writeId, keyAndBucketExtractorFactory);
}

@Override
public FileStoreTable copy(Map<String, String> dynamicOptions) {
return new OverwriteFileStoreTable(wrapped().copy(dynamicOptions));
}

@Override
public FileStoreTable copy(TableSchema newTableSchema) {
return new OverwriteFileStoreTable(wrapped().copy(newTableSchema));
}

@Override
public FileStoreTable copyWithoutQueryAuth() {
return new OverwriteFileStoreTable(wrapped().copyWithoutQueryAuth());
}

@Override
public FileStoreTable copyWithoutTimeTravel(Map<String, String> dynamicOptions) {
return new OverwriteFileStoreTable(wrapped().copyWithoutTimeTravel(dynamicOptions));
}

@Override
public FileStoreTable copyWithLatestSchema() {
return new OverwriteFileStoreTable(wrapped().copyWithLatestSchema());
}

@Override
public FileStoreTable switchToBranch(String branchName) {
return new OverwriteFileStoreTable(wrapped().switchToBranch(branchName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.paimon.KeyValue;
import org.apache.paimon.KeyValueFileStore;
import org.apache.paimon.annotation.VisibleForTesting;
import org.apache.paimon.data.InternalRow;
import org.apache.paimon.fs.FileIO;
import org.apache.paimon.fs.Path;
import org.apache.paimon.mergetree.compact.LookupMergeFunction;
Expand All @@ -33,6 +34,7 @@
import org.apache.paimon.schema.KeyValueFieldsExtractor;
import org.apache.paimon.schema.TableSchema;
import org.apache.paimon.table.query.LocalTableQuery;
import org.apache.paimon.table.sink.KeyAndBucketExtractor;
import org.apache.paimon.table.sink.TableWriteImpl;
import org.apache.paimon.table.source.DataTableScan;
import org.apache.paimon.table.source.InnerTableRead;
Expand All @@ -49,6 +51,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.apache.paimon.predicate.PredicateBuilder.and;
Expand Down Expand Up @@ -192,22 +195,33 @@ public TableWriteImpl<KeyValue> newWrite(String commitUser) {

@Override
public TableWriteImpl<KeyValue> newWrite(String commitUser, @Nullable Integer writeId) {
return newWrite(store().newWrite(commitUser, writeId));
return newWrite(commitUser, writeId, this::createRowKeyExtractor);
}

@Override
public TableWriteImpl<KeyValue> newWrite(
String commitUser,
@Nullable Integer writeId,
Function<RowType, KeyAndBucketExtractor<InternalRow>> keyAndBucketExtractorFactory) {
return newWrite(store().newWrite(commitUser, writeId), keyAndBucketExtractorFactory);
}

@Override
public TableWriteImpl<KeyValue> newPostponeFixedBucketWrite(
String commitUser, @Nullable Integer writeId) {
return newWrite(store().newPostponeFixedBucketWrite(commitUser));
return newWrite(
store().newPostponeFixedBucketWrite(commitUser), this::createRowKeyExtractor);
}

private TableWriteImpl<KeyValue> newWrite(AbstractFileStoreWrite<KeyValue> storeWrite) {
private TableWriteImpl<KeyValue> newWrite(
AbstractFileStoreWrite<KeyValue> storeWrite,
Function<RowType, KeyAndBucketExtractor<InternalRow>> keyAndBucketExtractorFactory) {
KeyValue kv = new KeyValue();
List<String> deleteNotNullFields = deleteNotNullFields(coreOptions());
return new TableWriteImpl<>(
rowType(),
storeWrite,
this::createRowKeyExtractor,
keyAndBucketExtractorFactory,
(record, rowKind) ->
kv.replace(
record.primaryKey(),
Expand Down
Loading
Loading