diff --git a/docs/Release Notes/Change Log.md b/docs/Release Notes/Change Log.md index 4545a4ef9..0e278661d 100644 --- a/docs/Release Notes/Change Log.md +++ b/docs/Release Notes/Change Log.md @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - [#112](https://github.com/mabel-dev/opteryx/issues/112) `SHOW COLUMNS` doesn't work for non sample datasets ([@joocer](https://github.com/joocer])) - [#113](https://github.com/mabel-dev/opteryx/issues/113) Sample data has NaN as a string, rather than the value ([@joocer](https://github.com/joocer])) - [#111](https://github.com/mabel-dev/opteryx/issues/111) `CROSS JOIN UNNEST` should return a `NONE` when the list is empty (or `NONE`) ([@joocer](https://github.com/joocer])) +- [#119](https://github.com/mabel-dev/opteryx/issues/119) 'NoneType' object is not iterable error on `UNNEST` ([@joocer](https://github.com/joocer])) ### [0.0.1] - 2022-05-09 diff --git a/opteryx/engine/planner/operations/cross_join_node.py b/opteryx/engine/planner/operations/cross_join_node.py index 6e8e8bb3c..3244d4d02 100644 --- a/opteryx/engine/planner/operations/cross_join_node.py +++ b/opteryx/engine/planner/operations/cross_join_node.py @@ -127,6 +127,9 @@ def _cross_join_unnest(left, column, alias): metadata = None + if alias is None: + alias = f"UNNEST({column[0]})" + for left_page in left: if metadata is None: @@ -149,7 +152,7 @@ def _cross_join_unnest(left, column, alias): new_column = [] for i, value in enumerate(column_data): # if the value isn't valid, we can't UNNEST it - if value.is_valid: + if value.is_valid and len(value.values) != 0: indexes.extend([i] * len(value)) new_column.extend(value) else: diff --git a/opteryx/version.py b/opteryx/version.py index df599446e..c02b8feaf 100644 --- a/opteryx/version.py +++ b/opteryx/version.py @@ -16,4 +16,4 @@ 2) we can import it in setup.py for the same reason """ -__version__ = "0.0.2-beta.3" +__version__ = "0.0.2-beta.4" diff --git a/tests/data/unnest_test/year_2000/month_01/day_01/unnest_test.jsonl b/tests/data/unnest_test/year_2000/month_01/day_01/unnest_test.jsonl new file mode 100644 index 000000000..f3bd21a42 --- /dev/null +++ b/tests/data/unnest_test/year_2000/month_01/day_01/unnest_test.jsonl @@ -0,0 +1,10 @@ +{ "id": 0, "values": [""] } +{ "id": 1, "values": [] } +{ "id": 2, "values": [null] } +{ "id": 3, "values": null } +{ "id": 4, "values": [] } +{ "id": 5, "values": ["value", null] } +{ "id": 6, "values": [null, "value"] } +{ "id": 7, "values": ["value1", "value2", "value3"] } +{ "id": 8, "values": [null, null] } +{ "id": 9 } \ No newline at end of file diff --git a/tests/sql_battery/test_battery_shape.py b/tests/sql_battery/test_battery_shape.py index 7ac8b0b8a..718e1e3e3 100644 --- a/tests/sql_battery/test_battery_shape.py +++ b/tests/sql_battery/test_battery_shape.py @@ -307,6 +307,8 @@ ("SELECT * FROM $planets LEFT JOIN $satellites ON $satellites.planetId = $planets.id ORDER BY $planets.name", 179, 28), # NAMED SUBQUERIES ("SELECT P.name FROM ( SELECT * FROM $planets ) AS P", 9, 1), + # UNNEST + ("SELECT * FROM tests.data.unnest_test CROSS JOIN UNNEST (values) AS value FOR '2000-01-01'", 15, 3), ] # fmt:on