Done[1]. Thanks for the guidance. [1] https://issues.apache.org/jira/browse/CALCITE-3142 Thanks, Gelbana
On Sat, Jun 22, 2019 at 3:58 PM Stamatis Zampetakis <[email protected]> wrote: > Hey Gelbana, > > I didn't have a chance to look into this but it looks like a bug so please > log a JIRA case with your analysis so far. JIRA is the first place where > people look for problems so it is better to continue the discussion there. > > Best, > Stamatis > > On Mon, Jun 17, 2019 at 1:03 PM Muhammad Gelbana <[email protected]> > wrote: > > > *This is the optimized generated code* > > final Object[] current = (Object[]) inputEnumerator.current(); > > final Integer inp0_ = (Integer) current[0]; > > final Integer inp1_ = (Integer) current[1]; > > final java.math.BigDecimal v1 = new java.math.BigDecimal( > > inp0_.intValue() / inp1_.intValue()); *// NPE* > > return inp0_ == null || inp1_ == null ? (java.math.BigDecimal) null : > > org.apache.calcite.runtime.SqlFunctions.sround(v1, 2); > > > > *This is the non-optimized one* > > final Object[] current = (Object[]) inputEnumerator.current(); > > final Integer inp0_ = (Integer) current[0]; > > final boolean inp0__unboxed = inp0_ == null; > > final Integer inp1_ = (Integer) current[1]; > > final boolean inp1__unboxed = inp1_ == null; > > final boolean v = inp0__unboxed || inp1__unboxed; > > final int inp0__unboxed0 = inp0_.intValue(); *// NPE* > > final int inp1__unboxed0 = inp1_.intValue(); *// NPE* > > final int v0 = inp0__unboxed0 / inp1__unboxed0; > > final java.math.BigDecimal v1 = new java.math.BigDecimal( > > v0); > > final java.math.BigDecimal v2 = v ? (java.math.BigDecimal) null : > > org.apache.calcite.runtime.SqlFunctions.sround(v1, 2); > > return v2; > > > > I'm still trying to understand how to fix this. I assume I need to avoid > > creating an Expression for "final int inp0__unboxed0 = inp0_.intValue()" > > and "final int inp1__unboxed0 = inp1_.intValue()". Any hints ? > > > > Thanks, > > Gelbana > > > > > > On Sun, Jun 16, 2019 at 9:28 PM Muhammad Gelbana <[email protected]> > > wrote: > > > > > Of course, my bad! > > > > > > -- Regular cast syntax > > > SELECT ROUND(CAST((X/Y) AS NUMERIC), 2) FROM (VALUES (1, 2), (NULLIF(5, > > > 5), NULLIF(5, 5))) A(X, Y) > > > > > > Thanks, > > > Gelbana > > > > > > > > > On Sun, Jun 16, 2019 at 8:43 PM Julian Hyde <[email protected]> > > > wrote: > > > > > >> Can you reproduce it with regular cast syntax? Make it as easy as > > >> possible for others to help you. > > >> > > >> Julian > > >> > > >> > On Jun 16, 2019, at 11:24 AM, Muhammad Gelbana <[email protected] > > > > >> wrote: > > >> > > > >> > The following query throws a NPE in the generated code because it > > >> assumes > > >> > the divided value to be an initialized Java object (Not null), which > > is > > >> > fine for the first row, but not for the second. > > >> > > > >> > SELECT ROUND((X/Y)::NUMERIC, 2) > > >> > FROM (VALUES (1, 2), (NULLIF(5, 5), NULLIF(5, 5))) A(X, Y) > > >> > > > >> > If I modify the query a little bit, it runs ok: > > >> > -- No casting > > >> > SELECT ROUND((X/Y), 2) FROM (VALUES (1, 2), (NULLIF(5, 5), NULLIF(5, > > >> 5))) > > >> > A(X, Y) > > >> > > > >> > -- No rounding > > >> > SELECT (X/Y)::NUMERIC FROM (VALUES (1, 2), (NULLIF(5, 5), NULLIF(5, > > 5))) > > >> > A(X, Y) > > >> > > > >> > What could be causing this ? Any hints ? > > >> > And was this reported before or should I create a new ticket ? > > >> > > > >> > Thanks, > > >> > Gelbana > > >> > > > > > >
