sqlalchemy-cratedb 0.44.0__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.44.0 → sqlalchemy_cratedb-0.45.0}/CHANGES.md +25 -1
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/CLAUDE.md +12 -9
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/DEVELOP.md +7 -3
- {sqlalchemy_cratedb-0.44.0/src/sqlalchemy_cratedb.egg-info → sqlalchemy_cratedb-0.45.0}/PKG-INFO +3 -3
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/pyproject.toml +2 -3
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/__init__.py +8 -15
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/compiler.py +7 -22
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/dialect.py +26 -5
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/type/geo.py +12 -2
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/type/vector.py +1 -5
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0/src/sqlalchemy_cratedb.egg-info}/PKG-INFO +3 -3
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb.egg-info/SOURCES.txt +1 -2
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb.egg-info/requires.txt +2 -2
- sqlalchemy_cratedb-0.45.0/tests/test_documentation.py +200 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/tests/test_error_handling.py +5 -1
- sqlalchemy_cratedb-0.45.0/tests/test_schema.py +47 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/tests/test_support_polyfill.py +1 -17
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/tests/test_type_compilation.py +11 -0
- sqlalchemy_cratedb-0.44.0/src/sqlalchemy_cratedb/compat/api13.py +0 -152
- sqlalchemy_cratedb-0.44.0/src/sqlalchemy_cratedb/compat/core10.py +0 -253
- sqlalchemy_cratedb-0.44.0/tests/test_schema.py +0 -24
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/CODE_OF_CONDUCT.md +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/CONTRIBUTING.md +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/LICENSE +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/MANIFEST.in +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/NOTICE +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/README.md +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/backlog.md +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/docs/_extra/robots.txt +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/docs/requirements.txt +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/setup.cfg +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/setup.py +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/compat/__init__.py +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/compat/core14.py +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/compat/core20.py +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/predicate.py +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/sa_version.py +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/support/__init__.py +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/support/pandas.py +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/support/polyfill.py +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/support/util.py +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/type/__init__.py +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/type/array.py +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/type/ip.py +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/type/object.py +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/type/unresolved.py +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/util.py +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb.egg-info/dependency_links.txt +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb.egg-info/entry_points.txt +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb.egg-info/top_level.txt +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/tests/test_support_pandas.py +0 -0
- {sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/tests/test_support_util.py +0 -0
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
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
|
|
4
28
|
- Dependencies: Replaced `cratedb-toolkit[testing]` with
|
|
5
29
|
`testcontainers>=4.15,<5` in the `test` extra
|
|
6
30
|
- Types: Fixed `UUID` columns rejecting every insert, since values were bound
|
|
@@ -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
|
|
|
@@ -21,7 +21,7 @@ Environment variables that influence bootstrap:
|
|
|
21
21
|
```bash
|
|
22
22
|
poe format # Auto-format code (ruff + black)
|
|
23
23
|
poe lint # Run linters (ruff, validate-pyproject)
|
|
24
|
-
poe test # Run pytest
|
|
24
|
+
poe test # Run pytest, including the doctests
|
|
25
25
|
poe check # lint + test combined
|
|
26
26
|
|
|
27
27
|
# Run specific tests
|
|
@@ -30,10 +30,11 @@ pytest -k SqlAlchemyCompilerTest
|
|
|
30
30
|
pytest -k test_score
|
|
31
31
|
|
|
32
32
|
# Run integration/doctests
|
|
33
|
-
|
|
33
|
+
pytest tests/test_documentation.py
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
|
|
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.
|
|
37
38
|
|
|
38
39
|
## Architecture
|
|
39
40
|
|
|
@@ -43,7 +44,7 @@ Most tests need the CrateDB node from `tests/docker-compose.yml` up and answerin
|
|
|
43
44
|
- **`compiler.py`** — SQL/DDL compilation: `CrateDDLCompiler`, `CrateTypeCompiler`, `CrateIdentifierPreparer`, and `rewrite_update()` for partial object updates
|
|
44
45
|
- **`predicate.py`** — `match()` predicate for full-text search
|
|
45
46
|
- **`sa_version.py`** — Version detection; exports `SA_VERSION`, `SA_1_4`, `SA_2_0`, `SA_2_1` constants
|
|
46
|
-
- **`compat/`** — Multi-version SQLAlchemy compatibility: `
|
|
47
|
+
- **`compat/`** — Multi-version SQLAlchemy compatibility: `core14.py` (SQLAlchemy 1.4), `core20.py` (2.0 and 2.1)
|
|
47
48
|
- **`type/`** — Custom CrateDB types: `ObjectType` (JSON objects), `ObjectArray`, `FloatVector`, `Geopoint`, `Geoshape`
|
|
48
49
|
- **`support/`** — Integrations and polyfills: `pandas.py` (bulk insert), `polyfill.py` (refresh-after-DML, uniqueness, autoincrement timestamps), `util.py`
|
|
49
50
|
|
|
@@ -60,11 +61,13 @@ Most tests need the CrateDB node from `tests/docker-compose.yml` up and answerin
|
|
|
60
61
|
### Testing
|
|
61
62
|
|
|
62
63
|
Tests in `tests/` follow two patterns:
|
|
63
|
-
- `*_test.py` files: unit
|
|
64
|
-
- `tests/
|
|
65
|
-
|
|
66
|
-
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
|
|
67
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`.
|
|
68
71
|
## Code Style
|
|
69
72
|
|
|
70
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.44.0/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
|
|
@@ -62,12 +62,12 @@ License-File: LICENSE
|
|
|
62
62
|
License-File: NOTICE
|
|
63
63
|
Requires-Dist: crate<3,>=2.2.1
|
|
64
64
|
Requires-Dist: geojson<4,>=2.5
|
|
65
|
-
Requires-Dist: sqlalchemy<2.2,>=1
|
|
65
|
+
Requires-Dist: sqlalchemy<2.2,>=1.4
|
|
66
66
|
Requires-Dist: verlib2<26.3
|
|
67
67
|
Provides-Extra: all
|
|
68
68
|
Requires-Dist: sqlalchemy-cratedb[vector]; extra == "all"
|
|
69
69
|
Provides-Extra: develop
|
|
70
|
-
Requires-Dist: mypy<2.
|
|
70
|
+
Requires-Dist: mypy<2.5; extra == "develop"
|
|
71
71
|
Requires-Dist: poethepoet<1; extra == "develop"
|
|
72
72
|
Requires-Dist: pyproject-fmt<3; extra == "develop"
|
|
73
73
|
Requires-Dist: ruff<0.16; extra == "develop"
|
|
@@ -80,14 +80,14 @@ dynamic = [
|
|
|
80
80
|
dependencies = [
|
|
81
81
|
"crate>=2.2.1,<3",
|
|
82
82
|
"geojson>=2.5,<4",
|
|
83
|
-
"sqlalchemy>=1,<2.2",
|
|
83
|
+
"sqlalchemy>=1.4,<2.2",
|
|
84
84
|
"verlib2<26.3",
|
|
85
85
|
]
|
|
86
86
|
optional-dependencies.all = [
|
|
87
87
|
"sqlalchemy-cratedb[vector]",
|
|
88
88
|
]
|
|
89
89
|
optional-dependencies.develop = [
|
|
90
|
-
"mypy<2.
|
|
90
|
+
"mypy<2.5",
|
|
91
91
|
"poethepoet<1",
|
|
92
92
|
"pyproject-fmt<3",
|
|
93
93
|
"ruff<0.16",
|
|
@@ -261,7 +261,6 @@ tasks.release = [
|
|
|
261
261
|
]
|
|
262
262
|
tasks.test = [
|
|
263
263
|
{ cmd = "pytest" },
|
|
264
|
-
{ cmd = "python -m unittest -vvv tests/integration.py" },
|
|
265
264
|
]
|
|
266
265
|
|
|
267
266
|
[tool.versioningit]
|
|
@@ -19,10 +19,9 @@
|
|
|
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
|
|
@@ -31,28 +30,22 @@ from .type.object import ObjectType
|
|
|
31
30
|
from .type.unresolved import UnresolvedType
|
|
32
31
|
from .type.vector import FloatVector, knn_match
|
|
33
32
|
|
|
34
|
-
if SA_VERSION <
|
|
33
|
+
if SA_VERSION < SA_2_0:
|
|
35
34
|
import textwrap
|
|
36
35
|
import warnings
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
SA13_DEPRECATION_WARNING = textwrap.dedent(
|
|
37
|
+
SA14_DEPRECATION_WARNING = textwrap.dedent(
|
|
40
38
|
"""
|
|
41
|
-
WARNING: SQLAlchemy 1.
|
|
39
|
+
WARNING: SQLAlchemy 1.4 is EOL.
|
|
42
40
|
|
|
43
|
-
SQLAlchemy 1.
|
|
44
|
-
Future versions of the CrateDB SQLAlchemy dialect will drop support for SQLAlchemy 1.
|
|
45
|
-
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:
|
|
46
44
|
|
|
47
|
-
- https://docs.sqlalchemy.org/en/14/changelog/migration_14.html
|
|
48
45
|
- https://docs.sqlalchemy.org/en/20/changelog/migration_20.html
|
|
49
46
|
""".lstrip("\n")
|
|
50
47
|
)
|
|
51
|
-
warnings.warn(message=
|
|
52
|
-
|
|
53
|
-
# SQLAlchemy 1.3 does not have the `exec_driver_sql` method, so add it.
|
|
54
|
-
monkeypatch_add_exec_driver_sql()
|
|
55
|
-
|
|
48
|
+
warnings.warn(message=SA14_DEPRECATION_WARNING, category=FutureWarning, stacklevel=2)
|
|
56
49
|
|
|
57
50
|
try:
|
|
58
51
|
from importlib.metadata import PackageNotFoundError, version
|
|
@@ -37,7 +37,6 @@ from sqlalchemy.sql.elements import (
|
|
|
37
37
|
)
|
|
38
38
|
from sqlalchemy.types import String
|
|
39
39
|
|
|
40
|
-
from .sa_version import SA_1_4, SA_VERSION
|
|
41
40
|
from .type.geo import Geopoint, Geoshape
|
|
42
41
|
from .type.object import MutableDict, ObjectTypeImpl
|
|
43
42
|
|
|
@@ -84,25 +83,15 @@ def rewrite_update(clauseelement, multiparams, params):
|
|
|
84
83
|
|
|
85
84
|
@sa.event.listens_for(sa.engine.Engine, "before_execute", retval=True)
|
|
86
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
|
+
"""
|
|
87
89
|
is_crate = type(conn.dialect).__name__ == "CrateDialect"
|
|
88
|
-
if is_crate
|
|
89
|
-
|
|
90
|
-
if params is None:
|
|
91
|
-
multiparams = ([],)
|
|
92
|
-
else:
|
|
93
|
-
multiparams = ([params],)
|
|
94
|
-
params = {}
|
|
95
|
-
|
|
96
|
-
clauseelement, multiparams, params = rewrite_update(clauseelement, multiparams, params)
|
|
97
|
-
|
|
98
|
-
if SA_VERSION >= SA_1_4:
|
|
99
|
-
if multiparams[0]:
|
|
100
|
-
params = multiparams[0][0]
|
|
101
|
-
else:
|
|
102
|
-
params = multiparams[0]
|
|
103
|
-
multiparams = []
|
|
90
|
+
if not is_crate or not isinstance(clauseelement, sa.sql.expression.Update) or multiparams:
|
|
91
|
+
return clauseelement, multiparams, params
|
|
104
92
|
|
|
105
|
-
|
|
93
|
+
clauseelement, rewritten, _ = rewrite_update(clauseelement, ([params],), {})
|
|
94
|
+
return clauseelement, [], rewritten[0][0]
|
|
106
95
|
|
|
107
96
|
|
|
108
97
|
def _require_numeric_precision(type_):
|
|
@@ -438,10 +427,6 @@ class CrateCompiler(compiler.SQLCompiler):
|
|
|
438
427
|
type_ = _SubscriptType(int_as_key=_is_top_level_object(binary.left))
|
|
439
428
|
if not index.required:
|
|
440
429
|
type_.literal_processor(self.dialect)(index.effective_value)
|
|
441
|
-
elif SA_VERSION < SA_1_4:
|
|
442
|
-
raise sa.exc.CompileError(
|
|
443
|
-
"A subscript taking its value on execution needs SQLAlchemy 1.4 or later"
|
|
444
|
-
)
|
|
445
430
|
if index.required or getattr(self, "cache_key", None) is not None:
|
|
446
431
|
kw["literal_execute"] = True
|
|
447
432
|
else:
|
|
@@ -35,7 +35,7 @@ from .compiler import (
|
|
|
35
35
|
CrateIdentifierPreparer,
|
|
36
36
|
CrateTypeCompiler,
|
|
37
37
|
)
|
|
38
|
-
from .sa_version import
|
|
38
|
+
from .sa_version import SA_2_0, SA_VERSION
|
|
39
39
|
from .type import IP, FloatVector, Geopoint, Geoshape, ObjectArray, ObjectType, UnresolvedType
|
|
40
40
|
from .util import SSLMode
|
|
41
41
|
|
|
@@ -238,14 +238,24 @@ if SA_VERSION >= SA_2_0:
|
|
|
238
238
|
from .compat.core20 import CrateCompilerSA20
|
|
239
239
|
|
|
240
240
|
statement_compiler = CrateCompilerSA20
|
|
241
|
-
|
|
241
|
+
else:
|
|
242
242
|
from .compat.core14 import CrateCompilerSA14
|
|
243
243
|
|
|
244
244
|
statement_compiler = CrateCompilerSA14
|
|
245
|
-
else:
|
|
246
|
-
from .compat.core10 import CrateCompilerSA10
|
|
247
245
|
|
|
248
|
-
|
|
246
|
+
|
|
247
|
+
def _is_read_timeout(error):
|
|
248
|
+
"""
|
|
249
|
+
Whether the driver raised ``error`` because a request exceeded its read timeout.
|
|
250
|
+
"""
|
|
251
|
+
from urllib3.exceptions import MaxRetryError, ReadTimeoutError
|
|
252
|
+
|
|
253
|
+
for inner in (error.__cause__, error.__context__):
|
|
254
|
+
if isinstance(inner, MaxRetryError):
|
|
255
|
+
inner = inner.reason
|
|
256
|
+
if isinstance(inner, ReadTimeoutError):
|
|
257
|
+
return True
|
|
258
|
+
return False
|
|
249
259
|
|
|
250
260
|
|
|
251
261
|
class CrateDialect(default.DefaultDialect):
|
|
@@ -301,6 +311,14 @@ class CrateDialect(default.DefaultDialect):
|
|
|
301
311
|
# original exception to the user
|
|
302
312
|
pass
|
|
303
313
|
|
|
314
|
+
def is_disconnect(self, e, connection, cursor):
|
|
315
|
+
exceptions = self.dbapi.exceptions
|
|
316
|
+
if isinstance(e, exceptions.ConnectionError):
|
|
317
|
+
return not _is_read_timeout(e)
|
|
318
|
+
if isinstance(e, exceptions.ProgrammingError):
|
|
319
|
+
return str(e) == "Connection closed"
|
|
320
|
+
return False
|
|
321
|
+
|
|
304
322
|
def connect(self, host=None, port=None, *args, **kwargs):
|
|
305
323
|
server = None
|
|
306
324
|
if host:
|
|
@@ -421,8 +439,11 @@ class CrateDialect(default.DefaultDialect):
|
|
|
421
439
|
|
|
422
440
|
@reflection.cache
|
|
423
441
|
def get_view_names(self, connection, schema=None, **kw):
|
|
442
|
+
if schema is None:
|
|
443
|
+
schema = self._get_effective_schema_name(connection)
|
|
424
444
|
cursor = connection.exec_driver_sql(
|
|
425
445
|
"SELECT table_name FROM information_schema.views "
|
|
446
|
+
"WHERE {0} = ? "
|
|
426
447
|
"ORDER BY table_name ASC, {0} ASC".format(self.schema_column),
|
|
427
448
|
(schema or self.default_schema_name,),
|
|
428
449
|
)
|
|
@@ -22,7 +22,12 @@ class Geopoint(sqltypes.UserDefinedType):
|
|
|
22
22
|
return process
|
|
23
23
|
|
|
24
24
|
def result_processor(self, dialect, coltype):
|
|
25
|
-
|
|
25
|
+
def process(value):
|
|
26
|
+
if value is None:
|
|
27
|
+
return None
|
|
28
|
+
return tuple(value)
|
|
29
|
+
|
|
30
|
+
return process
|
|
26
31
|
|
|
27
32
|
comparator_factory = Comparator
|
|
28
33
|
|
|
@@ -38,6 +43,11 @@ class Geoshape(sqltypes.UserDefinedType):
|
|
|
38
43
|
return "GEO_SHAPE"
|
|
39
44
|
|
|
40
45
|
def result_processor(self, dialect, coltype):
|
|
41
|
-
|
|
46
|
+
def process(value):
|
|
47
|
+
if value is None:
|
|
48
|
+
return None
|
|
49
|
+
return geojson.GeoJSON.to_instance(value)
|
|
50
|
+
|
|
51
|
+
return process
|
|
42
52
|
|
|
43
53
|
comparator_factory = Comparator
|
{sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb/type/vector.py
RENAMED
|
@@ -21,10 +21,6 @@ see `pgvector.sqlalchemy.Vector.comparator_factory`.
|
|
|
21
21
|
<#>: max_inner_product
|
|
22
22
|
<=>: cosine_distance
|
|
23
23
|
|
|
24
|
-
## Backlog
|
|
25
|
-
- After dropping support for SQLAlchemy 1.3, use
|
|
26
|
-
`class FloatVector(sa.TypeDecorator[t.Sequence[float]]):`
|
|
27
|
-
|
|
28
24
|
## Origin
|
|
29
25
|
This module is based on the corresponding pgvector implementation
|
|
30
26
|
by Andrew Kane. Thank you.
|
|
@@ -86,7 +82,7 @@ def to_db(value: t.Any, dim: t.Optional[int] = None) -> t.Optional[t.List]:
|
|
|
86
82
|
return value
|
|
87
83
|
|
|
88
84
|
|
|
89
|
-
class FloatVector(sa.TypeDecorator):
|
|
85
|
+
class FloatVector(sa.TypeDecorator[t.Sequence[float]]):
|
|
90
86
|
"""
|
|
91
87
|
SQLAlchemy `FloatVector` data type for CrateDB.
|
|
92
88
|
"""
|
{sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0/src/sqlalchemy_cratedb.egg-info}/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
|
|
@@ -62,12 +62,12 @@ License-File: LICENSE
|
|
|
62
62
|
License-File: NOTICE
|
|
63
63
|
Requires-Dist: crate<3,>=2.2.1
|
|
64
64
|
Requires-Dist: geojson<4,>=2.5
|
|
65
|
-
Requires-Dist: sqlalchemy<2.2,>=1
|
|
65
|
+
Requires-Dist: sqlalchemy<2.2,>=1.4
|
|
66
66
|
Requires-Dist: verlib2<26.3
|
|
67
67
|
Provides-Extra: all
|
|
68
68
|
Requires-Dist: sqlalchemy-cratedb[vector]; extra == "all"
|
|
69
69
|
Provides-Extra: develop
|
|
70
|
-
Requires-Dist: mypy<2.
|
|
70
|
+
Requires-Dist: mypy<2.5; extra == "develop"
|
|
71
71
|
Requires-Dist: poethepoet<1; extra == "develop"
|
|
72
72
|
Requires-Dist: pyproject-fmt<3; extra == "develop"
|
|
73
73
|
Requires-Dist: ruff<0.16; extra == "develop"
|
{sqlalchemy_cratedb-0.44.0 → sqlalchemy_cratedb-0.45.0}/src/sqlalchemy_cratedb.egg-info/SOURCES.txt
RENAMED
|
@@ -25,8 +25,6 @@ src/sqlalchemy_cratedb.egg-info/entry_points.txt
|
|
|
25
25
|
src/sqlalchemy_cratedb.egg-info/requires.txt
|
|
26
26
|
src/sqlalchemy_cratedb.egg-info/top_level.txt
|
|
27
27
|
src/sqlalchemy_cratedb/compat/__init__.py
|
|
28
|
-
src/sqlalchemy_cratedb/compat/api13.py
|
|
29
|
-
src/sqlalchemy_cratedb/compat/core10.py
|
|
30
28
|
src/sqlalchemy_cratedb/compat/core14.py
|
|
31
29
|
src/sqlalchemy_cratedb/compat/core20.py
|
|
32
30
|
src/sqlalchemy_cratedb/support/__init__.py
|
|
@@ -40,6 +38,7 @@ src/sqlalchemy_cratedb/type/ip.py
|
|
|
40
38
|
src/sqlalchemy_cratedb/type/object.py
|
|
41
39
|
src/sqlalchemy_cratedb/type/unresolved.py
|
|
42
40
|
src/sqlalchemy_cratedb/type/vector.py
|
|
41
|
+
tests/test_documentation.py
|
|
43
42
|
tests/test_error_handling.py
|
|
44
43
|
tests/test_schema.py
|
|
45
44
|
tests/test_support_pandas.py
|
|
@@ -0,0 +1,200 @@
|
|
|
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
|
+
from __future__ import absolute_import
|
|
23
|
+
|
|
24
|
+
import doctest
|
|
25
|
+
import logging
|
|
26
|
+
import os
|
|
27
|
+
import unittest
|
|
28
|
+
from pprint import pprint
|
|
29
|
+
|
|
30
|
+
import pytest
|
|
31
|
+
from crate.client import connect
|
|
32
|
+
|
|
33
|
+
from sqlalchemy_cratedb.sa_version import SA_2_0, SA_VERSION
|
|
34
|
+
|
|
35
|
+
log = logging.getLogger()
|
|
36
|
+
ch = logging.StreamHandler()
|
|
37
|
+
ch.setLevel(logging.ERROR)
|
|
38
|
+
log.addHandler(ch)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def cprint(s):
|
|
42
|
+
if isinstance(s, bytes):
|
|
43
|
+
s = s.decode("utf-8")
|
|
44
|
+
print(s) # noqa: T201
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def docs_path(*parts):
|
|
48
|
+
return os.path.abspath(os.path.join(os.path.dirname(os.path.dirname(__file__)), *parts))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def provision_database(crate_host):
|
|
52
|
+
drop_tables(crate_host)
|
|
53
|
+
|
|
54
|
+
with connect(crate_host) as conn:
|
|
55
|
+
cursor = conn.cursor()
|
|
56
|
+
|
|
57
|
+
with open(docs_path("tests/assets/locations.sql")) as s:
|
|
58
|
+
stmt = s.read()
|
|
59
|
+
cursor.execute(stmt)
|
|
60
|
+
stmt = "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 'locations'"
|
|
61
|
+
cursor.execute(stmt)
|
|
62
|
+
assert cursor.fetchall()[0][0] == 1
|
|
63
|
+
|
|
64
|
+
# `/assets` is mounted into the CrateDB container, see `tests/conftest.py`.
|
|
65
|
+
data_path = "/assets/locations.jsonl"
|
|
66
|
+
|
|
67
|
+
cursor.execute("COPY locations FROM ?", (data_path,))
|
|
68
|
+
cursor.execute("REFRESH TABLE locations")
|
|
69
|
+
cursor.execute(
|
|
70
|
+
"CREATE BLOB TABLE myfiles CLUSTERED INTO 1 SHARDS " + "WITH (number_of_replicas=0)"
|
|
71
|
+
)
|
|
72
|
+
cursor.execute("CREATE USER me WITH (password = 'my_secret_pw')")
|
|
73
|
+
cursor.execute("CREATE USER trusted_me")
|
|
74
|
+
|
|
75
|
+
cursor.close()
|
|
76
|
+
|
|
77
|
+
ddl_statements = [
|
|
78
|
+
"""
|
|
79
|
+
CREATE TABLE characters (
|
|
80
|
+
id STRING PRIMARY KEY,
|
|
81
|
+
name STRING,
|
|
82
|
+
quote STRING,
|
|
83
|
+
details OBJECT,
|
|
84
|
+
more_details ARRAY(OBJECT),
|
|
85
|
+
INDEX name_ft USING FULLTEXT(name) WITH (analyzer = 'english'),
|
|
86
|
+
INDEX quote_ft USING FULLTEXT(quote) WITH (analyzer = 'english')
|
|
87
|
+
)""",
|
|
88
|
+
"""
|
|
89
|
+
CREATE VIEW characters_view
|
|
90
|
+
AS SELECT * FROM characters
|
|
91
|
+
""",
|
|
92
|
+
"""
|
|
93
|
+
CREATE TABLE cities (
|
|
94
|
+
name STRING PRIMARY KEY,
|
|
95
|
+
coordinate GEO_POINT,
|
|
96
|
+
area GEO_SHAPE
|
|
97
|
+
)""",
|
|
98
|
+
"""
|
|
99
|
+
CREATE TABLE search (
|
|
100
|
+
name STRING PRIMARY KEY,
|
|
101
|
+
text STRING,
|
|
102
|
+
embedding FLOAT_VECTOR(3)
|
|
103
|
+
)""",
|
|
104
|
+
]
|
|
105
|
+
_execute_statements(crate_host, ddl_statements)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def drop_tables(crate_host):
|
|
109
|
+
"""
|
|
110
|
+
Drop all tables, views, and users created by the test suite.
|
|
111
|
+
"""
|
|
112
|
+
ddl_statements = [
|
|
113
|
+
"DROP TABLE IF EXISTS archived_tasks",
|
|
114
|
+
"DROP TABLE IF EXISTS characters",
|
|
115
|
+
"DROP TABLE IF EXISTS cities",
|
|
116
|
+
"DROP TABLE IF EXISTS foobar",
|
|
117
|
+
"DROP TABLE IF EXISTS locations",
|
|
118
|
+
"DROP BLOB TABLE IF EXISTS myfiles",
|
|
119
|
+
"DROP TABLE IF EXISTS search",
|
|
120
|
+
'DROP TABLE IF EXISTS "test-testdrive"',
|
|
121
|
+
"DROP TABLE IF EXISTS todos",
|
|
122
|
+
'DROP TABLE IF EXISTS "user"',
|
|
123
|
+
"DROP VIEW IF EXISTS characters_view",
|
|
124
|
+
"DROP USER IF EXISTS me",
|
|
125
|
+
"DROP USER IF EXISTS trusted_me",
|
|
126
|
+
]
|
|
127
|
+
_execute_statements(crate_host, ddl_statements)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _execute_statements(crate_host, statements, on_error="raise"):
|
|
131
|
+
with connect(crate_host) as conn:
|
|
132
|
+
cursor = conn.cursor()
|
|
133
|
+
for stmt in statements:
|
|
134
|
+
_execute_statement(cursor, stmt, on_error=on_error)
|
|
135
|
+
cursor.close()
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _execute_statement(cursor, stmt, on_error="raise"):
|
|
139
|
+
if on_error not in ["ignore", "raise"]:
|
|
140
|
+
raise ValueError(f"Invalid value for `on_error` argument: {on_error}")
|
|
141
|
+
try:
|
|
142
|
+
cursor.execute(stmt)
|
|
143
|
+
except Exception: # pragma: no cover
|
|
144
|
+
# FIXME: Why does this croak on statements like ``DROP TABLE cities``?
|
|
145
|
+
# Note: When needing to debug the test environment, you may want to
|
|
146
|
+
# enable this logger statement.
|
|
147
|
+
# log.exception("Executing SQL statement failed") # noqa: ERA001
|
|
148
|
+
if on_error == "ignore":
|
|
149
|
+
pass
|
|
150
|
+
elif on_error == "raise":
|
|
151
|
+
raise
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def setUp(test):
|
|
155
|
+
provision_database(test.globs["crate_host"])
|
|
156
|
+
|
|
157
|
+
test.globs["pprint"] = pprint
|
|
158
|
+
test.globs["print"] = cprint
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def tearDown(test):
|
|
162
|
+
# The CrateDB instance is shared with the rest of the test suite.
|
|
163
|
+
drop_tables(test.globs["crate_host"])
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
DOCTEST_FILES = [
|
|
167
|
+
"docs/getting-started.rst",
|
|
168
|
+
"docs/crud.rst",
|
|
169
|
+
"docs/working-with-types.rst",
|
|
170
|
+
"docs/advanced-querying.rst",
|
|
171
|
+
pytest.param(
|
|
172
|
+
"docs/dataframe.rst",
|
|
173
|
+
marks=pytest.mark.skipif(
|
|
174
|
+
SA_VERSION < SA_2_0,
|
|
175
|
+
reason="Don't run DataFrame integration tests on SQLAlchemy 1.4 and earlier",
|
|
176
|
+
),
|
|
177
|
+
),
|
|
178
|
+
"docs/inspection-reflection.rst",
|
|
179
|
+
]
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
@pytest.mark.parametrize("filename", DOCTEST_FILES)
|
|
183
|
+
def test_documentation(crate_host, filename):
|
|
184
|
+
"""
|
|
185
|
+
Run the doctests of a documentation page against the session's CrateDB instance.
|
|
186
|
+
"""
|
|
187
|
+
suite = doctest.DocFileSuite(
|
|
188
|
+
docs_path(filename),
|
|
189
|
+
module_relative=False,
|
|
190
|
+
setUp=setUp,
|
|
191
|
+
tearDown=tearDown,
|
|
192
|
+
globs={"crate_host": crate_host},
|
|
193
|
+
optionflags=doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS,
|
|
194
|
+
encoding="utf-8",
|
|
195
|
+
)
|
|
196
|
+
result = unittest.TestResult()
|
|
197
|
+
suite.run(result)
|
|
198
|
+
problems = result.failures + result.errors
|
|
199
|
+
if problems:
|
|
200
|
+
pytest.fail("\n".join(traceback for _, traceback in problems), pytrace=False)
|
|
@@ -14,7 +14,11 @@ def test_statement_with_error_trace(cratedb_service):
|
|
|
14
14
|
connection.execute(sa.text("CREATE TABLE foo AS SELECT 1 AS _id"))
|
|
15
15
|
|
|
16
16
|
# Make sure both variants match, to validate it's actually an error trace.
|
|
17
|
-
assert ex.match(
|
|
17
|
+
assert ex.match(
|
|
18
|
+
re.escape('InvalidColumnNameException["_id" conflicts with system column')
|
|
19
|
+
+ r"( pattern)?\]"
|
|
20
|
+
)
|
|
21
|
+
assert ex.match(re.escape('InvalidColumnNameException["_id" conflicts with system column'))
|
|
18
22
|
assert ex.match(
|
|
19
23
|
'io.crate.exceptions.InvalidColumnNameException: "_id" conflicts with system column'
|
|
20
24
|
)
|