sqlalchemy-cratedb 0.43.1__tar.gz → 0.45.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.
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/CHANGES.md +66 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/CLAUDE.md +12 -10
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/DEVELOP.md +7 -3
- {sqlalchemy_cratedb-0.43.1/src/sqlalchemy_cratedb.egg-info → sqlalchemy_cratedb-0.45.0}/PKG-INFO +7 -9
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/pyproject.toml +6 -9
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/__init__.py +12 -15
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/compiler.py +171 -25
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/dialect.py +144 -37
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/type/__init__.py +4 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/type/geo.py +12 -2
- sqlalchemy_cratedb-0.45.0/src/sqlalchemy_cratedb/type/ip.py +22 -0
- sqlalchemy_cratedb-0.45.0/src/sqlalchemy_cratedb/type/unresolved.py +10 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/type/vector.py +1 -5
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0/src/sqlalchemy_cratedb.egg-info}/PKG-INFO +7 -9
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb.egg-info/SOURCES.txt +5 -3
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb.egg-info/requires.txt +6 -12
- sqlalchemy_cratedb-0.45.0/tests/test_documentation.py +200 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/tests/test_error_handling.py +6 -2
- sqlalchemy_cratedb-0.45.0/tests/test_schema.py +47 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/tests/test_support_pandas.py +13 -29
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/tests/test_support_polyfill.py +4 -20
- sqlalchemy_cratedb-0.45.0/tests/test_type_compilation.py +116 -0
- sqlalchemy_cratedb-0.43.1/src/sqlalchemy_cratedb/compat/api13.py +0 -152
- sqlalchemy_cratedb-0.43.1/src/sqlalchemy_cratedb/compat/core10.py +0 -253
- sqlalchemy_cratedb-0.43.1/tests/test_schema.py +0 -26
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/CODE_OF_CONDUCT.md +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/CONTRIBUTING.md +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/LICENSE +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/MANIFEST.in +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/NOTICE +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/README.md +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/backlog.md +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/docs/_extra/robots.txt +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/docs/requirements.txt +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/setup.cfg +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/setup.py +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/compat/__init__.py +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/compat/core14.py +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/compat/core20.py +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/predicate.py +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/sa_version.py +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/support/__init__.py +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/support/pandas.py +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/support/polyfill.py +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/support/util.py +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/type/array.py +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/type/object.py +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/util.py +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb.egg-info/dependency_links.txt +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb.egg-info/entry_points.txt +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb.egg-info/top_level.txt +0 -0
- {sqlalchemy_cratedb-0.43.1 → sqlalchemy_cratedb-0.45.0}/tests/test_support_util.py +0 -0
|
@@ -1,5 +1,71 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2026/11/24 0.45.0
|
|
4
|
+
- BREAKING: Dropped support for SQLAlchemy 1.3, which is EOL since 2021.
|
|
5
|
+
The minimum supported version is SQLAlchemy 1.4
|
|
6
|
+
- Deprecated support for SQLAlchemy 1.4, which is EOL. Importing the dialect
|
|
7
|
+
with SQLAlchemy 1.4 emits a `FutureWarning`. A future release will
|
|
8
|
+
require SQLAlchemy 2.0
|
|
9
|
+
- Dialect: Fixed `get_view_names()` listing the views of every schema
|
|
10
|
+
- Dialect: Fixed an `UPDATE` with several parameter sets failing with "A value
|
|
11
|
+
is required for bind parameter". This includes an ORM flush that changes two
|
|
12
|
+
or more rows.
|
|
13
|
+
- Dialect: Report the driver's `ConnectionError` and a closed connection as
|
|
14
|
+
disconnects. `pool_pre_ping` now replaces such connections, a closed
|
|
15
|
+
connection no longer stays in the pool, and `connection_invalidated` is set
|
|
16
|
+
on the raised error. A statement that runs longer than the client's `timeout`
|
|
17
|
+
is not reported as a disconnect, because the server may still execute it.
|
|
18
|
+
- Types: Fixed reading a NULL `GEO_POINT` or `GEO_SHAPE` value raising
|
|
19
|
+
`TypeError: 'NoneType' object is not iterable`. NULL values now read as
|
|
20
|
+
`None`
|
|
21
|
+
|
|
22
|
+
## 2026/10/19 0.44.0
|
|
23
|
+
- Types: Fixed `sa.Time` raising `Cannot find data type: time`. `Time` columns
|
|
24
|
+
are created as `STRING` and hold values in ISO 8601 format.
|
|
25
|
+
- Types: Fixed `DateTime` results failing when the driver's `time_zone`
|
|
26
|
+
connect argument is set. Timezone-aware `datetime` values converted by the
|
|
27
|
+
driver now pass through unchanged
|
|
28
|
+
- Dependencies: Replaced `cratedb-toolkit[testing]` with
|
|
29
|
+
`testcontainers>=4.15,<5` in the `test` extra
|
|
30
|
+
- Types: Fixed `UUID` columns rejecting every insert, since values were bound
|
|
31
|
+
as 32 hex digits while CrateDB's `UUID` type takes the dashed form. The
|
|
32
|
+
portable `Uuid` type keeps its `CHAR(32)` storage. Storing `UUID` requires
|
|
33
|
+
CrateDB 6.2 or later
|
|
34
|
+
- Types: Added `uuid` and `uuid_array` to the reflected type map
|
|
35
|
+
- Types: Fixed `CLOB`, `NCHAR`, `NVARCHAR`, `DATETIME`, and `DATE` compiling to
|
|
36
|
+
type names CrateDB cannot parse. They now map to `STRING`, `CHAR`, `VARCHAR`,
|
|
37
|
+
and `TIMESTAMP` respectively, matching their generic lower-case counterparts
|
|
38
|
+
- BREAKING: Types: `cast(x, Date)` now renders `CAST(x AS DATE)` instead of
|
|
39
|
+
`CAST(x AS TIMESTAMP)`.
|
|
40
|
+
- Types: Mapped `Numeric` and `DECIMAL` to CrateDB's `NUMERIC`, carrying the
|
|
41
|
+
declared precision and scale into DDL and casts, where they previously
|
|
42
|
+
compiled to `LONG` and `DOUBLE` and lost them. Declaring such a column
|
|
43
|
+
without a precision now raises `CompileError`, since CrateDB only stores
|
|
44
|
+
the type with one. Storing the type requires CrateDB 5.9 or later
|
|
45
|
+
- BREAKING: Types: Bound `Decimal` values now reach the driver unconverted,
|
|
46
|
+
which serializes them as strings, storing every digit instead of rounding to
|
|
47
|
+
float. A `LONG` column that an earlier release created from `Numeric` rejects
|
|
48
|
+
any such value written with a decimal point, `1.00` included, so those
|
|
49
|
+
columns need migrating to `NUMERIC`
|
|
50
|
+
- Types: Added `numeric` and `numeric_array` to the reflected type map, where
|
|
51
|
+
they previously resolved to an abstract type that could not be compiled
|
|
52
|
+
- Compiler: Fixed array indexes rendering as object keys, as in `arr['1']`.
|
|
53
|
+
Added support for array slices, and for columns and expressions as indexes
|
|
54
|
+
- Compiler: Fixed cached statements on `sa.JSON` and `ObjectArray` columns
|
|
55
|
+
reusing the subscript of an earlier statement, which returned values of
|
|
56
|
+
another key. Fixed object keys containing a quote
|
|
57
|
+
- BREAKING: Compiler: A statement with a literal subscript on an `sa.JSON`,
|
|
58
|
+
`ObjectArray` or `ARRAY` column can't run with `executemany()` on a cached
|
|
59
|
+
engine. For that, use `execution_options(compiled_cache=None)`
|
|
60
|
+
- BREAKING: Compiler: An integer subscript on a nested object renders as an
|
|
61
|
+
array position. Write the key as a string, as in `obj['n']['1']`
|
|
62
|
+
- Compiler: `bool`, `float` and `None` subscripts raise `CompileError`
|
|
63
|
+
- Types: Added `geo_point`, `geo_shape`, `ip` and `character` to the
|
|
64
|
+
reflected type map, and arrays of mapped types
|
|
65
|
+
- Types: Reflected `CHAR` and `VARCHAR` columns keep their declared length
|
|
66
|
+
- Types: A reflected column of an unknown type warns and becomes
|
|
67
|
+
`UnresolvedType`, which raises `CompileError` naming the column in DDL
|
|
68
|
+
|
|
3
69
|
## 2026/06/22 0.43.1
|
|
4
70
|
- Compiler: Fixed `AttributeError: 'CrateCompilerSA20' object has no attribute
|
|
5
71
|
'visit_on_conflict_do_update'` by forwarding calls to
|
|
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
|
|
4
4
|
|
|
5
5
|
## Project Overview
|
|
6
6
|
|
|
7
|
-
`sqlalchemy-cratedb` is a SQLAlchemy dialect for CrateDB, a distributed SQL database. It supports SQLAlchemy 1.
|
|
7
|
+
`sqlalchemy-cratedb` is a SQLAlchemy dialect for CrateDB, a distributed SQL database. It supports SQLAlchemy 1.4 through 2.1.
|
|
8
8
|
|
|
9
9
|
## Development Setup
|
|
10
10
|
|
|
@@ -13,7 +13,6 @@ source bootstrap.sh # Creates .venv with Python 3.11, installs all deps in edi
|
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
Environment variables that influence bootstrap:
|
|
16
|
-
- `CRATEDB_VERSION` (default: `5.5.1`) — CrateDB Docker image version
|
|
17
16
|
- `SQLALCHEMY_VERSION` (default: `<2.2`) — SQLAlchemy version constraint
|
|
18
17
|
- `PIP_ALLOW_PRERELEASE=true` — allow pre-release packages
|
|
19
18
|
|
|
@@ -22,7 +21,7 @@ Environment variables that influence bootstrap:
|
|
|
22
21
|
```bash
|
|
23
22
|
poe format # Auto-format code (ruff + black)
|
|
24
23
|
poe lint # Run linters (ruff, validate-pyproject)
|
|
25
|
-
poe test # Run pytest
|
|
24
|
+
poe test # Run pytest, including the doctests
|
|
26
25
|
poe check # lint + test combined
|
|
27
26
|
|
|
28
27
|
# Run specific tests
|
|
@@ -31,10 +30,11 @@ pytest -k SqlAlchemyCompilerTest
|
|
|
31
30
|
pytest -k test_score
|
|
32
31
|
|
|
33
32
|
# Run integration/doctests
|
|
34
|
-
|
|
33
|
+
pytest tests/test_documentation.py
|
|
35
34
|
```
|
|
36
35
|
|
|
37
|
-
Tests require a live CrateDB instance via Docker
|
|
36
|
+
Tests require a live CrateDB instance via Docker, started automatically by the `cratedb_service` fixture through `testcontainers.community.cratedb`.
|
|
37
|
+
Select the CrateDB version with `CRATEDB_VERSION`, an image tag (default: `latest`), e.g. `CRATEDB_VERSION=5.10.16 pytest`. `nightly` uses `crate/crate:nightly`, any other tag the official `crate` image.
|
|
38
38
|
|
|
39
39
|
## Architecture
|
|
40
40
|
|
|
@@ -44,7 +44,7 @@ Tests require a live CrateDB instance via Docker (managed automatically by `crat
|
|
|
44
44
|
- **`compiler.py`** — SQL/DDL compilation: `CrateDDLCompiler`, `CrateTypeCompiler`, `CrateIdentifierPreparer`, and `rewrite_update()` for partial object updates
|
|
45
45
|
- **`predicate.py`** — `match()` predicate for full-text search
|
|
46
46
|
- **`sa_version.py`** — Version detection; exports `SA_VERSION`, `SA_1_4`, `SA_2_0`, `SA_2_1` constants
|
|
47
|
-
- **`compat/`** — Multi-version SQLAlchemy compatibility: `
|
|
47
|
+
- **`compat/`** — Multi-version SQLAlchemy compatibility: `core14.py` (SQLAlchemy 1.4), `core20.py` (2.0 and 2.1)
|
|
48
48
|
- **`type/`** — Custom CrateDB types: `ObjectType` (JSON objects), `ObjectArray`, `FloatVector`, `Geopoint`, `Geoshape`
|
|
49
49
|
- **`support/`** — Integrations and polyfills: `pandas.py` (bulk insert), `polyfill.py` (refresh-after-DML, uniqueness, autoincrement timestamps), `util.py`
|
|
50
50
|
|
|
@@ -61,11 +61,13 @@ Tests require a live CrateDB instance via Docker (managed automatically by `crat
|
|
|
61
61
|
### Testing
|
|
62
62
|
|
|
63
63
|
Tests in `tests/` follow two patterns:
|
|
64
|
-
- `*_test.py` files: unit
|
|
65
|
-
- `tests/
|
|
66
|
-
|
|
67
|
-
The `conftest.py` provides a session-scoped `cratedb_service` fixture that starts CrateDB via Docker containers.
|
|
64
|
+
- `*_test.py` and `test_*.py` files: pytest tests. Integration tests use the `cratedb_service` fixture; unit tests mock the driver's cursor and run offline
|
|
65
|
+
- `tests/test_documentation.py`: runs the doctests in `docs/*.rst` against the same CrateDB instance
|
|
68
66
|
|
|
67
|
+
The `conftest.py` provides:
|
|
68
|
+
- `cratedb_service`: session-scoped, starts one CrateDB container (`crate/crate:$CRATEDB_VERSION`) with `tests/assets` mounted at `/assets`
|
|
69
|
+
- `crate_host`: the container's `host:port`, used by the doctests
|
|
70
|
+
- `offline_default_server`: autouse, answers the driver's connect-time server version probe for the default address `localhost:4200`.
|
|
69
71
|
## Code Style
|
|
70
72
|
|
|
71
73
|
- Line length: 100 characters (ruff + black)
|
|
@@ -16,17 +16,21 @@ further commands.
|
|
|
16
16
|
|
|
17
17
|
Verify code by running all linters and software tests:
|
|
18
18
|
|
|
19
|
-
export CRATEDB_VERSION=latest
|
|
20
|
-
docker compose -f tests/docker-compose.yml up
|
|
21
19
|
poe check
|
|
22
20
|
|
|
21
|
+
The test suite starts a CrateDB instance using Docker. Select the CrateDB version with a tag of the official `crate` image (default: `latest`), or `nightly` for `crate/crate:nightly`:
|
|
22
|
+
version using the tag of the `crate/crate` image, the default is `latest`:
|
|
23
|
+
|
|
24
|
+
export CRATEDB_VERSION=6.4.6
|
|
25
|
+
poe test
|
|
26
|
+
|
|
23
27
|
Run specific tests:
|
|
24
28
|
|
|
25
29
|
pytest -k SqlAlchemyCompilerTest
|
|
26
30
|
pytest -k test_score
|
|
27
31
|
|
|
28
32
|
# Integration tests, written as doctests.
|
|
29
|
-
|
|
33
|
+
pytest tests/test_documentation.py
|
|
30
34
|
|
|
31
35
|
Format code:
|
|
32
36
|
|
{sqlalchemy_cratedb-0.43.1/src/sqlalchemy_cratedb.egg-info → sqlalchemy_cratedb-0.45.0}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sqlalchemy-cratedb
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.45.0
|
|
4
4
|
Summary: SQLAlchemy dialect for CrateDB.
|
|
5
5
|
Author-email: "Crate.io" <office@crate.io>
|
|
6
6
|
License: Apache License 2.0
|
|
@@ -60,17 +60,14 @@ Requires-Python: >=3.10
|
|
|
60
60
|
Description-Content-Type: text/markdown
|
|
61
61
|
License-File: LICENSE
|
|
62
62
|
License-File: NOTICE
|
|
63
|
-
Requires-Dist: backports.zoneinfo<1; python_version < "3.9"
|
|
64
63
|
Requires-Dist: crate<3,>=2.2.1
|
|
65
64
|
Requires-Dist: geojson<4,>=2.5
|
|
66
|
-
Requires-Dist:
|
|
67
|
-
Requires-Dist:
|
|
68
|
-
Requires-Dist: sqlalchemy<2.2,>=1
|
|
69
|
-
Requires-Dist: verlib2<0.4
|
|
65
|
+
Requires-Dist: sqlalchemy<2.2,>=1.4
|
|
66
|
+
Requires-Dist: verlib2<26.3
|
|
70
67
|
Provides-Extra: all
|
|
71
68
|
Requires-Dist: sqlalchemy-cratedb[vector]; extra == "all"
|
|
72
69
|
Provides-Extra: develop
|
|
73
|
-
Requires-Dist: mypy<
|
|
70
|
+
Requires-Dist: mypy<2.5; extra == "develop"
|
|
74
71
|
Requires-Dist: poethepoet<1; extra == "develop"
|
|
75
72
|
Requires-Dist: pyproject-fmt<3; extra == "develop"
|
|
76
73
|
Requires-Dist: ruff<0.16; extra == "develop"
|
|
@@ -80,15 +77,16 @@ Requires-Dist: crate-docs-theme>=0.26.5; extra == "doc"
|
|
|
80
77
|
Requires-Dist: sphinx<10,>=3.5; extra == "doc"
|
|
81
78
|
Provides-Extra: release
|
|
82
79
|
Requires-Dist: build<2; extra == "release"
|
|
83
|
-
Requires-Dist: twine<
|
|
80
|
+
Requires-Dist: twine<8; extra == "release"
|
|
84
81
|
Provides-Extra: test
|
|
85
|
-
Requires-Dist: cratedb-toolkit[testing]; extra == "test"
|
|
86
82
|
Requires-Dist: dask[dataframe]; extra == "test"
|
|
83
|
+
Requires-Dist: httpx; extra == "test"
|
|
87
84
|
Requires-Dist: pandas<2.4; extra == "test"
|
|
88
85
|
Requires-Dist: pueblo>=0.0.7; extra == "test"
|
|
89
86
|
Requires-Dist: pytest<10; extra == "test"
|
|
90
87
|
Requires-Dist: pytest-cov<8; extra == "test"
|
|
91
88
|
Requires-Dist: pytest-mock<4; extra == "test"
|
|
89
|
+
Requires-Dist: testcontainers<5,>=4.15; extra == "test"
|
|
92
90
|
Provides-Extra: vector
|
|
93
91
|
Requires-Dist: numpy; extra == "vector"
|
|
94
92
|
Dynamic: license-file
|
|
@@ -78,19 +78,16 @@ dynamic = [
|
|
|
78
78
|
"version",
|
|
79
79
|
]
|
|
80
80
|
dependencies = [
|
|
81
|
-
"backports.zoneinfo<1; python_version<'3.9'",
|
|
82
81
|
"crate>=2.2.1,<3",
|
|
83
82
|
"geojson>=2.5,<4",
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"sqlalchemy>=1,<2.2",
|
|
87
|
-
"verlib2<0.4",
|
|
83
|
+
"sqlalchemy>=1.4,<2.2",
|
|
84
|
+
"verlib2<26.3",
|
|
88
85
|
]
|
|
89
86
|
optional-dependencies.all = [
|
|
90
87
|
"sqlalchemy-cratedb[vector]",
|
|
91
88
|
]
|
|
92
89
|
optional-dependencies.develop = [
|
|
93
|
-
"mypy<
|
|
90
|
+
"mypy<2.5",
|
|
94
91
|
"poethepoet<1",
|
|
95
92
|
"pyproject-fmt<3",
|
|
96
93
|
"ruff<0.16",
|
|
@@ -102,16 +99,17 @@ optional-dependencies.doc = [
|
|
|
102
99
|
]
|
|
103
100
|
optional-dependencies.release = [
|
|
104
101
|
"build<2",
|
|
105
|
-
"twine<
|
|
102
|
+
"twine<8",
|
|
106
103
|
]
|
|
107
104
|
optional-dependencies.test = [
|
|
108
|
-
"cratedb-toolkit[testing]",
|
|
109
105
|
"dask[dataframe]",
|
|
106
|
+
"httpx",
|
|
110
107
|
"pandas<2.4",
|
|
111
108
|
"pueblo>=0.0.7",
|
|
112
109
|
"pytest<10",
|
|
113
110
|
"pytest-cov<8",
|
|
114
111
|
"pytest-mock<4",
|
|
112
|
+
"testcontainers>=4.15,<5",
|
|
115
113
|
]
|
|
116
114
|
optional-dependencies.vector = [
|
|
117
115
|
"numpy",
|
|
@@ -263,7 +261,6 @@ tasks.release = [
|
|
|
263
261
|
]
|
|
264
262
|
tasks.test = [
|
|
265
263
|
{ cmd = "pytest" },
|
|
266
|
-
{ cmd = "python -m unittest -vvv tests/integration.py" },
|
|
267
264
|
]
|
|
268
265
|
|
|
269
266
|
[tool.versioningit]
|
|
@@ -19,38 +19,33 @@
|
|
|
19
19
|
# with Crate these terms will supersede the license and you may use the
|
|
20
20
|
# software solely pursuant to the terms of the relevant commercial agreement.
|
|
21
21
|
|
|
22
|
-
from .compat.api13 import monkeypatch_add_exec_driver_sql
|
|
23
22
|
from .dialect import dialect
|
|
24
23
|
from .predicate import match
|
|
25
|
-
from .sa_version import SA_1_4, SA_VERSION
|
|
24
|
+
from .sa_version import SA_1_4, SA_2_0, SA_VERSION # noqa: F401 # Re-exported for compatibility.
|
|
26
25
|
from .support import insert_bulk
|
|
27
26
|
from .type.array import ObjectArray
|
|
28
27
|
from .type.geo import Geopoint, Geoshape
|
|
28
|
+
from .type.ip import IP
|
|
29
29
|
from .type.object import ObjectType
|
|
30
|
+
from .type.unresolved import UnresolvedType
|
|
30
31
|
from .type.vector import FloatVector, knn_match
|
|
31
32
|
|
|
32
|
-
if SA_VERSION <
|
|
33
|
+
if SA_VERSION < SA_2_0:
|
|
33
34
|
import textwrap
|
|
34
35
|
import warnings
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
SA13_DEPRECATION_WARNING = textwrap.dedent(
|
|
37
|
+
SA14_DEPRECATION_WARNING = textwrap.dedent(
|
|
38
38
|
"""
|
|
39
|
-
WARNING: SQLAlchemy 1.
|
|
39
|
+
WARNING: SQLAlchemy 1.4 is EOL.
|
|
40
40
|
|
|
41
|
-
SQLAlchemy 1.
|
|
42
|
-
Future versions of the CrateDB SQLAlchemy dialect will drop support for SQLAlchemy 1.
|
|
43
|
-
It is recommended that you transition to using SQLAlchemy
|
|
41
|
+
SQLAlchemy 1.4 is no longer maintained, its last release was 1.4.54 in September 2024.
|
|
42
|
+
Future versions of the CrateDB SQLAlchemy dialect will drop support for SQLAlchemy 1.4.
|
|
43
|
+
It is recommended that you transition to using SQLAlchemy 2.0 or later:
|
|
44
44
|
|
|
45
|
-
- https://docs.sqlalchemy.org/en/14/changelog/migration_14.html
|
|
46
45
|
- https://docs.sqlalchemy.org/en/20/changelog/migration_20.html
|
|
47
46
|
""".lstrip("\n")
|
|
48
47
|
)
|
|
49
|
-
warnings.warn(message=
|
|
50
|
-
|
|
51
|
-
# SQLAlchemy 1.3 does not have the `exec_driver_sql` method, so add it.
|
|
52
|
-
monkeypatch_add_exec_driver_sql()
|
|
53
|
-
|
|
48
|
+
warnings.warn(message=SA14_DEPRECATION_WARNING, category=FutureWarning, stacklevel=2)
|
|
54
49
|
|
|
55
50
|
try:
|
|
56
51
|
from importlib.metadata import PackageNotFoundError, version
|
|
@@ -72,8 +67,10 @@ __all__ = [
|
|
|
72
67
|
FloatVector,
|
|
73
68
|
Geopoint,
|
|
74
69
|
Geoshape,
|
|
70
|
+
IP,
|
|
75
71
|
ObjectArray,
|
|
76
72
|
ObjectType,
|
|
73
|
+
UnresolvedType,
|
|
77
74
|
match,
|
|
78
75
|
knn_match,
|
|
79
76
|
insert_bulk,
|
|
@@ -26,10 +26,17 @@ from collections import defaultdict
|
|
|
26
26
|
import sqlalchemy as sa
|
|
27
27
|
from sqlalchemy.dialects.postgresql.base import RESERVED_WORDS as POSTGRESQL_RESERVED_WORDS
|
|
28
28
|
from sqlalchemy.dialects.postgresql.base import PGCompiler
|
|
29
|
-
from sqlalchemy.sql import compiler
|
|
29
|
+
from sqlalchemy.sql import compiler, operators
|
|
30
|
+
from sqlalchemy.sql.elements import (
|
|
31
|
+
BinaryExpression,
|
|
32
|
+
BindParameter,
|
|
33
|
+
Grouping,
|
|
34
|
+
Null,
|
|
35
|
+
Slice,
|
|
36
|
+
TypeCoerce,
|
|
37
|
+
)
|
|
30
38
|
from sqlalchemy.types import String
|
|
31
39
|
|
|
32
|
-
from .sa_version import SA_1_4, SA_VERSION
|
|
33
40
|
from .type.geo import Geopoint, Geoshape
|
|
34
41
|
from .type.object import MutableDict, ObjectTypeImpl
|
|
35
42
|
|
|
@@ -76,25 +83,30 @@ def rewrite_update(clauseelement, multiparams, params):
|
|
|
76
83
|
|
|
77
84
|
@sa.event.listens_for(sa.engine.Engine, "before_execute", retval=True)
|
|
78
85
|
def crate_before_execute(conn, clauseelement, multiparams, params, *args, **kwargs):
|
|
86
|
+
"""
|
|
87
|
+
Rewrite an `UPDATE` with a single parameter set for partial `ObjectType` updates.
|
|
88
|
+
"""
|
|
79
89
|
is_crate = type(conn.dialect).__name__ == "CrateDialect"
|
|
80
|
-
if is_crate
|
|
81
|
-
|
|
82
|
-
if params is None:
|
|
83
|
-
multiparams = ([],)
|
|
84
|
-
else:
|
|
85
|
-
multiparams = ([params],)
|
|
86
|
-
params = {}
|
|
90
|
+
if not is_crate or not isinstance(clauseelement, sa.sql.expression.Update) or multiparams:
|
|
91
|
+
return clauseelement, multiparams, params
|
|
87
92
|
|
|
88
|
-
|
|
93
|
+
clauseelement, rewritten, _ = rewrite_update(clauseelement, ([params],), {})
|
|
94
|
+
return clauseelement, [], rewritten[0][0]
|
|
89
95
|
|
|
90
|
-
if SA_VERSION >= SA_1_4:
|
|
91
|
-
if multiparams[0]:
|
|
92
|
-
params = multiparams[0][0]
|
|
93
|
-
else:
|
|
94
|
-
params = multiparams[0]
|
|
95
|
-
multiparams = []
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
def _require_numeric_precision(type_):
|
|
98
|
+
if isinstance(type_, sa.types.ARRAY):
|
|
99
|
+
_require_numeric_precision(type_.item_type)
|
|
100
|
+
return
|
|
101
|
+
if isinstance(type_, sa.types.TypeDecorator):
|
|
102
|
+
_require_numeric_precision(type_.impl)
|
|
103
|
+
return
|
|
104
|
+
if isinstance(type_, sa.types.Numeric) and not isinstance(type_, sa.types.Float):
|
|
105
|
+
if type_.precision is None:
|
|
106
|
+
raise sa.exc.CompileError(
|
|
107
|
+
"CrateDB stores a NUMERIC column only with a precision, "
|
|
108
|
+
"as in Numeric(precision=10, scale=2)"
|
|
109
|
+
)
|
|
98
110
|
|
|
99
111
|
|
|
100
112
|
class CrateDDLCompiler(compiler.DDLCompiler):
|
|
@@ -106,6 +118,7 @@ class CrateDDLCompiler(compiler.DDLCompiler):
|
|
|
106
118
|
__clustered_opt_tmpl = " CLUSTERED{clustered_by}{number_of_shards}"
|
|
107
119
|
|
|
108
120
|
def get_column_specification(self, column, **kwargs):
|
|
121
|
+
_require_numeric_precision(column.type)
|
|
109
122
|
colspec = (
|
|
110
123
|
self.preparer.format_column(column)
|
|
111
124
|
+ " "
|
|
@@ -222,8 +235,17 @@ class CrateTypeCompiler(compiler.GenericTypeCompiler):
|
|
|
222
235
|
def visit_TEXT(self, type_, **kw):
|
|
223
236
|
return "STRING"
|
|
224
237
|
|
|
238
|
+
def visit_CLOB(self, type_, **kw):
|
|
239
|
+
return "STRING"
|
|
240
|
+
|
|
241
|
+
def visit_NCHAR(self, type_, **kw):
|
|
242
|
+
return self.visit_CHAR(type_, **kw)
|
|
243
|
+
|
|
244
|
+
def visit_NVARCHAR(self, type_, **kw):
|
|
245
|
+
return self.visit_VARCHAR(type_, **kw)
|
|
246
|
+
|
|
225
247
|
def visit_DECIMAL(self, type_, **kw):
|
|
226
|
-
return
|
|
248
|
+
return self.visit_NUMERIC(type_, **kw)
|
|
227
249
|
|
|
228
250
|
def visit_double(self, type_, **kw):
|
|
229
251
|
return "DOUBLE"
|
|
@@ -232,7 +254,15 @@ class CrateTypeCompiler(compiler.GenericTypeCompiler):
|
|
|
232
254
|
return "LONG"
|
|
233
255
|
|
|
234
256
|
def visit_NUMERIC(self, type_, **kw):
|
|
235
|
-
|
|
257
|
+
"""
|
|
258
|
+
A bare `NUMERIC` is a valid cast target; only columns require the
|
|
259
|
+
precision, which `CrateDDLCompiler` enforces.
|
|
260
|
+
"""
|
|
261
|
+
if type_.precision is None:
|
|
262
|
+
return "NUMERIC"
|
|
263
|
+
if type_.scale is None:
|
|
264
|
+
return "NUMERIC({0})".format(type_.precision)
|
|
265
|
+
return "NUMERIC({0}, {1})".format(type_.precision, type_.scale)
|
|
236
266
|
|
|
237
267
|
def visit_INTEGER(self, type_, **kw):
|
|
238
268
|
return "INT"
|
|
@@ -240,16 +270,30 @@ class CrateTypeCompiler(compiler.GenericTypeCompiler):
|
|
|
240
270
|
def visit_SMALLINT(self, type_, **kw):
|
|
241
271
|
return "SHORT"
|
|
242
272
|
|
|
243
|
-
def
|
|
273
|
+
def visit_DATETIME(self, type_, **kw):
|
|
244
274
|
return self.visit_TIMESTAMP(type_, **kw)
|
|
245
275
|
|
|
246
|
-
def
|
|
247
|
-
return "TIMESTAMP"
|
|
276
|
+
def visit_DATE(self, type_, **kw):
|
|
277
|
+
return "DATE" if kw.get("cast_target") else "TIMESTAMP"
|
|
278
|
+
|
|
279
|
+
def visit_TIME(self, type_, **kw):
|
|
280
|
+
"""
|
|
281
|
+
CrateDB has no storable `TIME` column type. Plain `TIME` does not exist,
|
|
282
|
+
and `TIME WITH TIME ZONE` (TIMETZ) is literal/cast-only ("does not support
|
|
283
|
+
storage"). So store the time-of-day as a `STRING`, holding the value in
|
|
284
|
+
ISO 8601 format (e.g. ``19:00:30.123456``).
|
|
285
|
+
"""
|
|
286
|
+
return "STRING"
|
|
248
287
|
|
|
249
288
|
def visit_ARRAY(self, type_, **kw):
|
|
250
289
|
if type_.dimensions is not None and type_.dimensions > 1:
|
|
251
290
|
raise NotImplementedError("CrateDB doesn't support multidimensional arrays")
|
|
252
|
-
return "ARRAY({0})".format(self.process(type_.item_type))
|
|
291
|
+
return "ARRAY({0})".format(self.process(type_.item_type, **kw))
|
|
292
|
+
|
|
293
|
+
def visit_unresolved(self, type_, **kw):
|
|
294
|
+
raise sa.exc.CompileError(
|
|
295
|
+
"Unable to represent CrateDB type '{0}' in SQLAlchemy".format(type_.type_name)
|
|
296
|
+
)
|
|
253
297
|
|
|
254
298
|
def visit_OBJECT(self, type_, **kw):
|
|
255
299
|
return "OBJECT"
|
|
@@ -293,15 +337,117 @@ class CrateTypeCompiler(compiler.GenericTypeCompiler):
|
|
|
293
337
|
return "OBJECT"
|
|
294
338
|
|
|
295
339
|
|
|
340
|
+
def _slice_bound(value):
|
|
341
|
+
if value is None:
|
|
342
|
+
return ""
|
|
343
|
+
if isinstance(value, bool) or not isinstance(value, int):
|
|
344
|
+
raise sa.exc.CompileError(f"CrateDB array slices take integer bounds, not {value!r}")
|
|
345
|
+
return str(value)
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
class _SubscriptType(sa.types.TypeEngine):
|
|
349
|
+
"""
|
|
350
|
+
Renders an array index, an array slice, or an object key as a literal.
|
|
351
|
+
|
|
352
|
+
With `int_as_key`, an integer renders as an object key.
|
|
353
|
+
"""
|
|
354
|
+
|
|
355
|
+
cache_ok = True
|
|
356
|
+
# Reject `None`, instead of rendering it as `NULL`.
|
|
357
|
+
should_evaluate_none = True
|
|
358
|
+
|
|
359
|
+
def __init__(self, int_as_key=False):
|
|
360
|
+
self.int_as_key = int_as_key
|
|
361
|
+
|
|
362
|
+
def literal_processor(self, dialect):
|
|
363
|
+
def process(value):
|
|
364
|
+
if isinstance(value, slice):
|
|
365
|
+
if value.step is not None:
|
|
366
|
+
raise sa.exc.CompileError("CrateDB array slices do not support a step")
|
|
367
|
+
return "%s:%s" % (_slice_bound(value.start), _slice_bound(value.stop))
|
|
368
|
+
if isinstance(value, bool) or not isinstance(value, (int, str)):
|
|
369
|
+
raise sa.exc.CompileError(
|
|
370
|
+
f"CrateDB subscripts take an integer index or a string key, not {value!r}"
|
|
371
|
+
)
|
|
372
|
+
if isinstance(value, int) and not self.int_as_key:
|
|
373
|
+
return str(value)
|
|
374
|
+
return "'%s'" % str(value).replace("'", "''")
|
|
375
|
+
|
|
376
|
+
return process
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
def _is_top_level_object(element):
|
|
380
|
+
"""
|
|
381
|
+
Whether `element` is an object, and not a value taken out of one, which
|
|
382
|
+
may be an array. CrateDB does not accept an array index on an object.
|
|
383
|
+
"""
|
|
384
|
+
while isinstance(element, Grouping):
|
|
385
|
+
element = element.element
|
|
386
|
+
if isinstance(element, BinaryExpression) and element.operator in (
|
|
387
|
+
operators.getitem,
|
|
388
|
+
operators.json_getitem_op,
|
|
389
|
+
):
|
|
390
|
+
return False
|
|
391
|
+
return isinstance(element.type, sa.types.JSON)
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
def _unwrap_bindparam(element):
|
|
395
|
+
"""
|
|
396
|
+
Return the bind parameter inside `element`, if it renders as a bare one.
|
|
397
|
+
"""
|
|
398
|
+
inner = element
|
|
399
|
+
while isinstance(inner, Grouping):
|
|
400
|
+
inner = inner.element
|
|
401
|
+
if isinstance(inner, TypeCoerce):
|
|
402
|
+
inner = inner.typed_expression
|
|
403
|
+
return inner if isinstance(inner, BindParameter) else element
|
|
404
|
+
|
|
405
|
+
|
|
296
406
|
class CrateCompiler(compiler.SQLCompiler):
|
|
407
|
+
def visit_typeclause(self, typeclause, **kw):
|
|
408
|
+
"""
|
|
409
|
+
Mark that a type is being rendered as a cast target.
|
|
410
|
+
"""
|
|
411
|
+
return super().visit_typeclause(typeclause, cast_target=True, **kw)
|
|
412
|
+
|
|
297
413
|
visit_on_conflict_do_update = PGCompiler.visit_on_conflict_do_update
|
|
298
414
|
_on_conflict_target = PGCompiler._on_conflict_target
|
|
299
415
|
|
|
416
|
+
def _render_subscript(self, binary, **kw):
|
|
417
|
+
left = self.process(binary.left, **kw)
|
|
418
|
+
index = _unwrap_bindparam(binary.right)
|
|
419
|
+
if isinstance(index, Slice):
|
|
420
|
+
return "%s[%s]" % (left, self._render_slice(index, **kw))
|
|
421
|
+
if not isinstance(index, BindParameter):
|
|
422
|
+
# CrateDB accepts bind parameters inside an expression.
|
|
423
|
+
return "%s[%s]" % (left, self.process(index, **kw))
|
|
424
|
+
|
|
425
|
+
# CrateDB does not accept a bind parameter as an array index or object
|
|
426
|
+
# key, so render it as a literal.
|
|
427
|
+
type_ = _SubscriptType(int_as_key=_is_top_level_object(binary.left))
|
|
428
|
+
if not index.required:
|
|
429
|
+
type_.literal_processor(self.dialect)(index.effective_value)
|
|
430
|
+
if index.required or getattr(self, "cache_key", None) is not None:
|
|
431
|
+
kw["literal_execute"] = True
|
|
432
|
+
else:
|
|
433
|
+
kw["literal_binds"] = True
|
|
434
|
+
index = sa.type_coerce(index, type_).typed_expression
|
|
435
|
+
return "%s[%s]" % (left, self.process(index, **kw))
|
|
436
|
+
|
|
437
|
+
def _render_slice(self, slice_, **kw):
|
|
438
|
+
# CrateDB accepts bind parameters as slice bounds.
|
|
439
|
+
if not isinstance(slice_.step, Null):
|
|
440
|
+
raise sa.exc.CompileError("CrateDB array slices do not support a step")
|
|
441
|
+
return ":".join(
|
|
442
|
+
"" if isinstance(bound, Null) else self.process(bound, **kw)
|
|
443
|
+
for bound in (slice_.start, slice_.stop)
|
|
444
|
+
)
|
|
445
|
+
|
|
300
446
|
def visit_getitem_binary(self, binary, operator, **kw):
|
|
301
|
-
return
|
|
447
|
+
return self._render_subscript(binary, **kw)
|
|
302
448
|
|
|
303
449
|
def visit_json_getitem_op_binary(self, binary, operator, _cast_applied=False, **kw):
|
|
304
|
-
return
|
|
450
|
+
return self._render_subscript(binary, **kw)
|
|
305
451
|
|
|
306
452
|
def visit_any(self, element, **kw):
|
|
307
453
|
return "%s%sANY (%s)" % (
|