suibianwanwank commented on code in PR #4403:
URL: https://github.com/apache/calcite/pull/4403#discussion_r2123210385
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlInternalOperators.java:
##########
@@ -224,6 +224,40 @@ private SqlInternalOperators() {
public static final SqlAggFunction LITERAL_AGG =
SqlLiteralAggFunction.INSTANCE;
+ /** CAST NOT NULL operator used for cast expression to make it non-nullable
in SqlNode.
+ *
+ * <p>For example:
+ * <pre>{@code COALESCE(a,b)
+ * }</pre>
+ *
+ * <p>is converted to
+ *
+ * <pre>{@code CASE WHEN a is not null THEN a ELSE b
+ * }</pre>
+ * by {@code SqlCoalesceFunction#rewriteCall}.
+ *
+ * <p>When a is nullable and b is non-nullable, the {@code COALESCE(a,b)}
data type will be
+ * non-nullable and {@code CASE WHEN a is not null THEN a ELSE b} data type
will be nullable.
Review Comment:
For example, a user wants to customize a special `SUBSTRING` function that
returns an empty string when the input str is null (the default implementation
should return null).
For convenience, let's assume the substring function takes the form
`substring(x, y, z)`.
To avoid implementing specific execution logic, I want to rewrite it in
`RewriteCall` as:
`case when [x] is null then '' else substring(x, y, z)`.
We want this function to return `not null` to enable more optimizations, but
the standard library's `substring(x, y, z)` will return nullable.
That is, sometimes nullable type inference cannot account for all complex
case. So the user should have a way to enforce the type.
--
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]