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

feat(duckdb): add support for exp.ArrayJoin #3102

Merged
merged 2 commits into from
Mar 8, 2024

Conversation

seruman
Copy link
Contributor

@seruman seruman commented Mar 8, 2024

Noticed this while transpiling a Snowflake query into DuckDB;

query = "SELECT ARRAY_TO_STRING(id, ',') AS ids FROM some_table;"
e = sqlglot.parse_one(query, read="snowflake")
dsql = e.sql(dialect="duckdb", pretty=True)

print(dsql)

# SELECT
#   ARRAY_JOIN(id, ',') AS ids
# FROM some_table

AFAIS equivalent of ArrayJoin in DuckDB -luckly- would be array_to_string.

I'm not sure I've totally understand the test structure though, should there be cases for each dialect or is it sufficient enough like this?

@@ -666,6 +666,13 @@ def test_duckdb(self):
"""SELECT i FROM GENERATE_SERIES(0, 12) AS _(i) ORDER BY i ASC""",
)

self.validate_all(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can delete this test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -678,6 +678,7 @@ def test_snowflake(self):
write={
"spark": "ARRAY_JOIN(x, '')",
"snowflake": "ARRAY_TO_STRING(x, '')",
"duckdb": "ARRAY_TO_STRING(x, '')",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a test here read={
"duckdb": "ARRAY_TO_STRING(x, '')"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@tobymao
Copy link
Owner

tobymao commented Mar 8, 2024

thanks!

@tobymao tobymao merged commit ddab9df into tobymao:main Mar 8, 2024
5 checks passed
@seruman seruman deleted the duckdb-array-join branch March 8, 2024 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants