Skip to content

Commit 361727a

Browse files
authored
fix concat ws simplify (#14213)
* fix concat ws simplify * fix * fix tests * fix
1 parent 2aff98e commit 361727a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

datafusion/functions/src/string/concat_ws.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::sync::Arc;
2121

2222
use arrow::datatypes::DataType;
2323

24+
use crate::string::concat;
2425
use crate::string::concat::simplify_concat;
2526
use crate::string::concat_ws;
2627
use crate::strings::{ColumnarValueRef, StringArrayBuilder};
@@ -317,7 +318,19 @@ fn simplify_concat_ws(delimiter: &Expr, args: &[Expr]) -> Result<ExprSimplifyRes
317318
match delimiter {
318319
// when the delimiter is an empty string,
319320
// we can use `concat` to replace `concat_ws`
320-
Some(delimiter) if delimiter.is_empty() => simplify_concat(args.to_vec()),
321+
Some(delimiter) if delimiter.is_empty() => {
322+
match simplify_concat(args.to_vec())? {
323+
ExprSimplifyResult::Original(_) => {
324+
Ok(ExprSimplifyResult::Simplified(Expr::ScalarFunction(
325+
ScalarFunction {
326+
func: concat(),
327+
args: args.to_vec(),
328+
},
329+
)))
330+
}
331+
expr => Ok(expr),
332+
}
333+
}
321334
Some(delimiter) => {
322335
let mut new_args = Vec::with_capacity(args.len());
323336
new_args.push(lit(delimiter));

datafusion/sqllogictest/test_files/expr.slt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,17 @@ SELECT concat_ws('|','a',NULL,NULL)
465465
----
466466
a
467467

468+
statement ok
469+
create table foo (a varchar, b varchar) as values ('a', 'b');
470+
471+
query T
472+
SELECT concat_ws('',a,b,'c') from foo
473+
----
474+
abc
475+
476+
statement ok
477+
drop table foo
478+
468479
query T
469480
SELECT initcap('')
470481
----

0 commit comments

Comments
 (0)