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

Amrish Lal commented on CALCITE-4608:
-------------------------------------

{quote}against which calcite version / commit
{quote}
I saw the NPE against Calcite version 1.19.0. However, from what I can see in 
the Calcite codebase, the NPE should be reproducible on any version / commit 
before CALCITE-4199 changes were committed.
{quote}how did you get it
{quote}
Please run the test case below against any Calcite version / commit before 
CALCITE-4199 changes.
{code:java}
package org.apache.calcite.sql.test;

import org.apache.calcite.sql.SqlBasicCall;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlNumericLiteral;
import org.apache.calcite.sql.SqlSelect;
import org.apache.calcite.sql.parser.SqlParser;

import org.junit.jupiter.api.Test;

public class CalciteSqlTest {

  @Test
  public void testCalciteSqlNPE() throws Exception {
    SqlSelect selectNode = (SqlSelect) SqlParser.create("select * from t where 
y < 1.7976931348623157E308").parseQuery();
    SqlBasicCall whereNode = (SqlBasicCall) selectNode.getWhere();

    SqlNode[] childNodes = whereNode.getOperands();
    for (SqlNode node : childNodes) {
      if (node instanceof SqlNumericLiteral) {
        SqlNumericLiteral numericLiteral = (SqlNumericLiteral) node;
        numericLiteral.isInteger(); // NPE
      }
    }
  }
}{code}
{quote}the stack trace
{quote}
If you run the test case above against Calcite version 1.19.0 (or any version / 
commit before CALCITE-4199), you should see something like:
{code:java}
java.lang.NullPointerExceptionjava.lang.NullPointerException at 
org.apache.calcite.sql.SqlNumericLiteral.isInteger(SqlNumericLiteral.java:116) 
at 
org.apache.pinot.sql.parsers.CalciteSqlTest.testCalciteSqlNPE(CalciteSqlTest.java:19)
 at 
{code}

> Fix NullPointerException in SqlNumericLiteral.isInteger()
> ---------------------------------------------------------
>
>                 Key: CALCITE-4608
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4608
>             Project: Calcite
>          Issue Type: Bug
>    Affects Versions: 1.26.0
>            Reporter: Amrish Lal
>            Assignee: Ruben Q L
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.27.0
>
>          Time Spent: 1h 50m
>  Remaining Estimate: 0h
>
> In 1.26, a NullPointerException is thrown in SqlNumericLiteral.isInteger(), 
> due to "this.scale" being null. This can be reproduced by compiling SQL 
> statement "SELECT * FROM testTable WHERE floatColumn > 
> 1.7976931348623157E308".
> A null check was added through CALCITE-4199 to fix the NullPointerException; 
> however, the root cause is that scale and precision are not being properly 
> set in {{SqlLiteral.createApproxNumeric}} function which is called to handle 
> {{APPROX_NUMERIC_LITERAL}} token.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to