[ 
https://issues.apache.org/jira/browse/CALCITE-7275?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18036107#comment-18036107
 ] 

Julian Hyde commented on CALCITE-7275:
--------------------------------------

In case you're not aware, if a SQL function is strong (i.e. if any arguments 
are null then the result is null) then the Java function that implements it 
does not need nullable arguments. The implementation will only call it if all 
arguments are not-null. I don't know whether this is happening in this case. 
Maybe things are different for UDFs.

> DATEDIFF should be able to handle NULL values
> ---------------------------------------------
>
>                 Key: CALCITE-7275
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7275
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Ulrich Kramer
>            Priority: Major
>
> Normally DATEDIFF handles NULL values by returning NULL.
> {noformat}
> SELECT DATEDIFF(day, NULL, '2024-01-15')        -- Result: NULL
> SELECT DATEDIFF(day, '2024-01-01', NULL)        -- Result: NULL
> SELECT DATEDIFF(day, NULL, NULL)                -- Result: NULL
> {noformat}
> But the builtin Method {{SqlFunctions.customDateDiff}} has only parameters 
> and a return code, which doesn't allow to handle this:
> {code}
>   public static int customDateDiff(DataContext root,
>       String timeFrameName, int date, int date2) 
> {code}
> {code:SQL}
> SELECT DATEDIFF(DAY,NULL,NULL)
> {code}
> generates invalid code:
> {noformat}
> ...
>             public Object current() {
>               return 
> Integer.valueOf(com.sap.sva.nucleus.resources.calcite.base.DateTimeUtil.dateDifference(org.apache.calcite.avatica.util.TimeUnitRange.DAY,
>  null, null));
>             }
> ...
> {noformat}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to