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
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import static org.apache.paimon.CoreOptions.SNAPSHOT_NUM_RETAINED_MIN;
import static org.apache.paimon.CoreOptions.STREAMING_READ_OVERWRITE;
import static org.apache.paimon.format.FileFormat.vectorFileFormat;
import static org.apache.paimon.schema.TableSchema.PAIMON_07_VERSION;
import static org.apache.paimon.table.PrimaryKeyTableUtils.createMergeFunctionFactory;
import static org.apache.paimon.table.SpecialFields.KEY_FIELD_PREFIX;
import static org.apache.paimon.table.SpecialFields.SYSTEM_FIELD_NAMES;
Expand Down Expand Up @@ -681,7 +682,9 @@ private static void validateBucket(TableSchema schema, CoreOptions options) {
} else if (bucket < 1 && !isPostponeBucketTable(schema, bucket)) {
throw new RuntimeException("The number of buckets needs to be greater than 0.");
} else {
if (schema.primaryKeys().isEmpty() && schema.bucketKeys().isEmpty()) {
if (schema.primaryKeys().isEmpty()
&& schema.bucketKeys().isEmpty()
&& (bucket != 1 || schema.version() != PAIMON_07_VERSION)) {
throw new RuntimeException(
"You should define a 'bucket-key' for bucketed append mode.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import static org.apache.paimon.CoreOptions.VECTOR_FIELD;
import static org.apache.paimon.CoreOptions.VECTOR_FILE_FORMAT;
import static org.apache.paimon.schema.SchemaValidation.validateTableSchema;
import static org.apache.paimon.schema.TableSchema.CURRENT_VERSION;
import static org.apache.paimon.schema.TableSchema.PAIMON_07_VERSION;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand Down Expand Up @@ -545,6 +547,69 @@ public void testMergeOnReadCoexistsWithVisibilityCallbackAndPostponeBucket() {
.doesNotThrowAnyException();
}

@Test
public void testBucketAppendBackwardCompatibility() {
List<DataField> fields =
Arrays.asList(
new DataField(0, "f0", DataTypes.INT()),
new DataField(1, "f1", DataTypes.STRING()));

Map<String, String> legacyOptions = new HashMap<>();
legacyOptions.put(BUCKET.key(), "1");

TableSchema legacySchema =
new TableSchema(
PAIMON_07_VERSION,
0L,
fields,
1,
emptyList(),
emptyList(),
legacyOptions,
"",
0L);

assertThatCode(() -> validateTableSchema(legacySchema)).doesNotThrowAnyException();

Map<String, String> currentOptions = new HashMap<>();
currentOptions.put(BUCKET.key(), "1");

TableSchema currentSchema =
new TableSchema(
CURRENT_VERSION,
0L,
fields,
1,
emptyList(),
emptyList(),
currentOptions,
"",
0L);

assertThatThrownBy(() -> validateTableSchema(currentSchema))
.isInstanceOf(RuntimeException.class)
.hasMessageContaining("bucket-key");

Map<String, String> legacyMultiBucketOptions = new HashMap<>();
legacyMultiBucketOptions.put(BUCKET.key(), "2");

TableSchema legacyMultiBucketSchema =
new TableSchema(
PAIMON_07_VERSION,
0L,
fields,
1,
emptyList(),
emptyList(),
legacyMultiBucketOptions,
"",
0L);

assertThatThrownBy(() -> validateTableSchema(legacyMultiBucketSchema))
.isInstanceOf(RuntimeException.class)
.hasMessageContaining("bucket-key");
}

@Test
public void testMergeOnReadRequiresDvEnabled() {
Map<String, String> options = new HashMap<>();
Expand Down