From aa0894c5b1f4011eafaaaa866fe817593637ecba Mon Sep 17 00:00:00 2001 From: etherge Date: Wed, 15 Feb 2017 15:18:18 +0800 Subject: [PATCH] KYLIN-2449 skip rewriting if no realiztion in OLAPAggregateRel --- .../test/resources/query/sql_subquery/query16.sql | 38 ++++++++++++++++++++++ .../kylin/query/relnode/OLAPAggregateRel.java | 5 +-- 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 kylin-it/src/test/resources/query/sql_subquery/query16.sql diff --git a/kylin-it/src/test/resources/query/sql_subquery/query16.sql b/kylin-it/src/test/resources/query/sql_subquery/query16.sql new file mode 100644 index 0000000..5477e54 --- /dev/null +++ b/kylin-it/src/test/resources/query/sql_subquery/query16.sql @@ -0,0 +1,38 @@ +-- +-- 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, COUNT(*) AS nums +FROM + (SELECT + f.leaf_categ_id + FROM + test_kylin_fact f inner join TEST_CATEGORY_GROUPINGS o on f.leaf_categ_id = o.leaf_categ_id and f.LSTG_SITE_ID = o.site_id + WHERE + f.lstg_format_name = 'ABIN') t1 + INNER JOIN + (SELECT + leaf_categ_id + FROM + test_kylin_fact f + INNER JOIN test_order o ON f.order_id = o.order_id + WHERE + buyer_id > 100) t2 ON t1.leaf_categ_id = t2.leaf_categ_id +GROUP BY t1.leaf_categ_id +ORDER BY nums, leaf_categ_id +limit 100 \ No newline at end of file diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java index 8d7c597..42adcf8 100644 --- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java +++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java @@ -252,7 +252,8 @@ public class OLAPAggregateRel extends Aggregate implements OLAPRel { @Override public void implementRewrite(RewriteImplementor implementor) { // only rewrite the innermost aggregation - if (!this.afterAggregate) { + boolean hasRealization = (null != this.context.realization); + if (hasRealization && !this.afterAggregate) { translateAggregation(); buildRewriteFieldsAndMetricsColumns(); } @@ -260,7 +261,7 @@ public class OLAPAggregateRel extends Aggregate implements OLAPRel { implementor.visitChild(this, getInput()); // only rewrite the innermost aggregation - if (!this.afterAggregate) { + if (hasRealization && !this.afterAggregate) { // rewrite the aggCalls this.rewriteAggCalls = new ArrayList(aggCalls.size()); for (int i = 0; i < this.aggCalls.size(); i++) { -- 2.9.3 (Apple Git-75)