From 8915b4b598fcb82ceba7ec722b1a422b8ad29f55 Mon Sep 17 00:00:00 2001 From: sirpkt Date: Wed, 31 Dec 2014 17:22:52 +0900 Subject: [PATCH 1/2] Filter push down is changed not to push down theta join condition --- .../tajo/engine/planner/TestLogicalPlanner.java | 2 +- .../apache/tajo/engine/query/TestJoinQuery.java | 14 ++++++++++++++ ...testCrossJoinWithThetaJoinConditionInWhere.sql | 2 ++ ...testInnerJoinWithThetaJoinConditionInWhere.sql | 2 ++ ...tCrossJoinWithThetaJoinConditionInWhere.result | 12 ++++++++++++ ...tInnerJoinWithThetaJoinConditionInWhere.result | 7 +++++++ .../plan/rewrite/rules/FilterPushDownRule.java | 15 +++++++++++++++ 7 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tajo-core/src/test/resources/queries/TestJoinQuery/testCrossJoinWithThetaJoinConditionInWhere.sql create mode 100644 tajo-core/src/test/resources/queries/TestJoinQuery/testInnerJoinWithThetaJoinConditionInWhere.sql create mode 100644 tajo-core/src/test/resources/results/TestJoinQuery/testCrossJoinWithThetaJoinConditionInWhere.result create mode 100644 tajo-core/src/test/resources/results/TestJoinQuery/testInnerJoinWithThetaJoinConditionInWhere.result diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlanner.java b/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlanner.java index 180033d1a6..3529ca2df0 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlanner.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestLogicalPlanner.java @@ -644,7 +644,7 @@ public final void testJoinWithMultipleJoinQual4() throws IOException, PlanningEx , new FieldEval(new Column("default.t.n_nationkey", Type.INT4)) , new FieldEval(new Column("default.s.s_suppkey", Type.INT4)) ); - joinQualMap.put(joinQual, Boolean.FALSE); + //joinQualMap.put(joinQual, Boolean.FALSE); LogicalNode[] nodes = PlannerUtil.findAllNodes(node, NodeType.JOIN); for(LogicalNode eachNode : nodes) { diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java index 223ea8e177..968490128a 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java @@ -120,6 +120,20 @@ public final void testCrossJoin() throws Exception { cleanupQuery(res); } + @Test + public final void testCrossJoinWithThetaJoinConditionInWhere() throws Exception { + ResultSet res = executeQuery(); + assertResultSet(res); + cleanupQuery(res); + } + + @Test + public final void testInnerJoinWithThetaJoinConditionInWhere() throws Exception { + ResultSet res = executeQuery(); + assertResultSet(res); + cleanupQuery(res); + } + @Test public final void testWhereClauseJoin1() throws Exception { ResultSet res = executeQuery(); diff --git a/tajo-core/src/test/resources/queries/TestJoinQuery/testCrossJoinWithThetaJoinConditionInWhere.sql b/tajo-core/src/test/resources/queries/TestJoinQuery/testCrossJoinWithThetaJoinConditionInWhere.sql new file mode 100644 index 0000000000..4e20e16baa --- /dev/null +++ b/tajo-core/src/test/resources/queries/TestJoinQuery/testCrossJoinWithThetaJoinConditionInWhere.sql @@ -0,0 +1,2 @@ +select a.r_name as a_name, b.r_name as b_name from region a, region b +where a_name < b_name; \ No newline at end of file diff --git a/tajo-core/src/test/resources/queries/TestJoinQuery/testInnerJoinWithThetaJoinConditionInWhere.sql b/tajo-core/src/test/resources/queries/TestJoinQuery/testInnerJoinWithThetaJoinConditionInWhere.sql new file mode 100644 index 0000000000..adb8c6d1dd --- /dev/null +++ b/tajo-core/src/test/resources/queries/TestJoinQuery/testInnerJoinWithThetaJoinConditionInWhere.sql @@ -0,0 +1,2 @@ +select a.r_regionkey, a.r_name, b.r_name from region a, region b +where a.r_regionkey = b.r_regionkey and a.r_name <= b.r_name; \ No newline at end of file diff --git a/tajo-core/src/test/resources/results/TestJoinQuery/testCrossJoinWithThetaJoinConditionInWhere.result b/tajo-core/src/test/resources/results/TestJoinQuery/testCrossJoinWithThetaJoinConditionInWhere.result new file mode 100644 index 0000000000..82b275753f --- /dev/null +++ b/tajo-core/src/test/resources/results/TestJoinQuery/testCrossJoinWithThetaJoinConditionInWhere.result @@ -0,0 +1,12 @@ +a_name,b_name +------------------------------- +AFRICA,AMERICA +AFRICA,ASIA +AFRICA,EUROPE +AFRICA,MIDDLE EAST +AMERICA,ASIA +AMERICA,EUROPE +AMERICA,MIDDLE EAST +ASIA,EUROPE +ASIA,MIDDLE EAST +EUROPE,MIDDLE EAST \ No newline at end of file diff --git a/tajo-core/src/test/resources/results/TestJoinQuery/testInnerJoinWithThetaJoinConditionInWhere.result b/tajo-core/src/test/resources/results/TestJoinQuery/testInnerJoinWithThetaJoinConditionInWhere.result new file mode 100644 index 0000000000..b388d0b706 --- /dev/null +++ b/tajo-core/src/test/resources/results/TestJoinQuery/testInnerJoinWithThetaJoinConditionInWhere.result @@ -0,0 +1,7 @@ +r_regionkey,r_name,r_name +------------------------------- +0,AFRICA,AFRICA +1,AMERICA,AMERICA +2,ASIA,ASIA +3,EUROPE,EUROPE +4,MIDDLE EAST,MIDDLE EAST \ No newline at end of file diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/FilterPushDownRule.java b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/FilterPushDownRule.java index 15750a148c..155b867da3 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/FilterPushDownRule.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/FilterPushDownRule.java @@ -210,6 +210,20 @@ public LogicalNode visitJoin(FilterPushDownContext context, LogicalPlan plan, Lo } } + // non-equi filter should not be push down as a join qualifier until theta join is implemented + List thetaJoinFilter = new ArrayList(); + for (EvalNode eachEval: context.pushingDownFilters) { + if (eachEval.getType() != EvalType.EQUAL) { + if (EvalTreeUtil.isJoinQual(block, + joinNode.getLeftChild().getOutSchema(), + joinNode.getRightChild().getOutSchema(), + eachEval, true)) { + thetaJoinFilter.add(eachEval); + } + } + } + context.pushingDownFilters.removeAll(thetaJoinFilter); + // get evals from ON clause List onConditions = new ArrayList(); if (joinNode.hasJoinQual()) { @@ -344,6 +358,7 @@ public LogicalNode visitJoin(FilterPushDownContext context, LogicalPlan plan, Lo } context.pushingDownFilters.addAll(outerJoinFilterEvalsExcludePredication); + context.pushingDownFilters.addAll(thetaJoinFilter); return joinNode; } From 376bd194c51a23d407cc0161b7c9c9dae6f36714 Mon Sep 17 00:00:00 2001 From: sirpkt Date: Fri, 2 Jan 2015 11:07:38 +0900 Subject: [PATCH 2/2] add test cases for inner, left outer, right outer joins --- .../apache/tajo/engine/query/TestJoinQuery.java | 14 ++++++++++++++ .../testInnerJoinWithThetaJoinConditionInWhere.sql | 5 +++-- ...tLeftOuterJoinWithThetaJoinConditionInWhere.sql | 3 +++ ...RightOuterJoinWithThetaJoinConditionInWhere.sql | 3 +++ ...ftOuterJoinWithThetaJoinConditionInWhere.result | 4 ++++ ...htOuterJoinWithThetaJoinConditionInWhere.result | 4 ++++ 6 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 tajo-core/src/test/resources/queries/TestJoinQuery/testLeftOuterJoinWithThetaJoinConditionInWhere.sql create mode 100644 tajo-core/src/test/resources/queries/TestJoinQuery/testRightOuterJoinWithThetaJoinConditionInWhere.sql create mode 100644 tajo-core/src/test/resources/results/TestJoinQuery/testLeftOuterJoinWithThetaJoinConditionInWhere.result create mode 100644 tajo-core/src/test/resources/results/TestJoinQuery/testRightOuterJoinWithThetaJoinConditionInWhere.result diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java index 968490128a..ecd933dfe8 100644 --- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java +++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestJoinQuery.java @@ -134,6 +134,20 @@ public final void testInnerJoinWithThetaJoinConditionInWhere() throws Exception cleanupQuery(res); } + @Test + public final void testLeftOuterJoinWithThetaJoinConditionInWhere() throws Exception { + ResultSet res = executeQuery(); + assertResultSet(res); + cleanupQuery(res); + } + + @Test + public final void testRightOuterJoinWithThetaJoinConditionInWhere() throws Exception { + ResultSet res = executeQuery(); + assertResultSet(res); + cleanupQuery(res); + } + @Test public final void testWhereClauseJoin1() throws Exception { ResultSet res = executeQuery(); diff --git a/tajo-core/src/test/resources/queries/TestJoinQuery/testInnerJoinWithThetaJoinConditionInWhere.sql b/tajo-core/src/test/resources/queries/TestJoinQuery/testInnerJoinWithThetaJoinConditionInWhere.sql index adb8c6d1dd..90f4822ea7 100644 --- a/tajo-core/src/test/resources/queries/TestJoinQuery/testInnerJoinWithThetaJoinConditionInWhere.sql +++ b/tajo-core/src/test/resources/queries/TestJoinQuery/testInnerJoinWithThetaJoinConditionInWhere.sql @@ -1,2 +1,3 @@ -select a.r_regionkey, a.r_name, b.r_name from region a, region b -where a.r_regionkey = b.r_regionkey and a.r_name <= b.r_name; \ No newline at end of file +select a.r_regionkey, a.r_name, b.r_name from region a join region b +on a.r_regionkey = b.r_regionkey +where a.r_name <= b.r_name; \ No newline at end of file diff --git a/tajo-core/src/test/resources/queries/TestJoinQuery/testLeftOuterJoinWithThetaJoinConditionInWhere.sql b/tajo-core/src/test/resources/queries/TestJoinQuery/testLeftOuterJoinWithThetaJoinConditionInWhere.sql new file mode 100644 index 0000000000..f9160c513b --- /dev/null +++ b/tajo-core/src/test/resources/queries/TestJoinQuery/testLeftOuterJoinWithThetaJoinConditionInWhere.sql @@ -0,0 +1,3 @@ +select * from region a left outer join customer b +on a.r_regionkey = b.c_custkey +where a.r_name < b.c_name; \ No newline at end of file diff --git a/tajo-core/src/test/resources/queries/TestJoinQuery/testRightOuterJoinWithThetaJoinConditionInWhere.sql b/tajo-core/src/test/resources/queries/TestJoinQuery/testRightOuterJoinWithThetaJoinConditionInWhere.sql new file mode 100644 index 0000000000..10d9918ca0 --- /dev/null +++ b/tajo-core/src/test/resources/queries/TestJoinQuery/testRightOuterJoinWithThetaJoinConditionInWhere.sql @@ -0,0 +1,3 @@ +select * from region a right outer join customer b +on a.r_regionkey = b.c_custkey +where a.r_name < b.c_name; \ No newline at end of file diff --git a/tajo-core/src/test/resources/results/TestJoinQuery/testLeftOuterJoinWithThetaJoinConditionInWhere.result b/tajo-core/src/test/resources/results/TestJoinQuery/testLeftOuterJoinWithThetaJoinConditionInWhere.result new file mode 100644 index 0000000000..c727791179 --- /dev/null +++ b/tajo-core/src/test/resources/results/TestJoinQuery/testLeftOuterJoinWithThetaJoinConditionInWhere.result @@ -0,0 +1,4 @@ +r_regionkey,r_name,r_comment,c_custkey,c_name,c_address,c_nationkey,c_phone,c_acctbal,c_mktsegment,c_comment +------------------------------- +1,AMERICA,hs use ironic, even requests. s,1,Customer#000000001,IVhzIApeRb ot,c,E,15,25-989-741-2988,711.56,BUILDING,to the even, regular platelets. regular, ironic epitaphs nag e +2,ASIA,ges. thinly even pinto beans ca,2,Customer#000000002,XSTf4,NCwDVaWNe6tEgvwfmRchLXak,13,23-768-687-3665,121.65,AUTOMOBILE,l accounts. blithely ironic theodolites integrate boldly: caref \ No newline at end of file diff --git a/tajo-core/src/test/resources/results/TestJoinQuery/testRightOuterJoinWithThetaJoinConditionInWhere.result b/tajo-core/src/test/resources/results/TestJoinQuery/testRightOuterJoinWithThetaJoinConditionInWhere.result new file mode 100644 index 0000000000..c727791179 --- /dev/null +++ b/tajo-core/src/test/resources/results/TestJoinQuery/testRightOuterJoinWithThetaJoinConditionInWhere.result @@ -0,0 +1,4 @@ +r_regionkey,r_name,r_comment,c_custkey,c_name,c_address,c_nationkey,c_phone,c_acctbal,c_mktsegment,c_comment +------------------------------- +1,AMERICA,hs use ironic, even requests. s,1,Customer#000000001,IVhzIApeRb ot,c,E,15,25-989-741-2988,711.56,BUILDING,to the even, regular platelets. regular, ironic epitaphs nag e +2,ASIA,ges. thinly even pinto beans ca,2,Customer#000000002,XSTf4,NCwDVaWNe6tEgvwfmRchLXak,13,23-768-687-3665,121.65,AUTOMOBILE,l accounts. blithely ironic theodolites integrate boldly: caref \ No newline at end of file