-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-41001] [CONNECT] [PYTHON] Implementing Connection String for Python Client #38485
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
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
90e9a69
implementing connection string
grundprinzip b46ce2a
fixing
grundprinzip 13c08f2
comments
grundprinzip cbfca9e
adding doc string
grundprinzip 493d613
pandas move
grundprinzip 45e777e
style
grundprinzip 7896f21
Update python/pyspark/sql/connect/client.py
grundprinzip e219dbc
missing quote
grundprinzip 9f9c131
removing unused import
grundprinzip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -18,6 +18,9 @@ | |
| import unittest | ||
| import shutil | ||
| import tempfile | ||
|
|
||
| import grpc # type: ignore | ||
grundprinzip marked this conversation as resolved.
Show resolved
Hide resolved
grundprinzip marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| from pyspark.testing.sqlutils import have_pandas | ||
|
|
||
| if have_pandas: | ||
|
|
@@ -27,7 +30,7 @@ | |
| from pyspark.sql.types import StructType, StructField, LongType, StringType | ||
|
|
||
| if have_pandas: | ||
| from pyspark.sql.connect.client import RemoteSparkSession | ||
| from pyspark.sql.connect.client import RemoteSparkSession, ChannelBuilder | ||
| from pyspark.sql.connect.function_builder import udf | ||
| from pyspark.sql.connect.functions import lit | ||
| from pyspark.sql.dataframe import DataFrame | ||
|
|
@@ -67,6 +70,7 @@ def setUpClass(cls: Any): | |
| @classmethod | ||
| def tearDownClass(cls: Any) -> None: | ||
| cls.spark_connect_clean_up_test_data() | ||
| ReusedPySparkTestCase.tearDownClass() | ||
|
|
||
| @classmethod | ||
| def spark_connect_load_test_data(cls: Any): | ||
|
|
@@ -167,6 +171,43 @@ def test_simple_datasource_read(self) -> None: | |
| self.assertEqual(len(expectResult), len(actualResult)) | ||
|
|
||
|
|
||
| class ChannelBuilderTests(ReusedPySparkTestCase): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be skipped by I made a PR for that. |
||
| def test_invalid_connection_strings(self): | ||
| invalid = [ | ||
| "scc://host:12", | ||
| "http://host", | ||
| "sc:/host:1234/path", | ||
| "sc://host/path", | ||
| "sc://host/;parm1;param2", | ||
| ] | ||
| for i in invalid: | ||
| self.assertRaises(AttributeError, ChannelBuilder, i) | ||
|
|
||
| self.assertRaises(AttributeError, ChannelBuilder("sc://host/;token=123").to_channel) | ||
|
|
||
| def test_valid_channel_creation(self): | ||
| chan = ChannelBuilder("sc://host").to_channel() | ||
| self.assertIsInstance(chan, grpc.Channel) | ||
|
|
||
| # Sets up a channel without tokens because ssl is not used. | ||
| chan = ChannelBuilder("sc://host/;use_ssl=true;token=abc").to_channel() | ||
| self.assertIsInstance(chan, grpc.Channel) | ||
|
|
||
| chan = ChannelBuilder("sc://host/;use_ssl=true").to_channel() | ||
| self.assertIsInstance(chan, grpc.Channel) | ||
|
|
||
| def test_channel_properties(self): | ||
| chan = ChannelBuilder("sc://host/;use_ssl=true;token=abc;param1=120%2021") | ||
| self.assertEqual("host:15002", chan.endpoint) | ||
| self.assertEqual(True, chan.secure) | ||
| self.assertEqual("120 21", chan.get("param1")) | ||
|
|
||
| def test_metadata(self): | ||
| chan = ChannelBuilder("sc://host/;use_ssl=true;token=abc;param1=120%2021;x-my-header=abcd") | ||
| md = chan.metadata() | ||
| self.assertEqual([("param1", "120 21"), ("x-my-header", "abcd")], md) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| from pyspark.sql.tests.connect.test_connect_basic import * # noqa: F401 | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.