-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat:implement sql style 'ends_with' and 'instr' string function #8862
Conversation
/// Returns true if string ends with suffix. | ||
/// ends_with('alphabet', 'abet') = 't' | ||
pub fn ends_with<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef> { | ||
let string_array = as_generic_string_array::<T>(&args[0])?; |
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.
We should be able to use https://docs.rs/arrow/latest/arrow/compute/kernels/comparison/fn.ends_with.html
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.
Do you mean that I can call this library function directly in the code or do I not need to implement this function?
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.
Do you mean that I can call this library function directly in the code or do I not need to implement this function?
Yes, I think the body of thus function could be reduced to something like
let string_array = as_generic_string_array::<T>(&args[0])?; | |
compute::comparison::ends_with(&args[0]) |
BuiltinScalarFunction::InitCap => Volatility::Immutable, | ||
BuiltinScalarFunction::InStr => Volatility::Immutable, |
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.
PostgreSQL has POSITION
(see https://www.postgresql.org/docs/9.1/functions-string.html)
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.
Does the function name we implement need to follow postgresql? If so, I will change the name of this function
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.
Spark has both position and instr and they are not quite the same signature:
https://spark.apache.org/docs/latest/api/sql/#position
https://spark.apache.org/docs/latest/api/sql/#instr
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 very much for this PR @zy-kkk -- it is very well tested and commented 🦾 .
It looks quite close to me. The only thing I think it needs prior to merging is to address the potential use of an arrow kernel rather than reimplementation for ends_with
but otherwise it is ready to go 🚀
Thanks again
/// Returns true if string ends with suffix. | ||
/// ends_with('alphabet', 'abet') = 't' | ||
pub fn ends_with<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef> { | ||
let string_array = as_generic_string_array::<T>(&args[0])?; |
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.
Do you mean that I can call this library function directly in the code or do I not need to implement this function?
Yes, I think the body of thus function could be reduced to something like
let string_array = as_generic_string_array::<T>(&args[0])?; | |
compute::comparison::ends_with(&args[0]) |
Boolean, | ||
BooleanArray | ||
); | ||
test_function!( |
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.
💯 for testing with NULL
…tations and extend tests for instr function
Hello @alamb, first of all thank you for your review of my PR, |
Thank you @zy-kkk -- I think we try to follow the postgres style, but making the function packages as compatible as possible is a good thing. In this case, perhaps you can add an alias for |
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 very much @zy-kkk -- I reviewed this PR and I think it looks quite good.
It would be nice to add a position
alias, but also think we can do that as a follow on PR as well
_ => None, | ||
}) | ||
.collect::<BooleanArray>(); | ||
let result = arrow::compute::kernels::comparison::starts_with(left, right)?; |
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, @alamb, I will continue to modify this PR so that |
Hi @alamb, I tested changing instr to position. If I want to support the syntax |
Hi @zy-kkk -- I didn't realize there was special syntax. Yes in order to support that special syntax we would need a change in sqlparser. What I suggest in this case is that we file a follow on ticket to support posgresql style and merge this PR. I will file the ticket shortly |
I filed #8969 to track adding the position function |
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 again @zy-kkk -- this is a really nice addition
Which issue does this PR close?
Closes #.
Rationale for this change
instr: https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_instr
ends_with: Refer to the existing starts_with function
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?