-
Notifications
You must be signed in to change notification settings - Fork 120
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
[master < T521-FL] Fix nested FOREACH variable shadowing bug #725
Conversation
As mentioned in Slack, this fix causes the following test to fail: while this fix solves the issue linked, which is to be able to run: Personally I think the first foreach query doesn't make sense and should throw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are on the good path, however I think there is one thing that can be confusing: the difference between the following two queries:
FOREACH (i IN [1] | FOREACH (j IN [3,4] | CREATE (i {prop: j})));
FOREACH (i IN [1] | FOREACH (j IN [3,4] | CREATE (o {prop: j})));
The first one won't create any nodes, but the second one will create 2 nodes. How could we phrase that properly for the users? In my opinion we cannot explain this behavior in a way that users can understand. As I see there are two ways to make this easier to understand for the users:
- Make shadowing a actual error. This is basically removing the "multi-scope" functionality we introduced with FOREACH.
- We should clearly check whether we are introducing a new identifier (e.g.:
CREATE (i {prop:1})
introducesi
) or want to reference and existing one (e.g.:CREATE (n {prop:j})
referencesj
, not introducing it). Every time we want to create an identifier, we only operate on the local scope, but when we want to reference a variable, then we should consider the parent scopes also. After Wednesday I can have a brief look and help you if you need help.
Even though I am against of releasing this in the current state (it will create a lot of confusion and angry users in my opinion), @gitbuda what do you think?
In the current state, shadowing does throw an error, that we are trying to redeclare a variable. It is intuitive to me that you wouldn't use a variable that you use for iteration inside the foreach, same as using the iterator in a for loop. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I was checking this PR on my local machine and somehow I messed up the pull and I was checking the wrong state of the PR.
Since like we are back on track here, I think we have time here 😄 |
Two more comment that popped into my mind: the functions
These are only my thoughts, not a decision from team/somebody, so please feel free to comment/argue them. |
I would agree that we don't need shadowing then, but we would need to see about edge cases, what are the arguments for having it. Do you maybe have some examples where shadowing is used? |
The only reason we did allow shadowing is being as close as Neo4j as possible. I would be surprised if it would change anything on the expressiveness of (the our subset of) openCypher, so I think we can be aggressive on this: remove and see if anybody complains about this. The very only reason I can think of is when a user is debugging a query and tries to nest foreaches, then it might be easier to copy-paste the inner part, but that doesn't worth keeping this (bugphrone) architecture alive in my opinion. |
I removed a total of 3 tests that were failing after removing local scope, coincidentally all related to FOREACH.
Note: I assumed
|
One inconvenience is, for:
query returns only one node, the last one created, while all three are created. |
@brunos252 don't forget to link to provide a link to docs PR if there is need for one and changelog PR so I can merge this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check what is with removed test, otherwise seems like changes Benjo requested are here and implemented.
[master < Task] PR