Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move getCosmosClientBuilderAccessor package private #18448

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ package com.azure.cosmos.spark

import java.util.UUID

import com.azure.cosmos.implementation.ImplementationBridgeHelpers.CosmosClientBuilderHelper
import com.azure.cosmos.implementation.{CosmosClientMetadataCachesSnapshot, TestConfigurations}
import com.azure.cosmos.{ConsistencyLevel, CosmosBridgeInternal, CosmosClientBuilder}
import com.azure.cosmos.implementation.{CosmosClientMetadataCachesSnapshot, SparkBridgeInternal}
import com.azure.cosmos.{ConsistencyLevel, CosmosClientBuilder}
import org.apache.spark.broadcast.Broadcast
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.connector.write.{DataWriter, DataWriterFactory, WriterCommitMessage}
import org.apache.spark.sql.types.{IntegerType, StringType, StructField, StructType}
import org.apache.spark.sql.types.StructType

class CosmosDataWriteFactory(userConfig: Map[String, String],
inputSchema: StructType,
Expand All @@ -33,9 +32,7 @@ class CosmosDataWriteFactory(userConfig: Map[String, String],
.endpoint(cosmosAccountConfig.endpoint)
.consistencyLevel(ConsistencyLevel.EVENTUAL);

val clientBuilderAccessor = CosmosClientBuilderHelper.getCosmosClientBuilderAccessor()
clientBuilderAccessor.setCosmosClientMetadataCachesSnapshot(builder, cosmosClientStateHandle.value)

SparkBridgeInternal.setMetadataCacheSnapshot(builder, cosmosClientStateHandle.value)
val client = builder.buildAsyncClient();

override def write(internalRow: InternalRow): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

package com.azure.cosmos.spark

import com.azure.cosmos.implementation.CosmosClientMetadataCachesSnapshot
import com.azure.cosmos.implementation.ImplementationBridgeHelpers.CosmosClientBuilderHelper
import com.azure.cosmos.{ConsistencyLevel, CosmosBridgeInternal, CosmosClientBuilder}
import com.azure.cosmos.CosmosClientBuilder
import com.azure.cosmos.implementation.{CosmosClientMetadataCachesSnapshot, SparkBridgeInternal}
import com.azure.cosmos.models.{CosmosParametrizedQuery, CosmosQueryRequestOptions}
import com.fasterxml.jackson.databind.node.ObjectNode
import org.apache.spark.broadcast.Broadcast
Expand Down Expand Up @@ -35,10 +34,9 @@ case class CosmosPartitionReader(config: Map[String, String],
.endpoint(endpointConfig.endpoint)
.key(endpointConfig.key)

val state = cosmosClientStateHandle.value;
val metadataCache = cosmosClientStateHandle.value;

val clientBuilderAccessor = CosmosClientBuilderHelper.getCosmosClientBuilderAccessor()
clientBuilderAccessor.setCosmosClientMetadataCachesSnapshot(builder, cosmosClientStateHandle.value)
SparkBridgeInternal.setMetadataCacheSnapshot(builder, metadataCache)
val client = builder.buildAsyncClient();

val cosmosAsyncContainer = client
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.cosmos.implementation

import com.azure.cosmos.CosmosClientBuilder
import com.azure.cosmos.implementation.ImplementationBridgeHelpers.CosmosClientBuilderHelper

object SparkBridgeInternal {
def setMetadataCacheSnapshot(cosmosClientBuilder: CosmosClientBuilder, metadataCache: CosmosClientMetadataCachesSnapshot): Unit = {
val clientBuilderAccessor = CosmosClientBuilderHelper.getCosmosClientBuilderAccessor()
clientBuilderAccessor.setCosmosClientMetadataCachesSnapshot(cosmosClientBuilder, metadataCache)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import com.azure.cosmos.CosmosClientBuilder;

public class ImplementationBridgeHelpers {
public abstract static class CosmosClientBuilderHelper {
public static final class CosmosClientBuilderHelper {
private static CosmosClientBuilderAccessor accessor;

protected CosmosClientBuilderHelper() {}
private CosmosClientBuilderHelper() {}

public static void setCosmosClientBuilderAccessor(final CosmosClientBuilderAccessor newAccessor) {
if (accessor != null) {
Expand All @@ -19,7 +19,7 @@ public static void setCosmosClientBuilderAccessor(final CosmosClientBuilderAcces
accessor = newAccessor;
}

public static CosmosClientBuilderAccessor getCosmosClientBuilderAccessor() {
static CosmosClientBuilderAccessor getCosmosClientBuilderAccessor() {
if (accessor == null) {
throw new IllegalStateException("accessor is not initialized yet!");
}
Expand Down