Skip to content

[master < T0808-MG] Implement foreach clause#351

Merged
kostasrim merged 26 commits intomasterfrom
T0808-MG-implement-foreach-clause
Apr 11, 2022
Merged

[master < T0808-MG] Implement foreach clause#351
kostasrim merged 26 commits intomasterfrom
T0808-MG-implement-foreach-clause

Conversation

@kostasrim
Copy link
Contributor

@kostasrim kostasrim commented Feb 9, 2022

[master < Epic] PR

  • Check, and update documentation if necessary
  • Update changelog
  • Write E2E tests
  • Compare the benchmarking results between the master branch and the Epic branch

[master < Task] PR

  • Check, and update documentation if necessary
  • Update changelog

Closes #308

@kostasrim kostasrim force-pushed the T0808-MG-implement-foreach-clause branch from 1c09161 to 2d7a57b Compare February 13, 2022 00:51
Copy link
Member

@gitbuda gitbuda left a comment

Choose a reason for hiding this comment

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

The PR is still in the draft phase, but I put a couple of comments 😄 It has a bunch of stuff, mostly adding new stuff, so the whole PR is mainly about the correctness of the newly added stuff rather than breaking the existing functionalities.

In addition to the comments in the code, please start writing docs pages under memgraph/docs and link them here. Outline basic things and then docs people can take over at some point and build examples and how-to guides 💪

Not far from being ready for 🚀

@kostasrim kostasrim self-assigned this Feb 28, 2022
@kostasrim kostasrim marked this pull request as ready for review February 28, 2022 19:29
@kostasrim kostasrim changed the title [master < T0808-MG] WIP - Implement foreach clause [master < T0808-MG] Implement foreach clause Feb 28, 2022
Copy link
Contributor

@antaljanosbenjamin antaljanosbenjamin left a comment

Choose a reason for hiding this comment

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

I still have to understand the rule based planner and check the tests, but my brain is burnt out.

@antaljanosbenjamin
Copy link
Contributor

After today's daily we discussed this PR and we found a good example why the current approach is not good:

CREATE (n {prop: [1,2]});
MATCH (n) FOREACH ( i IN n.prop | CREATE (:V { i: i})) RETURN n;

the second query should return one row, but for us it returns two. That is the main reason we should somehow embed another plane inside FOREACH instead of making one, "linear" plan.

Maybe we don't need the embed a plan, we can build one plan, but the FOREACH should have an additional side branch which contains all the inside clauses. Let's call them main and side. When the FOREACH is pulled, it should pull main once, populate the frame with everything that is necessary for side, and then it should exhaust side and "pass through" the original row from main. I don't see the exact implementation, but I think this is doable.

Tomorrow we will discuss this in more details.

@antaljanosbenjamin
Copy link
Contributor

Another query that doesn't behave correctly in my opinion: MATCH (n) FOREACH ( li IN n.prop | CREATE (:F4 {prop: li}) CREATE (m:F5 {prop2: li}) SET n.li = li) RETURN m;

It should fail because m shouldn't be defined in RETURN, but it succeeds:

memgraph> MATCH (n) DETACH DELETE n;
Empty set (0.001 sec)
memgraph> CREATE (n {prop: [1,2]});
Empty set (0.001 sec)
memgraph> MATCH (n) FOREACH ( li IN n.prop | CREATE (:F4 {prop: li}) CREATE (m:F5 {prop2: li}) SET n.li = li) RETURN m;
+------------------+
| m                |
+------------------+
| (:F5 {prop2: 1}) |
| (:F5 {prop2: 2}) |
+------------------+
2 rows in set (0.001 sec)

@kostasrim kostasrim force-pushed the T0808-MG-implement-foreach-clause branch from 9cd1ab0 to 2e89108 Compare March 31, 2022 19:57
@kostasrim kostasrim force-pushed the T0808-MG-implement-foreach-clause branch from 2e89108 to 124b070 Compare March 31, 2022 20:56
Copy link
Contributor

@antaljanosbenjamin antaljanosbenjamin left a comment

Choose a reason for hiding this comment

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

The improvement is quite good, however there are a few small things to change in my opinion.

@kostasrim kostasrim force-pushed the T0808-MG-implement-foreach-clause branch 4 times, most recently from 9172e92 to 4d74795 Compare April 3, 2022 11:14
@kostasrim kostasrim force-pushed the T0808-MG-implement-foreach-clause branch from 4d74795 to b130439 Compare April 3, 2022 12:43
@kostasrim kostasrim force-pushed the T0808-MG-implement-foreach-clause branch from 560b19b to 05f58f1 Compare April 3, 2022 18:24
Copy link
Contributor

@antaljanosbenjamin antaljanosbenjamin left a comment

Choose a reason for hiding this comment

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

Looking really nice. I commented on small things and plan to have another review tomorrow in the morning, to check SymbolGenerator/CypherMainVisitor again, to make sure I didn't miss anything.

@kostasrim
Copy link
Contributor Author

docs PR memgraph/docs#355

@kostasrim kostasrim merged commit ea2806b into master Apr 11, 2022
@kostasrim kostasrim deleted the T0808-MG-implement-foreach-clause branch April 11, 2022 10:55
as51340 pushed a commit that referenced this pull request Oct 24, 2025
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.

The FOREACH language construct for performing an operation on every list element

4 participants