databricks-sql-connector 4.1.4__tar.gz → 4.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/CHANGELOG.md +8 -0
  2. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/PKG-INFO +7 -1
  3. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/README.md +6 -0
  4. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/pyproject.toml +2 -1
  5. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/__init__.py +4 -1
  6. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/client.py +334 -9
  7. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/common/unified_http_client.py +5 -0
  8. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/exc.py +17 -0
  9. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/session.py +21 -0
  10. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/telemetry/models/event.py +108 -1
  11. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/telemetry/telemetry_client.py +1 -1
  12. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/LICENSE +0 -0
  13. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/__init__.py +0 -0
  14. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/auth/__init__.py +0 -0
  15. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/auth/auth.py +0 -0
  16. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/auth/auth_utils.py +0 -0
  17. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/auth/authenticators.py +0 -0
  18. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/auth/common.py +0 -0
  19. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/auth/endpoint.py +0 -0
  20. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/auth/oauth.py +0 -0
  21. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/auth/oauth_http_handler.py +0 -0
  22. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/auth/retry.py +0 -0
  23. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/auth/thrift_http_client.py +0 -0
  24. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/auth/token_federation.py +0 -0
  25. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/backend/databricks_client.py +0 -0
  26. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/backend/sea/backend.py +0 -0
  27. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/backend/sea/models/__init__.py +0 -0
  28. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/backend/sea/models/base.py +0 -0
  29. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/backend/sea/models/requests.py +0 -0
  30. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/backend/sea/models/responses.py +0 -0
  31. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/backend/sea/queue.py +0 -0
  32. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/backend/sea/result_set.py +0 -0
  33. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/backend/sea/utils/constants.py +0 -0
  34. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/backend/sea/utils/conversion.py +0 -0
  35. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/backend/sea/utils/filters.py +0 -0
  36. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/backend/sea/utils/http_client.py +0 -0
  37. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/backend/sea/utils/normalize.py +0 -0
  38. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/backend/thrift_backend.py +0 -0
  39. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/backend/types.py +0 -0
  40. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/backend/utils/__init__.py +0 -0
  41. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/backend/utils/guid_utils.py +0 -0
  42. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/cloudfetch/download_manager.py +0 -0
  43. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/cloudfetch/downloader.py +0 -0
  44. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/common/feature_flag.py +0 -0
  45. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/common/http.py +0 -0
  46. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/common/http_utils.py +0 -0
  47. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/experimental/__init__.py +0 -0
  48. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/experimental/oauth_persistence.py +0 -0
  49. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/parameters/__init__.py +0 -0
  50. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/parameters/native.py +0 -0
  51. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/parameters/py.typed +0 -0
  52. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/py.typed +0 -0
  53. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/result_set.py +0 -0
  54. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/telemetry/latency_logger.py +0 -0
  55. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/telemetry/models/endpoint_models.py +0 -0
  56. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/telemetry/models/enums.py +0 -0
  57. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/telemetry/models/frontend_logs.py +0 -0
  58. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/telemetry/utils.py +0 -0
  59. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/thrift_api/TCLIService/TCLIService-remote +0 -0
  60. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/thrift_api/TCLIService/TCLIService.py +0 -0
  61. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/thrift_api/TCLIService/__init__.py +0 -0
  62. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/thrift_api/TCLIService/constants.py +0 -0
  63. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/thrift_api/TCLIService/ttypes.py +0 -0
  64. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/thrift_api/__init__.py +0 -0
  65. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/types.py +0 -0
  66. {databricks_sql_connector-4.1.4 → databricks_sql_connector-4.2.1}/src/databricks/sql/utils.py +0 -0
@@ -1,5 +1,13 @@
1
1
  # Release History
2
2
 
