Skip to content

Refactor!: map duckdb LIST to ArrayAgg#7552

Merged
georgesittas merged 1 commit intomainfrom
jo/map_ddb_list_to_array_agg
Apr 23, 2026
Merged

Refactor!: map duckdb LIST to ArrayAgg#7552
georgesittas merged 1 commit intomainfrom
jo/map_ddb_list_to_array_agg

Conversation

@georgesittas
Copy link
Copy Markdown
Collaborator

@georgesittas georgesittas commented Apr 23, 2026

This is Copilot's response when I asked whether LIST and ARRAY_AGG are synonymous in DuckDB:

«In DuckDB, list(expr) and array_agg(expr) are essentially the same kind of aggregate: both collect the grouped input values into a single LIST (array) value.

Practical differences are mostly about name/compatibility and a few option/details, not the core semantics:

  • Purpose

    • array_agg is the more standard SQL / Postgres-style name.
    • list is a shorter DuckDB-friendly alias/name for the same idea.
  • Return type

    • Both return DuckDB’s LIST type (conceptually an array).
  • Options

    • Both typically support the same aggregate features you’d expect: DISTINCT, FILTER, and often ORDER BY within the aggregate (depending on DuckDB version).

So: yes, for normal usage they’re interchangeable—use array_agg if you want portability/readability for SQL folks, use list if you prefer the concise DuckDB idiom.

If you tell me your DuckDB version (or paste SELECT version();), I can be precise about any version-specific differences (e.g., ordering guarantees/availability of ORDER BY within the aggregate).»

Original PR: #7551

@georgesittas
Copy link
Copy Markdown
Collaborator Author

cc @maxa-jonathan-hallee

Comment thread sqlglot/parsers/duckdb.py
"JSON_ARRAY": lambda args: exp.JSONArray(expressions=args),
"JSON_EXTRACT_PATH": parser.build_extract_json_with_path(exp.JSONExtract),
"JSON_EXTRACT_STRING": parser.build_extract_json_with_path(exp.JSONExtractScalar),
"LIST": exp.ArrayAgg.from_arg_list,
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The advantage of this approach is that LIST is correctly identified as an AggFunc (because of ArrayAgg). The LIST function was added for Materializes' LIST function, which IIRC isn't an aggregate function. That's why I decided to change this.

@github-actions
Copy link
Copy Markdown
Contributor

SQLGlot Integration Test Results

Comparing:

  • this branch (sqlglot:jo/map_ddb_list_to_array_agg, sqlglot version: jo/map_ddb_list_to_array_agg)
  • baseline (main, sqlglot version: 0.0.1.dev1)

By Dialect

dialect main sqlglot:jo/map_ddb_list_to_array_agg transitions links
bigquery -> bigquery 24645/24650 passed (100.0%) 23495/23495 passed (100.0%) No change full result / delta
bigquery -> duckdb 867/1154 passed (75.1%) 0/0 passed (0.0%) Results not found full result / delta
duckdb -> duckdb 5823/5823 passed (100.0%) 5823/5823 passed (100.0%) No change full result / delta
snowflake -> duckdb 1063/1961 passed (54.2%) 1063/1961 passed (54.2%) No change full result / delta
snowflake -> snowflake 65133/65133 passed (100.0%) 65133/65133 passed (100.0%) No change full result / delta
databricks -> databricks 1370/1370 passed (100.0%) 1370/1370 passed (100.0%) No change full result / delta
postgres -> postgres 6042/6042 passed (100.0%) 6042/6042 passed (100.0%) No change full result / delta
redshift -> redshift 7101/7101 passed (100.0%) 7101/7101 passed (100.0%) No change full result / delta

Overall

main: 113234 total, 112044 passed (pass rate: 98.9%), sqlglot version: 0.0.1.dev1

sqlglot:jo/map_ddb_list_to_array_agg: 110925 total, 110027 passed (pass rate: 99.2%), sqlglot version: jo/map_ddb_list_to_array_agg

Transitions:
No change

Dialect pair changes: 0 previous results not found, 1 current results not found

✅ 34 test(s) passed

@georgesittas georgesittas merged commit e883b0b into main Apr 23, 2026
9 of 10 checks passed
@georgesittas georgesittas deleted the jo/map_ddb_list_to_array_agg branch April 23, 2026 17:55
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