[ https://issues.apache.org/jira/browse/PHOENIX-2886?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15297858#comment-15297858 ]
Sergey Soldatov commented on PHOENIX-2886: ------------------------------------------ [~aliciashu] as [~jamestaylor] mentioned, we need to track max scale and sort order. and select the best of them. MaxLength is better to keep as Integer, but not int. I also checked the case with {{select id, cast('foo' as char(10)) firstname, lastname from person;}} There is a couple surprises. First of all, at the first glance we don't need any coerce expressions here since firstname is char(10) as well as 'foo' with cast expression. But. actually cast('foo' as char(10)) become to coerce expression {{TO_CHAR('foo')}} with type PChar and max length 3 (!). So, when we try to get value using outer schema which has PChar with max length 10, we are getting troubles. First that came to my mind is to add an additional coerce if lengths are different. But here is an another surprise - {{PChar.coerceBytes}} is calling {{PDataType.coerceBytes}} which is not taking in consideration desiredMaxLength in the case of the same data types. As a possible solution we can change {{PChar.coerceBytes}} to extend ptr to desired size. So, there is no need to remove existing expressions. It will simplify code. I would also simplify how TargetDataExpressions is collected. I used a simple code {noformat} private static List<TargetDataExpression> checkit (List<QueryPlan> selectPlans) throws SQLException { int columnCount = selectPlans.get(0).getProjector().getColumnCount(); List<TargetDataExpression> result = new ArrayList<>(columnCount); for (int i = 0; i < columnCount; i++) { for (QueryPlan plan : selectPlans) { ColumnProjector cp = plan.getProjector().getColumnProjector(i); if(result.size() < i+1 ) { result.add(new TargetDataExpression(cp)); } else { result.get(i).update(cp); } } } return result; } {noformat} You don't need an additional cycle to check values, all logic for choosing best expression/length/order/scale can be hidden in {{update()}} as well as there is no need to modify constructor calls if something is need to be added (like scale/order) > 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 > > Attachments: PHOENIX-2886-v1.patch, PHOENIX-2886-v2.patch, > PHOENIX-2886-v3.patch, PHOENIX-2886.patch, UnionAllIT.java.diff > > > 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)