From edf9f2ffb6cdfed3884415e468cdf0b08b63aadd Mon Sep 17 00:00:00 2001 From: Alex Behm Date: Mon, 5 Jun 2017 16:41:53 -0700 Subject: [PATCH] IMPALA-5438: Always eval union const exprs in subplan. The bug was that the constant exprs of a union were only evaluated for the first fragment instance. However, for a union inside a subplan, we should always evaluate the constant exprs. Testing: - Added a regression test. - Locally ran test_nested_types.py and the union tests in test_queries.py Change-Id: Icd2f21f0213188e2304f8e9536019c7940c07768 Reviewed-on: http://gerrit.cloudera.org:8080/7091 Reviewed-by: Alex Behm Tested-by: Impala Public Jenkins --- be/src/exec/union-node.cc | 2 +- be/src/exec/union-node.h | 2 +- .../queries/QueryTest/nested-types-subplan.test | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/be/src/exec/union-node.cc b/be/src/exec/union-node.cc index cd16bea57..e1912c9de 100644 --- a/be/src/exec/union-node.cc +++ b/be/src/exec/union-node.cc @@ -246,7 +246,7 @@ Status UnionNode::GetNextMaterialized(RuntimeState* state, RowBatch* row_batch) } Status UnionNode::GetNextConst(RuntimeState* state, RowBatch* row_batch) { - DCHECK_EQ(state->instance_ctx().per_fragment_instance_idx, 0); + DCHECK(state->instance_ctx().per_fragment_instance_idx == 0 || IsInSubplan()); DCHECK_LT(const_expr_list_idx_, const_expr_lists_.size()); // Create new tuple buffer for row_batch. int64_t tuple_buf_size; diff --git a/be/src/exec/union-node.h b/be/src/exec/union-node.h index 311ae1775..79fdfba30 100644 --- a/be/src/exec/union-node.h +++ b/be/src/exec/union-node.h @@ -149,7 +149,7 @@ class UnionNode : public ExecNode { /// Returns true if there are still rows to be returned from constant expressions. bool HasMoreConst(const RuntimeState* state) const { - return state->instance_ctx().per_fragment_instance_idx == 0 && + return (state->instance_ctx().per_fragment_instance_idx == 0 || IsInSubplan()) && const_expr_list_idx_ < const_expr_lists_.size(); } diff --git a/testdata/workloads/functional-query/queries/QueryTest/nested-types-subplan.test b/testdata/workloads/functional-query/queries/QueryTest/nested-types-subplan.test index 9590c1bcd..45116e62b 100644 --- a/testdata/workloads/functional-query/queries/QueryTest/nested-types-subplan.test +++ b/testdata/workloads/functional-query/queries/QueryTest/nested-types-subplan.test @@ -577,7 +577,7 @@ where c_custkey = 1 BIGINT,BIGINT ==== ---- QUERY -# IMPALA-3678: union in a subplan - passthrough should be disabled. +# IMPALA-3678: Union in a subplan - passthrough should be disabled. select count(c.c_custkey), count(v.tot_price) from tpch_nested_parquet.customer c, ( select sum(o_totalprice) tot_price from c.c_orders @@ -611,3 +611,18 @@ WHERE ca.o_orderkey < cb.o_orderkey limit 2) v limit 51 ---- TYPES BIGINT ==== +---- QUERY +# IMPALA-5438: Union with constant exprs in a subplan. The 'c_custkey % 100' was chosen +# to have all impalads produce results to make sure the constant exprs in the union are +# evaluated regardless of which fragment instance they are in. +select c_custkey, order_cnt, union_cnt from tpch_nested_parquet.customer c, + (select count(o_orderkey) order_cnt from c.c_orders) v, + (select count(o_orderkey) union_cnt from ( + select o_orderkey from c.c_orders + union all + values(11),(22),(33)) v) v2 +where c_custkey % 100 = 0 and order_cnt != union_cnt - 3; +---- RESULTS +---- TYPES +bigint,bigint,bigint +====