crate 0.35.1__py2.py3-none-any.whl → 1.0.0.dev0__py2.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.
Files changed (42) hide show
  1. crate/client/__init__.py +1 -1
  2. crate/testing/test_datetime_old.py +90 -0
  3. crate-1.0.0.dev0-py3.11-nspkg.pth +1 -0
  4. {crate-0.35.1.dist-info → crate-1.0.0.dev0.dist-info}/METADATA +15 -19
  5. crate-1.0.0.dev0.dist-info/RECORD +26 -0
  6. {crate-0.35.1.dist-info → crate-1.0.0.dev0.dist-info}/WHEEL +1 -1
  7. crate/client/sqlalchemy/__init__.py +0 -50
  8. crate/client/sqlalchemy/compat/__init__.py +0 -0
  9. crate/client/sqlalchemy/compat/api13.py +0 -156
  10. crate/client/sqlalchemy/compat/core10.py +0 -264
  11. crate/client/sqlalchemy/compat/core14.py +0 -359
  12. crate/client/sqlalchemy/compat/core20.py +0 -447
  13. crate/client/sqlalchemy/compiler.py +0 -318
  14. crate/client/sqlalchemy/dialect.py +0 -369
  15. crate/client/sqlalchemy/predicates/__init__.py +0 -99
  16. crate/client/sqlalchemy/sa_version.py +0 -28
  17. crate/client/sqlalchemy/support.py +0 -62
  18. crate/client/sqlalchemy/tests/__init__.py +0 -59
  19. crate/client/sqlalchemy/tests/array_test.py +0 -111
  20. crate/client/sqlalchemy/tests/bulk_test.py +0 -256
  21. crate/client/sqlalchemy/tests/compiler_test.py +0 -434
  22. crate/client/sqlalchemy/tests/connection_test.py +0 -129
  23. crate/client/sqlalchemy/tests/create_table_test.py +0 -313
  24. crate/client/sqlalchemy/tests/datetime_test.py +0 -90
  25. crate/client/sqlalchemy/tests/dialect_test.py +0 -156
  26. crate/client/sqlalchemy/tests/dict_test.py +0 -460
  27. crate/client/sqlalchemy/tests/function_test.py +0 -47
  28. crate/client/sqlalchemy/tests/insert_from_select_test.py +0 -85
  29. crate/client/sqlalchemy/tests/match_test.py +0 -137
  30. crate/client/sqlalchemy/tests/query_caching.py +0 -143
  31. crate/client/sqlalchemy/tests/update_test.py +0 -115
  32. crate/client/sqlalchemy/tests/warnings_test.py +0 -64
  33. crate/client/sqlalchemy/types.py +0 -277
  34. crate/client/tests.py +0 -416
  35. crate/testing/tests.py +0 -34
  36. crate-0.35.1-py3.11-nspkg.pth +0 -1
  37. crate-0.35.1.dist-info/RECORD +0 -55
  38. crate-0.35.1.dist-info/entry_points.txt +0 -2
  39. {crate-0.35.1.dist-info → crate-1.0.0.dev0.dist-info}/LICENSE +0 -0
  40. {crate-0.35.1.dist-info → crate-1.0.0.dev0.dist-info}/NOTICE +0 -0
  41. {crate-0.35.1.dist-info → crate-1.0.0.dev0.dist-info}/namespace_packages.txt +0 -0
  42. {crate-0.35.1.dist-info → crate-1.0.0.dev0.dist-info}/top_level.txt +0 -0
