Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion cratedb_toolkit/testing/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""
Provide a CrateDB service instance to the test suite.
"""
db = CrateDBTestAdapter()
db = CrateDBTestAdapter(crate_version="nightly")

Check warning on line 13 in cratedb_toolkit/testing/pytest.py

View check run for this annotation

Codecov / codecov/patch

cratedb_toolkit/testing/pytest.py#L13

Added line #L13 was not covered by tests
db.start()
yield db
db.stop()
Expand Down
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
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def cratedb_custom_service():
"""
Provide a CrateDB service instance to the test suite.
"""
db = CrateDBTestAdapter()
db = CrateDBTestAdapter(crate_version="nightly")
db.start(ports={CRATEDB_HTTP_PORT: None}, cmd_opts=CRATEDB_SETTINGS)
db.reset(tables=RESET_TABLES)
yield db
Expand Down