From 0a306d4a061455da15217395d6024bf3a86c63a3 Mon Sep 17 00:00:00 2001 From: sunyerui Date: Sat, 4 Jun 2016 23:04:48 +0800 Subject: [PATCH] KYLIN-1762 Query threw NPE with 3 or more join conditions --- kylin-it/src/test/resources/query/sql/query100.sql | 28 ++++++++++++++++++++++ .../apache/kylin/query/relnode/OLAPJoinRel.java | 9 +++++-- 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 kylin-it/src/test/resources/query/sql/query100.sql diff --git a/kylin-it/src/test/resources/query/sql/query100.sql b/kylin-it/src/test/resources/query/sql/query100.sql new file mode 100644 index 0000000..1edf92d --- /dev/null +++ b/kylin-it/src/test/resources/query/sql/query100.sql @@ -0,0 +1,28 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +select t1.leaf_categ_id, max_price, min_price, sum_price +from +(select leaf_categ_id, sum(price) as sum_price from test_kylin_fact group by leaf_categ_id) t1 +join +(select leaf_categ_id, max(price) as max_price from test_kylin_fact group by leaf_categ_id) t2 +on t1.leaf_categ_id = t2.leaf_categ_id +join +(select leaf_categ_id, min(price) as min_price from test_kylin_fact group by leaf_categ_id) t3 +on t1.leaf_categ_id = t3.leaf_categ_id +order by t1.leaf_categ_id diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPJoinRel.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPJoinRel.java index efe404b..4b293bc 100644 --- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPJoinRel.java +++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPJoinRel.java @@ -121,12 +121,17 @@ public class OLAPJoinRel extends EnumerableJoin implements OLAPRel { implementor.visitChild(this.left, this); if (this.context != implementor.getContext() || ((OLAPRel) this.left).hasSubQuery()) { this.hasSubQuery = true; - implementor.freeContext(); + // child join node didn't allocated a new context, and free context should be skipped + if (!(this.left instanceof OLAPJoinRel)) { + implementor.freeContext(); + } } implementor.visitChild(this.right, this); if (this.context != implementor.getContext() || ((OLAPRel) this.right).hasSubQuery()) { this.hasSubQuery = true; - implementor.freeContext(); + if (!(this.right instanceof OLAPJoinRel)) { + implementor.freeContext(); + } } this.columnRowType = buildColumnRowType(); -- 2.3.2 (Apple Git-55)