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 AB233200AE3 for ; Wed, 4 May 2016 11:56:07 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A98631601A3; Wed, 4 May 2016 09:56:07 +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 CC7451601A2 for ; Wed, 4 May 2016 11:56:06 +0200 (CEST) Received: (qmail 8817 invoked by uid 500); 4 May 2016 09:56:01 -0000 Mailing-List: contact commits-help@hive.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hive-dev@hive.apache.org Delivered-To: mailing list commits@hive.apache.org Received: (qmail 8806 invoked by uid 99); 4 May 2016 09:56:01 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 May 2016 09:56:01 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E3EC4DFB14; Wed, 4 May 2016 09:56:00 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jcamacho@apache.org To: commits@hive.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: hive git commit: HIVE-13677: org.apache.hive.com.esotericsoftware.kryo.KryoException: java.lang.NullPointerException when folding CASE expression (Jesus Camacho Rodriguez, reviewed by Prasanth Jayachandran) Date: Wed, 4 May 2016 09:56:00 +0000 (UTC) archived-at: Wed, 04 May 2016 09:56:07 -0000 Repository: hive Updated Branches: refs/heads/branch-1 91c83f39d -> ad1ceb861 HIVE-13677: org.apache.hive.com.esotericsoftware.kryo.KryoException: java.lang.NullPointerException when folding CASE expression (Jesus Camacho Rodriguez, reviewed by Prasanth Jayachandran) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/ad1ceb86 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/ad1ceb86 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/ad1ceb86 Branch: refs/heads/branch-1 Commit: ad1ceb861def8505001bc0daedf2c1e4673848f8 Parents: 91c83f3 Author: Jesus Camacho Rodriguez Authored: Wed May 4 10:54:40 2016 +0100 Committer: Jesus Camacho Rodriguez Committed: Wed May 4 10:55:46 2016 +0100 ---------------------------------------------------------------------- .../optimizer/ConstantPropagateProcFactory.java | 19 +++++--- ql/src/test/queries/clientpositive/fold_case2.q | 13 ++++++ .../results/clientpositive/fold_case2.q.out | 46 ++++++++++++++++++++ 3 files changed, 71 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/ad1ceb86/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagateProcFactory.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagateProcFactory.java b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagateProcFactory.java index 70cdc95..064e304 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagateProcFactory.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/optimizer/ConstantPropagateProcFactory.java @@ -577,7 +577,7 @@ public final class ConstantPropagateProcFactory { } else if (op instanceof FilterOperator) { // we can still fold, since here null is equivalent to false. return Boolean.TRUE.equals(elseVal) ? - ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNot(), newExprs.subList(0, 1)) : Boolean.FALSE.equals(elseVal) ? + ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNot(), Lists.newArrayList(whenExpr)) : Boolean.FALSE.equals(elseVal) ? elseExpr : null; } else { // can't do much, expression is not in context of filter, so we can't treat null as equivalent to false here. @@ -589,7 +589,7 @@ public final class ConstantPropagateProcFactory { return thenExpr; } else if (thenVal instanceof Boolean && elseVal instanceof Boolean) { return Boolean.TRUE.equals(thenVal) ? whenExpr : - ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNot(), newExprs.subList(0, 1)); + ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNot(), Lists.newArrayList(whenExpr)); } else { return null; } @@ -617,19 +617,24 @@ public final class ConstantPropagateProcFactory { if (null == elseVal) { return thenExpr; } else if (op instanceof FilterOperator) { - return Boolean.TRUE.equals(elseVal) ? ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNotEqual(), newExprs.subList(0, 2)) : + return Boolean.TRUE.equals(elseVal) ? + ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNotEqual(), + Lists.newArrayList(newExprs.subList(0, 2))) : Boolean.FALSE.equals(elseVal) ? elseExpr : null; } else { return null; } } else if (null == elseVal && op instanceof FilterOperator) { - return Boolean.TRUE.equals(thenVal) ? ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPEqual(), newExprs.subList(0, 2)) : - Boolean.FALSE.equals(thenVal) ? thenExpr : null; + return Boolean.TRUE.equals(thenVal) ? ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPEqual(), + Lists.newArrayList(newExprs.subList(0, 2))) : + Boolean.FALSE.equals(thenVal) ? thenExpr : null; } else if(thenVal.equals(elseVal)){ return thenExpr; } else if (thenVal instanceof Boolean && elseVal instanceof Boolean) { - return Boolean.TRUE.equals(thenVal) ? ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPEqual(), newExprs.subList(0, 2)) : - ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNotEqual(), newExprs.subList(0, 2)); + return Boolean.TRUE.equals(thenVal) ? ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPEqual(), + Lists.newArrayList(newExprs.subList(0, 2))) : + ExprNodeGenericFuncDesc.newInstance(new GenericUDFOPNotEqual(), + Lists.newArrayList(newExprs.subList(0, 2))); } else { return null; } http://git-wip-us.apache.org/repos/asf/hive/blob/ad1ceb86/ql/src/test/queries/clientpositive/fold_case2.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientpositive/fold_case2.q b/ql/src/test/queries/clientpositive/fold_case2.q new file mode 100644 index 0000000..71c5bb8 --- /dev/null +++ b/ql/src/test/queries/clientpositive/fold_case2.q @@ -0,0 +1,13 @@ +drop table test1; +drop table test2; + +create table test1 (id int, desc string) stored as orc; +create table test2 (id int, desc string) stored as orc; + +select +case +when (case when a.desc='test' then 1 else 0 end)=0 then 'test' +else null +end as val +FROM test1 a +JOIN test2 b ON a.id=b.id; http://git-wip-us.apache.org/repos/asf/hive/blob/ad1ceb86/ql/src/test/results/clientpositive/fold_case2.q.out ---------------------------------------------------------------------- diff --git a/ql/src/test/results/clientpositive/fold_case2.q.out b/ql/src/test/results/clientpositive/fold_case2.q.out new file mode 100644 index 0000000..f87a097 --- /dev/null +++ b/ql/src/test/results/clientpositive/fold_case2.q.out @@ -0,0 +1,46 @@ +PREHOOK: query: drop table test1 +PREHOOK: type: DROPTABLE +POSTHOOK: query: drop table test1 +POSTHOOK: type: DROPTABLE +PREHOOK: query: drop table test2 +PREHOOK: type: DROPTABLE +POSTHOOK: query: drop table test2 +POSTHOOK: type: DROPTABLE +PREHOOK: query: create table test1 (id int, desc string) stored as orc +PREHOOK: type: CREATETABLE +PREHOOK: Output: database:default +PREHOOK: Output: default@test1 +POSTHOOK: query: create table test1 (id int, desc string) stored as orc +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: database:default +POSTHOOK: Output: default@test1 +PREHOOK: query: create table test2 (id int, desc string) stored as orc +PREHOOK: type: CREATETABLE +PREHOOK: Output: database:default +PREHOOK: Output: default@test2 +POSTHOOK: query: create table test2 (id int, desc string) stored as orc +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: database:default +POSTHOOK: Output: default@test2 +PREHOOK: query: select +case +when (case when a.desc='test' then 1 else 0 end)=0 then 'test' +else null +end as val +FROM test1 a +JOIN test2 b ON a.id=b.id +PREHOOK: type: QUERY +PREHOOK: Input: default@test1 +PREHOOK: Input: default@test2 +#### A masked pattern was here #### +POSTHOOK: query: select +case +when (case when a.desc='test' then 1 else 0 end)=0 then 'test' +else null +end as val +FROM test1 a +JOIN test2 b ON a.id=b.id +POSTHOOK: type: QUERY +POSTHOOK: Input: default@test1 +POSTHOOK: Input: default@test2 +#### A masked pattern was here ####