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

update dependencies to fix bug on databricks has_dataset #1436

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 14 additions & 20 deletions dlt/destinations/impl/databricks/sql_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from contextlib import contextmanager, suppress
from typing import Any, AnyStr, ClassVar, Iterator, Optional, Sequence, List, Union, Dict

import pendulum
from databricks import sql as databricks_lib
from databricks.sql.client import (
Connection as DatabricksSqlConnection,
Expand Down Expand Up @@ -88,28 +89,21 @@ def execute_sql(
@raise_database_error
def execute_query(self, query: AnyStr, *args: Any, **kwargs: Any) -> Iterator[DBApiCursor]:
curr: DBApiCursor = None
# TODO: databricks connector 3.0.0 will use :named paramstyle only
# if args:
# keys = [f"arg{i}" for i in range(len(args))]
# # Replace position arguments (%s) with named arguments (:arg0, :arg1, ...)
# # query = query % tuple(f":{key}" for key in keys)
# db_args = {}
# for key, db_arg in zip(keys, args):
# # Databricks connector doesn't accept pendulum objects
# if isinstance(db_arg, pendulum.DateTime):
# db_arg = to_py_datetime(db_arg)
# elif isinstance(db_arg, pendulum.Date):
# db_arg = to_py_date(db_arg)
# db_args[key] = db_arg
# else:
# db_args = None
db_args: Optional[Union[Dict[str, Any], Sequence[Any]]]
if kwargs:
db_args = kwargs
elif args:
db_args = args
if args:
keys = [f"arg{i}" for i in range(len(args))]
# Replace position arguments (%s) with named arguments (:arg0, :arg1, ...)
query = query % tuple(f":{key}" for key in keys)
db_args = {}
for key, db_arg in zip(keys, args):
# Databricks connector doesn't accept pendulum objects
if isinstance(db_arg, pendulum.DateTime):
db_arg = to_py_datetime(db_arg)
elif isinstance(db_arg, pendulum.Date):
db_arg = to_py_date(db_arg)
db_args[key] = db_arg
else:
db_args = None
oonyoontong marked this conversation as resolved.
Show resolved Hide resolved
db_args: Optional[Union[Dict[str, Any], Sequence[Any]]]
oonyoontong marked this conversation as resolved.
Show resolved Hide resolved
with self._conn.cursor() as curr:
curr.execute(query, db_args)
yield DBApiCursorImpl(curr) # type: ignore[abstract]
Expand Down
Loading
Loading