Skip to content

Commit 78c1459

Browse files
authored
OLTP Connector Synapse integration using Linked Service (Azure#22116)
OLTP Connector Synapse integration using Linked Service
1 parent 2337588 commit 78c1459

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.cosmos.spark
5+
6+
trait AccountDataResolver {
7+
def getAccountDataConfig(configs : Map[String, String]): Map[String, String]
8+
}

sdk/cosmos/azure-cosmos-spark_3-1_2-12/src/main/scala/com/azure/cosmos/spark/CosmosConfig.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import org.apache.spark.sql.connector.read.streaming.ReadLimit
2020
import java.net.{URI, URISyntaxException, URL}
2121
import java.time.format.DateTimeFormatter
2222
import java.time.{Duration, Instant}
23-
import java.util.Locale
23+
import java.util.{Locale, ServiceLoader}
2424
import scala.collection.immutable.{HashSet, Map}
2525

2626
// scalastyle:off underscore.import
@@ -124,6 +124,8 @@ private object CosmosConfigNames {
124124
}
125125
}
126126

127+
128+
127129
private object CosmosConfig {
128130
def getEffectiveConfig
129131
(
@@ -133,8 +135,18 @@ private object CosmosConfig {
133135
// spark application configteams
134136
userProvidedOptions: Map[String, String] // user provided config
135137
) : Map[String, String] = {
138+
var accountDataResolverCls = None : Option[AccountDataResolver]
139+
val serviceLoader = ServiceLoader.load(classOf[AccountDataResolver])
140+
val iterator = serviceLoader.iterator()
141+
if (iterator.hasNext()) {
142+
accountDataResolverCls = Some(iterator.next())
143+
}
136144

137145
var effectiveUserConfig = CaseInsensitiveMap(userProvidedOptions)
146+
if (accountDataResolverCls.isDefined) {
147+
val accountDataConfig = accountDataResolverCls.get.getAccountDataConfig(effectiveUserConfig)
148+
effectiveUserConfig = CaseInsensitiveMap(accountDataConfig)
149+
}
138150

139151
if (databaseName.isDefined) {
140152
effectiveUserConfig += (CosmosContainerConfig.DATABASE_NAME_KEY -> databaseName.get)

0 commit comments

Comments
 (0)