Skip to content

Commit c09508e

Browse files
change errors to align with spec, instead of arbitrary ValueError
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 2c22010 commit c09508e

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/databricks/sql/backend/sea/backend.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
BackendType,
3030
ExecuteResponse,
3131
)
32-
from databricks.sql.exc import DatabaseError, ServerOperationError
32+
from databricks.sql.exc import DatabaseError, ProgrammingError, ServerOperationError
3333
from databricks.sql.backend.sea.utils.http_client import SeaHttpClient
3434
from databricks.sql.types import SSLOptions
3535

@@ -152,7 +152,7 @@ def _extract_warehouse_id(self, http_path: str) -> str:
152152
The extracted warehouse ID
153153
154154
Raises:
155-
ValueError: If the warehouse ID cannot be extracted from the path
155+
ProgrammingError: If the warehouse ID cannot be extracted from the path
156156
"""
157157

158158
warehouse_pattern = re.compile(r".*/warehouses/(.+)")
@@ -176,7 +176,7 @@ def _extract_warehouse_id(self, http_path: str) -> str:
176176
f"Note: SEA only works for warehouses."
177177
)
178178
logger.error(error_message)
179-
raise ValueError(error_message)
179+
raise ProgrammingError(error_message)
180180

181181
@property
182182
def max_download_threads(self) -> int:
@@ -248,14 +248,14 @@ def close_session(self, session_id: SessionId) -> None:
248248
session_id: The session identifier returned by open_session()
249249
250250
Raises:
251-
ValueError: If the session ID is invalid
251+
ProgrammingError: If the session ID is invalid
252252
OperationalError: If there's an error closing the session
253253
"""
254254

255255
logger.debug("SeaDatabricksClient.close_session(session_id=%s)", session_id)
256256

257257
if session_id.backend_type != BackendType.SEA:
258-
raise ValueError("Not a valid SEA session ID")
258+
raise ProgrammingError("Not a valid SEA session ID")
259259
sea_session_id = session_id.to_sea_session_id()
260260

261261
request_data = DeleteSessionRequest(
@@ -433,7 +433,7 @@ def execute_command(
433433
"""
434434

435435
if session_id.backend_type != BackendType.SEA:
436-
raise ValueError("Not a valid SEA session ID")
436+
raise ProgrammingError("Not a valid SEA session ID")
437437

438438
sea_session_id = session_id.to_sea_session_id()
439439

@@ -508,11 +508,11 @@ def cancel_command(self, command_id: CommandId) -> None:
508508
command_id: Command identifier to cancel
509509
510510
Raises:
511-
ValueError: If the command ID is invalid
511+
ProgrammingError: If the command ID is invalid
512512
"""
513513

514514
if command_id.backend_type != BackendType.SEA:
515-
raise ValueError("Not a valid SEA command ID")
515+
raise ProgrammingError("Not a valid SEA command ID")
516516

517517
sea_statement_id = command_id.to_sea_statement_id()
518518

@@ -531,11 +531,11 @@ def close_command(self, command_id: CommandId) -> None:
531531
command_id: Command identifier to close
532532
533533
Raises:
534-
ValueError: If the command ID is invalid
534+
ProgrammingError: If the command ID is invalid
535535
"""
536536

537537
if command_id.backend_type != BackendType.SEA:
538-
raise ValueError("Not a valid SEA command ID")
538+
raise ProgrammingError("Not a valid SEA command ID")
539539

540540
sea_statement_id = command_id.to_sea_statement_id()
541541

@@ -557,11 +557,11 @@ def get_query_state(self, command_id: CommandId) -> CommandState:
557557
CommandState: The current state of the command
558558
559559
Raises:
560-
ValueError: If the command ID is invalid
560+
ProgrammingError: If the command ID is invalid
561561
"""
562562

563563
if command_id.backend_type != BackendType.SEA:
564-
raise ValueError("Not a valid SEA command ID")
564+
raise ProgrammingError("Not a valid SEA command ID")
565565

566566
sea_statement_id = command_id.to_sea_statement_id()
567567

@@ -592,11 +592,11 @@ def get_execution_result(
592592
SeaResultSet: A SeaResultSet instance with the execution results
593593
594594
Raises:
595-
ValueError: If the command ID is invalid
595+
ProgrammingError: If the command ID is invalid
596596
"""
597597

598598
if command_id.backend_type != BackendType.SEA:
599-
raise ValueError("Not a valid SEA command ID")
599+
raise ProgrammingError("Not a valid SEA command ID")
600600

601601
sea_statement_id = command_id.to_sea_statement_id()
602602

@@ -691,7 +691,7 @@ def get_schemas(
691691
) -> SeaResultSet:
692692
"""Get schemas by executing 'SHOW SCHEMAS IN catalog [LIKE pattern]'."""
693693
if not catalog_name:
694-
raise ValueError("Catalog name is required for get_schemas")
694+
raise DatabaseError("Catalog name is required for get_schemas")
695695

696696
operation = MetadataCommands.SHOW_SCHEMAS.value.format(catalog_name)
697697

@@ -773,7 +773,7 @@ def get_columns(
773773
) -> SeaResultSet:
774774
"""Get columns by executing 'SHOW COLUMNS IN CATALOG catalog [SCHEMA LIKE pattern] [TABLE LIKE pattern] [LIKE pattern]'."""
775775
if not catalog_name:
776-
raise ValueError("Catalog name is required for get_columns")
776+
raise DatabaseError("Catalog name is required for get_columns")
777777

778778
operation = MetadataCommands.SHOW_COLUMNS.value.format(catalog_name)
779779

0 commit comments

Comments
 (0)