Skip to content

Commit 20884d3

Browse files
committed
fixed type of client_app_name
Signed-off-by: Sai Shree Pradhan <saishree.pradhan@databricks.com>
1 parent dc0a3a8 commit 20884d3

File tree

2 files changed

+28
-62
lines changed

2 files changed

+28
-62
lines changed

src/databricks/sql/client.py

Lines changed: 25 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,13 @@
4343

4444
from databricks.sql.types import Row, SSLOptions
4545
from databricks.sql.auth.auth import get_python_sql_connector_auth_provider
46-
from databricks.sql.telemetry.telemetry_client import (
47-
telemetry_client,
48-
NoopTelemetryClient,
49-
)
46+
from databricks.sql.experimental.oauth_persistence import OAuthPersistence
47+
5048
from databricks.sql.thrift_api.TCLIService.ttypes import (
5149
TSparkParameter,
5250
TOperationState,
5351
)
52+
from databricks.sql.telemetry.telemetry_client import telemetry_client, NoopTelemetryClient
5453
from databricks.sql.telemetry.latency_logger import log_latency
5554
from databricks.sql.telemetry.models.enums import DriverVolumeOperationType
5655

@@ -241,9 +240,7 @@ def read(self) -> Optional[OAuthToken]:
241240
self.telemetry_enabled = (
242241
self.client_telemetry_enabled and self.server_telemetry_enabled
243242
)
244-
telemetry_batch_size = kwargs.get(
245-
"telemetry_batch_size", 100
246-
) # TODO: Decide on batch size
243+
telemetry_batch_size = kwargs.get("telemetry_batch_size", 100) # TODO: Decide on batch size
247244

248245
user_agent_entry = kwargs.get("user_agent_entry")
249246
if user_agent_entry is None:
@@ -305,16 +302,16 @@ def read(self) -> Optional[OAuthToken]:
305302
host=self.host,
306303
connection_uuid=self.get_session_id_hex(),
307304
auth_provider=auth_provider,
308-
is_authenticated=True, # TODO: Add authentication logic later
305+
is_authenticated=True, # TODO: Add authentication logic later
309306
batch_size=telemetry_batch_size,
310307
user_agent=useragent_header,
311308
)
312-
309+
313310
telemetry_client.export_initial_telemetry_log(
314-
http_path,
315-
self.port,
311+
http_path,
312+
self.port,
316313
kwargs.get("_socket_timeout", None),
317-
self.get_session_id_hex(),
314+
self.get_session_id_hex()
318315
)
319316
else:
320317
self.telemetry_client = NoopTelemetryClient()
@@ -515,10 +512,7 @@ def __iter__(self):
515512
for row in self.active_result_set:
516513
yield row
517514
else:
518-
raise Error(
519-
"There is no active result set",
520-
connection_uuid=self.connection.get_session_id_hex(),
521-
)
515+
raise Error("There is no active result set", connection_uuid=self.connection.get_session_id_hex())
522516

