You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Mickaël Sauvée (JIRA)" <ji...@apache.org> on 2019/06/27 07:58:00 UTC
[jira] [Created] (CALCITE-3150) NPE in UPPER when repeated and
combine with LIKE
Mickaël Sauvée created CALCITE-3150:
---------------------------------------
Summary: NPE in UPPER when repeated and combine with LIKE
Key: CALCITE-3150
URL: https://issues.apache.org/jira/browse/CALCITE-3150
Project: Calcite
Issue Type: Bug
Components: core
Affects Versions: next
Reporter: Mickaël Sauvée
Using a query using twice same UPPER with a LIKE, generated code do not protect UPPER call.
If inout is null, then UPPER is call and generates a NPE.
I've used the following test (in JdbcTest.java):
{code:java}
@Test
public void testNPEInUpper() {
CalciteAssert.hr()
.query("select e.\"name\" from \"hr\".\"emps\" as e WHERE (UPPER(e.\"name\") LIKE 'B%' AND UPPER(e.\"name\") LIKE '%L')" )
.returnsUnordered("name=Bill;");
}
{code}
And modify data to hava NULL for a name:
{code:java}
public final Employee[] emps = {
new Employee(100, 10, "Bill", 10000, 1000),
new Employee(200, 20, "Eric", 8000, 500),
new Employee(150, 10, null, 7000, null),
new Employee(110, 10, "Theodore", 11500, 250),
};
{code}
This generates this code:
{code:java}
/* 11 */ public boolean moveNext() {
/* 12 */ while (inputEnumerator.moveNext()) {
/* 13 */ final String inp2_ = ((org.apache.calcite.test.JdbcTest.Employee) inputEnumerator.current()).name;
/* 14 */ final String v = org.apache.calcite.runtime.SqlFunctions.upper(inp2_);
/* 15 */ if (inp2_ != null && org.apache.calcite.runtime.SqlFunctions.like(v, "B%") && (inp2_ != null && org.apache.calcite.runtime.SqlFunctions.like(v, "%L"))) {
/* 16 */ return true;
/* 17 */ }
/* 18 */ }
/* 19 */ return false;
/* 20 */ }
{code}
The variable v is computed whenever inp2_ is null. My guess is that v should not be inlined, or the function upper org.apache.calcite.runtime.SqlFunctions.upper should support null as parameter (and return null).
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)