Repository: kylin
Updated Branches:
  refs/heads/1.x-staging 24b7aa7f7 -> b1fe5eac8


KYLIN-1419 NPE occurs when query from subqueries with order by (revised by Yang)


Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/b1fe5eac
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/b1fe5eac
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/b1fe5eac

Branch: refs/heads/1.x-staging
Commit: b1fe5eac8555f3dda580c455d124f54f703c8ec9
Parents: 24b7aa7
Author: nichunen <nichu...@mininglamp.com>
Authored: Wed Feb 17 11:07:32 2016 +0800
Committer: Li, Yang <liy...@apache.org>
Committed: Wed Feb 17 11:08:35 2016 +0800

----------------------------------------------------------------------
 .../apache/kylin/query/relnode/OLAPSortRel.java |  5 +++
 .../resources/query/sql_subquery/query09.sql    | 33 ++++++++++++++++++++
 2 files changed, 38 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/b1fe5eac/query/src/main/java/org/apache/kylin/query/relnode/OLAPSortRel.java
----------------------------------------------------------------------
diff --git 
a/query/src/main/java/org/apache/kylin/query/relnode/OLAPSortRel.java 
b/query/src/main/java/org/apache/kylin/query/relnode/OLAPSortRel.java
index e8b7d17..6d13b07 100644
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPSortRel.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPSortRel.java
@@ -81,6 +81,11 @@ public class OLAPSortRel extends Sort implements OLAPRel {
     public void implementRewrite(RewriteImplementor implementor) {
         implementor.visitChild(this, getInput());
 
+        // No need to rewrite "order by" applied on non-olap context.
+        // Occurs in sub-query like "select ... from (...) inner join (...) 
order by ..."
+        if (this.context.realization == null)
+            return;
+        
         for (RelFieldCollation fieldCollation : 
this.collation.getFieldCollations()) {
             int index = fieldCollation.getFieldIndex();
             StorageContext.OrderEnum order = 
getOrderEnum(fieldCollation.getDirection());

http://git-wip-us.apache.org/repos/asf/kylin/blob/b1fe5eac/query/src/test/resources/query/sql_subquery/query09.sql
----------------------------------------------------------------------
diff --git a/query/src/test/resources/query/sql_subquery/query09.sql 
b/query/src/test/resources/query/sql_subquery/query09.sql
new file mode 100644
index 0000000..3502cd7
--- /dev/null
+++ b/query/src/test/resources/query/sql_subquery/query09.sql
@@ -0,0 +1,33 @@
+--
+-- 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.week_beg_dt, t1.sum_price, t2.cnt
+FROM (
+  select test_cal_dt.week_beg_dt, sum(test_kylin_fact.price) as sum_price
+  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
+  group by test_cal_dt.week_beg_dt
+) t1
+inner join  (
+  select test_cal_dt.week_beg_dt, count(*) as cnt
+  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
+  group by test_cal_dt.week_beg_dt
+) t2
+on t1.week_beg_dt=t2.week_beg_dt
+order by t1.week_beg_dt

Reply via email to