Skip to content

Commit b889eeb

Browse files
authored
refactor isSameDomain for JsonMetadataDomain (#2767)
<!-- Thanks for sending a pull request! Here are some tips for you: 1. If this is your first time, please read our contributor guidelines: https://github.com/delta-io/delta/blob/master/CONTRIBUTING.md 2. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP] Your PR title ...'. 3. Be sure to keep the PR description updated to reflect all changes. 4. Please write your PR title to summarize what this PR proposes. 5. If possible, provide a concise example to reproduce the issue for a faster review. 6. If applicable, include the corresponding issue number in the PR title and link it in the body. --> #### Which Delta project/connector is this regarding? <!-- Please add the component selected below to the beginning of the pull request title For example: [Spark] Title of my pull request --> - [x] Spark - [ ] Standalone - [ ] Flink - [ ] Kernel - [ ] Other (fill in here) ## Description <!-- - Describe what this PR changes. - Describe why we need the change. If this PR resolves an issue be sure to include "Resolves #XXX" to correctly link and close the issue upon merge. --> This refactors `RowTrackingMetadataDomain.isRowTrackingDomain` to `JsonMetadataDomain.isSameDomain` so that it can be useful for other domain metadata. ## How was this patch tested? Existing unit tests.
1 parent 3cdcdd1 commit b889eeb

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

spark/src/main/scala/org/apache/spark/sql/delta/ConflictChecker.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ private[delta] class ConflictChecker(
467467
winningDomainMetadataMap.get(domainMetadataFromCurrentTransaction.domain)) match {
468468
// No-conflict case.
469469
case (domain, None) => domain
470-
case (domain, _) if RowTrackingMetadataDomain.isRowTrackingDomain(domain) => domain
470+
case (domain, _) if RowTrackingMetadataDomain.isSameDomain(domain) => domain
471471
case (_, Some(_)) =>
472472
// Any conflict not specifically handled by a previous case must fail the transaction.
473473
throw new io.delta.exceptions.ConcurrentTransactionException(
@@ -541,7 +541,7 @@ private[delta] class ConflictChecker(
541541
}
542542
Some(a.copy(baseRowId = Some(newBaseRowId)))
543543
// The row ID high water mark will be replaced if it exists.
544-
case d: DomainMetadata if RowTrackingMetadataDomain.isRowTrackingDomain(d) => None
544+
case d: DomainMetadata if RowTrackingMetadataDomain.isSameDomain(d) => None
545545
case a => Some(a)
546546
}
547547
currentTransactionInfo = currentTransactionInfo.copy(

spark/src/main/scala/org/apache/spark/sql/delta/JsonMetadataDomain.scala

+2
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,7 @@ abstract class JsonMetadataDomainUtils[T: Manifest] {
4949

5050
protected def fromJsonConfiguration(domain: DomainMetadata): T =
5151
JsonUtils.fromJson[T](domain.configuration)
52+
53+
def isSameDomain(d: DomainMetadata): Boolean = d.domain == domainName
5254
}
5355

spark/src/main/scala/org/apache/spark/sql/delta/OptimisticTransaction.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,7 @@ trait OptimisticTransactionImpl extends TransactionalWrite
15991599
dataChanged = true
16001600
}
16011601
// Row tracking is able to resolve write conflicts regardless of isolation level.
1602-
case d: DomainMetadata if RowTrackingMetadataDomain.isRowTrackingDomain(d) =>
1602+
case d: DomainMetadata if RowTrackingMetadataDomain.isSameDomain(d) =>
16031603
// Do nothing
16041604
case _ =>
16051605
hasIncompatibleActions = true

spark/src/main/scala/org/apache/spark/sql/delta/RowId.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ object RowId {
4343
case d: DomainMetadata if d.domain == domainName => Some(fromJsonConfiguration(d))
4444
case _ => None
4545
}
46-
47-
def isRowTrackingDomain(d: DomainMetadata): Boolean = d.domain == domainName
4846
}
4947

5048
val MISSING_HIGH_WATER_MARK: Long = -1L
@@ -92,7 +90,7 @@ object RowId {
9290
throw DeltaErrors.rowIdAssignmentWithoutStats
9391
}
9492
a.copy(baseRowId = Some(baseRowId))
95-
case d: DomainMetadata if RowTrackingMetadataDomain.isRowTrackingDomain(d) =>
93+
case d: DomainMetadata if RowTrackingMetadataDomain.isSameDomain(d) =>
9694
throw new IllegalStateException(
9795
"Manually setting the Row ID high water mark is not allowed")
9896
case other => other

0 commit comments

Comments
 (0)