Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fixes 4703 aggregate expressions #5071

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

Merged
merged 15 commits into from
Mar 19, 2024

Conversation

griffio
Copy link
Contributor

@griffio griffio commented Mar 13, 2024

🚧 πŸ”
fixes #4703

Supports string_agg - function requires a separator argument with optional ORDER BY
See fixture tests for variations

SELECT articles.id, slug, title, description,
COALESCE (string_agg (DISTINCT tag, ',' ORDER BY tag DESC) 
FILTER (WHERE tag IS NOT NULL)) AS articleTags
FROM articles
LEFT JOIN tags ON articles.id = tags.article_id
JOIN users ON articles.author_id = users.id
GROUP BY articles.id, users.id;

Keep existing function string_agg for the simple use and new grammar for complex cases

Supports array_agg and single parameter use-case. Returns kotlin.Array<T>

SELECT breed,
array_agg(DISTINCT name ORDER BY name DESC) FILTER (WHERE is_good = 1)
FROM dog
GROUP BY breed
ORDER BY breed;

Adds Integration tests

  • Including Array types in data classes means equality checks won't work for structural equals

Work-arounds ➰ :

  • Resolve the Expr for array_agg in PostgreSqlTypeResolver
  • coalesce, nullif function needs to support array type

griffio added 15 commits March 13, 2024 12:57
not used as requires more complex grammar
string_agg is TEXT

Keep existing function as seems to keep it working
DISTINCT...ORDER BY
TODO - need to revisit
TODO: need to improve SqlExp code
Fixture and Integration
improve coverage of variations
Move the expr type to mixin
isArrayType is used to determine if a resolved type is an array using String :[
There doesn't appear to be a way to check this in the IntermediateType
Otherwise a String is resolved as the return type, without array support in Coalesce
Use existing ordering_term
@griffio griffio marked this pull request as ready for review March 17, 2024 16:42
@griffio griffio changed the title Fix 4703 aggregate expressions Fixes 4703 aggregate expressions Mar 18, 2024
Copy link
Collaborator

@hfhbd hfhbd left a comment

Choose a reason for hiding this comment

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

Thanks!

@hfhbd hfhbd merged commit 3602833 into sqldelight:master Mar 19, 2024
@griffio griffio deleted the fix-4703-aggregate-expressions branch March 20, 2024 07:25
hfhbd pushed a commit that referenced this pull request Apr 2, 2024
* First effort at string_agg grammar

* Remove string_agg function

not used as requires more complex grammar

* Fixture tests for aggregate expressions

Complext expressions

* Add type resolution

string_agg is TEXT

Keep existing function as seems to keep it working

* make string_agg_stmt the first in order

* Fixture test for simple string_agg function call with argument

* Add Integration test

DISTINCT...ORDER BY

* Add grammar for array_agg_stmt

TODO - need to revisit

* Add array type

TODO: need to improve SqlExp code

* Add tests for array_agg

Fixture and Integration

* More tests

improve coverage of variations

* Try to improve Resolver

Move the expr type to mixin

* Support coalesce with array type

isArrayType is used to determine if a resolved type is an array using String :[
There doesn't appear to be a way to check this in the IntermediateType

* Add test for Coalesce

Otherwise a String is resolved as the return type, without array support in Coalesce

* Improve Order By

Use existing ordering_term
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Support FILTER/WHERE and ORDER BY in aggregate expressions in Postgres dialect
2 participants