Skip to content

Commit 4b900a0

Browse files
committed
add more test cases; fix ICT disablement logic
1 parent b8904a5 commit 4b900a0

File tree

2 files changed

+64
-38
lines changed

2 files changed

+64
-38
lines changed

kernel/kernel-api/src/main/java/io/delta/kernel/internal/TransactionMetadataFactory.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,17 @@ private void handleInCommitTimestampDisablement() {
419419
final boolean txnExplicitlyDisablesICT =
420420
txnIctEnabledValue != null && txnIctEnabledValue.equalsIgnoreCase("false");
421421

422+
// Case 1: Txn is not explicitly disabling ICT. Exit.
422423
if (!txnExplicitlyDisablesICT) {
423424
return;
424425
}
425426

427+
// Case 2: Txn is explicitly disabling ICT on a catalogManaged table. Throw.
428+
if (getEffectiveProtocol().supportsFeature(TableFeatures.CATALOG_MANAGED_R_W_FEATURE_PREVIEW)) {
429+
throw new KernelException("Cannot disable inCommitTimestamp on a catalogManaged table");
430+
}
431+
432+
// Case 3 (normal case): Txn is explicitly disabling ICT. Remove the ICT enablement properties.
426433
final Set<String> ictKeysToRemove =
427434
new HashSet<>(
428435
Arrays.asList(

kernel/kernel-defaults/src/test/scala/io/delta/kernel/defaults/catalogManaged/CatalogManagedEnablementSuite.scala

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import org.scalatest.funsuite.AnyFunSuite
3131

3232
class CatalogManagedEnablementSuite extends AnyFunSuite with TestUtils {
3333

34-
case class CatalogManagedEnablementTestCase(
34+
case class CatalogManagedTestCase(
3535
testName: String,
3636
operationType: String, // "CREATE", "UPDATE", or "REPLACE"
3737
initialTableProperties: Map[String, String] = Map.empty,
@@ -42,42 +42,51 @@ class CatalogManagedEnablementSuite extends AnyFunSuite with TestUtils {
4242
expectedCatalogManagedSupported: Boolean = false)
4343

4444
val catalogManagedTestCases = Seq(
45-
CatalogManagedEnablementTestCase(
46-
testName = "CREATE: catalogManaged enablement flag => enables catalogManaged and ICT",
45+
// ===== CREATE cases =====
46+
CatalogManagedTestCase(
47+
testName = "CREATE: set catalogManaged=supported => enables catalogManaged and ICT",
4748
operationType = "CREATE",
4849
transactionProperties = Map("delta.feature.catalogOwned-preview" -> "supported"),
4950
expectedSuccess = true,
5051
expectedIctEnabled = true,
5152
expectedCatalogManagedSupported = true),
52-
CatalogManagedEnablementTestCase(
53-
testName = "UPDATE: catalogManaged enablement flag => enables catalogManaged and ICT",
53+
CatalogManagedTestCase(
54+
testName = "ILLEGAL CREATE: set catalogManaged=supported and explicitly disable ICT => THROW",
55+
operationType = "CREATE",
56+
transactionProperties = Map(
57+
"delta.feature.catalogOwned-preview" -> "supported",
58+
"delta.enableInCommitTimestamps" -> "false"),
59+
expectedSuccess = false,
60+
expectedExceptionMessage =
61+
Some("Cannot disable inCommitTimestamp when enabling catalogManaged")),
62+
63+
// ===== UPDATE cases =====
64+
CatalogManagedTestCase(
65+
testName = "UPDATE: set catalogManaged=supported => enables catalogManaged and ICT",
5466
operationType = "UPDATE",
5567
initialTableProperties = Map.empty, // Start with basic table
5668
transactionProperties = Map("delta.feature.catalogOwned-preview" -> "supported"),
5769
expectedSuccess = true,
5870
expectedIctEnabled = true,
5971
expectedCatalogManagedSupported = true),
60-
CatalogManagedEnablementTestCase(
61-
testName = "UPDATE: catalogManaged enablement flag => enables ICT if previously disabled",
72+
CatalogManagedTestCase(
73+
testName = "UPDATE: set catalogManaged=supported => enables ICT if previously disabled",
6274
operationType = "UPDATE",
6375
initialTableProperties = Map("delta.enableInCommitTimestamps" -> "false"),
6476
transactionProperties = Map("delta.feature.catalogOwned-preview" -> "supported"),
6577
expectedSuccess = true,
6678
expectedIctEnabled = true,
6779
expectedCatalogManagedSupported = true),
68-
CatalogManagedEnablementTestCase(
69-
testName =
70-
"ILLEGAL CREATE: catalogManaged enablement flag but ICT explicitly disabled too => THROW",
71-
operationType = "CREATE",
72-
transactionProperties = Map(
73-
"delta.feature.catalogOwned-preview" -> "supported",
74-
"delta.enableInCommitTimestamps" -> "false"),
75-
expectedSuccess = false,
76-
expectedExceptionMessage =
77-
Some("Cannot disable inCommitTimestamp when enabling catalogManaged")),
78-
CatalogManagedEnablementTestCase(
79-
testName =
80-
"ILLEGAL UPDATE: catalogManaged enablement flag but ICT explicitly disabled too => THROW",
80+
CatalogManagedTestCase(
81+
testName = "UPDATE: set catalogManaged=supported and ICT already enabled => Okay",
82+
operationType = "UPDATE",
83+
initialTableProperties = Map("delta.enableInCommitTimestamps" -> "true"),
84+
transactionProperties = Map("delta.feature.catalogOwned-preview" -> "supported"),
85+
expectedSuccess = true,
86+
expectedIctEnabled = true,
87+
expectedCatalogManagedSupported = true),
88+
CatalogManagedTestCase(
89+
testName = "ILLEGAL UPDATE: set catalogManaged=supported and disable ICT => THROW",
8190
operationType = "UPDATE",
8291
initialTableProperties = Map.empty,
8392
transactionProperties = Map(
@@ -86,38 +95,48 @@ class CatalogManagedEnablementSuite extends AnyFunSuite with TestUtils {
8695
expectedSuccess = false,
8796
expectedExceptionMessage =
8897
Some("Cannot disable inCommitTimestamp when enabling catalogManaged")),
89-
CatalogManagedEnablementTestCase(
90-
testName = "UPDATE: catalogManaged enablement flag => ICT already enabled",
98+
CatalogManagedTestCase(
99+
testName = "ILLEGAL UPDATE: catalogManaged already supported, then disable ICT => THROW",
91100
operationType = "UPDATE",
92-
initialTableProperties = Map("delta.enableInCommitTimestamps" -> "true"),
93-
transactionProperties = Map("delta.feature.catalogOwned-preview" -> "supported"),
94-
expectedSuccess = true,
95-
expectedIctEnabled = true,
96-
expectedCatalogManagedSupported = true),
97-
CatalogManagedEnablementTestCase(
98-
testName = "No-op: catalogManaged not being enabled should not affect ICT",
101+
initialTableProperties = Map("delta.feature.catalogOwned-preview" -> "supported"),
102+
transactionProperties = Map("delta.enableInCommitTimestamps" -> "false"),
103+
expectedSuccess = false,
104+
expectedExceptionMessage =
105+
Some("Cannot disable inCommitTimestamp on a catalogManaged table")),
106+
CatalogManagedTestCase(
107+
testName = "NO-OP UPDATE: catalogManaged not being enabled should not affect ICT",
99108
operationType = "UPDATE",
100109
initialTableProperties = Map.empty,
101110
transactionProperties = Map(),
102111
expectedSuccess = true,
103112
expectedIctEnabled = false,
104113
expectedCatalogManagedSupported = false),
105-
CatalogManagedEnablementTestCase(
106-
testName = "ILLEGAL REPLACE: catalogManaged enablement flag => THROW",
114+
115+
// ===== REPLACE cases =====
116+
CatalogManagedTestCase(
117+
testName = "REPLACE: normal replace should succeed on a catalogManaged table",
118+
operationType = "REPLACE",
119+
initialTableProperties = Map("delta.feature.catalogOwned-preview" -> "supported"),
120+
transactionProperties = Map(),
121+
expectedSuccess = true,
122+
expectedIctEnabled = true,
123+
expectedCatalogManagedSupported = true),
124+
CatalogManagedTestCase(
125+
testName = "ILLEGAL REPLACE: set catalogManaged=supported => THROW",
107126
operationType = "REPLACE",
108127
initialTableProperties = Map.empty,
109128
transactionProperties = Map("delta.feature.catalogOwned-preview" -> "supported"),
110129
expectedSuccess = false,
111130
expectedExceptionMessage =
112131
Some("Cannot enable the catalogManaged feature during a REPLACE command.")),
113-
CatalogManagedEnablementTestCase(
114-
testName = "REPLACE: should succeed on a catalogManaged table",
132+
CatalogManagedTestCase(
133+
testName = "ILLEGAL REPLACE: catalogManaged already supported, then disable ICT => THROW",
115134
operationType = "REPLACE",
116135
initialTableProperties = Map("delta.feature.catalogOwned-preview" -> "supported"),
117-
transactionProperties = Map(),
118-
expectedSuccess = true,
119-
expectedIctEnabled = true,
120-
expectedCatalogManagedSupported = true))
136+
transactionProperties = Map("delta.enableInCommitTimestamps" -> "false"),
137+
expectedSuccess = false,
138+
expectedExceptionMessage =
139+
Some("Cannot disable inCommitTimestamp on a catalogManaged table")))
121140

122141
catalogManagedTestCases.foreach { testCase =>
123142
test(testCase.testName) {
@@ -199,7 +218,7 @@ class CatalogManagedEnablementSuite extends AnyFunSuite with TestUtils {
199218
} else {
200219
// Transaction building should fail
201220
val exception = intercept[Exception] {
202-
txnBuilder.build(defaultEngine).commit(defaultEngine, emptyIterable[Row])
221+
txnBuilder.build(defaultEngine)
203222
}
204223

205224
testCase.expectedExceptionMessage.foreach { expectedMsg =>

0 commit comments

Comments
 (0)