Skip to content

Support for delta sharing profile via options in python - #789

Merged
PatrickJin-db merged 9 commits into
delta-io:mainfrom
kkoteeswaran:delta-credentials-as-opts-python
Dec 24, 2025
Merged

PatrickJin-db merged 9 commits into
delta-io:mainfrom
kkoteeswaran:delta-credentials-as-opts-python

Conversation

@kkoteeswaran

Copy link
Copy Markdown
Contributor

Adding support for delta sharing profile via options (reviving #573)
Separate PR for Scala - #786

Task List:

  • Add options to DeltaSharingOptions
  • Unit tests for DeltaSharingOptions
  • DeltaSharingProfile from DeltaSharingOptions
  • Unit tests for DeltaSharingProfileProvider
  • Conditional logic to create from options
  • Unit tests for conditional logic
  • Integration tests
  • Include Examples and Documentation

Examples

# Bearer Token
df = (
    spark.read.format("deltaSharing")
    .option("shareCredentialsVersion", "1")
    .option("endpoint", "https://example.com/delta-sharing")
    .option("bearerToken", "foobar")
    .option("expirationTime", "2022-01-01T00:00:00Z")
    .load("<share-name>.<schema-name>.<table-name>")
    .limit(10)
)

# OAuth
df = (
    spark.read.format("deltaSharing")
    .option("shareCredentialsVersion", "2")
    .option("shareCredentialsType", "oauth_client_credentials")
    .option("endpoint", "https://example.com/delta-sharing")
    .option("tokenEndpoint", "https://example.com/delta-sharing/oauth/token")
    .option("clientId", "abc")
    .option("clientSecret", "xyz")
    .load("<share-name>.<schema-name>.<table-name>")
    .limit(10)
)

# load_as_spark or load_table_changes_as_spark
import delta_sharing
from delta_sharing.protocol import DeltaSharingProfile

profile = DeltaSharingProfile( # also supports OAuth
    share_credentials_version=1,
    endpoint="https://example.com/delta-sharing",
    bearer_token="foobar",
    expiration_time="2022-01-01T00:00:00Z",
)

df = delta_sharing.load_as_spark(
    f"<share-name>.<schema-name>.<table-name>",
    version=version,
    timestamp=timestamp,
    delta_sharing_profile=profile
)

cc @prodeezy @stevenayers

@kkoteeswaran
kkoteeswaran force-pushed the delta-credentials-as-opts-python branch from e25f876 to dca3753 Compare November 10, 2025 16:51
@moderakh
moderakh self-requested a review November 10, 2025 21:26
@prodeezy

Copy link
Copy Markdown

This PR helps resolve #483

@PatrickJin-db PatrickJin-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but let's add a test for good measure. I can do that tomorrow since you don't have access to the cloud credentials for our integration tests.

@kkoteeswaran

Copy link
Copy Markdown
Contributor Author

Sounds good, thanks @PatrickJin-db

linzhou-db
linzhou-db previously approved these changes Nov 14, 2025

@linzhou-db linzhou-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PatrickJin-db are you thinking of a test in the same PR or a separate one?

@linzhou-db

Copy link
Copy Markdown
Collaborator

@kkoteeswaran in which version of delta-sharing-python would you need this?

@kkoteeswaran

Copy link
Copy Markdown
Contributor Author

@linzhou-db is there any correlation between DBR and delta-sharing-python versions? We want to make sure this is available in the version that is tied to DBR 15.4

@linzhou-db

Copy link
Copy Markdown
Collaborator

@linzhou-db is there any correlation between DBR and delta-sharing-python versions? We want to make sure this is available in the version that is tied to DBR 15.4

No there is no correlation.

So seems like you are ok with using the latest delta-sharing-python version that includes this change?

@kkoteeswaran

Copy link
Copy Markdown
Contributor Author

@linzhou-db is there any correlation between DBR and delta-sharing-python versions? We want to make sure this is available in the version that is tied to DBR 15.4

No there is no correlation.

So seems like you are ok with using the latest delta-sharing-python version that includes this change?

Yes, that works. Thanks @linzhou-db


def load_as_spark(
url: str, version: Optional[int] = None, timestamp: Optional[str] = None
url: str,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a check that the delta sharing profile cannot be in both url and delta_sharing_profile? In other words, if url contains a profile path, then delta_sharing_profile should not be populated, and vice versa.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PatrickJin-db the load_as_spark() passes the url to Spark and the validation is handled downstream in the Scala connector's parsePath() so it is not required here. Let me know if you think otherwise.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a) since there is no guarantee on the spark version being called by this function, there could be versions that support and not support this, what's the behavior on each?
b) even so, fail it early and locally makes more sense to me, instead of assuming on downstream behaviors, which could change without control.

cc @PatrickJin-db @moderakh

@PatrickJin-db

Copy link
Copy Markdown
Collaborator

Also, adding a test in a separate PR is fine

"`load_table_changes_as_spark` requires running in a PySpark application."
)
df = spark.read.format("deltaSharing").option("readChangeFeed", "true")
if delta_sharing_profile is not None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this block of code is duplicate same as above can we have a helper method for this?

"`load_as_spark` requires running in a PySpark application."
)
df = spark.read.format("deltaSharing")
if delta_sharing_profile is not None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this block of code is duplicate same as below can we have a helper method for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moderakh I have pulled that block of code out to a separate method

@linzhou-db

Copy link
Copy Markdown
Collaborator

how is this PR going?

@kkoteeswaran

Copy link
Copy Markdown
Contributor Author

@linzhou-db @moderakh @PatrickJin-db
I have already addressed the following in the PR:

  • Check both url and options are not set at the same time
  • Helper method for deltashare profile checks

Please let me know if any other changes are required.

@moderakh moderakh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from oauth perspective.

@PatrickJin-db
PatrickJin-db merged commit b9f75c9 into delta-io:main Dec 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants