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 86789ae commit dc63a7e
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: # pragma: nocover
from crate.client.sqlalchemy.dialect import CrateDialect as dialect

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: # pragma: nocover
from crate.client.sqlalchemy.support import insert_bulk

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: # pragma: nocover
from crate.client.sqlalchemy.support import insert_bulk

# 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==1.0.0dev0",
'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 dc63a7e

Please sign in to comment.