You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Mahadev Mishal <Ma...@rockwellautomation.com.INVALID> on 2025/09/12 05:24:04 UTC

Question regarding SqlFunctions.toDouble(Object) null handling in Calcite 1.40.0

Hello Calcite Team,

I am working with Apache Calcite 1.40.0 and encountered an issue related to the method org.apache.calcite.runtime.SqlFunctions.toDouble(Object o).

When Calcite executes a query like:

SELECT * FROM orders ORDER BY amount ASC;

if the amount column contains NULL values, the execution fails with the following error:

org.apache.calcite.runtime.CalciteException: Cannot convert null to double

On inspecting the implementation of SqlFunctions.toDouble(Object), I noticed that it returns a primitive double. Since primitive types cannot hold null, the method eventually throws a cannotConvert(null, double.class) exception instead of handling null values gracefully.

This raises a couple of questions:

1. What was the design reasoning behind skipping a null-check in this method? Or is this a possible oversight in the API design given that other SqlFunctions methods sometimes accept null?

2. Is there a recommended way to handle such cases?


Looking forward to your insights and guidance.


[Rockwell Automation]<https://www.rockwellautomation.com/>

Mahadev Mishal

Senior Software Engineer

A-Wing Mississippi Bldg Embassy Tech Zone,
Hinjewadi P2, Pune
India
M +91 9420886521
[Rockwell Automation Facebook]<https://www.facebook.com/ROKAutomation> [Rockwell Automation Instagram] <https://www.instagram.com/rokautomation/>  [Rockwell Automation LinkedIn] <http://www.linkedin.com/company/rockwell-automation>  [Rockwell Automation Twitter] <https://twitter.com/ROKAutomation>





Re: Question regarding SqlFunctions.toDouble(Object) null handling in Calcite 1.40.0

Posted by Mahadev Mishal <Ma...@rockwellautomation.com.INVALID>.
Hi Ruben

Thank you so much for the quick reply. Our Amount column was nullable now while defining the table columns, I am setting column as nullable and with this the issue is resolved.

Thanks,
Mahadev
________________________________
From: Mahadev Mishal <Ma...@rockwellautomation.com>
Sent: Friday, September 12, 2025 10:54 AM
To: dev@calcite.apache.org <de...@calcite.apache.org>
Cc: Vilas Dharma Suryawanshi <Vi...@rockwellautomation.com>
Subject: Question regarding SqlFunctions.toDouble(Object) null handling in Calcite 1.40.0

Hello Calcite Team,

I am working with Apache Calcite 1.40.0 and encountered an issue related to the method org.apache.calcite.runtime.SqlFunctions.toDouble(Object o).

When Calcite executes a query like:

SELECT * FROM orders ORDER BY amount ASC;

if the amount column contains NULL values, the execution fails with the following error:

org.apache.calcite.runtime.CalciteException: Cannot convert null to double

On inspecting the implementation of SqlFunctions.toDouble(Object), I noticed that it returns a primitive double. Since primitive types cannot hold null, the method eventually throws a cannotConvert(null, double.class) exception instead of handling null values gracefully.

This raises a couple of questions:

1. What was the design reasoning behind skipping a null-check in this method? Or is this a possible oversight in the API design given that other SqlFunctions methods sometimes accept null?

2. Is there a recommended way to handle such cases?


Looking forward to your insights and guidance.


[Rockwell Automation]<https://www.rockwellautomation.com/>

Mahadev Mishal

Senior Software Engineer

A-Wing Mississippi Bldg Embassy Tech Zone,
Hinjewadi P2, Pune
India
M +91 9420886521
[Rockwell Automation Facebook]<https://www.facebook.com/ROKAutomation> [Rockwell Automation Instagram] <https://www.instagram.com/rokautomation/>  [Rockwell Automation LinkedIn] <http://www.linkedin.com/company/rockwell-automation>  [Rockwell Automation Twitter] <https://twitter.com/ROKAutomation>





Re: Question regarding SqlFunctions.toDouble(Object) null handling in Calcite 1.40.0

Posted by Ruben Q L <ru...@gmail.com>.
Hello Mahadev!

What's the type of the "amount" column? Could it be possible that it is
(incorrectly) defined as NOT NULL? That could explain Calcite making the
assumption that it is safe to call SqlFunctions.toDouble on it, and hence
the problem at execution time when a null value arrives.

Best,
Ruben

PS: If you are not subscribed to the Calcite dev list, we encourage you to
do so as explained in https://calcite.apache.org/community/#mailing-lists



On Fri, Sep 12, 2025 at 6:29 AM Mahadev Mishal
<Ma...@rockwellautomation.com.invalid> wrote:

> Hello Calcite Team,
>
> I am working with Apache Calcite 1.40.0 and encountered an issue related
> to the method *org.apache.calcite.runtime.SqlFunctions.toDouble(Object
> o).*
>
> When Calcite executes a query like:
>
> *SELECT * FROM orders ORDER BY amount ASC;*
>
> if the amount column contains *NULL* values, the execution fails with the
> following error:
>
> org.apache.calcite.runtime.CalciteException: Cannot convert null to double
>
> On inspecting the implementation of SqlFunctions.toDouble(Object), I
> noticed that it returns a primitive double. Since primitive types cannot
> hold null, the method eventually throws a cannotConvert(null, double.class)
> exception instead of handling null values gracefully.
>
> This raises a couple of questions:
>
> 1. What was the design reasoning behind skipping a null-check in this
> method? Or is this a possible oversight in the API design given that other
> SqlFunctions methods sometimes accept null?
>
> 2. Is there a recommended way to handle such cases?
>
>
> Looking forward to your insights and guidance.
>
> [image: Rockwell Automation] <https://www.rockwellautomation.com/>
>
> *Mahadev Mishal*
>
> Senior Software Engineer
>
> A-Wing Mississippi Bldg Embassy Tech Zone,
> Hinjewadi P2, Pune
> India
> *M* +91 9420886521
> [image: Rockwell Automation Facebook]
> <https://www.facebook.com/ROKAutomation> [image: Rockwell Automation
> Instagram] <https://www.instagram.com/rokautomation/> [image: Rockwell
> Automation LinkedIn] <http://www.linkedin.com/company/rockwell-automation>
>  [image: Rockwell Automation Twitter] <https://twitter.com/ROKAutomation>
>
>
>
>
>