Skip to content

Commit

Permalink
Dependencies: Migrate from crate[sqlalchemy] to sqlalchemy-cratedb
Browse files Browse the repository at this point in the history
The CrateDB SQLAlchemy dialect needs more love, so it was separated from
the DBAPI HTTP driver.
  • Loading branch information
amotl committed Jun 11, 2024
1 parent b5ef351 commit e6e3f13
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


## Unreleased
- Dependencies: Migrate from `crate[sqlalchemy]` to `sqlalchemy-cratedb`

## 2024/05/30 v0.0.12
- Fix InfluxDB Cloud <-> CrateDB Cloud connectivity by using
Expand Down
9 changes: 6 additions & 3 deletions cratedb_toolkit/sqlalchemy/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ def get_effective_schema(engine: sa.Engine):
schema_name = schema_name_raw[0]
return schema_name

from crate.client.sqlalchemy.dialect import CrateDialect
try:
from sqlalchemy_cratedb import dialect
except ImportError:
from crate.client.sqlalchemy.dialect import CrateDialect as dialect

Check warning on line 28 in cratedb_toolkit/sqlalchemy/patch.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/sqlalchemy/patch.py#L27-L28

Added lines #L27 - L28 were not covered by tests

get_table_names_dist = CrateDialect.get_table_names
get_table_names_dist = dialect.get_table_names

def get_table_names(self, connection: sa.Connection, schema: t.Optional[str] = None, **kw: t.Any) -> t.List[str]:
if schema is None:
schema = get_effective_schema(connection.engine)
return get_table_names_dist(self, connection=connection, schema=schema, **kw)

CrateDialect.get_table_names = get_table_names # type: ignore
dialect.get_table_names = get_table_names # type: ignore
1 change: 1 addition & 0 deletions cratedb_toolkit/util/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def setup_logging(level=logging.INFO, verbose: bool = False):
logging.getLogger("sqlalchemy").setLevel(level)

logging.getLogger("crate.client").setLevel(level)
logging.getLogger("sqlalchemy_cratedb").setLevel(level)
logging.getLogger("urllib3.connectionpool").setLevel(level)

# logging.getLogger("docker.auth").setLevel(logging.INFO) # noqa: ERA001
Expand Down
12 changes: 10 additions & 2 deletions cratedb_toolkit/util/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ def import_csv_pandas(
Import CSV data using pandas.
"""
import pandas as pd
from crate.client.sqlalchemy.support import insert_bulk

try:
from sqlalchemy_cratedb.support import insert_bulk
except ImportError:
from crate.client.sqlalchemy.support import insert_bulk

Check warning on line 251 in cratedb_toolkit/util/database.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/util/database.py#L250-L251

Added lines #L250 - L251 were not covered by tests

df = pd.read_csv(filepath)
with self.engine.connect() as connection:
Expand All @@ -267,7 +271,11 @@ def import_csv_dask(
"""
import dask.dataframe as dd
import pandas as pd
from crate.client.sqlalchemy.support import insert_bulk

try:
from sqlalchemy_cratedb.support import insert_bulk
except ImportError:
from crate.client.sqlalchemy.support import insert_bulk

Check warning on line 278 in cratedb_toolkit/util/database.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/util/database.py#L277-L278

Added lines #L277 - L278 were not covered by tests

# Set a few defaults.
npartitions = npartitions or os.cpu_count()
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ dependencies = [
"colorama<1",
"colorlog",
"crash",
"crate[sqlalchemy]>=0.34",
"crate @ git+https://github.com/crate/crate-python.git@no-sqlalchemy",
'importlib-metadata; python_version <= "3.7"',
"python-dotenv<2",
"python-slugify<9",
"sqlalchemy",
"sqlalchemy-cratedb",
"sqlparse<0.6",
'typing-extensions<5; python_version <= "3.7"',
]
Expand Down

0 comments on commit e6e3f13

Please sign in to comment.