-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UDFs for Mapping Feed Ranges to Buckets (#43092)
* Added udfs and some tests for splitting ranges with hpks * Added test more test coverage * revert incorrect change * Reacting to comments * Fix method names in change log
- Loading branch information
Showing
16 changed files
with
430 additions
and
62 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
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
54 changes: 54 additions & 0 deletions
54
...os-spark_3_2-12/src/main/scala/com/azure/cosmos/spark/udf/GetFeedRangesForContainer.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.udf | ||
|
||
import com.azure.cosmos.implementation.SparkBridgeImplementationInternal | ||
import com.azure.cosmos.spark.{CosmosClientCache, CosmosClientCacheItem, CosmosClientConfiguration, CosmosConfig, CosmosContainerConfig, CosmosReadConfig, Loan} | ||
import org.apache.spark.sql.SparkSession | ||
import org.apache.spark.sql.api.java.UDF2 | ||
|
||
@SerialVersionUID(1L) | ||
class GetFeedRangesForContainer extends UDF2[Map[String, String], Option[Int], Array[String]] { | ||
override def call | ||
( | ||
userProvidedConfig: Map[String, String], | ||
targetedCount: Option[Int] | ||
): Array[String] = { | ||
|
||
val effectiveUserConfig = CosmosConfig.getEffectiveConfig(None, None, userProvidedConfig) | ||
var feedRanges = List[String]() | ||
val cosmosContainerConfig: CosmosContainerConfig = | ||
CosmosContainerConfig.parseCosmosContainerConfig(effectiveUserConfig, None, None) | ||
val readConfig = CosmosReadConfig.parseCosmosReadConfig(effectiveUserConfig) | ||
val cosmosClientConfig = CosmosClientConfiguration( | ||
effectiveUserConfig, | ||
useEventualConsistency = readConfig.forceEventualConsistency, | ||
CosmosClientConfiguration.getSparkEnvironmentInfo(SparkSession.getActiveSession)) | ||
Loan( | ||
List[Option[CosmosClientCacheItem]]( | ||
Some(CosmosClientCache( | ||
cosmosClientConfig, | ||
None, | ||
s"UDF GetFeedRangesForContainer" | ||
)) | ||
)) | ||
.to(cosmosClientCacheItems => { | ||
|
||
if (targetedCount.isEmpty) { | ||
feedRanges = SparkBridgeImplementationInternal.getFeedRangesForContainer( | ||
cosmosClientCacheItems.head.get.cosmosClient, | ||
cosmosContainerConfig.container, | ||
cosmosContainerConfig.database | ||
) | ||
} else { | ||
feedRanges = SparkBridgeImplementationInternal.trySplitFeedRanges( | ||
cosmosClientCacheItems.head.get.cosmosClient, | ||
cosmosContainerConfig.container, | ||
cosmosContainerConfig.database, | ||
targetedCount.get) | ||
} | ||
}) | ||
feedRanges.toArray | ||
|
||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...smos-spark_3_2-12/src/main/scala/com/azure/cosmos/spark/udf/GetOverlappingFeedRange.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,23 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.cosmos.spark.udf | ||
|
||
import com.azure.cosmos.implementation.SparkBridgeImplementationInternal | ||
import com.azure.cosmos.models.SparkModelBridgeInternal | ||
import com.azure.cosmos.spark.CosmosPredicates.requireNotNullOrEmpty | ||
import org.apache.spark.sql.api.java.UDF3 | ||
|
||
@SerialVersionUID(1L) | ||
class GetOverlappingFeedRange extends UDF3[String, Object, Array[String], String] { | ||
override def call | ||
( | ||
partitionKeyDefinitionJson: String, | ||
partitionKeyValue: Object, | ||
targetFeedRanges: Array[String] | ||
): String = { | ||
requireNotNullOrEmpty(partitionKeyDefinitionJson, "partitionKeyDefinitionJson") | ||
|
||
val pkDefinition = SparkModelBridgeInternal.createPartitionKeyDefinitionFromJson(partitionKeyDefinitionJson) | ||
SparkBridgeImplementationInternal.getOverlappingRange(targetFeedRanges, partitionKeyValue, pkDefinition) | ||
} | ||
} |
Oops, something went wrong.