I don’t think any such code exists in Calcite.

When I spoke recently I may have mistakenly said that Calcite had such code, 
but I was thinking of Morel. If you look at commit 
https://github.com/hydromatic/morel/commit/21c6fef0bfd2c0aa7f8ff83e83a025ab5b675876
 you will see that I added a ‘pos’ argument to MorelRuntimeException, and 
therefore any function call that might ever throw (e.g. Interactive.use, 
Real.sign, Relational.only, String.sub) will need to have a hidden ‘pos’ 
argument to pass to that exception.

It is an approach that we could replicate in Calcite. The RexCall to such 
throwable functions would have a hidden ‘pos’ parameter. The parameter should 
be populated at Sql-to-rel time, and if it is not present, 
SqlOperator.validareRexOperands should throw. Associating the position with the 
particular function call seems to me much more robust than associating it with 
the RelNode that contains the call.

Julian





> On Oct 24, 2023, at 1:22 PM, Mihai Budiu <mbu...@gmail.com> wrote:
> 
> Hello,
> 
> I would like to have some runtime errors, such as division by 0, report to 
> the user the source code position of the original operation within the SQL 
> query. However, I could not find any examples that do that, and I am not sure 
> how this information can be propagated through the Rel representation. I 
> understand that the CalciteContextException is designed for this purpose, but 
> I couldn't discover any instance where this is thrown at runtime (I found 
> instances thrown only at compilation time).
> 
> I would very much appreciate if someone could point me in the right 
> direction. A test that throws at runtime and prints source position would be 
> great.
> 
> If there isn't such information in Rel nodes, perhaps it should be added in 
> some of them? (I wrote in a blog post recently that such information exists 
> in RexCall nodes, but it seems that I was wrong.)
> 
> Thank you,
> Mihai

Reply via email to