pyexasol 2.2.3__tar.gz → 2.3.0__tar.gz

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.
Files changed (41) hide show
  1. {pyexasol-2.2.3 → pyexasol-2.3.0}/PKG-INFO +1 -1
  2. pyexasol-2.3.0/pyexasol/_sql_splitter.py +323 -0
  3. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/connection.py +20 -0
  4. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyproject.toml +5 -3
  5. {pyexasol-2.2.3 → pyexasol-2.3.0}/LICENSE.txt +0 -0
  6. {pyexasol-2.2.3 → pyexasol-2.3.0}/README.md +0 -0
  7. {pyexasol-2.2.3 → pyexasol-2.3.0}/exasol/driver/__init__.py +0 -0
  8. {pyexasol-2.2.3 → pyexasol-2.3.0}/exasol/driver/websocket/__init__.py +0 -0
  9. {pyexasol-2.2.3 → pyexasol-2.3.0}/exasol/driver/websocket/_connection.py +0 -0
  10. {pyexasol-2.2.3 → pyexasol-2.3.0}/exasol/driver/websocket/_cursor.py +0 -0
  11. {pyexasol-2.2.3 → pyexasol-2.3.0}/exasol/driver/websocket/_errors.py +0 -0
  12. {pyexasol-2.2.3 → pyexasol-2.3.0}/exasol/driver/websocket/_protocols.py +0 -0
  13. {pyexasol-2.2.3 → pyexasol-2.3.0}/exasol/driver/websocket/_types.py +0 -0
  14. {pyexasol-2.2.3 → pyexasol-2.3.0}/exasol/driver/websocket/dbapi2.py +0 -0
  15. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/__init__.py +0 -0
  16. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/__main__.py +0 -0
  17. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/_metadata.py +0 -0
  18. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/callback.py +0 -0
  19. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/constant.py +0 -0
  20. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/db2/__init__.py +0 -0
  21. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/exceptions.py +0 -0
  22. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/ext.py +0 -0
  23. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/formatter.py +0 -0
  24. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/http_transport.py +0 -0
  25. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/local_config.py +0 -0
  26. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/logger.py +0 -0
  27. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/mapper.py +0 -0
  28. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/meta.py +0 -0
  29. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/py.typed +0 -0
  30. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/script_output.py +0 -0
  31. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/statement.py +0 -0
  32. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol/warnings.py +0 -0
  33. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol_utils/__init__.py +0 -0
  34. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol_utils/bench.py +0 -0
  35. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol_utils/bench_sql/prepare.sql +0 -0
  36. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol_utils/bench_sql/t1_group_by.sql +0 -0
  37. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol_utils/bench_sql/t2_local_join.sql +0 -0
  38. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol_utils/bench_sql/t3_global_join.sql +0 -0
  39. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol_utils/bench_sql/t4_sort.sql +0 -0
  40. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol_utils/docker_util.py +0 -0
  41. {pyexasol-2.2.3 → pyexasol-2.3.0}/pyexasol_utils/script_output.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyexasol
