Skip to content

Implement list comprehension - #1739

Merged
dehowef merged 2 commits into
apache:PG13from
MuhammadTahaNaveed:list_comp_PG13
Apr 9, 2024
Merged

Implement list comprehension#1739
dehowef merged 2 commits into
apache:PG13from
MuhammadTahaNaveed:list_comp_PG13

Conversation

@MuhammadTahaNaveed

Copy link
Copy Markdown
Member

Adds the OpenCypher spec for List Comprehension to AGE. Also added a commit to remove shift/reduce conflict in grammar.

Syntax

[
<variable> // variable to assume values from list
IN <list> // a list or something that creates one
WHERE <condition> // optional condition using the above variable
| <mapping> // optional mapping function
]

Example

[u IN [1,2,3] WHERE u>1 | u^2]

Known Issue

List comprehension as property constraint of MERGE clause errors out. Created issue #1611 for that.

Co-authored-by:
John Jemignani
Zainab Saad
Muhammad Taha Naveed

MuhammadTahaNaveedand others added 2 commits April 8, 2024 11:13
* Add initial code for list comprehension
- Additionally, fixed a bug in nested queries.
* Resolve variable scope and ambigous variable issue
- For scoping the variable, remove the pnsi from namespace list after
being used by the list comprehension.
- To resolve the ambigous variable issue, only scan the pnsi of
list_comp subquery.
* Fix non agg plan node issue in list comprehension
- Resolved the issue 'aggref found in non-agg plan node'
when the list comprehension is used as a property constraint in
MATCH and other clauses or when used in WHERE clause. Intead of adding
qual in the jointree, we are now adding the qual in having node of
query.
e.g.
MATCH (n {list: [for i in [1,2,3]]})
MATCH (n) WHERE n.list=[for i in [1,2,3]]
WITH n WHERE n.list=[for i in [1,2,3]]
- Removed redundant call to function tranform_cypher_clause_with_where
by tranform_match_clause.
* Resolve variable reuse issue in list comprehension
- Also, for scoping list comprehension variable, instead of removing
the pnsi of list comp from namespace, now we just mark the cols of
pnsi as not visible.
* Modify grammer to match opencypher list comprehension grammer
- Also added initial regression tests for list comprehension
* Add regression tests for bugs resolved
- Includes tests for nested cases, ambigous variable issue, list
comprehension variable scoping and planner node aggref issue.
- Should be added more.
* Resolve invalid output on multiple list comprehensions
- Fix the output of multiple list comprehensions in the RETURN clause
and the WHERE clause.
- Added regression tests for the above and some for the previous bugs
resolved.
* Fix aggref found where not expected issue (#189)
- Resolved the 'aggref found where not expected' error thrown when
using list comprehensions in UNWIND, or as a property update
expression in SET or in the comparison expressions, typecasts or
string matching in WITH - WHERE clause
- Added an error to be thrown when using aggregation functions in UNWIND
and property update expr in SET clause
- Added regression tests
* cleanup: Remove dead code and formatting changes
---------
Co-authored-by: John Gemignani <jrgemignani@gmail.com>
Co-authored-by: Zainab Saad <105385638+Zainab-Saad@users.noreply.github.com>
- The grammar had a shift/reduce conflict due to the ambiguity of the
`IN` keyword. This is resolved by adding generic rule and manually
resolving to the correct specific rule.
- Added additional test cases.
@github-actionsgithub-actionsBot added the PG13 PostgreSQL13 label Apr 8, 2024
@dehowef
dehowef merged commit a69e5a2 into apache:PG13Apr 9, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PG13PostgreSQL13

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@MuhammadTahaNaveed@jrgemignani@dehowef