Skip to content

Commit

Permalink
chore(clickhouse): remove sqlalchemy dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Dec 22, 2023
1 parent 53bd3ea commit e04194d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
37 changes: 22 additions & 15 deletions ibis/backends/clickhouse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from contextlib import closing
from functools import partial
from typing import TYPE_CHECKING, Any, Literal
from urllib.parse import parse_qs, urlparse

import clickhouse_connect as cc
import pyarrow as pa
import pyarrow_hotfix # noqa: F401
import sqlalchemy as sa
import sqlglot as sg
import sqlglot.expressions as sge
import toolz
Expand Down Expand Up @@ -74,21 +74,28 @@ def _from_url(self, url: str, **kwargs) -> BaseBackend:
BaseBackend
A backend instance
"""
url = sa.engine.make_url(url)

kwargs = toolz.merge(
{
name: value
for name in ("host", "port", "database", "password")
if (value := getattr(url, name, None))
},
kwargs,
)
if username := url.username:
kwargs["user"] = username

kwargs.update(url.query)
url = urlparse(url)
database = url.path[1:]
query_params = parse_qs(url.query)

connect_args = {
"user": url.username,
"password": url.password or "",
"host": url.hostname,
"database": database or "",
}

for name, value in query_params.items():
if len(value) > 1:
connect_args[name] = value
elif len(value) == 1:
connect_args[name] = value[0]
else:
raise com.IbisError(f"Invalid URL parameter: {name}")

kwargs.update(connect_args)
self._convert_kwargs(kwargs)

return self.connect(**kwargs)

def _convert_kwargs(self, kwargs):
Expand Down
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ bigquery = [
"google-cloud-bigquery-storage",
"pydata-google-auth",
]
clickhouse = ["clickhouse-connect", "sqlalchemy"]
clickhouse = ["clickhouse-connect"]
dask = ["dask", "regex"]
datafusion = ["datafusion"]
druid = ["pydruid", "sqlalchemy"]
Expand Down

0 comments on commit e04194d

Please sign in to comment.