-
Notifications
You must be signed in to change notification settings - Fork 598
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 CONCAT_WS #2427
Conversation
src/expr/src/vector_op/concat_ws.rs
Outdated
@@ -0,0 +1,97 @@ | |||
// Copyright 2022 Singularity Data |
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.
WIP, this needs to be updated
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.
Some early suggestions. Hope they are helpful.
src/sqlparser/src/ast/mod.rs
Outdated
/// CONCAT_WS(SEP TEXT, STR "ANY" [, STR "ANY" [, ...] ]) | ||
ConcatWs { | ||
sep_expr: Box<Expr>, | ||
string_exprs: Vec<Expr>, | ||
}, |
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.
FYI we do not need to update the parser and add new variant / keyword for each new function. concat_ws(a, b, c)
can be parsed as the general function call syntax. The variants here are for those with special syntax.
For example, substring(v1 from 2)
needs special treatment because of the from
, but substr(v1, 2)
does not.
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.
To check my understanding: I should be parsing it into Expr::Function
variant instead?
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.
yes
@@ -107,6 +107,7 @@ impl FunctionCall { | |||
Ok(DataType::Boolean) | |||
} | |||
ExprType::Coalesce => Ok(inputs[0].return_type()), | |||
ExprType::ConcatWs => Ok(DataType::Varchar), // TODO: Validate input types, see below on how to recursively do so. |
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 should have left some comments here... The infer_type
can only handle functions with a limited number of parameters, while the ones listed here (case-when, in-list, coalesce, concat) are all variadic.
To insert cast expr over all input expr to string/varchar, call cast_explicit
on them.
- It can be a little bit confusing as the cast is actually implicit. But casting to varchar implicitly is disallowed in general cases and
concat
is just special here. - As you may noticed in Tracking: Basic Built-in Functions #112, casting from another type to string has not been implemented in backend except for boolean.
Migrated over to #2470 for CI to run correctly. |
What's changed and what's your intention?
WIP, will fill these up later. #2405 , #112
Function
insteadsrc/expr/expr_concat.ws
.PLEASE DO NOT LEAVE THIS EMPTY !!!
Please explain IN DETAIL what the changes are in this PR and why they are needed:
Checklist
Refer to a related PR or issue link (optional)