[
https://issues.apache.org/jira/browse/PHOENIX-1237?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14132453#comment-14132453
]
James Taylor commented on PHOENIX-1237:
---------------------------------------
Thanks for the patch, [~tzolkin]. It's not applying to the head of 3.0, 4.0, or
master branch - would you mind rebasing on top of latest?
Here's some additional feedback:
- No changes are necessary to the CoalesceFunction. The change you've made
below will cause problems if the second argument is not a constant, as it
cannot be evaluated in that case with a null Tuple argument:
{code}
public CoalesceFunction(List<Expression> children) throws SQLException {
super(children);
- if
(!children.get(1).getDataType().isCoercibleTo(children.get(0).getDataType())) {
+
+ // evaluate second parameter for determite if is coercible
+ ImmutableBytesWritable ptr = new ImmutableBytesPtr();
+ children.get(1).evaluate(null, ptr);
+
+ if
(!children.get(1).getDataType().isCoercibleTo(children.get(0).getDataType(),
children.get(1).getDataType().toObject(ptr))) {
{code}
- In the evaluate method, you should return true only if the second argument
was able to be evaluated and false otherwise:
{code}
if (tuple.isImmutable()) {
- return children.get(1).evaluate(tuple, ptr);
+ Expression secondChild = children.get(1);
+ if (secondChild.evaluate(tuple, ptr)) {
+ // Coerce the type of the second child to the type of the
first child
+ getDataType().coerceBytes(ptr, secondChild.getDataType(),
secondChild.getSortOrder(), getSortOrder());
// TODO: return true here
}
- return false;
+
+ }
+ return true; // TODO: return false here
{code}
> 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)