-
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
feat: Support Substring(str [from int] [for int]) #1621
Conversation
@@ -499,6 +499,16 @@ async fn test_interval_expressions() -> Result<()> { | |||
Ok(()) | |||
} | |||
|
|||
#[cfg(feature = "unicode_expressions")] |
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 didnt find any helpers to assert that function return error, should I introduce a new one or did I miss something?
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 did not find one either.
You could potentially use the #[should_panic
annotation. For example, something like (untested):
#[tokio::test]
#[should_panic(expected = "negative substring length not allowed")]
async fn test_substring_expr_bad() -> Result<()> {
test_expression!("substring('alphabet' from -1 for 1)", "l");
}
A helper would be great
Thanks @ovr ! Lol, I also have just done exactly this for #175 Our idea is same, transfer let sql_expr = SQLExpr::Function(Function {
name: ObjectName(
[Ident {
value: "substr".to_string(),
quote_style: None,
}]
.to_vec(),
),
args: [
FunctionArg::Unnamed(*expr.clone()),
FunctionArg::Unnamed(from_expr),
FunctionArg::Unnamed(for_expr),
]
.to_vec(),
over: None,
distinct: false,
});
dbg!(schema.clone());
self.sql_expr_to_logical_expr(&sql_expr, schema) I'll help to review after getting up |
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 to me @ovr -- thank you for the contribution!
Do you want to add a negative test to this PR, or perhaps as a follow on?
@@ -499,6 +499,16 @@ async fn test_interval_expressions() -> Result<()> { | |||
Ok(()) | |||
} | |||
|
|||
#[cfg(feature = "unicode_expressions")] |
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 did not find one either.
You could potentially use the #[should_panic
annotation. For example, something like (untested):
#[tokio::test]
#[should_panic(expected = "negative substring length not allowed")]
async fn test_substring_expr_bad() -> Result<()> {
test_expression!("substring('alphabet' from -1 for 1)", "l");
}
A helper would be great
Hi, @ovr I do some case tests with Postgres in my local. The followings are some differences.
BTW, It'll be better to integration testing to compare with postgres |
@@ -499,6 +499,16 @@ async fn test_interval_expressions() -> Result<()> { | |||
Ok(()) | |||
} | |||
|
|||
#[cfg(feature = "unicode_expressions")] | |||
#[tokio::test] | |||
async fn test_substring_expr() -> Result<()> { |
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 can add a test which from k
(k <=0)
@ovr would you like to address the discrepancies that @xudong963 found with postgres? |
Good catch!
@alamb I've created an additional PR to fix that - #1660, it will be better to land it before this PR. Thanks |
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 @ovr |
Which issue does this PR close?
I didn't create an issue for it.
Rationale for this change
DF supports
substr
function, but it doesn't support substring expression. In this PR I've implemented support for substring expression in planner.What changes are included in this PR?
Are there any user-facing changes?
Nope.
Thanks