@@ -1,264 +0,0 @@
1
- # -*- coding: utf-8; -*-
2
- #
3
- # Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
4
- # license agreements. See the NOTICE file distributed with this work for
5
- # additional information regarding copyright ownership. Crate licenses
6
- # this file to you under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License. You may
8
- # obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
- # License for the specific language governing permissions and limitations
16
- # under the License.
17
- #
18
- # However, if you have executed another commercial license agreement
19
- # with Crate these terms will supersede the license and you may use the
20
- # software solely pursuant to the terms of the relevant commercial agreement.
21
-
22
- import sqlalchemy as sa
23
- from sqlalchemy.dialects.postgresql.base import PGCompiler
24
- from sqlalchemy.sql.crud import (REQUIRED, _create_bind_param,
25
- _extend_values_for_multiparams,
26
- _get_multitable_params,
27
- _get_stmt_parameters_params,
28
- _key_getters_for_crud_column, _scan_cols,
29
- _scan_insert_from_select_cols)
30
-
31
- from crate.client.sqlalchemy.compiler import CrateCompiler
32
-
33
-
34
- class CrateCompilerSA10(CrateCompiler):
35
-
36
- def returning_clause(self, stmt, returning_cols):
37
- """
38
- Generate RETURNING clause, PostgreSQL-compatible.
39
- """
40
- return PGCompiler.returning_clause(self, stmt, returning_cols)
41
-
42
- def visit_update(self, update_stmt, **kw):
43
- """
44
- used to compile <sql.expression.Update> expressions
45
- Parts are taken from the SQLCompiler base class.
46
- """
47
-
48
- # [10] CrateDB patch.
49
- if not update_stmt.parameters and \
50
- not hasattr(update_stmt, '_crate_specific'):
51
- return super().visit_update(update_stmt, **kw)
52
-
53
- self.isupdate = True
54
-
55
- extra_froms = update_stmt._extra_froms
56
-
57
- text = 'UPDATE '
58
-
59
- if update_stmt._prefixes:
60
- text += self._generate_prefixes(update_stmt,
61
- update_stmt._prefixes, **kw)
62
-
63
- table_text = self.update_tables_clause(update_stmt, update_stmt.table,
64
- extra_froms, **kw)
65
-
66
- dialect_hints = None
67
- if update_stmt._hints:
68
- dialect_hints, table_text = self._setup_crud_hints(
69
- update_stmt, table_text
70
- )
71
-
72
- # [10] CrateDB patch.
73
- crud_params = _get_crud_params(self, update_stmt, **kw)
74
-
75
- text += table_text
76
-
77
- text += ' SET '
78
-
79
- # [10] CrateDB patch begin.
80
- include_table = \
81
- extra_froms and self.render_table_with_column_in_update_from
82
-
83
- set_clauses = []
84
-
85
- for k, v in crud_params:
86
- clause = k._compiler_dispatch(self,
87
- include_table=include_table) + \
88
- ' = ' + v
89
- set_clauses.append(clause)
90
-
91
- for k, v in update_stmt.parameters.items():
92
- if isinstance(k, str) and '[' in k:
93
- bindparam = sa.sql.bindparam(k, v)
94
- set_clauses.append(k + ' = ' + self.process(bindparam))
95
-
96
- text += ', '.join(set_clauses)
97
- # [10] CrateDB patch end.
98
-
99
- if self.returning or update_stmt._returning:
100
- if not self.returning:
101
- self.returning = update_stmt._returning
102
- if self.returning_precedes_values:
103
- text += " " + self.returning_clause(
104
- update_stmt, self.returning)
105
-
106
- if extra_froms:
107
- extra_from_text = self.update_from_clause(
108
- update_stmt,
109
- update_stmt.table,
110
- extra_froms,
111
- dialect_hints,
112
- **kw)
113
- if extra_from_text:
114
- text += " " + extra_from_text
115
-
116
- if update_stmt._whereclause is not None:
117
- t = self.process(update_stmt._whereclause)
118
- if t:
119
- text += " WHERE " + t
120
-
121
- limit_clause = self.update_limit_clause(update_stmt)
122
- if limit_clause:
123
- text += " " + limit_clause
124
-
125
- if self.returning and not self.returning_precedes_values:
126
- text += " " + self.returning_clause(
127
- update_stmt, self.returning)
128
-
129
- return text
130
-
131
-
132
- def _get_crud_params(compiler, stmt, **kw):
133
- """create a set of tuples representing column/string pairs for use
134
- in an INSERT or UPDATE statement.
135
-
136
- Also generates the Compiled object's postfetch, prefetch, and
137
- returning column collections, used for default handling and ultimately
138
- populating the ResultProxy's prefetch_cols() and postfetch_cols()
139
- collections.
140
-
141
- """
142
-
143
- compiler.postfetch = []
144
- compiler.insert_prefetch = []
145
- compiler.update_prefetch = []
146
- compiler.returning = []
147
-
148
- # no parameters in the statement, no parameters in the
149
- # compiled params - return binds for all columns
150
- if compiler.column_keys is None and stmt.parameters is None:
151
- return [
152
- (c, _create_bind_param(compiler, c, None, required=True))
153
- for c in stmt.table.columns
154
- ]
155
-
156
- if stmt._has_multi_parameters:
157
- stmt_parameters = stmt.parameters[0]
158
- else:
159
- stmt_parameters = stmt.parameters
160
-
161
- # getters - these are normally just column.key,
162
- # but in the case of mysql multi-table update, the rules for
163
- # .key must conditionally take tablename into account
164
- (
165
- _column_as_key,
166
- _getattr_col_key,
167
- _col_bind_name,
168
- ) = _key_getters_for_crud_column(compiler, stmt)
169
-
170
- # if we have statement parameters - set defaults in the
171
- # compiled params
172
- if compiler.column_keys is None:
173
- parameters = {}
174
- else:
175
- parameters = dict(
176
- (_column_as_key(key), REQUIRED)
177
- for key in compiler.column_keys
178
- if not stmt_parameters or key not in stmt_parameters
179
- )
180
-
181
- # create a list of column assignment clauses as tuples
182
- values = []
183
-
184
- if stmt_parameters is not None:
185
- _get_stmt_parameters_params(
186
- compiler, parameters, stmt_parameters, _column_as_key, values, kw
187
- )
188
-
189
- check_columns = {}
190
-
191
- # special logic that only occurs for multi-table UPDATE
192
- # statements
193
- if compiler.isupdate and stmt._extra_froms and stmt_parameters:
194
- _get_multitable_params(
195
- compiler,
196
- stmt,
197
- stmt_parameters,
198
- check_columns,
199
- _col_bind_name,
200
- _getattr_col_key,
201
- values,
202
- kw,
203
- )
204
-
205
- if compiler.isinsert and stmt.select_names:
206
- _scan_insert_from_select_cols(
207
- compiler,
208
- stmt,
209
- parameters,
210
- _getattr_col_key,
211
- _column_as_key,
212
- _col_bind_name,
213
- check_columns,
214
- values,
215
- kw,
216
- )
217
- else:
218
- _scan_cols(
219
- compiler,
220
- stmt,
221
- parameters,
222
- _getattr_col_key,
223
- _column_as_key,
224
- _col_bind_name,
225
- check_columns,
226
- values,
227
- kw,
228
- )
229
-
230
- # [10] CrateDB patch.
231
- #
232
- # This sanity check performed by SQLAlchemy currently needs to be
233
- # deactivated in order to satisfy the rewriting logic of the CrateDB
234
- # dialect in `rewrite_update` and `visit_update`.
235
- #
236
- # It can be quickly reproduced by activating this section and running the
237
- # test cases::
238
- #
239
- # ./bin/test -vvvv -t dict_test
240
- #
241
- # That croaks like::
242
- #
243
- # sqlalchemy.exc.CompileError: Unconsumed column names: characters_name, data['nested']
244
- #
245
- # TODO: Investigate why this is actually happening and eventually mitigate
246
- # the root cause.
247
- """
248
- if parameters and stmt_parameters:
249
- check = (
250
- set(parameters)
251
- .intersection(_column_as_key(k) for k in stmt_parameters)
252
- .difference(check_columns)
253
- )
254
- if check:
255
- raise exc.CompileError(
256
- "Unconsumed column names: %s"
257
- % (", ".join("%s" % c for c in check))
258
- )
259
- """
260
-
261
- if stmt._has_multi_parameters:
262
- values = _extend_values_for_multiparams(compiler, stmt, values, kw)
263
-
264
- return values
@@ -1,359 +0,0 @@
1
- # -*- coding: utf-8; -*-
2
- #
3
- # Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
4
- # license agreements. See the NOTICE file distributed with this work for
5
- # additional information regarding copyright ownership. Crate licenses
6
- # this file to you under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License. You may
8
- # obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
- # License for the specific language governing permissions and limitations
16
- # under the License.
17
- #
18
- # However, if you have executed another commercial license agreement
19
- # with Crate these terms will supersede the license and you may use the
20
- # software solely pursuant to the terms of the relevant commercial agreement.
21
-
22
- import sqlalchemy as sa
23
- from sqlalchemy.dialects.postgresql.base import PGCompiler
24
- from sqlalchemy.sql import selectable
25
- from sqlalchemy.sql.crud import (REQUIRED, _create_bind_param,
26
- _extend_values_for_multiparams,
27
- _get_stmt_parameter_tuples_params,
28
- _get_update_multitable_params,
29
- _key_getters_for_crud_column, _scan_cols,
30
- _scan_insert_from_select_cols)
31
-
32
- from crate.client.sqlalchemy.compiler import CrateCompiler
33
-
34
-
35
- class CrateCompilerSA14(CrateCompiler):
36
-
37
- def returning_clause(self, stmt, returning_cols):
38
- """
39
- Generate RETURNING clause, PostgreSQL-compatible.
40
- """
41
- return PGCompiler.returning_clause(self, stmt, returning_cols)
42
-
43
- def visit_update(self, update_stmt, **kw):
44
-
45
- compile_state = update_stmt._compile_state_factory(
46
- update_stmt, self, **kw
47
- )
48
- update_stmt = compile_state.statement
49
-
50
- # [14] CrateDB patch.
51
- if not compile_state._dict_parameters and \
52
- not hasattr(update_stmt, '_crate_specific'):
53
- return super().visit_update(update_stmt, **kw)
54
-
55
- toplevel = not self.stack
56
- if toplevel:
57
- self.isupdate = True
58
- if not self.compile_state:
59
- self.compile_state = compile_state
60
-
61
- extra_froms = compile_state._extra_froms
62
- is_multitable = bool(extra_froms)
63
-
64
- if is_multitable:
65
- # main table might be a JOIN
66
- main_froms = set(selectable._from_objects(update_stmt.table))
67
- render_extra_froms = [
68
- f for f in extra_froms if f not in main_froms
69
- ]
70
- correlate_froms = main_froms.union(extra_froms)
71
- else:
72
- render_extra_froms = []
73
- correlate_froms = {update_stmt.table}
74
-
75
- self.stack.append(
76
- {
77
- "correlate_froms": correlate_froms,
78
- "asfrom_froms": correlate_froms,
79
- "selectable": update_stmt,
80
- }
81
- )
82
-
83
- text = "UPDATE "
84
-
85
- if update_stmt._prefixes:
86
- text += self._generate_prefixes(
87
- update_stmt, update_stmt._prefixes, **kw
88
- )
89
-
90
- table_text = self.update_tables_clause(
91
- update_stmt, update_stmt.table, render_extra_froms, **kw
92
- )
93
-
94
- # [14] CrateDB patch.
95
- crud_params = _get_crud_params(
96
- self, update_stmt, compile_state, **kw
97
- )
98
-
99
- if update_stmt._hints:
100
- dialect_hints, table_text = self._setup_crud_hints(
101
- update_stmt, table_text
102
- )
103
- else:
104
- dialect_hints = None
105
-
106
- if update_stmt._independent_ctes:
107
- for cte in update_stmt._independent_ctes:
108
- cte._compiler_dispatch(self, **kw)
109
-
110
- text += table_text
111
-
112
- text += " SET "
113
-
114
- # [14] CrateDB patch begin.
115
- include_table = \
116
- extra_froms and self.render_table_with_column_in_update_from
117
-
118
- set_clauses = []
119
-
120
- for c, expr, value in crud_params:
121
- key = c._compiler_dispatch(self, include_table=include_table)
122
- clause = key + ' = ' + value
123
- set_clauses.append(clause)
124
-
125
- for k, v in compile_state._dict_parameters.items():
126
- if isinstance(k, str) and '[' in k:
127
- bindparam = sa.sql.bindparam(k, v)
128
- clause = k + ' = ' + self.process(bindparam)
129
- set_clauses.append(clause)
130
-
131
- text += ', '.join(set_clauses)
132
- # [14] CrateDB patch end.
133
-
134
- if self.returning or update_stmt._returning:
135
- if self.returning_precedes_values:
136
- text += " " + self.returning_clause(
137
- update_stmt, self.returning or update_stmt._returning
138
- )
139
-
140
- if extra_froms:
141
- extra_from_text = self.update_from_clause(
142
- update_stmt,
143
- update_stmt.table,
144
- render_extra_froms,
145
- dialect_hints,
146
- **kw
147
- )
148
- if extra_from_text:
149
- text += " " + extra_from_text
150
-
151
- if update_stmt._where_criteria:
152
- t = self._generate_delimited_and_list(
153
- update_stmt._where_criteria, **kw
154
- )
155
- if t:
156
- text += " WHERE " + t
157
-
158
- limit_clause = self.update_limit_clause(update_stmt)
159
- if limit_clause:
160
- text += " " + limit_clause
161
-
162
- if (
163
- self.returning or update_stmt._returning
164
- ) and not self.returning_precedes_values:
165
- text += " " + self.returning_clause(
166
- update_stmt, self.returning or update_stmt._returning
167
- )
168
-
169
- if self.ctes:
170
- nesting_level = len(self.stack) if not toplevel else None
171
- text = self._render_cte_clause(nesting_level=nesting_level) + text
172
-
173
- self.stack.pop(-1)
174
-
175
- return text
176
-
177
-
178
- def _get_crud_params(compiler, stmt, compile_state, **kw):
179
- """create a set of tuples representing column/string pairs for use
180
- in an INSERT or UPDATE statement.
181
-
182
- Also generates the Compiled object's postfetch, prefetch, and
183
- returning column collections, used for default handling and ultimately
184
- populating the CursorResult's prefetch_cols() and postfetch_cols()
185
- collections.
186
-
187
- """
188
-
189
- compiler.postfetch = []
190
- compiler.insert_prefetch = []
191
- compiler.update_prefetch = []
192
- compiler.returning = []
193
-
194
- # getters - these are normally just column.key,
195
- # but in the case of mysql multi-table update, the rules for
196
- # .key must conditionally take tablename into account
197
- (
198
- _column_as_key,
199
- _getattr_col_key,
200
- _col_bind_name,
201
- ) = getters = _key_getters_for_crud_column(compiler, stmt, compile_state)
202
-
203
- compiler._key_getters_for_crud_column = getters
204
-
205
- # no parameters in the statement, no parameters in the
206
- # compiled params - return binds for all columns
207
- if compiler.column_keys is None and compile_state._no_parameters:
208
- return [
209
- (
210
- c,
211
- compiler.preparer.format_column(c),
212
- _create_bind_param(compiler, c, None, required=True),
213
- )
214
- for c in stmt.table.columns
215
- ]
216
-
217
- if compile_state._has_multi_parameters:
218
- spd = compile_state._multi_parameters[0]
219
- stmt_parameter_tuples = list(spd.items())
220
- elif compile_state._ordered_values:
221
- spd = compile_state._dict_parameters
222
- stmt_parameter_tuples = compile_state._ordered_values
223
- elif compile_state._dict_parameters:
224
- spd = compile_state._dict_parameters
225
- stmt_parameter_tuples = list(spd.items())
226
- else:
227
- stmt_parameter_tuples = spd = None
228
-
229
- # if we have statement parameters - set defaults in the
230
- # compiled params
231
- if compiler.column_keys is None:
232
- parameters = {}
233
- elif stmt_parameter_tuples:
234
- parameters = dict(
235
- (_column_as_key(key), REQUIRED)
236
- for key in compiler.column_keys
237
- if key not in spd
238
- )
239
- else:
240
- parameters = dict(
241
- (_column_as_key(key), REQUIRED) for key in compiler.column_keys
242
- )
243
-
244
- # create a list of column assignment clauses as tuples
245
- values = []
246
-
247
- if stmt_parameter_tuples is not None:
248
- _get_stmt_parameter_tuples_params(
249
- compiler,
250
- compile_state,
251
- parameters,
252
- stmt_parameter_tuples,
253
- _column_as_key,
254
- values,
255
- kw,
256
- )
257
-
258
- check_columns = {}
259
-
260
- # special logic that only occurs for multi-table UPDATE
261
- # statements
262
- if compile_state.isupdate and compile_state.is_multitable:
263
- _get_update_multitable_params(
264
- compiler,
265
- stmt,
266
- compile_state,
267
- stmt_parameter_tuples,
268
- check_columns,
269
- _col_bind_name,
270
- _getattr_col_key,
271
- values,
272
- kw,
273
- )
274
-
275
- if compile_state.isinsert and stmt._select_names:
276
- _scan_insert_from_select_cols(
277
- compiler,
278
- stmt,
279
- compile_state,
280
- parameters,
281
- _getattr_col_key,
282
- _column_as_key,
283
- _col_bind_name,
284
- check_columns,
285
- values,
286
- kw,
287
- )
288
- else:
289
- _scan_cols(
290
- compiler,
291
- stmt,
292
- compile_state,
293
- parameters,
294
- _getattr_col_key,
295
- _column_as_key,
296
- _col_bind_name,
297
- check_columns,
298
- values,
299
- kw,
300
- )
301
-
302
- # [14] CrateDB patch.
303
- #
304
- # This sanity check performed by SQLAlchemy currently needs to be
305
- # deactivated in order to satisfy the rewriting logic of the CrateDB
306
- # dialect in `rewrite_update` and `visit_update`.
307
- #
308
- # It can be quickly reproduced by activating this section and running the
309
- # test cases::
310
- #
311
- # ./bin/test -vvvv -t dict_test
312
- #
313
- # That croaks like::
314
- #
315
- # sqlalchemy.exc.CompileError: Unconsumed column names: characters_name, data['nested']
316
- #
317
- # TODO: Investigate why this is actually happening and eventually mitigate
318
- # the root cause.
319
- """
320
- if parameters and stmt_parameter_tuples:
321
- check = (
322
- set(parameters)
323
- .intersection(_column_as_key(k) for k, v in stmt_parameter_tuples)
324
- .difference(check_columns)
325
- )
326
- if check:
327
- raise exc.CompileError(
328
- "Unconsumed column names: %s"
329
- % (", ".join("%s" % (c,) for c in check))
330
- )
331
- """
332
-
333
- if compile_state._has_multi_parameters:
334
- values = _extend_values_for_multiparams(
335
- compiler,
336
- stmt,
337
- compile_state,
338
- values,
339
- _column_as_key,
340
- kw,
341
- )
342
- elif (
343
- not values
344
- and compiler.for_executemany # noqa: W503
345
- and compiler.dialect.supports_default_metavalue # noqa: W503
346
- ):
347
- # convert an "INSERT DEFAULT VALUES"
348
- # into INSERT (firstcol) VALUES (DEFAULT) which can be turned
349
- # into an in-place multi values. This supports
350
- # insert_executemany_returning mode :)
351
- values = [
352
- (
353
- stmt.table.columns[0],
354
- compiler.preparer.format_column(stmt.table.columns[0]),
355
- "DEFAULT",
356
- )
357
- ]
358
-
359
- return values