Skip to content

Commit

Permalink
chore(deps): update dependency duckdb to >=0.9,<1.2 (#170)
Browse files Browse the repository at this point in the history
* chore(deps): update dependency duckdb to >=0.9,<1.2

* 1.1.0 map support

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: eakmanrq <6326532+eakmanrq@users.noreply.github.com>
  • Loading branch information
renovate[bot] and eakmanrq committed Sep 11, 2024
1 parent 38eaddb commit 7eaeedf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"google-cloud-bigquery-storage>=2,<3",
],
"dev": [
"duckdb>=0.9,<1.1",
"duckdb>=0.9,<1.2",
"findspark>=2,<3",
"mypy>=1.10.0,<1.12",
"openai>=1.30,<1.45",
Expand All @@ -54,7 +54,7 @@
"pymdown-extensions",
],
"duckdb": [
"duckdb>=0.9,<1.1",
"duckdb>=0.9,<1.2",
"pandas>=2,<3",
],
"openai": [
Expand Down
10 changes: 8 additions & 2 deletions sqlframe/duckdb/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ def __init__(self, conn: t.Optional[DuckDBPyConnection] = None, *args, **kwargs)

@classmethod
def _try_get_map(cls, value: t.Any) -> t.Optional[t.Dict[str, t.Any]]:
if value and isinstance(value, dict) and "key" in value and "value" in value:
return dict(zip(value["key"], value["value"]))
if value and isinstance(value, dict):
# DuckDB < 1.1.0 support
if "key" in value and "value" in value:
return dict(zip(value["key"], value["value"]))
# DuckDB >= 1.1.0 support
# If a key is not a string then it must not represent a column and therefore must be a map
if len([k for k in value if not isinstance(k, str)]) > 0:
return value
return None

def _execute(self, sql: str) -> None:
Expand Down
14 changes: 9 additions & 5 deletions tests/integration/engines/test_int_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ def test_lit(get_session_and_func, arg, expected):
if isinstance(session, SnowflakeSession):
if isinstance(arg, Row):
pytest.skip("Snowflake doesn't support literal row types")
if isinstance(session, DuckDBSession):
if isinstance(arg, dict):
expected = Row(**expected)
assert session.range(1).select(lit(arg).alias("test")).collect() == [Row(test=expected)]


Expand Down Expand Up @@ -2111,11 +2114,12 @@ def test_create_map(get_session_and_func, get_func):
session, create_map = get_session_and_func("create_map")
col = get_func("col", session)
df = session.createDataFrame([("Alice", 2), ("Bob", 5)], ("name", "age"))
expected = (
[Row(value={"Alice": 2}), Row(value={"Bob": 5})]
if isinstance(session, (SparkSession, PySparkSession))
else [Row(value={"alice": 2}), Row(value={"bob": 5})]
)
if isinstance(session, (SparkSession, PySparkSession)):
expected = [Row(value={"Alice": 2}), Row(value={"Bob": 5})]
elif isinstance(session, DuckDBSession):
expected = [Row(value=Row(**{"Alice": 2})), Row(value=Row(**{"Bob": 5}))]
else:
expected = [Row(value={"alice": 2}), Row(value={"bob": 5})]
# Added the cast for age for Snowflake so the data type would be correct
assert df.select(create_map("name", col("age").cast("int")).alias("blah")).collect() == expected
assert df.select(create_map([df.name, df.age.cast("int")]).alias("blah")).collect() == expected
Expand Down

0 comments on commit 7eaeedf

Please sign in to comment.