ILuffZhe commented on code in PR #3258:
URL: https://github.com/apache/calcite/pull/3258#discussion_r1231652240
##########
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.
+ * "CONCAT(null)" returns "".
+ * "CONCAT(null, null, null)" returns "".
+ *
+ * <p>It differs from {@link #CONCAT_FUNCTION} when processing
+ * null values. */
+ @LibraryOperator(libraries = {MSSQL, POSTGRESQL})
+ public static final SqlFunction CONCAT_FUNCTION_WITH_NULL =
+ SqlBasicFunction.create("CONCAT",
+ ReturnTypes.MULTIVALENT_STRING_SUM_PRECISION_NOT_NULLABLE,
+ OperandTypes.repeat(SqlOperandCountRanges.from(1),
+ OperandTypes.STRING),
+ SqlFunctionCategory.STRING)
+ .withOperandTypeInference(InferTypes.RETURN_TYPE)
+ .withKind(SqlKind.CONCAT_WITH_NULL);
Review Comment:
Those two functions(CONCAT_FUNCTION and CONCAT_FUNCTION_WITH_NULL) have the
same operator name and operands type/count, so we need a new SqlKind when
overloading functions.
You can also see CONCAT2 function that enabled in Oracle, and we use
SqlKind.CONCAT2 to make it different.
--
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]