From 876a93b17f0d55e8e778e596d970395c68198681 Mon Sep 17 00:00:00 2001 From: Cheng Wang Date: Tue, 5 Jul 2016 10:16:20 +0800 Subject: [PATCH] KYLIN 1792 it fixed when join contains subquery, kylin will return no results. --- .../java/org/apache/kylin/query/relnode/OLAPJoinRel.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 dc16dad..f66351b 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 @@ -117,11 +117,14 @@ public class OLAPJoinRel extends EnumerableJoin implements OLAPRel { this.isTopJoin = !this.context.hasJoin; this.context.hasJoin = true; + int nJoinPossibility = 0; + // as we keep the first table as fact table, we need to visit from left to right implementor.visitChild(this.left, this); if (this.context != implementor.getContext() || ((OLAPRel) this.left).hasSubQuery()) { this.hasSubQuery = true; // if child is also an OLAPJoin, then the context has already been popped + nJoinPossibility--; if (this.context != implementor.getContext()) { implementor.freeContext(); } @@ -129,6 +132,7 @@ public class OLAPJoinRel extends EnumerableJoin implements OLAPRel { implementor.visitChild(this.right, this); if (this.context != implementor.getContext() || ((OLAPRel) this.right).hasSubQuery()) { this.hasSubQuery = true; + nJoinPossibility++; // if child is also an OLAPJoin, then the context has already been popped if (this.context != implementor.getContext()) { implementor.freeContext(); @@ -136,6 +140,7 @@ public class OLAPJoinRel extends EnumerableJoin implements OLAPRel { } this.columnRowType = buildColumnRowType(); + if (isTopJoin) { this.context.afterJoin = true; } @@ -152,6 +157,16 @@ public class OLAPJoinRel extends EnumerableJoin implements OLAPRel { join.setType(joinType); this.context.joins.add(join); + } else if (0 != nJoinPossibility) { + //When join contains subquery, the join-condition fields of fact_table will add into context. + Map joinCol = new HashMap(); + translateJoinColumn((RexCall) this.getCondition(), joinCol); + + for (Map.Entry columnPair : joinCol.entrySet()) { + TblColRef fromCol = (-1 == nJoinPossibility ? columnPair.getValue() : columnPair.getKey()); + this.context.groupByColumns.add(fromCol); + } + joinCol.clear(); } } -- 2.7.4 (Apple Git-66)