You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by sh...@apache.org on 2018/12/14 06:54:34 UTC
[kylin] branch 2.4.x updated: KYLIN-2841 LIMIT is buggy with
subquery
This is an automated email from the ASF dual-hosted git repository.
shaofengshi pushed a commit to branch 2.4.x
in repository https://gitbox.apache.org/repos/asf/kylin.git
The following commit(s) were added to refs/heads/2.4.x by this push:
new 900f64f KYLIN-2841 LIMIT is buggy with subquery
900f64f is described below
commit 900f64f460a8e78f990431b55efa405d7ed2c990
Author: zhengdong <zh...@outlook.com>
AuthorDate: Wed Sep 6 18:01:03 2017 +0800
KYLIN-2841 LIMIT is buggy with subquery
Signed-off-by: shaofengshi <sh...@apache.org>
---
.../test/resources/query/sql_subquery/query35.sql | 2 ++
.../sql_subquery/{query35.sql => query37.sql} | 25 +++++++++++++---------
.../kylin/query/relnode/OLAPAggregateRel.java | 1 +
.../apache/kylin/query/relnode/OLAPContext.java | 2 ++
.../apache/kylin/query/relnode/OLAPLimitRel.java | 3 ++-
5 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/kylin-it/src/test/resources/query/sql_subquery/query35.sql b/kylin-it/src/test/resources/query/sql_subquery/query35.sql
index a15a452..1101c2f 100644
--- a/kylin-it/src/test/resources/query/sql_subquery/query35.sql
+++ b/kylin-it/src/test/resources/query/sql_subquery/query35.sql
@@ -15,6 +15,8 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
+
+
SELECT "TEST_KYLIN_FACT"."CAL_DT", SUM("TEST_KYLIN_FACT"."PRICE") AS "sum_PRICE_ok" FROM "TEST_KYLIN_FACT" "TEST_KYLIN_FACT"
RIGHT JOIN (
SELECT COUNT(1) AS "XTableau_join_flag", SUM("TEST_KYLIN_FACT"."PRICE") AS "X__alias__A", "TEST_KYLIN_FACT"."CAL_DT" AS "none_CAL_DT_ok" FROM "TEST_KYLIN_FACT" "TEST_KYLIN_FACT"
diff --git a/kylin-it/src/test/resources/query/sql_subquery/query35.sql b/kylin-it/src/test/resources/query/sql_subquery/query37.sql
similarity index 56%
copy from kylin-it/src/test/resources/query/sql_subquery/query35.sql
copy to kylin-it/src/test/resources/query/sql_subquery/query37.sql
index a15a452..b96b544 100644
--- a/kylin-it/src/test/resources/query/sql_subquery/query35.sql
+++ b/kylin-it/src/test/resources/query/sql_subquery/query37.sql
@@ -15,13 +15,18 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-SELECT "TEST_KYLIN_FACT"."CAL_DT", SUM("TEST_KYLIN_FACT"."PRICE") AS "sum_PRICE_ok" FROM "TEST_KYLIN_FACT" "TEST_KYLIN_FACT"
- RIGHT JOIN (
- SELECT COUNT(1) AS "XTableau_join_flag", SUM("TEST_KYLIN_FACT"."PRICE") AS "X__alias__A", "TEST_KYLIN_FACT"."CAL_DT" AS "none_CAL_DT_ok" FROM "TEST_KYLIN_FACT" "TEST_KYLIN_FACT"
- GROUP BY "TEST_KYLIN_FACT"."CAL_DT" ORDER BY 2 DESC LIMIT 7 )
- "t0" ON
- CASE WHEN 1 = 1
- THEN ("TEST_KYLIN_FACT"."CAL_DT" = "t0"."none_CAL_DT_ok")
- ELSE "TEST_KYLIN_FACT"."CAL_DT" = "t0"."none_CAL_DT_ok"
- END
- GROUP BY "TEST_KYLIN_FACT"."CAL_DT"
+
+SELECT count(1) cnt
+ FROM (
+ select LSTG_FORMAT_NAME, sum(test_kylin_fact.price) as sum_price, count(1) as cnt_1
+ from test_kylin_fact
+inner JOIN edw.test_cal_dt as test_cal_dt
+ ON test_kylin_fact.cal_dt = test_cal_dt.cal_dt
+ inner JOIN test_category_groupings
+ ON test_kylin_fact.leaf_categ_id = test_category_groupings.leaf_categ_id AND test_kylin_fact.lstg_site_id = test_category_groupings.site_id
+ inner JOIN edw.test_sites as test_sites
+ ON test_kylin_fact.lstg_site_id = test_sites.site_id
+ group by LSTG_FORMAT_NAME
+ )
+ limit 1
+
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
old mode 100644
new mode 100755
index ab8be1b..90bd0cf
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java
@@ -199,6 +199,7 @@ public class OLAPAggregateRel extends Aggregate implements OLAPRel {
this.context.limitPrecedesAggr = true;
}
} else {
+ this.context.afterOuterAggregate = true;
for (AggregateCall aggCall : aggCalls) {
// check if supported by kylin
if (aggCall.isDistinct()) {
diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPContext.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPContext.java
old mode 100644
new mode 100755
index e43c257..389b198
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPContext.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPContext.java
@@ -133,6 +133,8 @@ public class OLAPContext {
public boolean afterJoin = false;
public boolean hasJoin = false;
public boolean hasWindow = false;
+ public boolean groupByExpression = false; // checkout if group by column has operator
+ public boolean afterOuterAggregate = false;
// cube metadata
public IRealization realization;
diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPLimitRel.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPLimitRel.java
old mode 100644
new mode 100755
index 1c3de45..7ec489b
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPLimitRel.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPLimitRel.java
@@ -81,7 +81,8 @@ public class OLAPLimitRel extends SingleRel implements OLAPRel {
// ignore limit after having clause
// ignore limit after another limit, e.g. select A, count(*) from (select A,B from fact group by A,B limit 100) limit 10
- if (!context.afterHavingClauseFilter && !context.afterLimit) {
+ // ignore limit after outer aggregate, e.g. select count(1) from (select A,B from fact group by A,B ) limit 10
+ if (!context.afterHavingClauseFilter && !context.afterLimit && !context.afterOuterAggregate) {
Number limitValue = (Number) (((RexLiteral) localFetch).getValue());
int limit = limitValue.intValue();
this.context.storageContext.setLimit(limit);