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: add support to_json() in DuckDB #330

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

keen85
Copy link

@keen85 keen85 commented Mar 9, 2025

Adds support for DuckDB's to_json() function; compatible to PySparks's to_json()

@keen85 keen85 marked this pull request as ready for review March 9, 2025 09:10
@keen85 keen85 requested a review from eakmanrq as a code owner March 9, 2025 09:10
@@ -2360,7 +2360,7 @@ def from_json(
return Column.invoke_anonymous_function(col, "FROM_JSON", schema)


@meta(unsupported_engines=["bigquery", "duckdb", "postgres", "snowflake"])
@meta(unsupported_engines=["bigquery", "postgres", "snowflake"])
def to_json(col: ColumnOrName, options: t.Optional[t.Dict[str, str]] = None) -> Column:
if options is not None:
Copy link
Author

@keen85 keen85 Mar 9, 2025

Choose a reason for hiding this comment

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

I just noticed that DuckDB's behavior is a little bit different to PySpark's when applied to a STRUCT column:
DuckDB inludes all struct fields no matter what; PySpark omits fields containing NULL values.
So DuckDB's to_json(col) is equivalent to PySpark's to_json(col, options={"ignoreNullFields": False})

@eakmanrq, should we raise an error if options.get("ignoreNullFields", True) is not False; should we warn the users that options are not supported in DuckDB except ignoreNullFields=False

@keen85 keen85 marked this pull request as draft March 9, 2025 13:23
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.

1 participant