Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8C92B2009F3 for ; Sat, 21 May 2016 03:45:17 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 8B251160A2A; Sat, 21 May 2016 01:45:17 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id AAFEE160A25 for ; Sat, 21 May 2016 03:45:16 +0200 (CEST) Received: (qmail 6853 invoked by uid 500); 21 May 2016 01:45:15 -0000 Mailing-List: contact dev-help@phoenix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.apache.org Delivered-To: mailing list dev@phoenix.apache.org Received: (qmail 6837 invoked by uid 99); 21 May 2016 01:45:15 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 21 May 2016 01:45:15 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 6C62AC214F for ; Sat, 21 May 2016 01:45:15 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.646 X-Spam-Level: X-Spam-Status: No, score=-4.646 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id 2xM7vbbv9Erg for ; Sat, 21 May 2016 01:45:14 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with SMTP id 04A695F368 for ; Sat, 21 May 2016 01:45:13 +0000 (UTC) Received: (qmail 6297 invoked by uid 99); 21 May 2016 01:45:13 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 21 May 2016 01:45:13 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id F3D1B2C1F5D for ; Sat, 21 May 2016 01:45:12 +0000 (UTC) Date: Sat, 21 May 2016 01:45:12 +0000 (UTC) From: "James Taylor (JIRA)" To: dev@phoenix.incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (PHOENIX-2886) Union ALL with Char column not present in the table in Query 1 but in Query 2 throw exception MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Sat, 21 May 2016 01:45:17 -0000 [ https://issues.apache.org/jira/browse/PHOENIX-2886?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15294632#comment-15294632 ] James Taylor commented on PHOENIX-2886: --------------------------------------- Thanks for the patch, [~ayingshu] and the reviews, [~sergey.soldatov]. Here's some feedback: - You shouldn't need the special case for CoerceExpression here or below, as the data type and max length of the outermost expression (CoerceExpression or not) is what you're interested in. {code} + if (pro.getExpression() instanceof CoerceExpression) { + Expression expr = ((CoerceExpression)pro.getExpression()).getChild(); + targetTypes.add(new TargetDataExpression(expr.getDataType(), + pro.getExpression().getMaxLength() == null? + 0 : pro.getExpression().getMaxLength())); + } else { + targetTypes.add(new TargetDataExpression(pro.getExpression().getDataType(), + pro.getExpression().getMaxLength() == null? + 0 : pro.getExpression().getMaxLength())); + } {code} - In addition to keeping track of the max length, you should keep track of the max scale as well (when it's not null). You should track this in your TargetDataExpression object. - You need to track sort order across all top level projector expressions and have the coerce use the common one (if they're all the same), or SortOrder.getDefault() if they're different. You should track this in your TargetDataExpression object. - What happens if TargetDataExpression ends up with a 0 for max length? You should be using a null for max length in the case. Why not make TargetDataExpression.maxLength an Integer instead and allow it to stay null? - Same for scale. Add it to TargetDataExpression as an Integer and handle null correctly. - Need tests for the above - mix of different scales, all varchars (where maxLength would end up 0), different sort orders. - Here, when you create the Expression[], just call CoerceExpression.create() as it's a noop if the type, maxLength, scale, etc. are the same. You don't want to repeat that logic here. {code} + private static TupleProjector getTupleProjector(RowProjector rowProj, + List targetTypes) throws SQLException { + Expression[] exprs = new Expression[targetTypes.size()]; + int i = 0; + Expression expr = null; + for (ColumnProjector colProj : rowProj.getColumnProjectors()) { + if (!colProj.getExpression().getDataType().equals(targetTypes.get(i).getType())) { + expr = CoerceExpression.create(colProj.getExpression(), + targetTypes.get(i).getType(), colProj.getExpression().getSortOrder(), + targetTypes.get(i).getMaxLength()); + exprs[i] = expr; + } else + exprs[i] = colProj.getExpression(); + i++; + } + return new TupleProjector(exprs); + } {code} - Minor nit, but use { } here and no need to check for {{targetTypes.get(i).getType() == type}} as isCoercibleTo handles that already. {code} + private static void compareExperssions(int i, Expression expression, PDataType type, + List targetTypes) throws SQLException { + if (targetTypes.get(i).getType() == type || + type.isCoercibleTo(targetTypes.get(i).getType())) + ; + else if (targetTypes.get(i).getType().isCoercibleTo(type)) { {code} > 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 > > > 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)