Skip to content

feat: add object_agg transformation#315

Open
ilkinulas wants to merge 1 commit intotekumara:mainfrom
ilkinulas:add-object-agg
Open

feat: add object_agg transformation#315
ilkinulas wants to merge 1 commit intotekumara:mainfrom
ilkinulas:add-object-agg

Conversation

@ilkinulas
Copy link

Adds support for Snowflake's OBJECT_AGG aggregate function, which builds a JSON object from key-value pairs.

Example

Snowflake query:

SELECT id, OBJECT_AGG(key_col, value_col) AS obj
FROM test_table GROUP BY id ORDER BY id;

Duckdb equivalent:

SELECT id, TO_JSON(MAP(
    LIST(key_col) FILTER (WHERE NOT key_col IS NULL AND NOT value_col IS NULL),
    LIST(value_col) FILTER (WHERE NOT key_col IS NULL AND NOT value_col IS NULL)
)) AS obj
FROM test_table GROUP BY id ORDER BY id;
  • Uses FILTER to skip NULL values, matching Snowflake's default behavior
  • Wraps values in TO_JSON to preserve their original types
  • Follows the same pattern as the existing array_agg transformation

Convert Snowflake's OBJECT_AGG(key, value) to DuckDB equivalent using
TO_JSON(MAP(LIST(...) FILTER(...), LIST(TO_JSON(...)) FILTER(...))).
Skips NULL values to match Snowflake behavior.
@ilkinulas ilkinulas changed the title feat: add object_agg transformationc feat: add object_agg transformation Mar 18, 2026
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