[
https://issues.apache.org/jira/browse/PHOENIX-1237?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14135107#comment-14135107
]
James Taylor commented on PHOENIX-1237:
---------------------------------------
I see why you used the other form of isCoercibleTo that provides the actual
value. It's correct that INTEGER is not automatically coercible to
UNSIGNED_INT, as a negative integer cannot be coerced.
How about we do this to handle the literal-as-second-arg case?
- if the second arg is a literal (secondArg.isStateless() &&
secondArg.isDeterministic()), then evaluate it with a null Tuple argument and
use the isCoercibleTo method that takes an ImmutableBytesWritable ptr for the
value instead of calling the single argument isCoercibleTo method.
- if a call is made like this COALESCE(unsigned_int_column, int_column), it'll
get a compilation exception and you'd need to put an explicit cast in like
this: COALESCE(unsigned_int_column, CAST(int_column AS UNSIGNED_INT)).
> COALESCE Function - type of second parameter
> --------------------------------------------
>
> Key: PHOENIX-1237
> URL: https://issues.apache.org/jira/browse/PHOENIX-1237
> Project: Phoenix
> Issue Type: Bug
> Affects Versions: 5.0.0, 3.1, 4.1
> Reporter: Vaclav Loffelmann
> Assignee: Vaclav Loffelmann
> Attachments: PHOENIX-1237.fix.patch, PHOENIX_1237.patch
>
>
> There is an issue with automatic set data type of second parameter to
> coalesce function.
> For instance table:
> {code:sql}
> CREATE TABLE IF NOT EXISTS TEST_COALESCE(
> ID BIGINT NOT NULL,
> COUNT UNSIGNED_INT
> CONSTRAINT pk PRIMARY KEY(ID));
> {code}
> and query:
> {code:sql}
> SELECT COALESCE(SUM(COUNT), 0) FROM TEST_SUM GROUP BY ID;
> {code}
> This will cause in:
> {quote}SQLException: ERROR 507 (42846): Cannot convert type. COALESCE
> expected UNSIGNED_INT, but got INTEGER {quote}
> Hence second parameter is typed to its input value (eg. 0 is signed int not
> long), and long is expected. That is cause for ArrayIndexOutOfBoundsException
> described in PHOENIX-1229.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)