apache / apache/datafusion

Postgres `ARRAY_AGG(JSON_BUILD_OBJECT())` equivalent? Possible with `struct` SQL operator?

Open
#1,897 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
9.3k
Forks
2.4k
Avg merge
3d 7h
Merged PRs (30d)
344

Description

Curious whether it's possible to write SQL queries that do nested JSON selections in Datafusion.
IE, something like the below:

```sql
select json_agg(json_build_object(
'id', "houses"."id",
'address', "houses"."address",
'users', (
select json_agg(json_build_object(
'id', "users"."id",
'name', "users"."name"
))
from "users"
where "users"."house_id" = "houses"."id"
)
))
from "houses" as "houses"
```

Thank you =)

Contributor guide

Open the contributing guide

Research direction

The issue provides no file, test, or entry point. Start by checking DataFusion's SQL support for JSON aggregation, struct operators, and correlated nested queries, then define the supported equivalent and add coverage for the supplied houses-and-users example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, sql
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.