From fa65718ea2eda5053bad05c09be566a6e400503f Mon Sep 17 00:00:00 2001 From: Zhongshuai Pei <799203320@qq.com> Date: Fri, 22 May 2015 13:55:41 +0800 Subject: [PATCH 01/12] Update Optimizer.scala --- .../sql/catalyst/optimizer/Optimizer.scala | 131 +++++++++++------- 1 file changed, 78 insertions(+), 53 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala index c2818d957cc79..ae28292d941bb 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala @@ -36,6 +36,8 @@ object DefaultOptimizer extends Optimizer { // SubQueries are only needed for analysis and can be removed before execution. Batch("Remove SubQueries", FixedPoint(100), EliminateSubQueries) :: + Batch("Transform Condition", FixedPoint(100), + TransformCondition) :: Batch("Operator Reordering", FixedPoint(100), UnionPushdown, CombineFilters, @@ -60,6 +62,80 @@ object DefaultOptimizer extends Optimizer { ConvertToLocalRelation) :: Nil } +/** + * Transform and/or Condition: + * 1. a && a => a + * 2. (a || b) && (a || c) => a || (b && c) + * 3. a || a => a + * 4. (a && b) || (a && c) => a && (b || c) + */ +object TransformCondition extends Rule[LogicalPlan] with PredicateHelper { + def apply(plan: LogicalPlan): LogicalPlan = plan transform { + case q: LogicalPlan => q transformExpressionsUp { + case and @ And(left, right) => (left, right) match { + + // a && a => a + case (l, r) if l fastEquals r => l + // (a || b) && (a || c) => a || (b && c) + case _ => + // 1. Split left and right to get the disjunctive predicates, + // i.e. lhsSet = (a, b), rhsSet = (a, c) + // 2. Find the common predict between lhsSet and rhsSet, i.e. common = (a) + // 3. Remove common predict from lhsSet and rhsSet, i.e. ldiff = (b), rdiff = (c) + // 4. Apply the formula, get the optimized predicate: common || (ldiff && rdiff) + val lhsSet = splitDisjunctivePredicates(left).toSet + val rhsSet = splitDisjunctivePredicates(right).toSet + val common = lhsSet.intersect(rhsSet) + if (common.isEmpty) { + // No common factors, return the original predicate + and + } else { + val ldiff = lhsSet.diff(common) + val rdiff = rhsSet.diff(common) + if (ldiff.isEmpty || rdiff.isEmpty) { + // (a || b || c || ...) && (a || b) => (a || b) + common.reduce(Or) + } else { + // (a || b || c || ...) && (a || b || d || ...) => + // ((c || ...) && (d || ...)) || a || b + (common + And(ldiff.reduce(Or), rdiff.reduce(Or))).reduce(Or) + } + } + } // end of And(left, right) + + case or @ Or(left, right) => (left, right) match { + + case (l, r) if l fastEquals r => l + // (a && b) || (a && c) => a && (b || c) + case _ => + // 1. Split left and right to get the conjunctive predicates, + // i.e. lhsSet = (a, b), rhsSet = (a, c) + // 2. Find the common predict between lhsSet and rhsSet, i.e. common = (a) + // 3. Remove common predict from lhsSet and rhsSet, i.e. ldiff = (b), rdiff = (c) + // 4. Apply the formula, get the optimized predicate: common && (ldiff || rdiff) + val lhsSet = splitConjunctivePredicates(left).toSet + val rhsSet = splitConjunctivePredicates(right).toSet + val common = lhsSet.intersect(rhsSet) + if (common.isEmpty) { + // No common factors, return the original predicate + or + } else { + val ldiff = lhsSet.diff(common) + val rdiff = rhsSet.diff(common) + if (ldiff.isEmpty || rdiff.isEmpty) { + // (a && b) || (a && b && c && ...) => a && b + common.reduce(And) + } else { + // (a && b && c && ...) || (a && b && d && ...) => + // ((c && ...) || (d && ...)) && a && b + (common + Or(ldiff.reduce(And), rdiff.reduce(And))).reduce(And) + } + } + } // end of Or(left, right) + } + } +} + /** * Pushes operations to either side of a Union. */ @@ -347,32 +423,7 @@ object BooleanSimplification extends Rule[LogicalPlan] with PredicateHelper { // l && false => false case (_, Literal(false, BooleanType)) => Literal(false) // a && a => a - case (l, r) if l fastEquals r => l - // (a || b) && (a || c) => a || (b && c) - case _ => - // 1. Split left and right to get the disjunctive predicates, - // i.e. lhsSet = (a, b), rhsSet = (a, c) - // 2. Find the common predict between lhsSet and rhsSet, i.e. common = (a) - // 3. Remove common predict from lhsSet and rhsSet, i.e. ldiff = (b), rdiff = (c) - // 4. Apply the formula, get the optimized predicate: common || (ldiff && rdiff) - val lhsSet = splitDisjunctivePredicates(left).toSet - val rhsSet = splitDisjunctivePredicates(right).toSet - val common = lhsSet.intersect(rhsSet) - if (common.isEmpty) { - // No common factors, return the original predicate - and - } else { - val ldiff = lhsSet.diff(common) - val rdiff = rhsSet.diff(common) - if (ldiff.isEmpty || rdiff.isEmpty) { - // (a || b || c || ...) && (a || b) => (a || b) - common.reduce(Or) - } else { - // (a || b || c || ...) && (a || b || d || ...) => - // ((c || ...) && (d || ...)) || a || b - (common + And(ldiff.reduce(Or), rdiff.reduce(Or))).reduce(Or) - } - } + case _ => and } // end of And(left, right) case or @ Or(left, right) => (left, right) match { @@ -384,33 +435,7 @@ object BooleanSimplification extends Rule[LogicalPlan] with PredicateHelper { case (Literal(false, BooleanType), r) => r // l || false => l case (l, Literal(false, BooleanType)) => l - // a || a => a - case (l, r) if l fastEquals r => l - // (a && b) || (a && c) => a && (b || c) - case _ => - // 1. Split left and right to get the conjunctive predicates, - // i.e. lhsSet = (a, b), rhsSet = (a, c) - // 2. Find the common predict between lhsSet and rhsSet, i.e. common = (a) - // 3. Remove common predict from lhsSet and rhsSet, i.e. ldiff = (b), rdiff = (c) - // 4. Apply the formula, get the optimized predicate: common && (ldiff || rdiff) - val lhsSet = splitConjunctivePredicates(left).toSet - val rhsSet = splitConjunctivePredicates(right).toSet - val common = lhsSet.intersect(rhsSet) - if (common.isEmpty) { - // No common factors, return the original predicate - or - } else { - val ldiff = lhsSet.diff(common) - val rdiff = rhsSet.diff(common) - if (ldiff.isEmpty || rdiff.isEmpty) { - // (a && b) || (a && b && c && ...) => a && b - common.reduce(And) - } else { - // (a && b && c && ...) || (a && b && d && ...) => - // ((c && ...) || (d && ...)) && a && b - (common + Or(ldiff.reduce(And), rdiff.reduce(And))).reduce(And) - } - } + case _ => or } // end of Or(left, right) case not @ Not(exp) => exp match { From d98bc35e62a60a21c3c9bd5ef814aef664e75197 Mon Sep 17 00:00:00 2001 From: Zhongshuai Pei <799203320@qq.com> Date: Fri, 22 May 2015 17:51:29 +0800 Subject: [PATCH 02/12] Update FilterPushdownSuite.scala --- .../optimizer/FilterPushdownSuite.scala | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala index be33cb9bb8eaa..4728714d20e06 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala @@ -33,6 +33,8 @@ class FilterPushdownSuite extends PlanTest { val batches = Batch("Subqueries", Once, EliminateSubQueries) :: + Batch("Transform Condition", Once, + TransformCondition) :: Batch("Filter Pushdown", Once, CombineFilters, PushPredicateThroughProject, @@ -197,6 +199,26 @@ class FilterPushdownSuite extends PlanTest { comparePlans(optimized, correctAnswer) } + + test("joins: push to one side after transformCondition") { + val x = testRelation.subquery('x) + val y = testRelation1.subquery('y) + + val originalQuery = { + x.join(y, Inner) + .where(("x.a".attr === 1 && "y.d".attr === "x.b".attr) || + ("x.a".attr === 1 && "y.d".attr === "x.c".attr)) + } + + val optimized = Optimize.execute(originalQuery.analyze) + val left = testRelation.where('a === 1) + val right = testRelation1 + val correctAnswer = + left.join(right, condition = Some("d".attr === "b".attr || "d".attr === "c".attr)).analyze + + comparePlans(optimized, correctAnswer) + } + test("joins: rewrite filter to push to either side") { val x = testRelation.subquery('x) From 8df716ac5a4a660904c7703c438df175608d3c9a Mon Sep 17 00:00:00 2001 From: Zhongshuai Pei <799203320@qq.com> Date: Sat, 23 May 2015 09:08:54 +0800 Subject: [PATCH 03/12] Update FilterPushdownSuite.scala --- .../spark/sql/catalyst/optimizer/FilterPushdownSuite.scala | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala index 4728714d20e06..4fc60def94a45 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala @@ -158,11 +158,9 @@ class FilterPushdownSuite extends PlanTest { .where('a === 1 && 'a === 2) .select('a).analyze - comparePlans(optimized, correctAnswer) } - test("joins: push to either side") { val x = testRelation.subquery('x) val y = testRelation.subquery('y) @@ -218,7 +216,6 @@ class FilterPushdownSuite extends PlanTest { comparePlans(optimized, correctAnswer) } - test("joins: rewrite filter to push to either side") { val x = testRelation.subquery('x) @@ -596,6 +593,5 @@ class FilterPushdownSuite extends PlanTest { .select('b).analyze comparePlans(optimized1, analysis.EliminateSubQueries(correctAnswer1)) - } } From be6b1d5c495a23037a2316b8d22f1d0e0fc20c77 Mon Sep 17 00:00:00 2001 From: Zhongshuai Pei <799203320@qq.com> Date: Wed, 27 May 2015 10:42:54 +0800 Subject: [PATCH 04/12] Update Optimizer.scala --- .../sql/catalyst/optimizer/Optimizer.scala | 138 +++++++----------- 1 file changed, 56 insertions(+), 82 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala index ae28292d941bb..83277c0bd4d90 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala @@ -36,23 +36,20 @@ object DefaultOptimizer extends Optimizer { // SubQueries are only needed for analysis and can be removed before execution. Batch("Remove SubQueries", FixedPoint(100), EliminateSubQueries) :: - Batch("Transform Condition", FixedPoint(100), - TransformCondition) :: - Batch("Operator Reordering", FixedPoint(100), + Batch("Operator Optimizations", FixedPoint(100), UnionPushdown, CombineFilters, PushPredicateThroughProject, - PushPredicateThroughJoin, PushPredicateThroughGenerate, ColumnPruning, ProjectCollapsing, - CombineLimits) :: - Batch("ConstantFolding", FixedPoint(100), + CombineLimits, NullPropagation, OptimizeIn, ConstantFolding, LikeSimplification, BooleanSimplification, + PushPredicateThroughJoin, SimplifyFilters, SimplifyCasts, SimplifyCaseConversionExpressions) :: @@ -62,80 +59,6 @@ object DefaultOptimizer extends Optimizer { ConvertToLocalRelation) :: Nil } -/** - * Transform and/or Condition: - * 1. a && a => a - * 2. (a || b) && (a || c) => a || (b && c) - * 3. a || a => a - * 4. (a && b) || (a && c) => a && (b || c) - */ -object TransformCondition extends Rule[LogicalPlan] with PredicateHelper { - def apply(plan: LogicalPlan): LogicalPlan = plan transform { - case q: LogicalPlan => q transformExpressionsUp { - case and @ And(left, right) => (left, right) match { - - // a && a => a - case (l, r) if l fastEquals r => l - // (a || b) && (a || c) => a || (b && c) - case _ => - // 1. Split left and right to get the disjunctive predicates, - // i.e. lhsSet = (a, b), rhsSet = (a, c) - // 2. Find the common predict between lhsSet and rhsSet, i.e. common = (a) - // 3. Remove common predict from lhsSet and rhsSet, i.e. ldiff = (b), rdiff = (c) - // 4. Apply the formula, get the optimized predicate: common || (ldiff && rdiff) - val lhsSet = splitDisjunctivePredicates(left).toSet - val rhsSet = splitDisjunctivePredicates(right).toSet - val common = lhsSet.intersect(rhsSet) - if (common.isEmpty) { - // No common factors, return the original predicate - and - } else { - val ldiff = lhsSet.diff(common) - val rdiff = rhsSet.diff(common) - if (ldiff.isEmpty || rdiff.isEmpty) { - // (a || b || c || ...) && (a || b) => (a || b) - common.reduce(Or) - } else { - // (a || b || c || ...) && (a || b || d || ...) => - // ((c || ...) && (d || ...)) || a || b - (common + And(ldiff.reduce(Or), rdiff.reduce(Or))).reduce(Or) - } - } - } // end of And(left, right) - - case or @ Or(left, right) => (left, right) match { - - case (l, r) if l fastEquals r => l - // (a && b) || (a && c) => a && (b || c) - case _ => - // 1. Split left and right to get the conjunctive predicates, - // i.e. lhsSet = (a, b), rhsSet = (a, c) - // 2. Find the common predict between lhsSet and rhsSet, i.e. common = (a) - // 3. Remove common predict from lhsSet and rhsSet, i.e. ldiff = (b), rdiff = (c) - // 4. Apply the formula, get the optimized predicate: common && (ldiff || rdiff) - val lhsSet = splitConjunctivePredicates(left).toSet - val rhsSet = splitConjunctivePredicates(right).toSet - val common = lhsSet.intersect(rhsSet) - if (common.isEmpty) { - // No common factors, return the original predicate - or - } else { - val ldiff = lhsSet.diff(common) - val rdiff = rhsSet.diff(common) - if (ldiff.isEmpty || rdiff.isEmpty) { - // (a && b) || (a && b && c && ...) => a && b - common.reduce(And) - } else { - // (a && b && c && ...) || (a && b && d && ...) => - // ((c && ...) || (d && ...)) && a && b - (common + Or(ldiff.reduce(And), rdiff.reduce(And))).reduce(And) - } - } - } // end of Or(left, right) - } - } -} - /** * Pushes operations to either side of a Union. */ @@ -423,7 +346,32 @@ object BooleanSimplification extends Rule[LogicalPlan] with PredicateHelper { // l && false => false case (_, Literal(false, BooleanType)) => Literal(false) // a && a => a - case _ => and + case (l, r) if l fastEquals r => l + // (a || b) && (a || c) => a || (b && c) + case _ => + // 1. Split left and right to get the disjunctive predicates, + // i.e. lhsSet = (a, b), rhsSet = (a, c) + // 2. Find the common predict between lhsSet and rhsSet, i.e. common = (a) + // 3. Remove common predict from lhsSet and rhsSet, i.e. ldiff = (b), rdiff = (c) + // 4. Apply the formula, get the optimized predicate: common || (ldiff && rdiff) + val lhsSet = splitDisjunctivePredicates(left).toSet + val rhsSet = splitDisjunctivePredicates(right).toSet + val common = lhsSet.intersect(rhsSet) + if (common.isEmpty) { + // No common factors, return the original predicate + and + } else { + val ldiff = lhsSet.diff(common) + val rdiff = rhsSet.diff(common) + if (ldiff.isEmpty || rdiff.isEmpty) { + // (a || b || c || ...) && (a || b) => (a || b) + common.reduce(Or) + } else { + // (a || b || c || ...) && (a || b || d || ...) => + // ((c || ...) && (d || ...)) || a || b + (common + And(ldiff.reduce(Or), rdiff.reduce(Or))).reduce(Or) + } + } } // end of And(left, right) case or @ Or(left, right) => (left, right) match { @@ -435,7 +383,33 @@ object BooleanSimplification extends Rule[LogicalPlan] with PredicateHelper { case (Literal(false, BooleanType), r) => r // l || false => l case (l, Literal(false, BooleanType)) => l - case _ => or + // a || b = a + case (l, r) if l fastEquals r => l + // (a && b) || (a && c) => a && (b || c) + case _ => + // 1. Split left and right to get the conjunctive predicates, + // i.e. lhsSet = (a, b), rhsSet = (a, c) + // 2. Find the common predict between lhsSet and rhsSet, i.e. common = (a) + // 3. Remove common predict from lhsSet and rhsSet, i.e. ldiff = (b), rdiff = (c) + // 4. Apply the formula, get the optimized predicate: common && (ldiff || rdiff) + val lhsSet = splitConjunctivePredicates(left).toSet + val rhsSet = splitConjunctivePredicates(right).toSet + val common = lhsSet.intersect(rhsSet) + if (common.isEmpty) { + // No common factors, return the original predicate + or + } else { + val ldiff = lhsSet.diff(common) + val rdiff = rhsSet.diff(common) + if (ldiff.isEmpty || rdiff.isEmpty) { + // (a && b) || (a && b && c && ...) => a && b + common.reduce(And) + } else { + // (a && b && c && ...) || (a && b && d && ...) => + // ((c && ...) || (d && ...)) && a && b + (common + Or(ldiff.reduce(And), rdiff.reduce(And))).reduce(And) + } + } } // end of Or(left, right) case not @ Not(exp) => exp match { From f2ee5fe8e184c9bce8efd7d00598c9806f05b778 Mon Sep 17 00:00:00 2001 From: Zhongshuai Pei <799203320@qq.com> Date: Wed, 27 May 2015 10:46:05 +0800 Subject: [PATCH 05/12] Update Optimizer.scala --- .../spark/sql/catalyst/optimizer/Optimizer.scala | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala index 83277c0bd4d90..c795c0069fbc5 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala @@ -383,15 +383,15 @@ object BooleanSimplification extends Rule[LogicalPlan] with PredicateHelper { case (Literal(false, BooleanType), r) => r // l || false => l case (l, Literal(false, BooleanType)) => l - // a || b = a + // a || b => a case (l, r) if l fastEquals r => l // (a && b) || (a && c) => a && (b || c) case _ => - // 1. Split left and right to get the conjunctive predicates, - // i.e. lhsSet = (a, b), rhsSet = (a, c) - // 2. Find the common predict between lhsSet and rhsSet, i.e. common = (a) - // 3. Remove common predict from lhsSet and rhsSet, i.e. ldiff = (b), rdiff = (c) - // 4. Apply the formula, get the optimized predicate: common && (ldiff || rdiff) + // 1. Split left and right to get the conjunctive predicates, + // i.e. lhsSet = (a, b), rhsSet = (a, c) + // 2. Find the common predict between lhsSet and rhsSet, i.e. common = (a) + // 3. Remove common predict from lhsSet and rhsSet, i.e. ldiff = (b), rdiff = (c) + // 4. Apply the formula, get the optimized predicate: common && (ldiff || rdiff) val lhsSet = splitConjunctivePredicates(left).toSet val rhsSet = splitConjunctivePredicates(right).toSet val common = lhsSet.intersect(rhsSet) From 11beb61bf37b75972572f4569cadd123271a3f60 Mon Sep 17 00:00:00 2001 From: Zhongshuai Pei <799203320@qq.com> Date: Wed, 27 May 2015 10:47:48 +0800 Subject: [PATCH 06/12] Update FilterPushdownSuite.scala --- .../spark/sql/catalyst/optimizer/FilterPushdownSuite.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala index 4fc60def94a45..7e34785064be3 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala @@ -33,11 +33,10 @@ class FilterPushdownSuite extends PlanTest { val batches = Batch("Subqueries", Once, EliminateSubQueries) :: - Batch("Transform Condition", Once, - TransformCondition) :: Batch("Filter Pushdown", Once, CombineFilters, PushPredicateThroughProject, + BooleanSimplification, PushPredicateThroughJoin, PushPredicateThroughGenerate, ColumnPruning, From a04ffae9a10dc943d16e0f2bf3d4371cf37226ca Mon Sep 17 00:00:00 2001 From: Zhongshuai Pei <799203320@qq.com> Date: Wed, 27 May 2015 10:48:27 +0800 Subject: [PATCH 07/12] Update Optimizer.scala --- .../org/apache/spark/sql/catalyst/optimizer/Optimizer.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala index c795c0069fbc5..582031ee71464 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala @@ -383,7 +383,7 @@ object BooleanSimplification extends Rule[LogicalPlan] with PredicateHelper { case (Literal(false, BooleanType), r) => r // l || false => l case (l, Literal(false, BooleanType)) => l - // a || b => a + // a || a => a case (l, r) if l fastEquals r => l // (a && b) || (a && c) => a && (b || c) case _ => From ae3af6d7614c3c7ad3d0407393cffc4796d04f2f Mon Sep 17 00:00:00 2001 From: Zhongshuai Pei <799203320@qq.com> Date: Mon, 1 Jun 2015 09:09:13 +0800 Subject: [PATCH 08/12] Update FilterPushdownSuite.scala --- .../spark/sql/catalyst/optimizer/FilterPushdownSuite.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala index 7e34785064be3..22d2010445743 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala @@ -196,14 +196,14 @@ class FilterPushdownSuite extends PlanTest { comparePlans(optimized, correctAnswer) } - + test("joins: push to one side after transformCondition") { val x = testRelation.subquery('x) val y = testRelation1.subquery('y) val originalQuery = { x.join(y, Inner) - .where(("x.a".attr === 1 && "y.d".attr === "x.b".attr) || + .where(("x.a".attr === 1 && "y.d".attr === "x.b".attr) || ("x.a".attr === 1 && "y.d".attr === "x.c".attr)) } From c529d9fb76d07bd30a3165a0c3f2a43661fffb1a Mon Sep 17 00:00:00 2001 From: Zhongshuai Pei <799203320@qq.com> Date: Mon, 1 Jun 2015 11:58:54 +0800 Subject: [PATCH 09/12] Update FilterPushdownSuite.scala --- .../spark/sql/catalyst/optimizer/FilterPushdownSuite.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala index 22d2010445743..87603e93dce7a 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala @@ -202,7 +202,7 @@ class FilterPushdownSuite extends PlanTest { val y = testRelation1.subquery('y) val originalQuery = { - x.join(y, Inner) + x.join(y) .where(("x.a".attr === 1 && "y.d".attr === "x.b".attr) || ("x.a".attr === 1 && "y.d".attr === "x.c".attr)) } From f8b93143af5eb0e7782824d43b084405780b5b2a Mon Sep 17 00:00:00 2001 From: Zhongshuai Pei <799203320@qq.com> Date: Mon, 1 Jun 2015 12:41:35 +0800 Subject: [PATCH 10/12] Update FilterPushdownSuite.scala --- .../sql/catalyst/optimizer/FilterPushdownSuite.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala index 87603e93dce7a..c0fe5db9b60f0 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/FilterPushdownSuite.scala @@ -581,15 +581,15 @@ class FilterPushdownSuite extends PlanTest { // push down invalid val originalQuery1 = { x.select('a, 'b) - .sortBy(SortOrder('a, Ascending)) - .select('b) + .sortBy(SortOrder('a, Ascending)) + .select('b) } val optimized1 = Optimize.execute(originalQuery1.analyze) val correctAnswer1 = x.select('a, 'b) - .sortBy(SortOrder('a, Ascending)) - .select('b).analyze + .sortBy(SortOrder('a, Ascending)) + .select('b).analyze comparePlans(optimized1, analysis.EliminateSubQueries(correctAnswer1)) } From 0ba5f42ff34ded072a0241409b1e366baa77e506 Mon Sep 17 00:00:00 2001 From: Zhongshuai Pei <799203320@qq.com> Date: Wed, 10 Jun 2015 11:48:59 +0800 Subject: [PATCH 11/12] Update Optimizer.scala --- .../apache/spark/sql/catalyst/optimizer/Optimizer.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala index 582031ee71464..c2818d957cc79 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala @@ -36,20 +36,21 @@ object DefaultOptimizer extends Optimizer { // SubQueries are only needed for analysis and can be removed before execution. Batch("Remove SubQueries", FixedPoint(100), EliminateSubQueries) :: - Batch("Operator Optimizations", FixedPoint(100), + Batch("Operator Reordering", FixedPoint(100), UnionPushdown, CombineFilters, PushPredicateThroughProject, + PushPredicateThroughJoin, PushPredicateThroughGenerate, ColumnPruning, ProjectCollapsing, - CombineLimits, + CombineLimits) :: + Batch("ConstantFolding", FixedPoint(100), NullPropagation, OptimizeIn, ConstantFolding, LikeSimplification, BooleanSimplification, - PushPredicateThroughJoin, SimplifyFilters, SimplifyCasts, SimplifyCaseConversionExpressions) :: From 20de7bebef6beee02d68f9b21c2d1432ca5c7ede Mon Sep 17 00:00:00 2001 From: Zhongshuai Pei <799203320@qq.com> Date: Wed, 10 Jun 2015 11:51:12 +0800 Subject: [PATCH 12/12] Update Optimizer.scala --- .../apache/spark/sql/catalyst/optimizer/Optimizer.scala | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala index c16f08d389955..f8f1efcc7e990 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala @@ -38,21 +38,20 @@ object DefaultOptimizer extends Optimizer { EliminateSubQueries) :: Batch("Distinct", FixedPoint(100), ReplaceDistinctWithAggregate) :: - Batch("Operator Reordering", FixedPoint(100), + Batch("Operator Optimizations", FixedPoint(100), UnionPushdown, CombineFilters, PushPredicateThroughProject, - PushPredicateThroughJoin, PushPredicateThroughGenerate, ColumnPruning, ProjectCollapsing, - CombineLimits) :: - Batch("ConstantFolding", FixedPoint(100), + CombineLimits, NullPropagation, OptimizeIn, ConstantFolding, LikeSimplification, BooleanSimplification, + PushPredicateThroughJoin, SimplifyFilters, SimplifyCasts, SimplifyCaseConversionExpressions) ::