rubenada commented on code in PR #3258:
URL: https://github.com/apache/calcite/pull/3258#discussion_r1231883768
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -831,16 +831,43 @@ static RelDataType deriveTypeSplit(SqlOperatorBinding
operatorBinding,
new SqlLikeOperator("NOT RLIKE", SqlKind.RLIKE, true, true);
/** The "CONCAT(arg, ...)" function that concatenates strings.
- * For example, "CONCAT('a', 'bc', 'd')" returns "abcd". */
- @LibraryOperator(libraries = {MYSQL, POSTGRESQL, BIG_QUERY})
+ * For example, "CONCAT('a', 'bc', 'd')" returns "abcd".
+ *
+ * <p>It accepts at least 1 argument and returns null if any of
+ * the arguments is null. */
+ @LibraryOperator(libraries = {MYSQL, BIG_QUERY})
public static final SqlFunction CONCAT_FUNCTION =
SqlBasicFunction.create("CONCAT",
ReturnTypes.MULTIVALENT_STRING_SUM_PRECISION_NULLABLE,
- OperandTypes.repeat(SqlOperandCountRanges.from(2),
+ OperandTypes.repeat(SqlOperandCountRanges.from(1),
OperandTypes.STRING),
SqlFunctionCategory.STRING)
.withOperandTypeInference(InferTypes.RETURN_TYPE);
+ /** The "CONCAT(arg, ...)" function that concatenates strings,
+ * which never returns null.
+ * For example, "CONCAT('a', 'bc', 'd')" returns "abcd".
+ *
+ * <p>If one of the arguments is null, it will be treated as empty string.
+ * "CONCAT('a', null)" returns "a".
+ * "CONCAT('a', null, 'b')" returns "ab".
+ *
+ * <p>Returns empty string only when all arguments are null.
Review Comment:
Nit pick: this does not seem entirely correct, I assume it should be
"Returns empty string only when all arguments are null *or the empty string"*,
is that correct?
```
"CONCAT('')" returns ""
"CONCAT('', null, '')" returns ""
```
Maybe the new tests added by this PR should have some scenarios with the
empty string, just to cover these cases.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]