-
Notifications
You must be signed in to change notification settings - Fork 982
Add pyhive connection timeout #7300
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -160,7 +160,8 @@ def __init__( | |||||||||||
| check_hostname=None, | ||||||||||||
| ssl_cert=None, | ||||||||||||
| thrift_transport=None, | ||||||||||||
| ssl_context=None | ||||||||||||
| ssl_context=None, | ||||||||||||
| connection_timeout=None, | ||||||||||||
| ): | ||||||||||||
| """Connect to HiveServer2 | ||||||||||||
|
|
||||||||||||
|
|
@@ -175,6 +176,7 @@ def __init__( | |||||||||||
| Incompatible with host, port, auth, kerberos_service_name, and password. | ||||||||||||
| :param ssl_context: A custom SSL context to use for HTTPS connections. If provided, | ||||||||||||
| this overrides check_hostname and ssl_cert parameters. | ||||||||||||
| :param connection_timeout: Millisecond timeout for Thrift connections. | ||||||||||||
|
||||||||||||
| :param connection_timeout: Millisecond timeout for Thrift connections. | |
| :param connection_timeout: Millisecond timeout for Thrift connections when using the | |
| built-in HTTP/HTTPS transport. | |
| Note: connection_timeout is ignored when thrift_transport is provided. Configure | |
| timeout on the custom transport object instead. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -259,6 +259,17 @@ def test_basic_ssl_context(self): | |
| cursor.execute('SELECT 1 FROM one_row') | ||
| self.assertEqual(cursor.fetchall(), [(1,)]) | ||
|
|
||
| def test_connection_timeout(self): | ||
| """Test that a connection timeout is set without error.""" | ||
| with contextlib.closing(hive.connect( | ||
| host=_HOST, | ||
| port=10000, | ||
| connection_timeout=10 * 1000 | ||
| )) as connection: | ||
| with contextlib.closing(connection.cursor()) as cursor: | ||
| # Use the same query pattern as other tests | ||
| cursor.execute('SELECT 1 FROM one_row') | ||
| self.assertEqual(cursor.fetchall(), [(1,)]) | ||
|
Comment on lines
+262
to
+272
|
||
|
|
||
| def _restart_hs2(): | ||
| subprocess.check_call(['sudo', 'service', 'hive-server2', 'restart']) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The connection_timeout parameter should be validated to ensure it's a positive value. Negative or zero timeout values could cause unexpected behavior. Consider adding validation like: