Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,13 @@ public RexNode visit(Expression.ScalarFunctionInvocation expr, Context context)
.collect(Collectors.toList());

RelDataType returnType = typeConverter.toCalcite(typeFactory, expr.outputType());
if (operator == SqlStdOperatorTable.CONCAT && args.size() > 2) {
return args.stream()
.skip(1)
.reduce(
args.get(0),
(left, right) -> rexBuilder.makeCall(returnType, operator, List.of(left, right)));
}
return rexBuilder.makeCall(returnType, operator, args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.calcite.rex.RexCall;
import org.apache.calcite.rex.RexNode;
import org.apache.calcite.sql.SqlKind;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.junit.jupiter.api.Test;

/**
Expand Down Expand Up @@ -212,6 +213,31 @@ void concatStringLiteralAndChar() throws Exception {
assertProtoPlanRoundrip("select 'brand_'||P_BRAND from PART");
}

@Test
void variadicConcat() {
ScalarFunctionInvocation concat =
sb.scalarFn(
DefaultExtensionCatalog.FUNCTIONS_STRING,
"concat:str",
TypeCreator.REQUIRED.STRING,
Expression.StrLiteral.builder().value("a").build(),
Expression.StrLiteral.builder().value("b").build(),
Expression.StrLiteral.builder().value("c").build());

RexCall outer =
assertInstanceOf(
RexCall.class, concat.accept(expressionRexConverter, Context.newContext()));
assertEquals(SqlStdOperatorTable.CONCAT, outer.getOperator());
assertEquals(2, outer.getOperands().size());

RexCall inner = assertInstanceOf(RexCall.class, outer.getOperands().get(0));
assertEquals(SqlStdOperatorTable.CONCAT, inner.getOperator());
assertEquals(2, inner.getOperands().size());
assertEquals("'a':VARCHAR", inner.getOperands().get(0).toString());
assertEquals("'b':VARCHAR", inner.getOperands().get(1).toString());
assertEquals("'c':VARCHAR", outer.getOperands().get(1).toString());
}

@Test
void strptimeTime() {
Expression.StrLiteral inputString = Expression.StrLiteral.builder().value("12:34:56").build();
Expand Down
Loading