3
- Version: 2.2.3
3
+ Version: 2.3.0
4
4
  Summary: Exasol python driver with extra features
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE.txt
@@ -0,0 +1,323 @@
1
+ from enum import (
2
+ Enum,
3
+ auto,
4
+ )
5
+
6
+
7
+ class ScanState(Enum):
8
+ NORMAL = auto()
9
+ SINGLE_QUOTE = auto()
10
+ DOUBLE_QUOTE = auto()
11
+ LINE_COMMENT = auto()
12
+ BLOCK_COMMENT = auto()
13
+ SCRIPT_BODY = auto()
14
+
15
+
16
+ class ScriptHeaderState(Enum):
17
+ NONE = auto()
18
+ SAW_CREATE = auto()
19
+ SAW_POSSIBLE_SCRIPT_LANGUAGE = auto()
20
+ SAW_SCRIPT_LANGUAGE = auto()
21
+ SAW_SCRIPT = auto()
22
+
23
+
24
+ SCRIPT_HEADER_WORDS = {
25
+ "ADAPTER",
26
+ "JAVA",
27
+ "LUA",
28
+ "OR",
29
+ "PREPROCESSOR",
30
+ "PYTHON",
31
+ "PYTHON3",
32
+ "R",
33
+ "REPLACE",
34
+ "SCALAR",
35
+ "SET",
36
+ }
37
+
38
+
39
+ class _CommentStripper:
40
+ def __init__(self, sql: str) -> None:
41
+ self.sql = sql
42
+ self.output: list[str] = []
43
+ self.state = ScanState.NORMAL
44
+ self.position = 0
45
+
46
+ def run(self) -> str:
47
+ while self.position < len(self.sql):
48
+ self.consume_current_character()
49
+
50
+ return "".join(self.output)
51
+
52
+ def consume_current_character(self) -> None:
53
+ if self.state == ScanState.SINGLE_QUOTE:
54
+ self.consume_quote("'")
55
+ elif self.state == ScanState.DOUBLE_QUOTE:
56
+ self.consume_quote('"')
57
+ elif self.current_char == "'":
58
+ self.enter_quote(ScanState.SINGLE_QUOTE)
59
+ elif self.current_char == '"':
60
+ self.enter_quote(ScanState.DOUBLE_QUOTE)
61
+ elif self.current_char == "-" and self.next_char == "-":
62
+ self.consume_line_comment()
63
+ elif self.current_char == "/" and self.next_char == "*":
64
+ self.consume_block_comment()
65
+ else:
66
+ self.append_current_char()
67
+
68
+ @property
69
+ def current_char(self) -> str:
70
+ return self.sql[self.position]
71
+
72
+ @property
73
+ def next_char(self) -> str | None:
74
+ lookahead = self.position + 1
75
+ return self.sql[lookahead] if lookahead < len(self.sql) else None
76
+
77
+ def consume_quote(self, quote: str) -> None:
78
+ self.append_current_char()
79
+ if self.output[-1] == quote:
80
+ self.state = ScanState.NORMAL
81
+
82
+ def enter_quote(self, state: ScanState) -> None:
83
+ self.output.append(self.current_char)
84
+ self.state = state
85
+ self.position += 1
86
+
87
+ def append_current_char(self) -> None:
88
+ self.output.append(self.current_char)
89
+ self.position += 1
90
+
91
+ def consume_line_comment(self) -> None:
92
+ self.output.append(" ")
93
+ self.position += 2
94
+ while self.position < len(self.sql) and self.current_char != "\n":
95
+ self.position += 1
96
+
97
+ def consume_block_comment(self) -> None:
98
+ self.output.append(" ")
99
+ self.position += 2
100
+ while self.position < len(self.sql):
101
+ if self.current_char == "*" and self.next_char == "/":
102
+ self.position += 2
103
+ return
104
+ self.position += 1
105
+
106
+
107
+ def strip_comments(sql: str) -> str:
108
+ return _CommentStripper(sql).run()
109
+
110
+
111
+ class _SqlScriptSplitter:
112
+ def __init__(self, sql: str) -> None:
113
+ self.sql = sql
114
+ self.statements: list[str] = []
115
+ self.current: list[str] = []
116
+ self.word: list[str] = []
117
+ self.state = ScanState.NORMAL
118
+ self.script_header = ScriptHeaderState.NONE
119
+ self.line_start = True
120
+ self.position = 0
121
+
122
+ def run(self) -> list[str]:
123
+ while self.position < len(self.sql):
124
+ self.consume_current_character()
125
+
126
+ self.finish_word()
127
+ self.flush_statement()
128
+ return self.statements
129
+
130
+ def consume_current_character(self) -> None:
131
+ if self.state == ScanState.NORMAL:
132
+ self.consume_normal()
133
+ elif self.state == ScanState.SCRIPT_BODY:
134
+ self.consume_script_body()
135
+ elif self.state == ScanState.SINGLE_QUOTE:
136
+ self.consume_quote("'")
137
+ elif self.state == ScanState.DOUBLE_QUOTE:
138
+ self.consume_quote('"')
139
+ elif self.state == ScanState.LINE_COMMENT:
140
+ self.consume_line_comment()
141
+ else:
142
+ self.consume_block_comment()
143
+
144
+ @property
145
+ def current_char(self) -> str:
146
+ return self.sql[self.position]
147
+
148
+ @property
149
+ def next_char(self) -> str | None:
150
+ lookahead = self.position + 1
151
+ return self.sql[lookahead] if lookahead < len(self.sql) else None
152
+
153
+ def consume_normal(self) -> None:
154
+ if self.current_char.isalnum() or self.current_char == "_":
155
+ self.word.append(self.current_char)
156
+ self.append_current_char()
157
+ elif self.finish_word():
158
+ self.enter_script_body()
159
+ elif self.current_char == "'":
160
+ self.enter_state(ScanState.SINGLE_QUOTE)
161
+ elif self.current_char == '"':
162
+ self.enter_state(ScanState.DOUBLE_QUOTE)
163
+ elif self.current_char == "-" and self.next_char == "-":
164
+ self.enter_two_character_state(ScanState.LINE_COMMENT)
165
+ elif self.current_char == "/" and self.next_char == "*":
166
+ self.enter_two_character_state(ScanState.BLOCK_COMMENT)
167
+ elif self.current_char == ";":
168
+ self.script_header = ScriptHeaderState.NONE
169
+ self.flush_statement()
170
+ self.position += 1
171
+ else:
172
+ self.append_current_char()
173
+
174
+ def consume_script_body(self) -> None:
175
+ if self.slash_terminates_script_body():
176
+ self.finish_script_body()
177
+ return
178
+
179
+ self.current.append(self.current_char)
180
+ if self.current_char == "\n":
181
+ self.line_start = True
182
+ elif self.current_char not in " \t":
183
+ self.line_start = False
184
+ self.position += 1
185
+
186
+ def consume_quote(self, quote: str) -> None:
187
+ self.append_current_char()
188
+ if self.current[-1] == quote:
189
+ self.state = ScanState.NORMAL
190
+
191
+ def consume_line_comment(self) -> None:
192
+ self.append_current_char()
193
+ if self.current[-1] == "\n":
194
+ self.state = ScanState.NORMAL
195
+
196
+ def consume_block_comment(self) -> None:
197
+ next_char = self.next_char
198
+ self.current.append(self.current_char)
199
+ if self.current_char == "*" and next_char == "/":
200
+ self.current.append(next_char)
201
+ self.state = ScanState.NORMAL
202
+ self.position += 2
203
+ else:
204
+ self.position += 1
205
+
206
+ def enter_state(self, state: ScanState) -> None:
207
+ self.current.append(self.current_char)
208
+ self.state = state
209
+ self.position += 1
210
+
211
+ def enter_two_character_state(self, state: ScanState) -> None:
212
+ next_char = self.next_char
213
+ if next_char is None:
214
+ msg = "Expected two-character token while splitting SQL script."
215
+ raise ValueError(msg)
216
+ self.current.append(self.current_char)
217
+ self.current.append(next_char)
218
+ self.state = state
219
+ self.position += 2
220
+
221
+ def enter_script_body(self) -> None:
222
+ self.script_header = ScriptHeaderState.NONE
223
+ self.state = ScanState.SCRIPT_BODY
224
+ self.current.append(self.current_char)
225
+ self.line_start = self.current_char in " \t\n"
226
+ self.position += 1
227
+
228
+ def finish_script_body(self) -> None:
229
+ if self.current and self.current[-1] == "\n":
230
+ self.current.pop()
231
+ self.flush_statement()
232
+ self.script_header = ScriptHeaderState.NONE
233
+ self.state = ScanState.NORMAL
234
+ self.position += 1
235
+ self.skip_script_terminator_trailing_whitespace()
236
+
237
+ def skip_script_terminator_trailing_whitespace(self) -> None:
238
+ while self.position < len(self.sql) and self.current_char in " \t":
239
+ self.position += 1
240
+ if self.position < len(self.sql) and self.current_char == "\r":
241
+ self.position += 1
242
+
243
+ def append_current_char(self) -> None:
244
+ self.current.append(self.current_char)
245
+ self.position += 1
246
+
247
+ def flush_statement(self) -> None:
248
+ statement = "".join(self.current).strip()
249
+ if statement and strip_comments(statement).strip():
250
+ self.statements.append(statement)
251
+ self.current.clear()
252
+
253
+ def finish_word(self) -> bool:
254
+ if not self.word:
255
+ return False
256
+
257
+ upper_word = "".join(self.word).upper()
258
+ self.word.clear()
259
+ return self.update_script_header(upper_word)
260
+
261
+ def update_script_header(self, upper_word: str) -> bool:
262
+ if self.script_header == ScriptHeaderState.NONE:
263
+ self.update_empty_script_header(upper_word)
264
+ elif self.script_header == ScriptHeaderState.SAW_CREATE:
265
+ self.update_create_script_header(upper_word)
266
+ elif self.script_header == ScriptHeaderState.SAW_POSSIBLE_SCRIPT_LANGUAGE:
267
+ self.update_possible_language_script_header(upper_word)
268
+ elif self.script_header == ScriptHeaderState.SAW_SCRIPT_LANGUAGE:
269
+ self.update_language_script_header(upper_word)
270
+ elif upper_word == "AS":
271
+ return True
272
+
273
+ return False
274
+
275
+ def update_empty_script_header(self, upper_word: str) -> None:
276
+ if upper_word == "CREATE":
277
+ self.script_header = ScriptHeaderState.SAW_CREATE
278
+
279
+ def update_create_script_header(self, upper_word: str) -> None:
280
+ if upper_word == "SCRIPT":
281
+ self.script_header = ScriptHeaderState.SAW_SCRIPT
282
+ elif upper_word not in SCRIPT_HEADER_WORDS:
283
+ self.script_header = ScriptHeaderState.SAW_POSSIBLE_SCRIPT_LANGUAGE
284
+
285
+ def update_possible_language_script_header(self, upper_word: str) -> None:
286
+ if upper_word in SCRIPT_HEADER_WORDS:
287
+ self.script_header = ScriptHeaderState.SAW_SCRIPT_LANGUAGE
288
+ else:
289
+ self.script_header = ScriptHeaderState.NONE
290
+
291
+ def update_language_script_header(self, upper_word: str) -> None:
292
+ if upper_word == "SCRIPT":
293
+ self.script_header = ScriptHeaderState.SAW_SCRIPT
294
+ elif upper_word not in SCRIPT_HEADER_WORDS:
295
+ self.script_header = ScriptHeaderState.NONE
296
+
297
+ def slash_terminates_script_body(self) -> bool:
298
+ if not self.line_start or self.current_char != "/":
299
+ return False
300
+
301
+ lookahead = self.position + 1
302
+ while lookahead < len(self.sql) and self.sql[lookahead] in " \t":
303
+ lookahead += 1
304
+
305
+ if lookahead == len(self.sql) or self.sql[lookahead] == "\n":
306
+ return True
307
+
308
+ return self.sql[lookahead] == "\r" and (
309
+ lookahead + 1 == len(self.sql) or self.sql[lookahead + 1] == "\n"
310
+ )
311
+
312
+
313
+ def split_sql_script(sql: str) -> list[str]:
314
+ """
315
+ Split an Exasol SQL script into executable statements.
316
+
317
+ The splitter is lexical, not a full SQL parser. It treats semicolons as
318
+ statement terminators except inside string literals, quoted identifiers,
319
+ line comments, block comments, and Exasol script bodies. Exasol script
320
+ bodies are entered after ``CREATE ... SCRIPT ... AS`` and are terminated by
321
+ a standalone ``/`` line.
322
+ """
323
+ return _SqlScriptSplitter(sql).run()
@@ -36,6 +36,7 @@ from packaging.version import Version
36
36
  from . import callback as cb
