-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix: Support double quotes in date_part
#10833
Conversation
@@ -127,7 +127,7 @@ impl ScalarUDFImpl for DatePartFunc { | |||
ColumnarValue::Scalar(scalar) => scalar.to_array()?, | |||
}; | |||
|
|||
let arr = match part.to_lowercase().as_str() { | |||
let arr = match part.to_lowercase().trim_matches('\'').trim_matches('"') { |
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.
key change
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.
TIL https://doc.rust-lang.org/std/primitive.str.html#method.trim_matches -- perfect 👍
date_part
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 @Weijun-H 🙏
Looks like there are a few test failures to resolve but otherwise 👍
@@ -127,7 +127,7 @@ impl ScalarUDFImpl for DatePartFunc { | |||
ColumnarValue::Scalar(scalar) => scalar.to_array()?, | |||
}; | |||
|
|||
let arr = match part.to_lowercase().as_str() { | |||
let arr = match part.to_lowercase().trim_matches('\'').trim_matches('"') { |
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.
TIL https://doc.rust-lang.org/std/primitive.str.html#method.trim_matches -- perfect 👍
9de8175
to
9606336
Compare
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.
Just curious, does this let you get away with something funky like:
select extract('''epoch''' from now());
It seems the invalid input @Jefffrey DataFusion CLI v39.0.0
> select extract('''epoch''' from now()); 🤔 Invalid statement: sql parser error: Expected date/time field, found: ''epoch'' |
Ah whoops. What about: select extract("''''epoch''''" from now()); FWIW this is how Postgres treats it:
|
6df48a4
to
9043875
Compare
let arr = match part | ||
.to_lowercase() | ||
.replacen('\'', "", 2) | ||
.replacen('\"', "", 2) | ||
.as_str() |
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.
Hmm, this will still let select extract("'epoch'" from now());
through
But this is quite a minor thing, not sure how much it matters in the wider picture 😅
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 found a workaround, but it should be a better way to handle it in sqlparser. Because it should have many use cases.
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.
Looks good, I agree would be nice to upstream to sqlparser in future if possible 👍
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.
* fix: Support double quotes in date_part.rs * chore * chore * refacor: Use Regex to extract * chore * chore: Use replaceen * chore * fix
Which issue does this PR close?
Parts #10826
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?