graph LR
DB_API_Cursor_Base["DB-API Cursor Base"]
Hive_Cursor["Hive Cursor"]
Presto_Cursor["Presto Cursor"]
Trino_Cursor["Trino Cursor"]
Parameter_Escaper["Parameter Escaper"]
Thrift_API_Client["Thrift API Client"]
HTTP_Client["HTTP Client"]
Exception_Management["Exception Management"]
Hive_Cursor -- "inherits from" --> DB_API_Cursor_Base
Hive_Cursor -- "calls methods of" --> DB_API_Cursor_Base
Presto_Cursor -- "inherits from" --> DB_API_Cursor_Base
Presto_Cursor -- "calls methods of" --> DB_API_Cursor_Base
Trino_Cursor -- "inherits from" --> Presto_Cursor
Trino_Cursor -- "calls methods of" --> Presto_Cursor
Hive_Cursor -- "interacts with" --> Thrift_API_Client
Hive_Cursor -- "sends requests to" --> Thrift_API_Client
Presto_Cursor -- "interacts with" --> HTTP_Client
Presto_Cursor -- "sends requests to" --> HTTP_Client
Trino_Cursor -- "interacts with" --> HTTP_Client
Trino_Cursor -- "sends requests to" --> HTTP_Client
Hive_Cursor -- "uses for parameter formatting" --> Parameter_Escaper
Presto_Cursor -- "uses for parameter formatting" --> Parameter_Escaper
Trino_Cursor -- "uses for parameter formatting" --> Parameter_Escaper
DB_API_Cursor_Base -- "raises" --> Exception_Management
Parameter_Escaper -- "raises" --> Exception_Management
Hive_Cursor -- "raises" --> Exception_Management
Presto_Cursor -- "raises" --> Exception_Management
Trino_Cursor -- "raises" --> Exception_Management
This system provides a set of DB-API compliant database cursors for various data sources like Hive, Presto, and Trino. It establishes a common base for cursor functionalities, handles SQL parameter escaping, manages interactions with specific database APIs (Thrift for Hive, HTTP for Presto/Trino), and incorporates a centralized exception management system to ensure robust database operations.
This component provides the fundamental interface and common logic for all database cursors in PyHive, adhering to the Python DB-API specification. It manages the cursor's internal state, handles generic fetching mechanisms like fetchone and executemany, and defines abstract methods that concrete cursor implementations must provide.
Related Classes/Methods:
pyhive.common.DBAPICursor(27:192)pyhive.common.DBAPICursor:__init__(34:37)pyhive.common.DBAPICursor:_fetch_while(49:53)pyhive.common.DBAPICursor:executemany(85:98)pyhive.common.DBAPICursor:fetchone(100:117)pyhive.common.DBAPICursor:__next__(177:186)pyhive.common.DBAPICursor._reset_state(39:47)pyhive.common.DBAPICursor._fetch_more(64:66)
This component implements the DB-API cursor specifically for HiveServer2. It handles the execution of SQL queries, manages the Thrift operation handle, and retrieves results by interacting with the HiveServer2 Thrift API.
Related Classes/Methods:
pyhive.hive.Cursor(361:570)pyhive.hive.Cursor:__init__(369:373)pyhive.hive.Cursor:_reset_state(375:385)pyhive.hive.Cursor:execute(453:482)pyhive.hive._check_status(607:611)
This component implements the DB-API cursor for Presto. It manages HTTP-based query execution, sends requests to the Presto REST API, and processes the JSON responses to retrieve query results and metadata.
Related Classes/Methods:
pyhive.presto.Cursor(91:355)pyhive.presto.Cursor:__init__(99:206)pyhive.presto.Cursor:_reset_state(208:212)pyhive.presto.Cursor:description(215:242)pyhive.presto.Cursor:execute(244:278)pyhive.presto.Cursor:_process_response(325:355)
This component extends the Presto cursor to provide specific functionalities for Trino. It primarily customizes the HTTP headers and response processing to align with Trino's API, while leveraging the core logic from the Presto cursor.
Related Classes/Methods:
pyhive.trino.Cursor(58:132)pyhive.trino.Cursor:execute(66:100)pyhive.trino.Cursor:_process_response(102:132)
This component is responsible for safely formatting and escaping parameters for SQL queries. It provides methods to handle various data types such as numbers, strings, sequences, and datetime objects, with specialized implementations for Hive, Presto, and Trino to ensure correct syntax and prevent SQL injection.
Related Classes/Methods:
pyhive.common.ParamEscaper(209:260)pyhive.common.ParamEscaper:escape_args(214:220)pyhive.common.ParamEscaper:escape_item(246:260)pyhive.common.ParamEscaper:escape_number(222:223)pyhive.common.ParamEscaper:escape_string(225:235)pyhive.common.ParamEscaper:escape_sequence(237:239)pyhive.common.ParamEscaper:escape_datetime(241:244)pyhive.presto.PrestoParamEscaper(45:49)pyhive.presto.PrestoParamEscaper:escape_datetime(46:49)pyhive.trino.TrinoParamEscaper(33:34)pyhive.hive.HiveParamEscaper(114:131)
This component encapsulates the interactions with the HiveServer2 Thrift API. It is responsible for constructing and sending Thrift requests (e.g., for closing operations or executing statements) and processing the Thrift responses, ensuring proper communication with the Hive server.
Related Classes/Methods:
TCLIService.ttypes.TCloseOperationReq(full file reference)TCLIService.ttypes.TExecuteStatementReq(full file reference)
This component handles the underlying HTTP communication for Presto and Trino. It is responsible for sending HTTP requests (e.g., POST for query execution, GET for polling, DELETE for cancellation) and processing the HTTP responses, including status codes and JSON payloads.
Related Classes/Methods: None
This component defines and manages various database-related exceptions, such as ProgrammingError, OperationalError, DatabaseError, and NotSupportedError. It is responsible for raising appropriate exceptions based on error conditions encountered during database operations.
Related Classes/Methods: