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
<mahadev.mis...@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>
>
>
>
>
>

Reply via email to