This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new 7b92ef8bbbe branch-4.2: [fix](iceberg) Honor standard row-level
isolation properties (#69702) (#70294)
7b92ef8bbbe is described below
commit 7b92ef8bbbe90f91e86c2c29ff02c21a58505b85
Author: daidai <[email protected]>
AuthorDate: Tue Nov 24 15:32:05 2026 +0800
branch-4.2: [fix](iceberg) Honor standard row-level isolation properties
(#69702) (#70294)
pick #69702
Uses branch-4.2's existing IcebergTransaction and statement context to
distinguish SQL MERGE from UPDATE. Isolation is resolved and cached
before backend execution, with standard-key > legacy-key > SDK-default
precedence from the final merged PR. Invalid selected values fail before
backend writes.
---
.../datasource/iceberg/IcebergTransaction.java | 34 ++-
.../trees/plans/commands/IcebergMergeCommand.java | 1 +
.../insert/IcebergInsertCommandContext.java | 10 +
.../iceberg/IcebergCoverageTestFixture.java | 5 +-
.../iceberg/IcebergRowLevelIsolationTest.java | 318 +++++++++++++++++++++
.../datasource/iceberg/IcebergTransactionTest.java | 1 +
.../iceberg/IcebergWriteKnownBugsTest.java | 3 -
7 files changed, 355 insertions(+), 17 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergTransaction.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergTransaction.java
index 596c5e4cb24..623841a025a 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergTransaction.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergTransaction.java
@@ -43,6 +43,7 @@ import org.apache.iceberg.DeleteFile;
import org.apache.iceberg.FileFormat;
import org.apache.iceberg.FileScanTask;
import org.apache.iceberg.HasTableOperations;
+import org.apache.iceberg.IsolationLevel;
import org.apache.iceberg.OverwriteFiles;
import org.apache.iceberg.PartitionField;
import org.apache.iceberg.PartitionSpec;
@@ -56,6 +57,7 @@ import org.apache.iceberg.Table;
import org.apache.iceberg.TableMetadata;
import org.apache.iceberg.TableMetadataParser;
import org.apache.iceberg.TableOperations;
+import org.apache.iceberg.TableProperties;
import org.apache.iceberg.TableScan;
import org.apache.iceberg.encryption.EncryptionManager;
import org.apache.iceberg.exceptions.CleanableFailure;
@@ -86,8 +88,7 @@ import java.util.function.BooleanSupplier;
public class IcebergTransaction implements Transaction {
private static final Logger LOG =
LogManager.getLogger(IcebergTransaction.class);
- private static final String DELETE_ISOLATION_LEVEL =
"delete_isolation_level";
- private static final String DELETE_ISOLATION_LEVEL_DEFAULT =
"serializable";
+ private static final String LEGACY_DELETE_ISOLATION_LEVEL =
"delete_isolation_level";
private final IcebergMetadataOps ops;
private Table table;
@@ -102,6 +103,7 @@ public class IcebergTransaction implements Transaction {
private Optional<IcebergWriteSchemaContext> writeSchemaContext =
Optional.empty();
private String branchName;
private Long baseSnapshotId;
+ private IsolationLevel rowLevelIsolationLevel;
private boolean hasStagedUpdates;
private boolean commitMayHaveSucceeded;
private Map<String, List<DeleteFile>>
rewrittenDeleteFilesByReferencedDataFile = Collections.emptyMap();
@@ -349,7 +351,10 @@ public class IcebergTransaction implements Transaction {
+ " must have format version 2 or higher for
position deletes");
}
}
- this.transaction = newWriteTransaction();
+ org.apache.iceberg.Transaction opened = newWriteTransaction();
+ this.rowLevelIsolationLevel =
resolveIsolationLevel(opened.table(),
+ TableProperties.DELETE_ISOLATION_LEVEL,
TableProperties.DELETE_ISOLATION_LEVEL_DEFAULT);
+ this.transaction = opened;
this.rewrittenDeleteFilesByReferencedDataFile =
Collections.emptyMap();
LOG.info("Started delete transaction for table: {}",
dorisTable.getName());
});
@@ -445,7 +450,13 @@ public class IcebergTransaction implements Transaction {
+ " must have format version 2 or higher for
position deletes");
}
}
- this.transaction = newWriteTransaction();
+ org.apache.iceberg.Transaction opened = newWriteTransaction();
+ boolean mergeInto = insertCtx != null &&
insertCtx.isMergeInto();
+ this.rowLevelIsolationLevel =
resolveIsolationLevel(opened.table(),
+ mergeInto ? TableProperties.MERGE_ISOLATION_LEVEL :
TableProperties.UPDATE_ISOLATION_LEVEL,
+ mergeInto ?
TableProperties.MERGE_ISOLATION_LEVEL_DEFAULT
+ :
TableProperties.UPDATE_ISOLATION_LEVEL_DEFAULT);
+ this.transaction = opened;
this.rewrittenDeleteFilesByReferencedDataFile =
Collections.emptyMap();
LOG.info("Started merge transaction for table: {}",
dorisTable.getName());
return null;
@@ -1001,7 +1012,7 @@ public class IcebergTransaction implements Transaction {
List<TIcebergCommitData> commitDataList, List<String>
referencedDataFiles) {
applyBaseSnapshotValidation(rowDelta);
applyConflictDetectionFilter(rowDelta, icebergTable, commitDataList);
- if (isSerializableIsolationLevel(icebergTable)) {
+ if (rowLevelIsolationLevel == IsolationLevel.SERIALIZABLE) {
rowDelta.validateNoConflictingDataFiles();
}
rowDelta.validateDeletedFiles();
@@ -1126,13 +1137,12 @@ public class IcebergTransaction implements Transaction {
return Collections.emptyList();
}
- private boolean isSerializableIsolationLevel(Table icebergTable) {
- if (icebergTable == null) {
- return true;
- }
- String level = icebergTable.properties()
- .getOrDefault(DELETE_ISOLATION_LEVEL,
DELETE_ISOLATION_LEVEL_DEFAULT);
- return "serializable".equalsIgnoreCase(level);
+ private IsolationLevel resolveIsolationLevel(Table icebergTable, String
property, String defaultLevel) {
+ // Resolve before BE file writes and retain the selection for this
statement's commit.
+ // Standard operation settings override the legacy key; parse only the
selected value.
+ Map<String, String> properties = icebergTable.properties();
+ return IsolationLevel.fromName(properties.getOrDefault(property,
+ properties.getOrDefault(LEGACY_DELETE_ISOLATION_LEVEL,
defaultLevel)));
}
private boolean shouldRewritePreviousDeleteFiles() {
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/IcebergMergeCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/IcebergMergeCommand.java
index 8692449b867..f23ca68300d 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/IcebergMergeCommand.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/IcebergMergeCommand.java
@@ -569,6 +569,7 @@ public class IcebergMergeCommand extends Command implements
ForwardWithSync, Exp
String label = String.format("iceberg_merge_into_%x_%x",
ctx.queryId().hi, ctx.queryId().lo);
IcebergInsertCommandContext icebergInsertContext = new
IcebergInsertCommandContext();
+ icebergInsertContext.setMergeInto(true);
icebergInsertContext.setWriteSchemaContext(Optional.of(writeSchemaContext));
Optional<InsertCommandContext> insertContext =
Optional.of(icebergInsertContext);
IcebergMergeExecutor insertExecutor = new IcebergMergeExecutor(
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/IcebergInsertCommandContext.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/IcebergInsertCommandContext.java
index 21090a057b4..a452d720e97 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/IcebergInsertCommandContext.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/IcebergInsertCommandContext.java
@@ -34,6 +34,8 @@ public class IcebergInsertCommandContext extends
BaseExternalTableInsertCommandC
// (col='val', ...)
private Map<String, String> staticPartitionValues = Maps.newHashMap();
private boolean rewriting = false;
+ // SQL MERGE shares the UPDATE executor but uses its own isolation-level
property.
+ private boolean mergeInto;
private Optional<IcebergWriteSchemaContext> writeSchemaContext =
Optional.empty();
public Optional<String> getBranchName() {
@@ -69,6 +71,14 @@ public class IcebergInsertCommandContext extends
BaseExternalTableInsertCommandC
this.rewriting = rewriting;
}
+ public boolean isMergeInto() {
+ return mergeInto;
+ }
+
+ public void setMergeInto(boolean mergeInto) {
+ this.mergeInto = mergeInto;
+ }
+
public Optional<IcebergWriteSchemaContext> getWriteSchemaContext() {
return writeSchemaContext;
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergCoverageTestFixture.java
b/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergCoverageTestFixture.java
index bebd87f6e02..f3bfac06cd2 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergCoverageTestFixture.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergCoverageTestFixture.java
@@ -43,6 +43,7 @@ final class IcebergCoverageTestFixture implements
AutoCloseable {
final IcebergMetadataOps ops;
final IcebergExternalTable dorisTable;
final Writer writer;
+ final IcebergExternalMetaCache.WritableTableLease lease;
private final MockedStatic<IcebergUtils> utilities;
private final ThreadPoolExecutor executor = new ThreadPoolExecutor(
1, 1, 0, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
@@ -60,8 +61,7 @@ final class IcebergCoverageTestFixture implements
AutoCloseable {
Mockito.when(dorisTable.getRemoteDbName()).thenReturn("db");
Mockito.when(dorisTable.getRemoteName()).thenReturn("events");
Mockito.when(dorisTable.getOrBuildNameMapping()).thenReturn(NameMapping.createForTest("db",
"events"));
- IcebergExternalMetaCache.WritableTableLease lease =
-
Mockito.mock(IcebergExternalMetaCache.WritableTableLease.class);
+ lease =
Mockito.mock(IcebergExternalMetaCache.WritableTableLease.class);
Mockito.when(lease.getTable()).thenReturn(table);
Mockito.when(lease.getOps()).thenReturn(ops);
Mockito.when(lease.getAuthenticator()).thenReturn(new
ExecutionAuthenticator() { });
@@ -88,6 +88,7 @@ final class IcebergCoverageTestFixture implements
AutoCloseable {
WriteContext(Operation operation, boolean overwrite, Map<String,
String> partitions, Optional<String> branch) {
this.operation = operation;
+ insert.setMergeInto(operation == Operation.MERGE);
insert.setOverwrite(overwrite);
insert.setStaticPartitionValues(partitions);
insert.setBranchName(branch);
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergRowLevelIsolationTest.java
b/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergRowLevelIsolationTest.java
new file mode 100644
index 00000000000..6265e592fd1
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergRowLevelIsolationTest.java
@@ -0,0 +1,318 @@
+// 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.doris.datasource.iceberg;
+
+import org.apache.doris.common.jmockit.Deencapsulation;
+import
org.apache.doris.datasource.iceberg.IcebergCoverageTestFixture.Operation;
+import
org.apache.doris.datasource.iceberg.IcebergCoverageTestFixture.WriteContext;
+import org.apache.doris.thrift.TFileContent;
+import org.apache.doris.thrift.TIcebergCommitData;
+
+import org.apache.iceberg.DataFiles;
+import org.apache.iceberg.FileScanTask;
+import org.apache.iceberg.MetricsConfig;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.inmemory.InMemoryCatalog;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.types.Types;
+import org.apache.thrift.TSerializer;
+import org.apache.thrift.protocol.TBinaryProtocol;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.mockito.Mockito;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Proxy;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+public class IcebergRowLevelIsolationTest {
+ private static final TableIdentifier IDENTIFIER = TableIdentifier.of("db",
"events");
+ private static final String SEED = "s3://bucket/events/seed.parquet";
+ private static final String APPENDED =
"s3://bucket/events/appended.parquet";
+ private static final String REPLACEMENT =
"s3://bucket/events/replacement.parquet";
+ private static final String LEGACY_KEY = "delete_isolation_level";
+
+ @ParameterizedTest
+ @EnumSource(value = Operation.class, names = {"DELETE", "UPDATE", "MERGE"})
+ void missingPropertiesDefaultToSerializable(Operation operation) throws
Exception {
+ assertConcurrentAppend(operation, Collections.emptyMap(), false);
+ }
+
+ @ParameterizedTest
+ @EnumSource(value = Operation.class, names = {"DELETE", "UPDATE", "MERGE"})
+ void legacySnapshotPermitsConcurrentAppends(Operation operation) throws
Exception {
+ assertConcurrentAppend(operation, Collections.singletonMap(LEGACY_KEY,
"snapshot"), true);
+ }
+
+ @ParameterizedTest
+ @EnumSource(value = Operation.class, names = {"DELETE", "UPDATE", "MERGE"})
+ void standardKeyOverridesInvalidLegacyAndOtherOperationKeys(Operation
operation) throws Exception {
+ Map<String, String> properties = new HashMap<>();
+ properties.put(LEGACY_KEY, "invalid");
+ properties.put(TableProperties.DELETE_ISOLATION_LEVEL, "invalid");
+ properties.put(TableProperties.UPDATE_ISOLATION_LEVEL, "invalid");
+ properties.put(TableProperties.MERGE_ISOLATION_LEVEL, "invalid");
+ properties.put(isolationKey(operation), "SNAPSHOT");
+ assertConcurrentAppend(operation, properties, true);
+ }
+
+ @ParameterizedTest
+ @EnumSource(value = Operation.class, names = {"DELETE", "UPDATE", "MERGE"})
+ void standardSerializableOverridesLegacySnapshot(Operation operation)
throws Exception {
+ Map<String, String> properties = new HashMap<>();
+ properties.put(LEGACY_KEY, "snapshot");
+ properties.put(isolationKey(operation), "serializable");
+ assertConcurrentAppend(operation, properties, false);
+ }
+
+ @ParameterizedTest
+ @EnumSource(value = Operation.class, names = {"DELETE", "UPDATE", "MERGE"})
+ void invalidSelectedPropertyFailsBeforeWritesAndReleasesLease(Operation
operation) throws Exception {
+ for (String property : Arrays.asList(isolationKey(operation),
LEGACY_KEY)) {
+ Map<String, String> properties = new HashMap<>();
+ properties.put(LEGACY_KEY, "snapshot");
+ properties.put(property, "invalid");
+ InMemoryCatalog catalog = catalog();
+ Table table = create(catalog, properties);
+ IcebergCoverageTestFixture fixture = new
IcebergCoverageTestFixture(catalog, table);
+ IcebergExternalMetaCache.WritableTableLease lease = fixture.lease;
+ try (IcebergCoverageTestFixture ignored = fixture) {
+ RuntimeException failure =
Assertions.assertThrows(RuntimeException.class,
+ () -> fixture.writer.beginWrite(context(operation)));
+ Assertions.assertTrue(failure.getMessage().contains("Invalid
isolation level: invalid"));
+
Assertions.assertNull(Deencapsulation.getField(fixture.writer.transaction,
"transaction"));
+
Assertions.assertTrue(fixture.writer.transaction.getCommitDataList().isEmpty());
+
Assertions.assertNull(catalog.loadTable(IDENTIFIER).currentSnapshot());
+ Mockito.verify(lease).close();
+ // A failed preparation must release the lease so the
transaction can be prepared again.
+ table.updateProperties().set(property, "snapshot").commit();
+ fixture.writer.beginWrite(context(operation));
+
Assertions.assertNotNull(Deencapsulation.getField(fixture.writer.transaction,
"transaction"));
+ }
+ Mockito.verify(lease, Mockito.times(2)).close();
+ }
+ }
+
+ @ParameterizedTest
+ @EnumSource(value = Operation.class, names = {"DELETE", "UPDATE", "MERGE"})
+ void isolationIsParsedFromOpenedTransactionMetadata(Operation operation) {
+ InMemoryCatalog catalog = catalog();
+ Table table = create(catalog,
Collections.singletonMap(isolationKey(operation), "snapshot"));
+ Table refreshing = (Table)
Proxy.newProxyInstance(Table.class.getClassLoader(), new Class<?>[]
{Table.class},
+ (proxy, method, args) -> {
+ if ("newTransaction".equals(method.getName())) {
+ table.updateProperties().set(isolationKey(operation),
"invalid").commit();
+ }
+ try {
+ return method.invoke(table, args);
+ } catch (InvocationTargetException e) {
+ throw e.getCause();
+ }
+ });
+ try (IcebergCoverageTestFixture fixture = new
IcebergCoverageTestFixture(catalog, refreshing)) {
+ RuntimeException failure =
Assertions.assertThrows(RuntimeException.class,
+ () -> fixture.writer.beginWrite(context(operation)));
+ Assertions.assertTrue(failure.getMessage().contains("Invalid
isolation level: invalid"));
+
Assertions.assertNull(Deencapsulation.getField(fixture.writer.transaction,
"transaction"));
+ Mockito.verify(fixture.lease).close();
+ }
+ }
+
+ @ParameterizedTest
+ @EnumSource(value = Operation.class, names = {"DELETE", "UPDATE", "MERGE"})
+ void commitKeepsBeginTimeIsolationDespitePropertyChanges(Operation
operation) throws Exception {
+ for (String initial : Arrays.asList("snapshot", "serializable")) {
+ InMemoryCatalog catalog = catalog();
+ Table table = create(catalog,
Collections.singletonMap(isolationKey(operation), initial));
+ append(table, SEED);
+ try (IcebergCoverageTestFixture fixture = new
IcebergCoverageTestFixture(catalog, table)) {
+ fixture.writer.beginWrite(context(operation));
+ org.apache.iceberg.Transaction opened =
+ Deencapsulation.getField(fixture.writer.transaction,
"transaction");
+ opened.table().updateProperties().set(isolationKey(operation),
+ "snapshot".equals(initial) ? "invalid" :
"snapshot").commit();
+ append(catalog.loadTable(IDENTIFIER), APPENDED);
+ stageFiles(fixture, operation, SEED);
+ assertCommit(catalog, fixture, operation,
"snapshot".equals(initial));
+ }
+ }
+ }
+
+ @ParameterizedTest
+ @EnumSource(value = Operation.class, names = {"UPDATE", "MERGE"})
+ void
standardSnapshotWithPinnedWriterMetadataPermitsConcurrentAppend(Operation
operation) throws Exception {
+ InMemoryCatalog catalog = catalog();
+ Table table = create(catalog,
Collections.singletonMap(isolationKey(operation), "snapshot"));
+ append(table, SEED);
+ try (IcebergCoverageTestFixture fixture = new
IcebergCoverageTestFixture(catalog, table)) {
+ WriteContext context = context(operation);
+
context.insert.setWriteSchemaContext(Optional.of(IcebergWriteSchemaContext.forSchema(
+ table.schema(), 2, table.spec(), table.sortOrder(),
IcebergUtils.getFileFormat(table),
+ MetricsConfig.forTable(table),
IcebergUtils.getFileCompress(table),
+ IcebergUtils.dataLocation(table), table.properties(),
true, true)));
+ fixture.writer.beginWrite(context);
+ append(catalog.loadTable(IDENTIFIER), APPENDED);
+ stageFiles(fixture, operation, SEED);
+ assertCommit(catalog, fixture, operation, true);
+ }
+ }
+
+ @ParameterizedTest
+ @EnumSource(value = Operation.class, names = {"DELETE", "UPDATE", "MERGE"})
+ void snapshotStillValidatesReferencedDataFiles(Operation operation) throws
Exception {
+ InMemoryCatalog catalog = catalog();
+ Table table = create(catalog,
Collections.singletonMap(isolationKey(operation), "snapshot"));
+ append(table, SEED);
+ try (IcebergCoverageTestFixture fixture = new
IcebergCoverageTestFixture(catalog, table)) {
+ fixture.writer.beginWrite(context(operation));
+ Table concurrent = catalog.loadTable(IDENTIFIER);
+ try (CloseableIterable<FileScanTask> tasks =
concurrent.newScan().planFiles()) {
+
concurrent.newDelete().deleteFile(tasks.iterator().next().file()).commit();
+ }
+ stageFiles(fixture, operation, SEED);
+ RuntimeException failure =
Assertions.assertThrows(RuntimeException.class, fixture.writer::commit);
+ Assertions.assertTrue(failure.getMessage().contains("Cannot
commit, missing data files: [" + SEED + "]"),
+ failure.getMessage());
+ Assertions.assertEquals("delete",
catalog.loadTable(IDENTIFIER).currentSnapshot().operation());
+ }
+ }
+
+ @ParameterizedTest
+ @EnumSource(value = Operation.class, names = {"INSERT", "OVERWRITE"})
+ void insertsDoNotParseRowLevelProperties(Operation operation) {
+ Map<String, String> properties = new HashMap<>();
+ for (String property : Arrays.asList(LEGACY_KEY,
TableProperties.DELETE_ISOLATION_LEVEL,
+ TableProperties.UPDATE_ISOLATION_LEVEL,
TableProperties.MERGE_ISOLATION_LEVEL)) {
+ properties.put(property, "invalid");
+ }
+ InMemoryCatalog catalog = catalog();
+ Table table = create(catalog, properties);
+ try (IcebergCoverageTestFixture fixture = new
IcebergCoverageTestFixture(catalog, table)) {
+ Assertions.assertDoesNotThrow(() ->
fixture.writer.beginWrite(context(operation)));
+
Assertions.assertNotNull(Deencapsulation.getField(fixture.writer.transaction,
"transaction"));
+ }
+ }
+
+ private static void assertConcurrentAppend(Operation operation,
Map<String, String> properties,
+ boolean permitsAppend) throws Exception {
+ InMemoryCatalog catalog = catalog();
+ Table table = create(catalog, properties);
+ append(table, SEED);
+ try (IcebergCoverageTestFixture fixture = new
IcebergCoverageTestFixture(catalog, table)) {
+ fixture.writer.beginWrite(context(operation));
+ append(catalog.loadTable(IDENTIFIER), APPENDED);
+ stageFiles(fixture, operation, SEED);
+ assertCommit(catalog, fixture, operation, permitsAppend);
+ }
+ }
+
+ private static void assertCommit(InMemoryCatalog catalog,
IcebergCoverageTestFixture fixture,
+ Operation operation, boolean permitsAppend) throws Exception {
+ long before =
catalog.loadTable(IDENTIFIER).currentSnapshot().snapshotId();
+ if (permitsAppend) {
+ fixture.writer.commit();
+ Table committed = catalog.loadTable(IDENTIFIER);
+ Assertions.assertNotEquals(before,
committed.currentSnapshot().snapshotId());
+ Assertions.assertEquals("1",
committed.currentSnapshot().summary().get("added-delete-files"));
+ Set<String> paths = new HashSet<>();
+ try (CloseableIterable<FileScanTask> tasks =
committed.newScan().planFiles()) {
+ for (FileScanTask task : tasks) {
+ paths.add(task.file().path().toString());
+ }
+ }
+ Set<String> expected = new HashSet<>(Arrays.asList(SEED,
APPENDED));
+ if (operation != Operation.DELETE) {
+ expected.add(REPLACEMENT);
+ }
+ Assertions.assertEquals(expected, paths);
+ } else {
+ RuntimeException failure =
Assertions.assertThrows(RuntimeException.class, fixture.writer::commit);
+ Assertions.assertTrue(failure.getMessage().contains("Found
conflicting files"), failure.getMessage());
+ Assertions.assertEquals(before,
catalog.loadTable(IDENTIFIER).currentSnapshot().snapshotId());
+ }
+ }
+
+ private static void stageFiles(IcebergCoverageTestFixture fixture,
Operation operation, String referenced)
+ throws Exception {
+ TIcebergCommitData delete =
fragment("s3://bucket/events/delete.parquet", TFileContent.POSITION_DELETES);
+ delete.setReferencedDataFilePath(referenced);
+ TSerializer serializer = new TSerializer(new
TBinaryProtocol.Factory());
+ fixture.writer.addCommitData(serializer.serialize(delete));
+ if (operation != Operation.DELETE) {
+
fixture.writer.addCommitData(serializer.serialize(fragment(REPLACEMENT,
TFileContent.DATA)));
+ }
+ }
+
+ private static TIcebergCommitData fragment(String path, TFileContent
content) {
+ TIcebergCommitData fragment = new TIcebergCommitData();
+ fragment.setFilePath(path);
+ fragment.setFileContent(content);
+ fragment.setFileSize(1024);
+ fragment.setRowCount(1);
+ fragment.setAffectedRows(1);
+ return fragment;
+ }
+
+ private static WriteContext context(Operation operation) {
+ return new WriteContext(operation, operation == Operation.OVERWRITE,
Collections.emptyMap(), Optional.empty());
+ }
+
+ private static String isolationKey(Operation operation) {
+ switch (operation) {
+ case DELETE:
+ return TableProperties.DELETE_ISOLATION_LEVEL;
+ case UPDATE:
+ return TableProperties.UPDATE_ISOLATION_LEVEL;
+ case MERGE:
+ return TableProperties.MERGE_ISOLATION_LEVEL;
+ default:
+ throw new IllegalArgumentException("Not a row-level operation:
" + operation);
+ }
+ }
+
+ private static void append(Table table, String path) {
+
table.newAppend().appendFile(DataFiles.builder(table.spec()).withPath(path)
+
.withFileSizeInBytes(1024).withRecordCount(3).build()).commit();
+ }
+
+ private static InMemoryCatalog catalog() {
+ InMemoryCatalog catalog = new InMemoryCatalog();
+ catalog.initialize("isolation", Collections.emptyMap());
+ catalog.createNamespace(Namespace.of("db"));
+ return catalog;
+ }
+
+ private static Table create(InMemoryCatalog catalog, Map<String, String>
properties) {
+ Map<String, String> tableProperties = new HashMap<>(properties);
+ tableProperties.put(TableProperties.FORMAT_VERSION, "2");
+ return catalog.createTable(IDENTIFIER, new
Schema(Types.NestedField.required(1, "id", Types.IntegerType.get())),
+ PartitionSpec.unpartitioned(), tableProperties);
+ }
+}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergTransactionTest.java
b/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergTransactionTest.java
index d9d8fefc93f..eead945a1c3 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergTransactionTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergTransactionTest.java
@@ -1298,6 +1298,7 @@ public class IcebergTransactionTest {
org.apache.iceberg.Transaction retainedTransaction =
Mockito.mock(org.apache.iceberg.Transaction.class);
Mockito.when(retainedTable.newTransaction()).thenReturn(retainedTransaction);
+ Mockito.when(retainedTransaction.table()).thenReturn(retainedTable);
try (MockedStatic<IcebergUtils> mockedUtils =
Mockito.mockStatic(IcebergUtils.class)) {
mockWritableTable(mockedUtils, retainedTable);
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergWriteKnownBugsTest.java
b/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergWriteKnownBugsTest.java
index 5fd86894fbc..cfa9769afa2 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergWriteKnownBugsTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/datasource/iceberg/IcebergWriteKnownBugsTest.java
@@ -57,19 +57,16 @@ public class IcebergWriteKnownBugsTest {
private static final String DELETED = "s3://bucket/events/deleted.parquet";
@Test
- @Disabled("Known issue: DELETE ignores the standard snapshot isolation
property.")
public void deleteHonorsStandardSnapshotIsolationProperty() throws
Exception {
assertStandardSnapshotIsolation(Operation.DELETE,
"write.delete.isolation-level");
}
@Test
- @Disabled("Known issue: UPDATE ignores the standard snapshot isolation
property.")
public void updateHonorsStandardSnapshotIsolationProperty() throws
Exception {
assertStandardSnapshotIsolation(Operation.UPDATE,
"write.update.isolation-level");
}
@Test
- @Disabled("Known issue: MERGE ignores the standard snapshot isolation
property.")
public void mergeHonorsStandardSnapshotIsolationProperty() throws
Exception {
assertStandardSnapshotIsolation(Operation.MERGE,
"write.merge.isolation-level");
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]