37
37
  from . import constant
38
38
  from ._metadata import __version__
39
+ from ._sql_splitter import split_sql_script
39
40
  from .exceptions import (
40
41
  ExaAuthError,
41
42
  ExaCommunicationError,
@@ -332,6 +333,25 @@ class ExaConnection:
332
333
  """
333
334
  return self.cls_statement(self, query, query_params)
334
335
 
336
+ def execute_sql_script(self, script: str) -> list[ExaStatement]:
337
+ """
338
+ Execute a SQL script containing one or more statements.
339
+
340
+ The script is split into statements before execution. Semicolons inside
341
+ string literals, quoted SQL identifiers, line comments, block comments,
342
+ and Exasol script bodies do not terminate statements. Exasol script
343
+ bodies are terminated by a standalone ``/`` line.
344
+
345
+ Statements are executed sequentially using :meth:`execute`. The method
346
+ returns a list with one :class:`pyexasol.ExaStatement` for each executed
347
+ statement, in execution order. If one statement fails, the original
348
+ exception is raised and following statements are not executed.
349
+
350
+ Query parameters are intentionally not supported for SQL scripts.
351
+ Use :meth:`execute` for parameterized single statements.
352
+ """
353
+ return [self.execute(statement) for statement in split_sql_script(script)]
354
+
335
355
  def execute_udf_output(self, query: str, query_params: dict | None = None):
336
356
  """
337
357
  Execute SQL query with UDF script, capture output
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pyexasol"
3
- version = "2.2.3"
3
+ version = "2.3.0"
4
4
  description = "Exasol python driver with extra features"
5
5
  authors = [
6
6
  { name = "Vitaly Markov", email = "wild.desu@gmail.com" },
@@ -80,9 +80,9 @@ dev = [
80
80
  "nox>=2023.4.22,<2024",
81
81
  "pytest>=7.0.0,<10",
82
82
  "docutils>=0.21.2,<0.22",
83
- "exasol-integration-test-docker-environment>=5.0.0,<7",
83
+ "exasol-integration-test-docker-environment>=6.4.1,<7",
84
84
  "faker>=24.14.1,<25",
85
- "exasol-toolbox>=10.0.0,<11",
85
+ "exasol-toolbox>=10.3.0,<11",
86
86
  "types-ujson>=5.10.0.20250326,<6",
87
87
  "pytest-repeat>=0.9.4, <1.0.0",
88
88
  "pandas-stubs>=2.3.3.251219,<3",
@@ -178,4 +178,6 @@ markers = [
178
178
  "tls: tests related to tls.",
179
179
  "transaction: tests related to transaction management.",
180
180
  "udf: tests related to user defined functions.",
181
+ "with_cert: tests related to certificate verification.",
182
+ "no_cert: tests related to certificate verification disabled.",
181
183
  ]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes