Skip to content
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

Use Scopes to resolve lambda argument references in ExpressionAnalyzer #9026

Closed
wants to merge 4 commits into from
Closed

Use Scopes to resolve lambda argument references in ExpressionAnalyzer #9026

wants to merge 4 commits into from

Conversation

findepi
Copy link
Contributor

@findepi findepi commented Sep 21, 2017

Use Scope to resolve lambda arguments in ExpressionAnalyzer.

Fixes #9023, #7784

For #7790 following things are still needed:

@findepi findepi changed the title Use Scopes to resolve lambda argument references Use Scopes to resolve lambda argument references in ExpressionAnalyzer Sep 21, 2017
@sopel39
Copy link
Contributor

sopel39 commented Sep 26, 2017

Duplicate of #7790? I am not sure it is possible to use Scopes only in ExpressionAnalyzer without modifying other classes that resolve lambda arguments (I don't think arguments resolution would behave consistently then).

@findepi
Copy link
Contributor Author

findepi commented Sep 26, 2017

This is related to #7790 -- a step towards that direction.

I agree there is risk of inconsistency. However, there already is some inconsistency (#9025) even though scopes were used nowhere, so I think this still is a good step in a good direction.

@findepi
Copy link
Contributor Author

findepi commented Oct 3, 2017

@martint , did you have time to look into this?

@martint
Copy link
Contributor

martint commented Oct 3, 2017

I did. The code looks good, but I need to think about the comment @sopel39 made above regarding inconsistencies. It'd be great if we can find concrete examples where it wouldn't work as expected (beyond the once you listed in #9025)

@findepi
Copy link
Contributor Author

findepi commented Oct 3, 2017

@sopel39 , did you have anything specific in mind?

@sopel39
Copy link
Contributor

sopel39 commented Oct 3, 2017

Resolution works differently than in TranslationMap (although it might be consistent. However this is a tricky code with edge cases). Why can't you simply make ExpressionAnalyzer.Visitor#visitIdentifier to behave like the one in TranslationMap#translateNamesToSymbols? This way we wouldn't introduce second (possibly inconsistent) resolution method for lambda arguments.

@findepi
Copy link
Contributor Author

findepi commented Oct 3, 2017

TranslationMap#translateNamesToSymbols already does it differently than ExpressionAnalyzer, see my today comments in #9025.

Can we have an example of a query that will work incorrectly after this change and used to work correctly or at least fail before?

@sopel39
Copy link
Contributor

sopel39 commented Oct 3, 2017

Can we have an example of a query that will work incorrectly after this change and used to work correctly or at least fail before?

I am not sure (I haven't deeply though about it), but this doesn't mean that there won't be any new regressions. It seems that it would be easier to make both TranslationMap and ExpressionAnalyzer to behave consistently for now (using current lambda resolution mechanism) instead of using yet another resolution method in ExpressionAnalyzer .

Then after #7398 we could switch completely to scopes for lambda resolution.

@findepi
Copy link
Contributor Author

findepi commented Oct 3, 2017

@sopel39 but the problem is in master they both do wrong (differently). After this PR, ExpressionAnalyzer will correctly resolve lambda references and captures within lambda and translation map needs to follow (I'm working on it currently) or abstain from any use of scopes (#7398).

I did a quick look into doing #7398, but the code seems both complex and 'there is room for improvement'-ish.

@sopel39
Copy link
Contributor

sopel39 commented Oct 3, 2017

translation map needs to follow

Yeah, but then you probably should use Scope for lambda arguments resolution in TranslationMap too (in order to be consistent). I am just not sure it's worth the work since Scopes would be removed from actual planning.

@sopel39
Copy link
Contributor

sopel39 commented Oct 3, 2017

but then you probably should use Scope for lambda arguments resolution in TranslationMap too

Or maybe couple of TODOs would do for now too. I don't have strong opinion either way.

@findepi
Copy link
Contributor Author

findepi commented Oct 3, 2017

@martint , @sopel39
i created follow-up PR that fixes TranslationMap and thus fixes #9025: #9090. This is not much code so it doesn't get us away from #7398 (it doesn't get us closer either).

@sopel39
Copy link
Contributor

sopel39 commented Oct 3, 2017

Yeah, but then you probably should use Scope for lambda arguments resolution in TranslationMap too

This is probably not true after all. I think in TranslationMap you can just check if node is column ref or lambda argument ref.

@findepi
Copy link
Contributor Author

findepi commented Oct 4, 2017

@sopel39 let's move the discussion related to #9090 there. Do you have any other comments relating this PR? Can @martint merge it?

@sopel39
Copy link
Contributor

sopel39 commented Oct 4, 2017

I haven't reviewed it yet (I don't know if I will have time). However, the approach to use Scope in ExpressionAnalzyzer seems legit. I would avoid using it in TranslationMap though. Generally, it appears to be easier to switch to Scope for lambda args resolution than I thought.

@findepi findepi mentioned this pull request Oct 4, 2017
@findepi
Copy link
Contributor Author

findepi commented Oct 4, 2017

@sopel39 i don't think you need to review this thoroughly, as @martint already did.

@findepi
Copy link
Contributor Author

findepi commented Oct 11, 2017

Superseded by #9099

@findepi findepi closed this Oct 11, 2017
@findepi findepi deleted the findepi/scope-lambda branch November 4, 2017 19:35
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.

Wrong query results when lambda scope shadows column name Analysis error for table alias in lambda
4 participants