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

James Taylor commented on PHOENIX-2886:
---------------------------------------

That's close, [~ayingshu]. At a high level, you want to make sure you're always 
convert to a type that has a higher precision/scale.

bq. If there are unsigned and signed data types, convert to unsigned
If there are both signed and unsigned types, convert to signed.

If there are decimal usages, convert everything to decimal (keeping the highest 
precision and scale found, similar to char case for length).

There are other examples of this code. For example, 
CaseExpression.coerceIfNecessary(). You'd want to do something similar, using 
PDataType.isCoercible() to know which of two types to coerce to as this follows 
the above rule and only returns true if you won't lose precision/scale. You 
wouldn't want to hard code this logic again inside of your new method.

> Union ALL with Char column  not present in the table in Query 1 but in Query 
> 2 throw exception
> ----------------------------------------------------------------------------------------------
>
>                 Key: PHOENIX-2886
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-2886
>             Project: Phoenix
>          Issue Type: Bug
>            Reporter: Alicia Ying Shu
>            Assignee: Alicia Ying Shu
>             Fix For: 4.8.0
>
>
> To reproduce:
> create table person ( id bigint not null primary key, firstname char(10), 
> lastname varchar(10) );
> upsert into person values( 1, 'john', 'doe');
> upsert into person values( 2, 'jane', 'doe');
> -- fixed value for char(10)
> select id, 'foo' firstname, lastname from person union all select * from 
> person;
> java.lang.RuntimeException: java.sql.SQLException: ERROR 201 (22000): Illegal 
> data. Expected length of at least 106 bytes, but had 13
> -- fixed value for bigint
> select cast( 10 AS bigint) id, 'foo' firstname, lastname from person union 
> all select * from person;
> java.lang.RuntimeException: java.sql.SQLException: ERROR 201 (22000): Illegal 
> data. Expected length of at least 106 bytes, but had 13



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to