risingwave_expr_impl/scalar/
concat.rs1use std::fmt::Write;
16
17use risingwave_common::row::Row;
18use risingwave_common::types::ToText;
19use risingwave_expr::function;
20
21#[function("concat(variadic anyarray) -> varchar")]
37fn concat(vals: impl Row, writer: &mut impl Write) {
38 for string in vals.iter().flatten() {
39 string.write(writer).unwrap();
40 }
41}
42
43#[cfg(test)]
44mod tests {
45 use risingwave_common::array::DataChunk;
46 use risingwave_common::row::Row;
47 use risingwave_common::test_prelude::DataChunkTestExt;
48 use risingwave_common::types::ToOwnedDatum;
49 use risingwave_common::util::iter_util::ZipEqDebug;
50 use risingwave_expr::expr::build_from_pretty;
51
52 #[tokio::test]
53 async fn test_concat() {
54 let concat = build_from_pretty("(concat:varchar $0:varchar $1:varchar $2:varchar)");
55 let (input, expected) = DataChunk::from_pretty(
56 "T T T T
57 a b c abc
58 . b c bc
59 . . . (empty)",
60 )
61 .split_column_at(3);
62
63 let output = concat.eval(&input).await.unwrap();
65 assert_eq!(&output, expected.column_at(0));
66
67 for (row, expected) in input.rows().zip_eq_debug(expected.rows()) {
69 let result = concat.eval_row(&row.to_owned_row()).await.unwrap();
70 assert_eq!(result, expected.datum_at(0).to_owned_datum());
71 }
72 }
73}