You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Jungtaek Lim (JIRA)" <ji...@apache.org> on 2016/09/27 05:48:21 UTC
[jira] [Created] (CALCITE-1387) CAST(ITEM() as INTEGER) throws
RuntimeException in Runtime when return value of ITEM() is null
Jungtaek Lim created CALCITE-1387:
-------------------------------------
Summary: CAST(ITEM() as INTEGER) throws RuntimeException in Runtime when return value of ITEM() is null
Key: CALCITE-1387
URL: https://issues.apache.org/jira/browse/CALCITE-1387
Project: Calcite
Issue Type: Bug
Components: core
Affects Versions: 1.9.0
Reporter: Jungtaek Lim
Assignee: Julian Hyde
Suppose we're defining the following table:
{code}
.field("ID", SqlTypeName.INTEGER)
.field("MAPFIELD", SqlTypeName.ANY)
.field("NESTEDMAPFIELD", SqlTypeName.ANY)
.field("ARRAYFIELD", SqlTypeName.ANY)
{code}
and query like this:
{code}
SELECT * FROM <TBL> WHERE CAST(MAPFIELD['a'] AS INTEGER) = 1
{code}
When ITEM returns null (because MAPFIELD\['a'] is really null, or there's no key 'a'), CAST throws RuntimeException, saying "cannot convert null to int".
Generated code block is here:
{code}
outputValues[0] = inp1_ == null ? (Boolean) null : Boolean.valueOf(org.apache.calcite.runtime.SqlFunctions.toInt(org.apache.calcite.runtime.SqlFunctions.item(inp1_, "a")) == 2);
{code}
Btw, CAST(COALESCE(MAPFIELD\['a'], -1) AS INTEGER) throws
java.lang.RuntimeException: org.codehaus.commons.compiler.CompileException: Incompatible expression types "java.lang.Object" and "int".
Code for where expression is below:
{code}
final Object inp1_ = (context.values)[1];
outputValues[0] = inp1_ != null && inp1_ == null ? (Boolean) null : Boolean.valueOf(org.apache.calcite.runtime.SqlFunctions.toInt(inp1_ != null ? org.apache.calcite.runtime.SqlFunctions.item(inp1_, "a") : -1) == 2);
{code}
CAST(COALESCE(MAPFIELD\['a'], CAST(-1 AS ANY)) AS INTEGER) is generating same code block and also throws same Exception above.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)