confluent-sql 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,209 @@
1
+ """
2
+ Exception classes for Confluent SQL DB-API driver.
3
+
4
+ This module defines the standard DB-API v2 exception hierarchy for the
5
+ Confluent SQL driver.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import TYPE_CHECKING, Any
11
+
12
+ if TYPE_CHECKING:
13
+ from .statement import Phase, Statement
14
+
15
+
16
+ class Warning(Exception):
17
+ """
18
+ Exception raised for important warnings like data truncations.
19
+
20
+ This exception is raised when the database issues a warning that
21
+ should be brought to the user's attention.
22
+ """
23
+
24
+ pass
25
+
26
+
27
+ class Error(Exception):
28
+ """
29
+ Exception that is the base class of all other error exceptions.
30
+
31
+ This is the base class for all database-related exceptions in the
32
+ DB-API specification.
33
+ """
34
+
35
+ pass
36
+
37
+
38
+ class InterfaceError(Error):
39
+ """
40
+ Exception raised for errors related to the database interface.
41
+
42
+ This exception is raised when there are problems with the database
43
+ interface rather than the database itself.
44
+ """
45
+
46
+ pass
47
+
48
+
49
+ class TypeMismatchError(InterfaceError):
50
+ """Raised when a TypeConverter is being driven with the wrong type, either when
51
+ converting parameter values to SQL literals or when processing Flink statement
52
+ results.
53
+
54
+ Subclass of InterfaceError.
55
+
56
+ Generally indicates a programming error in the driver."""
57
+
58
+ def __init__(self, converter_name: str, method_name: str, expected_type: str, bad_value: Any):
59
+ super().__init__(
60
+ f"Expected {expected_type} value for {converter_name}::{method_name}"
61
+ f" but got {type(bad_value).__name__}"
62
+ )
63
+
64
+
65
+ class DatabaseError(Error):
66
+ """
67
+ Exception raised for errors related to the database.
68
+
69
+ This exception is raised when there are problems with the database
70
+ itself, such as connection failures or database-specific errors.
71
+ """
72
+
73
+ pass
74
+
75
+
76
+ class DataError(DatabaseError):
77
+ """
78
+ Exception raised for errors due to problems with the processed data.
79
+
80
+ This exception is raised when there are problems with the data being
81
+ processed, such as division by zero, numeric value out of range, etc.
82
+ """
83
+
84
+ pass
85
+
86
+
87
+ class OperationalError(DatabaseError):
88
+ """
89
+ Exception raised for errors related to the database's operation.
90
+
91
+ This exception is raised when there are errors that are not under
92
+ the control of the programmer, such as unexpected disconnection,
93
+ the data source name not found, a transaction could not be processed,
94
+ a memory allocation error occurred during processing, etc.
95
+ """
96
+
97
+ pass
98
+
99
+
100
+ class ComputePoolExhaustedError(OperationalError):
101
+ """
102
+ Exception raised when a statement cannot be executed due to compute pool exhaustion.
103
+
104
+ This is a subclass of OperationalError.
105
+
106
+ Attributes:
107
+ statement_name: The name of the statement that could not be executed.
108
+ statement_deleted: Whether the statement was successfully deleted.
109
+ """
110
+
111
+ def __init__(self, message: str, statement_name: str, statement_deleted: bool):
112
+ super().__init__(message)
113
+ self.statement_name = statement_name
114
+ self.statement_deleted = statement_deleted
115
+
116
+
117
+ class StatementStoppedError(OperationalError):
118
+ """
119
+ Exception raised when a streaming statement stops unexpectedly.
120
+
121
+ Streaming queries run indefinitely until externally stopped or deleted. When
122
+ the statement enters a terminal phase (STOPPED, FAILED, COMPLETED), this
123
+ exception is raised to indicate the unexpected termination.
124
+
125
+ This is a subclass of OperationalError.
126
+
127
+ Attributes:
128
+ statement_name: The name of the statement that stopped.
129
+ statement: The Statement object (if available for inspection).
130
+ phase: The terminal phase (STOPPED, FAILED, COMPLETED, etc.) if available.
131
+ """
132
+
133
+ def __init__(
134
+ self,
135
+ message: str,
136
+ statement_name: str,
137
+ statement: Statement | None = None,
138
+ phase: Phase | None = None,
139
+ ):
140
+ super().__init__(message)
141
+ self.statement_name = statement_name
142
+ self.statement = statement
143
+ self.phase = phase
144
+
145
+
146
+ class StatementDeletedError(StatementStoppedError):
147
+ """
148
+ Exception raised when attempting to access a statement that has been deleted.
149
+
150
+ This is a subclass of StatementStoppedError raised specifically when the server
151
+ returns a 404 status code for a statement that previously existed but has
152
+ since been deleted (either explicitly or by the server).
153
+
154
+ Attributes:
155
+ statement_name: The name of the statement that was deleted.
156
+ statement: Always None (deleted statements have no state).
157
+ phase: Always None (deleted statements have no phase).
158
+ """
159
+
160
+ def __init__(self, message: str, statement_name: str):
161
+ super().__init__(message, statement_name, statement=None, phase=None)
162
+
163
+
164
+ class IntegrityError(DatabaseError):
165
+ """
166
+ Exception raised when the relational integrity of the database is affected.
167
+
168
+ This exception is raised when the relational integrity of the database
169
+ is affected, e.g. a foreign key check fails, duplicate key, etc.
170
+ """
171
+
172
+ pass
173
+
174
+
175
+ class InternalError(DatabaseError):
176
+ """
177
+ Exception raised when the database encounters an internal error.
178
+
179
+ This exception is raised when the database encounters an internal
180
+ error, e.g. the cursor is not valid anymore, the transaction is
181
+ out of sync, etc.
182
+ """
183
+
184
+ pass
185
+
186
+
187
+ class ProgrammingError(DatabaseError):
188
+ """
189
+ Exception raised for programming errors.
190
+
191
+ This exception is raised for programming errors, such as table not
192
+ found or already exists, syntax error in the SQL statement, wrong
193
+ number of parameters specified, etc.
194
+ """
195
+
196
+ pass
197
+
198
+
199
+ class NotSupportedError(DatabaseError):
200
+ """
201
+ Exception raised when a method or database API is not supported.
202
+
203
+ This exception is raised when a method or database API was used
204
+ which is not supported by the database, e.g. requesting a
205
+ .rollback() on a connection that does not support transaction
206
+ or has transactions turned off.
207
+ """
208
+
209
+ pass
@@ -0,0 +1,34 @@
1
+ from enum import Enum
2
+
3
+
4
+ class ExecutionMode(Enum):
5
+ """Controls statement execution and result handling behavior."""
6
+
7
+ SNAPSHOT = "snapshot"
8
+ """Submit the statement as a snapshot query -- point in time results, bounded result set."""
9
+
10
+ STREAMING_QUERY = "streaming_query"
11
+ """Submit the statement as a streaming query -- possibly(probably) unbounded result set."""
12
+
13
+ SNAPSHOT_DDL = "snapshot_ddl"
14
+ """Submit the statement as a snapshot DDL -- point in time schema change. Any queries done
15
+ as part of this DDL will be executed as snapshot queries. No results will be returned."""
16
+
17
+ STREAMING_DDL = "streaming_ddl"
18
+ """Submit the statement as a streaming DDL -- ongoing schema change. Any queries done as part
19
+ of this DDL will be executed as long-lived streaming queries. No results will be returned."""
20
+
21
+ @property
22
+ def is_ddl(self) -> bool:
23
+ """Check if the execution mode is for DDL statements."""
24
+ return self in {ExecutionMode.SNAPSHOT_DDL, ExecutionMode.STREAMING_DDL}
25
+
26
+ @property
27
+ def is_snapshot(self) -> bool:
28
+ """Check if the execution mode is for snapshot statements."""
29
+ return self in {ExecutionMode.SNAPSHOT, ExecutionMode.SNAPSHOT_DDL}
30
+
31
+ @property
32
+ def is_streaming(self) -> bool:
33
+ """Check if the execution mode is for streaming statements."""
34
+ return self in {ExecutionMode.STREAMING_QUERY, ExecutionMode.STREAMING_DDL}