-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cosmos DB Spark Connector - query optimizations for queries targeting…
… logical partitions (#25889) * Extending CosmosCatalog in Spark Allowing the following new options when creating new containers: - analyticalStorageTttlInSeconds - this is required to make the Catalog integration useful in Synapse - partitionKeyVersion - we don't allow creating containers with Hash V2 (whichis needed to support long partition keys and requirement to later support hierarchical Pk) Also allowing to retrieve more container properties mapped into TBLPROPERTIES when using DESCRIBE TABLE EXTENDED command * Spark query perf improvement when only targeting single/few logical partitions * Query optimizations without tests yet * Adding unit test coverage * Adding suffix to FeedRangeCacheInterval
- Loading branch information
1 parent
933087a
commit 84779c9
Showing
14 changed files
with
314 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...osmos-spark_3-1_2-12/src/main/scala/com/azure/cosmos/spark/ContainerFeedRangesCache.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.cosmos.spark | ||
|
||
import com.azure.cosmos.{CosmosAsyncContainer, SparkBridgeInternal} | ||
import com.azure.cosmos.models.FeedRange | ||
import reactor.core.scala.publisher.SMono | ||
import reactor.core.scala.publisher.SMono.PimpJMono | ||
|
||
import java.time.Instant | ||
import java.time.temporal.ChronoUnit | ||
import scala.collection.concurrent.TrieMap | ||
// scalastyle:off underscore.import | ||
import scala.collection.JavaConverters._ | ||
// scalastyle:on underscore.import | ||
|
||
private[spark] object ContainerFeedRangesCache { | ||
|
||
private val cache = new TrieMap[String, CachedFeedRanges] | ||
|
||
def getFeedRanges | ||
( | ||
container: CosmosAsyncContainer | ||
): SMono[List[FeedRange]] = { | ||
|
||
val key = SparkBridgeInternal.getCacheKeyForContainer(container) | ||
|
||
cache.get(key) match { | ||
case Some(cached) => | ||
if (cached | ||
.retrievedAt | ||
.compareTo(Instant.now.minus(CosmosConstants.feedRangesCacheIntervalInMinutes, ChronoUnit.MINUTES)) >= 0) { | ||
|
||
SMono.just(cached.feedRanges) | ||
} else { | ||
refreshFeedRanges(key, container) | ||
} | ||
case None => refreshFeedRanges(key, container) | ||
} | ||
} | ||
|
||
private[this] def refreshFeedRanges(key: String, container: CosmosAsyncContainer): SMono[List[FeedRange]] = { | ||
container | ||
.getFeedRanges | ||
.map[List[FeedRange]](javaList => { | ||
val scalaList = javaList.asScala.toList | ||
cache.put(key, CachedFeedRanges(scalaList, Instant.now)) | ||
scalaList | ||
}) | ||
.asScala | ||
} | ||
|
||
private case class CachedFeedRanges(feedRanges: List[FeedRange], retrievedAt: Instant) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.