-
Notifications
You must be signed in to change notification settings - Fork 550
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
Support relation visitor to visit the Option
field
#1556
Conversation
Option
field
Option
fieldOption
field
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 @goldmedal . I think there were some other fields that have some wrapping structure simply because this feature was missing
I think we will also have to release a new version of sqlparser derive (which we don't always do) as part of this release given the change to the proc macro; I left a note to remind us here
I will also test this with DataFusion as well and report back
@@ -7653,6 +7653,7 @@ impl fmt::Display for ShowStatementInParentType { | |||
pub struct ShowStatementIn { | |||
pub clause: ShowStatementInClause, | |||
pub parent_type: Option<ShowStatementInParentType>, | |||
#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))] |
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 took a look through the code, and it appears there are oehter fields that hold relation names that are not visited
For example:
https://github.com/alamb/sqlparser-rs/blob/a8432b57db6b8efc635e4903d712e76f7adb6e6d/src/ast/ddl.rs#L712-L713
datafusion-sqlparser-rs/src/ast/dml.rs
Lines 580 to 581 in 4c629e8
/// Multi tables delete are supported in mysql | |
pub tables: Vec<ObjectName>, |
Maybe we can file a ticket to annotate these ones 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.
Filed #1568 to track it.
fn is_option(ty: &Type) -> bool { | ||
if let Type::Path(TypePath { path: Path { segments, .. }, .. }) = ty { | ||
if let Some(segment) = segments.last() { | ||
if segment.ident == "Option" { |
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.
it seems in theory this would match anything called Option
(even if it wasn't std::Option
) but I think that seems ok to me (I don't think we'll have anything else realistically)
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.
Agreed, I think we won't have another struct called Option
in this project 🤔. Or we can match the full path with std::option::Option
or core::option::Option
if required.
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.
Thanks @goldmedal!
I double checked with apache/datafusion#13546 and this works great. Thank you again @goldmedal and @iffyio |
close #1554
If the field is a
Option
and add#[with = "visit_xxx"]
to the field, the generated codewill try to access the field only if it is
Some
:This will generate