523517
def _determine_parameter_approach(
524518
self, params: Optional[TParameterCollection]
@@ -655,10 +649,7 @@ def _close_and_clear_active_result_set(self):
655649

656650
def _check_not_closed(self):
657651
if not self.open:
658-
raise Error(
659-
"Attempting operation on closed cursor",
660-
connection_uuid=self.connection.get_session_id_hex(),
661-
)
652+
raise Error("Attempting operation on closed cursor", connection_uuid=self.connection.get_session_id_hex())
662653

663654
def _handle_staging_operation(
664655
self, staging_allowed_local_path: Union[None, str, List[str]]
@@ -677,7 +668,7 @@ def _handle_staging_operation(
677668
else:
678669
raise Error(
679670
"You must provide at least one staging_allowed_local_path when initialising a connection to perform ingestion commands",
680-
connection_uuid=self.connection.get_session_id_hex(),
671+
connection_uuid=self.connection.get_session_id_hex()
681672
)
682673

683674
abs_staging_allowed_local_paths = [
@@ -707,7 +698,7 @@ def _handle_staging_operation(
707698
if not allow_operation:
708699
raise Error(
709700
"Local file operations are restricted to paths within the configured staging_allowed_local_path",
710-
connection_uuid=self.connection.get_session_id_hex(),
701+
connection_uuid=self.connection.get_session_id_hex()
711702
)
712703

713704
# May be real headers, or could be json string
@@ -738,7 +729,7 @@ def _handle_staging_operation(
738729
raise Error(
739730
f"Operation {row.operation} is not supported. "
740731
+ "Supported operations are GET, PUT, and REMOVE",
741-
connection_uuid=self.connection.get_session_id_hex(),
732+
connection_uuid=self.connection.get_session_id_hex()
742733
)
743734

744735
@log_latency()
@@ -751,10 +742,7 @@ def _handle_staging_put(
751742
"""
752743

753744
if local_file is None:
754-
raise Error(
755-
"Cannot perform PUT without specifying a local_file",
756-
connection_uuid=self.connection.get_session_id_hex(),
757-
)
745+
raise Error("Cannot perform PUT without specifying a local_file", connection_uuid=self.connection.get_session_id_hex())
758746

759747
self.volume_operation_type = DriverVolumeOperationType.PUT
760748
self.volume_path = local_file
@@ -774,8 +762,7 @@ def _handle_staging_put(
774762

775763
if r.status_code not in [OK, CREATED, NO_CONTENT, ACCEPTED]:
776764
raise Error(
777-
f"Staging operation over HTTP was unsuccessful: {r.status_code}-{r.text}",
778-
connection_uuid=self.connection.get_session_id_hex(),
765+
f"Staging operation over HTTP was unsuccessful: {r.status_code}-{r.text}", connection_uuid=self.connection.get_session_id_hex()
779766
)
780767

781768
if r.status_code == ACCEPTED:
@@ -794,10 +781,7 @@ def _handle_staging_get(
794781
"""
795782

796783
if local_file is None:
797-
raise Error(
798-
"Cannot perform GET without specifying a local_file",
799-
connection_uuid=self.connection.get_session_id_hex(),
800-
)
784+
raise Error("Cannot perform GET without specifying a local_file", connection_uuid=self.connection.get_session_id_hex())
801785

802786
self.volume_operation_type = DriverVolumeOperationType.GET
803787
self.volume_path = local_file
@@ -808,8 +792,7 @@ def _handle_staging_get(
808792
# Any 2xx or 3xx will evaluate r.ok == True
809793
if not r.ok:
810794
raise Error(
811-
f"Staging operation over HTTP was unsuccessful: {r.status_code}-{r.text}",
812-
connection_uuid=self.connection.get_session_id_hex(),
795+
f"Staging operation over HTTP was unsuccessful: {r.status_code}-{r.text}", connection_uuid=self.connection.get_session_id_hex()
813796
)
814797

815798
with open(local_file, "wb") as fp:
@@ -822,9 +805,7 @@ def _handle_staging_remove(
822805
"""Make an HTTP DELETE request to the presigned_url"""
823806

824807
self.volume_operation_type = DriverVolumeOperationType.DELETE
825-
self.volume_path = (
826-
presigned_url # Using presigned URL as path since there's no local file
827-
)
808+
self.volume_path = presigned_url # Using presigned URL as path since there's no local file
828809

829810
r = requests.delete(url=presigned_url, headers=headers)
830811

@@ -1029,8 +1010,7 @@ def get_async_execution_result(self):
10291010
return self
10301011
else:
10311012
raise Error(
1032-
f"get_execution_result failed with Operation status {operation_state}",
1033-
connection_uuid=self.connection.get_session_id_hex(),
1013+
f"get_execution_result failed with Operation status {operation_state}", connection_uuid=self.connection.get_session_id_hex()
10341014
)
10351015

10361016
def executemany(self, operation, seq_of_parameters):
@@ -1180,10 +1160,7 @@ def fetchall(self) -> List[Row]:
11801160
if self.active_result_set:
11811161
return self.active_result_set.fetchall()
11821162
else:
1183-
raise Error(
1184-
"There is no active result set",
1185-
connection_uuid=self.connection.get_session_id_hex(),
1186-
)
1163+
raise Error("There is no active result set", connection_uuid=self.connection.get_session_id_hex())
11871164

11881165
def fetchone(self) -> Optional[Row]:
11891166
"""
@@ -1197,10 +1174,7 @@ def fetchone(self) -> Optional[Row]:
11971174
if self.active_result_set:
11981175
return self.active_result_set.fetchone()
11991176
else:
1200-
raise Error(
1201-
"There is no active result set",
1202-
connection_uuid=self.connection.get_session_id_hex(),
1203-
)
1177+
raise Error("There is no active result set", connection_uuid=self.connection.get_session_id_hex())
12041178

12051179
def fetchmany(self, size: int) -> List[Row]:
12061180
"""
@@ -1222,30 +1196,21 @@ def fetchmany(self, size: int) -> List[Row]:
12221196
if self.active_result_set:
12231197
return self.active_result_set.fetchmany(size)
12241198
else:
1225-
raise Error(
1226-
"There is no active result set",
1227-
connection_uuid=self.connection.get_session_id_hex(),
1228-
)
1199+
raise Error("There is no active result set", connection_uuid=self.connection.get_session_id_hex())
12291200

12301201
def fetchall_arrow(self) -> "pyarrow.Table":
12311202
self._check_not_closed()
12321203
if self.active_result_set:
12331204
return self.active_result_set.fetchall_arrow()
12341205
else:
1235-
raise Error(
1236-
"There is no active result set",
1237-
connection_uuid=self.connection.get_session_id_hex(),
1238-
)
1206+
raise Error("There is no active result set", connection_uuid=self.connection.get_session_id_hex())
12391207

12401208
def fetchmany_arrow(self, size) -> "pyarrow.Table":
12411209
self._check_not_closed()
12421210
if self.active_result_set:
12431211
return self.active_result_set.fetchmany_arrow(size)
12441212
else:
1245-
raise Error(
1246-
"There is no active result set",
1247-
connection_uuid=self.connection.get_session_id_hex(),
1248-
)
1213+
raise Error("There is no active result set", connection_uuid=self.connection.get_session_id_hex())
12491214

12501215
def cancel(self) -> None:
12511216
"""

src/databricks/sql/telemetry/telemetry_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import sys
2525
import platform
2626
import uuid
27+
import locale
2728

2829
logger = logging.getLogger(__name__)
2930

@@ -46,8 +47,8 @@ def getDriverSystemConfiguration(cls) -> DriverSystemConfiguration:
4647
os_name=platform.system(),
4748
os_version=platform.release(),
4849
os_arch=platform.machine(),
49-
client_app_name=None, # TODO: Add client app name
50-
locale_name=f"{platform.system()}_{platform.release()}",
50+
client_app_name="unknown", # TODO: Add client app name
51+
locale_name=locale.getlocale()[0] or locale.getdefaultlocale()[0],
5152
char_set_encoding=sys.getdefaultencoding(),
5253
)
5354
return cls._DRIVER_SYSTEM_CONFIGURATION

0 commit comments

Comments
 (0)