-
Notifications
You must be signed in to change notification settings - Fork 567
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
Propagate locations throughout the parser #790
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What is the purpose of wrapping this in
Located<>
?Another alternative would be to add a location field to the
Ident
struct likeBoth will be breaking changes, but I am thinking to a future where there is location information on all structs -- if all fields all wrapped in
Location<..>
it is going to be a lot of replicatedLocation<>
in the codeIf they each have a
location
field then the location will only be added by the parser (though the tests will need updating too)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.
Great question. For some background context, I've been working on a SQL compiler that uses the
sqlparser-rs
library as our parser. We added these locations to improve the error messages in the compiler.We actually started by embedding the
location
inIdent
, but there are places where we actually want to store theIdent
itself (e.g. a map fromIdent
to some binder state about it), and in those places we don't care about theLocation
. There are also places where we want to do things like convert astring
into anIdent
, and iflocation
is a field on theIdent
, we'll have to make it empty/unknown. This isn't an issue in-and-of-itself, it just means that we won't get the typesystem's help to enforce whether or not anIdent
has a location.A second benefit to wrapping in
Located
is that we can write a bunch of functions that takeLocated<T>
(e.g. error messages) and use the location (yes, this could be accomplished with aLocated
trait too). It's essentially like a smart pointer.All of that said, I'm happy to consider another approach — I only have perspective from the one project I've been working on and want to ensure that the contributions are aligned with the long term of the community around this repo.
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.
this makes sense -- I guess I am worried about the implications on downstream crates of changing all fields to
Location
-- specifically when used inmatch
expressions there are lots of patterns like https://github.com/apache/arrow-datafusion/blob/350cb47289a76e579b221fe374e4cf09db332569/datafusion/sql/src/expr/function.rs#L168-L184Adding
Located
will require all such locations to add a new level of Located. If we add
locationas a field then at least where there are matches with default match arms
..` no changes will be required.with located wouldn't this end up looking something like
In terms of converting String to Ident what about something like an optional location? Like
And then have
I agree this would be a better approach
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 don't think so — but apologies if I'm missing something.
Located
is exactly like a smart pointer (e.g. likeBox
), so you can writeand then "pretend"
name
is just anIdent
, except that you can also call.location()
on it.Yes that's true, but the problem is that now you don't have the typesystem's help to know whether or not something has a location. For example, imagine you put these idents into a map where you "don't care" about locations. You'd need
Hash
,Eq
, etc. to ignore thelocation
field. However, there may be a separate use case where you do care about locations — what do you do then?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.
Thank you for your thoughtful reply @ankrgyl -- I plan to give this a try in the next few days. I am sorry I just don't have very much focus time to devote to sqlparser at the moment
This PR is definitely on my list
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.
Thank you! I actually open sourced the project I'm working on that uses
sqlparser-rs
this weekend: https://github.com/qscl/queryscript. It's not ready for real use yet, but you can see the fork of sqlparser, and if you feel compelled, how we use it in the code (e.g. the VSCode uses Locations to show errors in the exact right locations). Happy to chat further about it offline too if helpful.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 am sorry for my lack of communication here.
Basically I have (obviously) extremely limited time for maintenance of this crate and for that I apologize.
Given the limited maintenance bandwidth, I am very hesitant to accept a change that causes downstream churn given the possibility of requiring non trivial effort to fix here.
Basically, to merge a PR like this I would like to see what changes are required to an existing project that uses AST matching extensively. Any project that uses sqlparser-rs would do (though I am personally very familiar with https://github.com/apache/arrow-datafusion)
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.
So specifically, I want to see a PR to an existing project that pins sqlparser to this branch and shows the tests / CI passing as a demonstration of how much downstream impact it would have)
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.
Posted as a top-level comment, whoops! #790 (comment)