3
+ # 4.2.1 (2025-11-20)
4
+ - Ignore transactions by default (databricks/databricks-sql-python#711 by @jayantsing-db)
5
+
6
+ # 4.2.0 (2025-11-14)
7
+ - Add multi-statement transaction support (databricks/databricks-sql-python#704 by @jayantsing-db)
8
+ - Add a workflow to parallelise the E2E tests (databricks/databricks-sql-python#697 by @msrathore-db)
9
+ - Bring Python telemetry event model consistent with JDBC (databricks/databricks-sql-python#701 by @nikhilsuri-db)
10
+
3
11
  # 4.1.4 (2025-10-15)
4
12
  - Add support for Token Federation (databricks/databricks-sql-python#691 by @madhav-db)
5
13
  - Add metric view support (databricks/databricks-sql-python#688 by @shivam2680)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: databricks-sql-connector
3
- Version: 4.1.4
3
+ Version: 4.2.1
4
4
  Summary: Databricks SQL Connector for Python
5
5
  License: Apache-2.0
6
6
  License-File: LICENSE
@@ -102,6 +102,12 @@ or to a Databricks Runtime interactive cluster (e.g. /sql/protocolv1/o/123456789
102
102
  > to authenticate the target Databricks user account and needs to open the browser for authentication. So it
103
103
  > can only run on the user's machine.
104
104
 
105
+ ## Transaction Support
106
+
107
+ The connector supports multi-statement transactions with manual commit/rollback control. Set `connection.autocommit = False` to disable autocommit mode, then use `connection.commit()` and `connection.rollback()` to control transactions.
108
+
109
+ For detailed documentation, examples, and best practices, see **[TRANSACTIONS.md](TRANSACTIONS.md)**.
110
+
105
111
  ## SQLAlchemy
106
112
  Starting from `databricks-sql-connector` version 4.0.0 SQLAlchemy support has been extracted to a new library `databricks-sqlalchemy`.
107
113
 
@@ -67,6 +67,12 @@ or to a Databricks Runtime interactive cluster (e.g. /sql/protocolv1/o/123456789
67
67
  > to authenticate the target Databricks user account and needs to open the browser for authentication. So it
68
68
  > can only run on the user's machine.
69
69
 
70
+ ## Transaction Support
71
+
72
+ The connector supports multi-statement transactions with manual commit/rollback control. Set `connection.autocommit = False` to disable autocommit mode, then use `connection.commit()` and `connection.rollback()` to control transactions.
73
+
74
+ For detailed documentation, examples, and best practices, see **[TRANSACTIONS.md](TRANSACTIONS.md)**.
75
+
70
76
  ## SQLAlchemy
71
77
  Starting from `databricks-sql-connector` version 4.0.0 SQLAlchemy support has been extracted to a new library `databricks-sqlalchemy`.
72
78
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "databricks-sql-connector"
3
- version = "4.1.4"
3
+ version = "4.2.1"
4
4
  description = "Databricks SQL Connector for Python"
5
5
  authors = ["Databricks <databricks-sql-connector-maintainers@databricks.com>"]
6
6
  license = "Apache-2.0"
@@ -39,6 +39,7 @@ pylint = ">=2.12.0"
39
39
  black = "^22.3.0"
40
40
  pytest-dotenv = "^0.5.2"
41
41
  pytest-cov = "^4.0.0"
42
+ pytest-xdist = "^3.0.0"
42
43
  numpy = [
43
44
  { version = ">=1.16.6", python = ">=3.8,<3.11" },
44
45
  { version = ">=1.23.4", python = ">=3.11" },
@@ -8,6 +8,9 @@ threadsafety = 1 # Threads may share the module, but not connections.
8
8
 
9
9
  paramstyle = "named"
10
10
 
11
+ # Transaction isolation level constants (extension to PEP 249)
12
+ TRANSACTION_ISOLATION_LEVEL_REPEATABLE_READ = "REPEATABLE_READ"
13
+
11
14
  import re
12
15
 
13
16
  from typing import TYPE_CHECKING
@@ -68,7 +71,7 @@ DATETIME = DBAPITypeObject("timestamp")
68
71
  DATE = DBAPITypeObject("date")
69
72
  ROWID = DBAPITypeObject()
70
73
 
71
- __version__ = "4.1.4"
74
+ __version__ = "4.2.1"
72
75
  USER_AGENT_NAME = "PyDatabricksSqlConnector"
73
76
 
74
77
  # These two functions are pyhive legacy
@@ -9,6 +9,7 @@ except ImportError:
9
9
  import json
10
10
  import os
11
11
  import decimal
12
+ from urllib.parse import urlparse
12
13
  from uuid import UUID
13
14
 
14
15
  from databricks.sql import __version__
@@ -20,6 +21,8 @@ from databricks.sql.exc import (
20
21
  InterfaceError,
21
22
  NotSupportedError,
22
23
  ProgrammingError,
24
+ TransactionError,
25
+ DatabaseError,
23
26
  )
24
27
 
25
28
  from databricks.sql.thrift_api.TCLIService import ttypes
@@ -86,6 +89,9 @@ DEFAULT_ARRAY_SIZE = 100000
86
89
 
87
90
  NO_NATIVE_PARAMS: List = []
88
91
 
92
+ # Transaction isolation level constants (extension to PEP 249)
93
+ TRANSACTION_ISOLATION_LEVEL_REPEATABLE_READ = "REPEATABLE_READ"
94
+
89
95
 
90
96
  class Connection:
91
97
  def __init__(
@@ -98,6 +104,7 @@ class Connection:
98
104
  catalog: Optional[str] = None,
99
105
  schema: Optional[str] = None,
100
106
  _use_arrow_native_complex_types: Optional[bool] = True,
107
+ ignore_transactions: bool = True,
101
108
  **kwargs,
102
109
  ) -> None:
103
110
  """
@@ -206,6 +213,17 @@ class Connection:
206
213
  This allows
207
214
  1. cursor.tables() to return METRIC_VIEW table type
208
215
  2. cursor.columns() to return "measure" column type
216
+ :param fetch_autocommit_from_server: `bool`, optional (default is False)
217
+ When True, the connection.autocommit property queries the server for current state
218
+ using SET AUTOCOMMIT instead of returning cached value.
219
+ Set to True if autocommit might be changed by external means (e.g., external SQL commands).
220
+ When False (default), uses cached state for better performance.
221
+ :param ignore_transactions: `bool`, optional (default is True)
222
+ When True, transaction-related operations behave as follows:
223
+ - commit(): no-op (does nothing)
224
+ - rollback(): raises NotSupportedError
225
+ - autocommit setter: no-op (does nothing)
226
+ When False, transaction operations execute normally.
209
227
  """
210
228
 
211
229
  # Internal arguments in **kwargs:
@@ -304,6 +322,10 @@ class Connection:
304
322
  kwargs.get("use_inline_params", False)
305
323
  )
306
324
  self.staging_allowed_local_path = kwargs.get("staging_allowed_local_path", None)
325
+ self._fetch_autocommit_from_server = kwargs.get(
326
+ "fetch_autocommit_from_server", False
327
+ )
328
+ self.ignore_transactions = ignore_transactions
307
329
 
308
330
  self.force_enable_telemetry = kwargs.get("force_enable_telemetry", False)
309
331
  self.enable_telemetry = kwargs.get("enable_telemetry", False)
@@ -322,6 +344,20 @@ class Connection:
322
344
  session_id_hex=self.get_session_id_hex()
323
345
  )
324
346
 
347
+ # Determine proxy usage
348
+ use_proxy = self.http_client.using_proxy()
349
+ proxy_host_info = None
350
+ if (
351
+ use_proxy
352
+ and self.http_client.proxy_uri
353
+ and isinstance(self.http_client.proxy_uri, str)
354
+ ):
355
+ parsed = urlparse(self.http_client.proxy_uri)
356
+ proxy_host_info = HostDetails(
357
+ host_url=parsed.hostname or self.http_client.proxy_uri,
358
+ port=parsed.port or 8080,
359
+ )
360
+
325
361
  driver_connection_params = DriverConnectionParameters(
326
362
  http_path=http_path,
327
363
  mode=DatabricksClientType.SEA
@@ -331,13 +367,31 @@ class Connection:
331
367
  auth_mech=TelemetryHelper.get_auth_mechanism(self.session.auth_provider),
332
368
  auth_flow=TelemetryHelper.get_auth_flow(self.session.auth_provider),
333
369
  socket_timeout=kwargs.get("_socket_timeout", None),
370
+ azure_workspace_resource_id=kwargs.get("azure_workspace_resource_id", None),
371
+ azure_tenant_id=kwargs.get("azure_tenant_id", None),
372
+ use_proxy=use_proxy,
373
+ use_system_proxy=use_proxy,
374
+ proxy_host_info=proxy_host_info,
375
+ use_cf_proxy=False, # CloudFlare proxy not yet supported in Python
376
+ cf_proxy_host_info=None, # CloudFlare proxy not yet supported in Python
377
+ non_proxy_hosts=None,
378
+ allow_self_signed_support=kwargs.get("_tls_no_verify", False),
379
+ use_system_trust_store=True, # Python uses system SSL by default
380
+ enable_arrow=pyarrow is not None,
381
+ enable_direct_results=True, # Always enabled in Python
382
+ enable_sea_hybrid_results=kwargs.get("use_hybrid_disposition", False),
383
+ http_connection_pool_size=kwargs.get("pool_maxsize", None),
384
+ rows_fetched_per_block=DEFAULT_ARRAY_SIZE,
385
+ async_poll_interval_millis=2000, # Default polling interval
386
+ support_many_parameters=True, # Native parameters supported
387
+ enable_complex_datatype_support=_use_arrow_native_complex_types,
388
+ allowed_volume_ingestion_paths=self.staging_allowed_local_path,
334
389
  )
335
390
 
336
391
  self._telemetry_client.export_initial_telemetry_log(
337
392
  driver_connection_params=driver_connection_params,
338
393
  user_agent=self.session.useragent_header,
339
394
  )
340
- self.staging_allowed_local_path = kwargs.get("staging_allowed_local_path", None)
341
395
 
342
396
  def _set_use_inline_params_with_warning(self, value: Union[bool, str]):
343
397
  """Valid values are True, False, and "silent"
@@ -473,15 +527,286 @@ class Connection:
473
527
  if self.http_client:
474
528
  self.http_client.close()
475
529
 
476
- def commit(self):
477
- """No-op because Databricks does not support transactions"""
478
- pass
530
+ @property
531
+ def autocommit(self) -> bool:
532
+ """
533
+ Get auto-commit mode for this connection.
479
534
 
480
- def rollback(self):
481
- raise NotSupportedError(
482
- "Transactions are not supported on Databricks",
483
- session_id_hex=self.get_session_id_hex(),
484
- )
535
+ Extension to PEP 249. Returns cached value by default.
536
+ If fetch_autocommit_from_server=True was set during connection,
537
+ queries server for current state.
538
+
539
+ Returns:
540
+ bool: True if auto-commit is enabled, False otherwise
541
+
542
+ Raises:
543
+ InterfaceError: If connection is closed
544
+ TransactionError: If fetch_autocommit_from_server=True and query fails
545
+ """
546
+ if not self.open:
547
+ raise InterfaceError(
548
+ "Cannot get autocommit on closed connection",
549
+ session_id_hex=self.get_session_id_hex(),
550
+ )
551
+
552
+ if self._fetch_autocommit_from_server:
553
+ return self._fetch_autocommit_state_from_server()
554
+
555
+ return self.session.get_autocommit()
556
+
557
+ @autocommit.setter
558
+ def autocommit(self, value: bool) -> None:
559
+ """
560
+ Set auto-commit mode for this connection.
561
+
562
+ Extension to PEP 249. Executes SET AUTOCOMMIT command on server.
563
+
564
+ Args:
565
+ value: True to enable auto-commit, False to disable
566
+
567
+ When ignore_transactions is True:
568
+ - This method is a no-op (does nothing)
569
+
570
+ Raises:
571
+ InterfaceError: If connection is closed
572
+ TransactionError: If server rejects the change
573
+ """
574
+ # No-op when ignore_transactions is True
575
+ if self.ignore_transactions:
576
+ return
577
+
578
+ if not self.open:
579
+ raise InterfaceError(
580
+ "Cannot set autocommit on closed connection",
581
+ session_id_hex=self.get_session_id_hex(),
582
+ )
583
+
584
+ # Create internal cursor for transaction control
585
+ cursor = None
586
+ try:
587
+ cursor = self.cursor()
588
+ sql = f"SET AUTOCOMMIT = {'TRUE' if value else 'FALSE'}"
589
+ cursor.execute(sql)
590
+
591
+ # Update cached state on success
592
+ self.session.set_autocommit(value)
593
+
594
+ except DatabaseError as e:
595
+ # Wrap in TransactionError with context
596
+ raise TransactionError(
597
+ f"Failed to set autocommit to {value}: {e.message}",
598
+ context={
599
+ **e.context,
600
+ "operation": "set_autocommit",
601
+ "autocommit_value": value,
602
+ },
603
+ session_id_hex=self.get_session_id_hex(),
604
+ ) from e
605
+ finally:
606
+ if cursor:
607
+ cursor.close()
608
+
609
+ def _fetch_autocommit_state_from_server(self) -> bool:
610
+ """
611
+ Query server for current autocommit state using SET AUTOCOMMIT.
612
+
613
+ Returns:
614
+ bool: Server's autocommit state
615
+
616
+ Raises:
617
+ TransactionError: If query fails
618
+ """
619
+ cursor = None
620
+ try:
621
+ cursor = self.cursor()
622
+ cursor.execute("SET AUTOCOMMIT")
623
+
624
+ # Fetch result: should return row with value column
625
+ result = cursor.fetchone()
626
+ if result is None:
627
+ raise TransactionError(
628
+ "No result returned from SET AUTOCOMMIT query",
629
+ context={"operation": "fetch_autocommit"},
630
+ session_id_hex=self.get_session_id_hex(),
631
+ )
632
+
633
+ # Parse value (first column should be "true" or "false")
634
+ value_str = str(result[0]).lower()
635
+ autocommit_state = value_str == "true"
636
+
637
+ # Update cache
638
+ self.session.set_autocommit(autocommit_state)
639
+
640
+ return autocommit_state
641
+
642
+ except TransactionError:
643
+ # Re-raise TransactionError as-is
644
+ raise
645
+ except DatabaseError as e:
646
+ # Wrap other DatabaseErrors
647
+ raise TransactionError(
648
+ f"Failed to fetch autocommit state from server: {e.message}",
649
+ context={**e.context, "operation": "fetch_autocommit"},
650
+ session_id_hex=self.get_session_id_hex(),
651
+ ) from e
652
+ finally:
653
+ if cursor:
654
+ cursor.close()
655
+
656
+ def commit(self) -> None:
657
+ """
658
+ Commit the current transaction.
659
+
660
+ Per PEP 249. Should be called only when autocommit is disabled.
661
+
662
+ When autocommit is False:
663
+ - Commits the current transaction
664
+ - Server automatically starts new transaction
665
+
666
+ When autocommit is True:
667
+ - Server may throw error if no active transaction
668
+
669
+ When ignore_transactions is True:
670
+ - This method is a no-op (does nothing)
671
+
672
+ Raises:
673
+ InterfaceError: If connection is closed
674
+ TransactionError: If commit fails (e.g., no active transaction)
675
+ """
676
+ # No-op when ignore_transactions is True
677
+ if self.ignore_transactions:
678
+ return
679
+
680
+ if not self.open:
681
+ raise InterfaceError(
682
+ "Cannot commit on closed connection",
683
+ session_id_hex=self.get_session_id_hex(),
684
+ )
685
+
686
+ cursor = None
687
+ try:
688
+ cursor = self.cursor()
689
+ cursor.execute("COMMIT")
690
+
691
+ except DatabaseError as e:
692
+ raise TransactionError(
693
+ f"Failed to commit transaction: {e.message}",
694
+ context={**e.context, "operation": "commit"},
695
+ session_id_hex=self.get_session_id_hex(),
696
+ ) from e
697
+ finally:
698
+ if cursor:
699
+ cursor.close()
700
+
701
+ def rollback(self) -> None:
702
+ """
703
+ Rollback the current transaction.
704
+
705
+ Per PEP 249. Should be called only when autocommit is disabled.
706
+
707
+ When autocommit is False:
708
+ - Rolls back the current transaction
709
+ - Server automatically starts new transaction
710
+
711
+ When autocommit is True:
712
+ - ROLLBACK is forgiving (no-op, doesn't throw exception)
713
+
714
+ When ignore_transactions is True:
715
+ - Raises NotSupportedError
716
+
717
+ Note: ROLLBACK is safe to call even without active transaction.
718
+
719
+ Raises:
720
+ InterfaceError: If connection is closed
721
+ NotSupportedError: If ignore_transactions is True
722
+ TransactionError: If rollback fails
723
+ """
724
+ # Raise NotSupportedError when ignore_transactions is True
725
+ if self.ignore_transactions:
726
+ raise NotSupportedError(
727
+ "Transactions are not supported on Databricks",
728
+ session_id_hex=self.get_session_id_hex(),
729
+ )
730
+
731
+ if not self.open:
732
+ raise InterfaceError(
733
+ "Cannot rollback on closed connection",
734
+ session_id_hex=self.get_session_id_hex(),
735
+ )
736
+
737
+ cursor = None
738
+ try:
739
+ cursor = self.cursor()
740
+ cursor.execute("ROLLBACK")
741
+
742
+ except DatabaseError as e:
743
+ raise TransactionError(
744
+ f"Failed to rollback transaction: {e.message}",
745
+ context={**e.context, "operation": "rollback"},
746
+ session_id_hex=self.get_session_id_hex(),
747
+ ) from e
748
+ finally:
749
+ if cursor:
750
+ cursor.close()
751
+
752
+ def get_transaction_isolation(self) -> str:
753
+ """
754
+ Get the transaction isolation level.
755
+
756
+ Extension to PEP 249.
757
+
758
+ Databricks supports REPEATABLE_READ isolation level (Snapshot Isolation),
759
+ which is the default and only supported level.
760
+
761
+ Returns:
762
+ str: "REPEATABLE_READ" - the transaction isolation level constant
763
+
764
+ Raises:
765
+ InterfaceError: If connection is closed
766
+ """
767
+ if not self.open:
768
+ raise InterfaceError(
769
+ "Cannot get transaction isolation on closed connection",
770
+ session_id_hex=self.get_session_id_hex(),
771
+ )
772
+
773
+ return TRANSACTION_ISOLATION_LEVEL_REPEATABLE_READ
774
+
775
+ def set_transaction_isolation(self, level: str) -> None:
776
+ """
777
+ Set transaction isolation level.
778
+
779
+ Extension to PEP 249.
780
+
781
+ Databricks supports only REPEATABLE_READ isolation level (Snapshot Isolation).
782
+ This method validates that the requested level is supported but does not
783
+ execute any SQL, as REPEATABLE_READ is the default server behavior.
784
+
785
+ Args:
786
+ level: Isolation level. Must be "REPEATABLE_READ" or "REPEATABLE READ"
787
+ (case-insensitive, underscores and spaces are interchangeable)
788
+
789
+ Raises:
790
+ InterfaceError: If connection is closed
791
+ NotSupportedError: If isolation level not supported
792
+ """
793
+ if not self.open:
794
+ raise InterfaceError(
795
+ "Cannot set transaction isolation on closed connection",
796
+ session_id_hex=self.get_session_id_hex(),
797
+ )
798
+
799
+ # Normalize and validate isolation level
800
+ normalized_level = level.upper().replace("_", " ")
801
+
802
+ if normalized_level != TRANSACTION_ISOLATION_LEVEL_REPEATABLE_READ.replace(
803
+ "_", " "
804
+ ):
805
+ raise NotSupportedError(
806
+ f"Setting transaction isolation level '{level}' is not supported. "
807
+ f"Only {TRANSACTION_ISOLATION_LEVEL_REPEATABLE_READ} is supported.",
808
+ session_id_hex=self.get_session_id_hex(),
809
+ )
485
810
 
486
811
 
487
812
  class Cursor:
@@ -301,6 +301,11 @@ class UnifiedHttpClient:
301
301
  """Check if proxy support is available (not whether it's being used for a specific request)."""
302
302
  return self._proxy_pool_manager is not None
303
303
 
304
+ @property
305
+ def proxy_uri(self) -> Optional[str]:
306
+ """Get the configured proxy URI, if any."""
307
+ return self._proxy_uri
308
+
304
309
  def close(self):
305
310
  """Close the underlying connection pools."""
306
311
  if self._direct_pool_manager:
@@ -70,6 +70,23 @@ class NotSupportedError(DatabaseError):
70
70
  pass
71
71
 
72
72
 
73
+ class TransactionError(DatabaseError):
74
+ """
75
+ Exception raised for transaction-specific errors.
76
+
77
+ This exception is used when transaction control operations fail, such as:
78
+ - Setting autocommit mode (AUTOCOMMIT_SET_DURING_ACTIVE_TRANSACTION)
79
+ - Committing a transaction (MULTI_STATEMENT_TRANSACTION_NO_ACTIVE_TRANSACTION)
80
+ - Rolling back a transaction
81
+ - Setting transaction isolation level
82
+
83
+ The exception includes context about which transaction operation failed
84
+ and preserves the underlying cause via exception chaining.
85
+ """
86
+
87
+ pass
88
+
89
+
73
90
  ### Custom error classes ###
74
91
  class InvalidServerResponseError(OperationalError):
75
92
  """Thrown if the server does not set the initial namespace correctly"""
@@ -45,6 +45,9 @@ class Session:
45
45
  self.schema = schema
46
46
  self.http_path = http_path
47
47
 
48
+ # Initialize autocommit state (JDBC default is True)
49
+ self._autocommit = True
50
+
48
51
  user_agent_entry = kwargs.get("user_agent_entry")
49
52
  if user_agent_entry is None:
50
53
  user_agent_entry = kwargs.get("_user_agent_entry")
@@ -168,6 +171,24 @@ class Session:
168
171
  """Get the session ID in hex format"""
169
172
  return self._session_id.hex_guid
170
173
 
174
+ def get_autocommit(self) -> bool:
175
+ """
176
+ Get the cached autocommit state for this session.
177
+
178
+ Returns:
179
+ bool: True if autocommit is enabled, False otherwise
180
+ """
181
+ return self._autocommit
182
+
183
+ def set_autocommit(self, value: bool) -> None:
184
+ """
185
+ Update the cached autocommit state for this session.
186
+
187
+ Args:
188
+ value: True to cache autocommit as enabled, False as disabled
189
+ """
190
+ self._autocommit = value
191
+
171
192
  def close(self) -> None:
172
193
  """Close the underlying session."""
173
194
  logger.info("Closing session %s", self.guid_hex)
@@ -38,6 +38,25 @@ class DriverConnectionParameters(JsonSerializableMixin):
38
38
  auth_mech (AuthMech): The authentication mechanism used
39
39
  auth_flow (AuthFlow): The authentication flow type
40
40
  socket_timeout (int): Connection timeout in milliseconds
41
+ azure_workspace_resource_id (str): Azure workspace resource ID
42
+ azure_tenant_id (str): Azure tenant ID
43
+ use_proxy (bool): Whether proxy is being used
44
+ use_system_proxy (bool): Whether system proxy is being used
45
+ proxy_host_info (HostDetails): Proxy host details if configured
46
+ use_cf_proxy (bool): Whether CloudFlare proxy is being used
47
+ cf_proxy_host_info (HostDetails): CloudFlare proxy host details if configured
48
+ non_proxy_hosts (list): List of hosts that bypass proxy
49
+ allow_self_signed_support (bool): Whether self-signed certificates are allowed
50
+ use_system_trust_store (bool): Whether system trust store is used
51
+ enable_arrow (bool): Whether Arrow format is enabled
52
+ enable_direct_results (bool): Whether direct results are enabled
53
+ enable_sea_hybrid_results (bool): Whether SEA hybrid results are enabled
54
+ http_connection_pool_size (int): HTTP connection pool size
55
+ rows_fetched_per_block (int): Number of rows fetched per block
56
+ async_poll_interval_millis (int): Async polling interval in milliseconds
57
+ support_many_parameters (bool): Whether many parameters are supported
58
+ enable_complex_datatype_support (bool): Whether complex datatypes are supported
59
+ allowed_volume_ingestion_paths (str): Allowed paths for volume ingestion
41
60
  """
42
61
 
43
62
  http_path: str
@@ -46,6 +65,25 @@ class DriverConnectionParameters(JsonSerializableMixin):
46
65
  auth_mech: Optional[AuthMech] = None
47
66
  auth_flow: Optional[AuthFlow] = None
48
67
  socket_timeout: Optional[int] = None
68
+ azure_workspace_resource_id: Optional[str] = None
69
+ azure_tenant_id: Optional[str] = None
70
+ use_proxy: Optional[bool] = None
71
+ use_system_proxy: Optional[bool] = None
72
+ proxy_host_info: Optional[HostDetails] = None
73
+ use_cf_proxy: Optional[bool] = None
74
+ cf_proxy_host_info: Optional[HostDetails] = None
75
+ non_proxy_hosts: Optional[list] = None
76
+ allow_self_signed_support: Optional[bool] = None
77
+ use_system_trust_store: Optional[bool] = None
78
+ enable_arrow: Optional[bool] = None
79
+ enable_direct_results: Optional[bool] = None
80
+ enable_sea_hybrid_results: Optional[bool] = None
81
+ http_connection_pool_size: Optional[int] = None
82
+ rows_fetched_per_block: Optional[int] = None
83
+ async_poll_interval_millis: Optional[int] = None
84
+ support_many_parameters: Optional[bool] = None
85
+ enable_complex_datatype_support: Optional[bool] = None
86
+ allowed_volume_ingestion_paths: Optional[str] = None
49
87
 
50
88
 
51
89
  @dataclass
@@ -111,6 +149,69 @@ class DriverErrorInfo(JsonSerializableMixin):
111
149
  stack_trace: str
112
150
 
113
151
 
152
+ @dataclass
153
+ class ChunkDetails(JsonSerializableMixin):
154
+ """
155
+ Contains detailed metrics about chunk downloads during result fetching.
156
+
157
+ These metrics are accumulated across all chunk downloads for a single statement.
158
+
159
+ Attributes:
160
+ initial_chunk_latency_millis (int): Latency of the first chunk download
161
+ slowest_chunk_latency_millis (int): Latency of the slowest chunk download
162
+ total_chunks_present (int): Total number of chunks available
163
+ total_chunks_iterated (int): Number of chunks actually downloaded
164
+ sum_chunks_download_time_millis (int): Total time spent downloading all chunks
165
+ """
166
+
167
+ initial_chunk_latency_millis: Optional[int] = None
168
+ slowest_chunk_latency_millis: Optional[int] = None
169
+ total_chunks_present: Optional[int] = None
170
+ total_chunks_iterated: Optional[int] = None
171
+ sum_chunks_download_time_millis: Optional[int] = None
172
+
173
+
174
+ @dataclass
175
+ class ResultLatency(JsonSerializableMixin):
176
+ """
177
+ Contains latency metrics for different phases of query execution.
178
+
179
+ This tracks two distinct phases:
180
+ 1. result_set_ready_latency_millis: Time from query submission until results are available (execute phase)
181
+ - Set when execute() completes
182
+ 2. result_set_consumption_latency_millis: Time spent iterating/fetching results (fetch phase)
183
+ - Measured from first fetch call until no more rows available
184
+ - In Java: tracked via markResultSetConsumption(hasNext) method
185
+ - Records start time on first fetch, calculates total on last fetch
186
+
187
+ Attributes:
188
+ result_set_ready_latency_millis (int): Time until query results are ready (execution phase)
189
+ result_set_consumption_latency_millis (int): Time spent fetching/consuming results (fetch phase)
190
+
191
+ """
192
+
193
+ result_set_ready_latency_millis: Optional[int] = None
194
+ result_set_consumption_latency_millis: Optional[int] = None
195
+
196
+
197
+ @dataclass
198
+ class OperationDetail(JsonSerializableMixin):
199
+ """
200
+ Contains detailed information about the operation being performed.
201
+
202
+ Attributes:
203
+ n_operation_status_calls (int): Number of status polling calls made
204
+ operation_status_latency_millis (int): Total latency of all status calls
205
+ operation_type (str): Specific operation type (e.g., EXECUTE_STATEMENT, LIST_TABLES, CANCEL_STATEMENT)
206
+ is_internal_call (bool): Whether this is an internal driver operation
207
+ """
208
+
209
+ n_operation_status_calls: Optional[int] = None
210
+ operation_status_latency_millis: Optional[int] = None
211
+ operation_type: Optional[str] = None
212
+ is_internal_call: Optional[bool] = None
213
+
214
+
114
215
  @dataclass
115
216
  class SqlExecutionEvent(JsonSerializableMixin):
116
217
  """
@@ -122,7 +223,10 @@ class SqlExecutionEvent(JsonSerializableMixin):
122
223
  is_compressed (bool): Whether the result is compressed
123
224
  execution_result (ExecutionResultFormat): Format of the execution result
124
225
  retry_count (int): Number of retry attempts made
125
- chunk_id (int): ID of the chunk if applicable
226
+ chunk_id (int): ID of the chunk if applicable (used for error tracking)
227
+ chunk_details (ChunkDetails): Aggregated chunk download metrics
228
+ result_latency (ResultLatency): Latency breakdown by execution phase
229
+ operation_detail (OperationDetail): Detailed operation information
126
230
  """
127
231
 
128
232
  statement_type: StatementType
@@ -130,6 +234,9 @@ class SqlExecutionEvent(JsonSerializableMixin):
130
234
  execution_result: ExecutionResultFormat
131
235
  retry_count: Optional[int]
132
236
  chunk_id: Optional[int]
237
+ chunk_details: Optional[ChunkDetails] = None
238
+ result_latency: Optional[ResultLatency] = None
239
+ operation_detail: Optional[OperationDetail] = None
133
240
 
134
241
 
135
242
  @dataclass
@@ -380,7 +380,7 @@ class TelemetryClientFactory:
380
380
  # Shared flush thread for all clients
381
381
  _flush_thread = None
382
382
  _flush_event = threading.Event()
383
- _flush_interval_seconds = 90
383
+ _flush_interval_seconds = 300 # 5 minutes
384
384
 
385
385
  DEFAULT_BATCH_SIZE = 100
386
386