1+ from __future__ import annotations
2+
13import logging
24import time
35import re
1618
1719if TYPE_CHECKING :
1820 from databricks .sql .client import Cursor
19- from databricks .sql .result_set import ResultSet
21+ from databricks .sql .result_set import SeaResultSet
2022
2123from databricks .sql .backend .databricks_client import DatabricksClient
2224from databricks .sql .backend .types import (
2628 BackendType ,
2729 ExecuteResponse ,
2830)
29- from databricks .sql .exc import DatabaseError , ServerOperationError
31+ from databricks .sql .exc import DatabaseError , ProgrammingError , ServerOperationError
3032from databricks .sql .backend .sea .utils .http_client import SeaHttpClient
3133from databricks .sql .types import SSLOptions
3234
@@ -171,7 +173,7 @@ def _extract_warehouse_id(self, http_path: str) -> str:
171173 f"Note: SEA only works for warehouses."
172174 )
173175 logger .error (error_message )
174- raise ValueError (error_message )
176+ raise ProgrammingError (error_message )
175177
176178 @property
177179 def max_download_threads (self ) -> int :
@@ -243,14 +245,14 @@ def close_session(self, session_id: SessionId) -> None:
243245 session_id: The session identifier returned by open_session()
244246
245247 Raises:
246- ValueError : If the session ID is invalid
248+ ProgrammingError : If the session ID is invalid
247249 OperationalError: If there's an error closing the session
248250 """
249251
250252 logger .debug ("SeaDatabricksClient.close_session(session_id=%s)" , session_id )
251253
252254 if session_id .backend_type != BackendType .SEA :
253- raise ValueError ("Not a valid SEA session ID" )
255+ raise ProgrammingError ("Not a valid SEA session ID" )
254256 sea_session_id = session_id .to_sea_session_id ()
255257
256258 request_data = DeleteSessionRequest (
@@ -402,12 +404,12 @@ def execute_command(
402404 max_rows : int ,
403405 max_bytes : int ,
404406 lz4_compression : bool ,
405- cursor : " Cursor" ,
407+ cursor : Cursor ,
406408 use_cloud_fetch : bool ,
407409 parameters : List [ttypes .TSparkParameter ],
408410 async_op : bool ,
409411 enforce_embedded_schema_correctness : bool ,
410- ) -> Union ["ResultSet" , None ]:
412+ ) -> Union [SeaResultSet , None ]:
411413 """
412414 Execute a SQL command using the SEA backend.
413415
@@ -428,7 +430,7 @@ def execute_command(
428430 """
429431
430432 if session_id .backend_type != BackendType .SEA :
431- raise ValueError ("Not a valid SEA session ID" )
433+ raise ProgrammingError ("Not a valid SEA session ID" )
432434
433435 sea_session_id = session_id .to_sea_session_id ()
434436
@@ -503,11 +505,11 @@ def cancel_command(self, command_id: CommandId) -> None:
503505 command_id: Command identifier to cancel
504506
505507 Raises:
506- ValueError : If the command ID is invalid
508+ ProgrammingError : If the command ID is invalid
507509 """
508510
509511 if command_id .backend_type != BackendType .SEA :
510- raise ValueError ("Not a valid SEA command ID" )
512+ raise ProgrammingError ("Not a valid SEA command ID" )
511513
512514 sea_statement_id = command_id .to_sea_statement_id ()
513515
@@ -526,11 +528,11 @@ def close_command(self, command_id: CommandId) -> None:
526528 command_id: Command identifier to close
527529
528530 Raises:
529- ValueError : If the command ID is invalid
531+ ProgrammingError : If the command ID is invalid
530532 """
531533
532534 if command_id .backend_type != BackendType .SEA :
533- raise ValueError ("Not a valid SEA command ID" )
535+ raise ProgrammingError ("Not a valid SEA command ID" )
534536
535537 sea_statement_id = command_id .to_sea_statement_id ()
536538
@@ -552,7 +554,7 @@ def get_query_state(self, command_id: CommandId) -> CommandState:
552554 CommandState: The current state of the command
553555
554556 Raises:
555- ValueError : If the command ID is invalid
557+ ProgrammingError : If the command ID is invalid
556558 """
557559
558560 if command_id .backend_type != BackendType .SEA :
@@ -574,8 +576,8 @@ def get_query_state(self, command_id: CommandId) -> CommandState:
574576 def get_execution_result (
575577 self ,
576578 command_id : CommandId ,
577- cursor : " Cursor" ,
578- ) -> "ResultSet" :
579+ cursor : Cursor ,
580+ ) -> SeaResultSet :
579581 """
580582 Get the result of a command execution.
581583
@@ -584,14 +586,14 @@ def get_execution_result(
584586 cursor: Cursor executing the command
585587
586588 Returns:
587- ResultSet : A SeaResultSet instance with the execution results
589+ SeaResultSet : A SeaResultSet instance with the execution results
588590
589591 Raises:
590592 ValueError: If the command ID is invalid
591593 """
592594
593595 if command_id .backend_type != BackendType .SEA :
594- raise ValueError ("Not a valid SEA command ID" )
596+ raise ProgrammingError ("Not a valid SEA command ID" )
595597
596598 sea_statement_id = command_id .to_sea_statement_id ()
597599
@@ -628,8 +630,8 @@ def get_catalogs(
628630 session_id : SessionId ,
629631 max_rows : int ,
630632 max_bytes : int ,
631- cursor : " Cursor" ,
632- ) -> "ResultSet" :
633+ cursor : Cursor ,
634+ ) -> SeaResultSet :
633635 """Get available catalogs by executing 'SHOW CATALOGS'."""
634636 result = self .execute_command (
635637 operation = MetadataCommands .SHOW_CATALOGS .value ,
@@ -651,13 +653,13 @@ def get_schemas(
651653 session_id : SessionId ,
652654 max_rows : int ,
653655 max_bytes : int ,
654- cursor : " Cursor" ,
656+ cursor : Cursor ,
655657 catalog_name : Optional [str ] = None ,
656658 schema_name : Optional [str ] = None ,
657- ) -> "ResultSet" :
659+ ) -> SeaResultSet :
658660 """Get schemas by executing 'SHOW SCHEMAS IN catalog [LIKE pattern]'."""
659661 if not catalog_name :
660- raise ValueError ("Catalog name is required for get_schemas" )
662+ raise DatabaseError ("Catalog name is required for get_schemas" )
661663
662664 operation = MetadataCommands .SHOW_SCHEMAS .value .format (catalog_name )
663665
@@ -684,12 +686,12 @@ def get_tables(
684686 session_id : SessionId ,
685687 max_rows : int ,
686688 max_bytes : int ,
687- cursor : " Cursor" ,
689+ cursor : Cursor ,
688690 catalog_name : Optional [str ] = None ,
689691 schema_name : Optional [str ] = None ,
690692 table_name : Optional [str ] = None ,
691693 table_types : Optional [List [str ]] = None ,
692- ) -> "ResultSet" :
694+ ) -> SeaResultSet :
693695 """Get tables by executing 'SHOW TABLES IN catalog [SCHEMA LIKE pattern] [LIKE pattern]'."""
694696 operation = (
695697 MetadataCommands .SHOW_TABLES_ALL_CATALOGS .value
@@ -719,12 +721,6 @@ def get_tables(
719721 )
720722 assert result is not None , "execute_command returned None in synchronous mode"
721723
722- from databricks .sql .result_set import SeaResultSet
723-
724- assert isinstance (
725- result , SeaResultSet
726- ), "execute_command returned a non-SeaResultSet"
727-
728724 # Apply client-side filtering by table_types
729725 from databricks .sql .backend .sea .utils .filters import ResultSetFilter
730726
@@ -737,15 +733,15 @@ def get_columns(
737733 session_id : SessionId ,
738734 max_rows : int ,
739735 max_bytes : int ,
740- cursor : " Cursor" ,
736+ cursor : Cursor ,
741737 catalog_name : Optional [str ] = None ,
742738 schema_name : Optional [str ] = None ,
743739 table_name : Optional [str ] = None ,
744740 column_name : Optional [str ] = None ,
745- ) -> "ResultSet" :
741+ ) -> SeaResultSet :
746742 """Get columns by executing 'SHOW COLUMNS IN CATALOG catalog [SCHEMA LIKE pattern] [TABLE LIKE pattern] [LIKE pattern]'."""
747743 if not catalog_name :
748- raise ValueError ("Catalog name is required for get_columns" )
744+ raise DatabaseError ("Catalog name is required for get_columns" )
749745
750746 operation = MetadataCommands .SHOW_COLUMNS .value .format (catalog_name )
751747
0 commit comments