Skip to content

Commit 64aafc5

Browse files
committed
revert changes in Analyzer + add UT
1 parent 87fc62a commit 64aafc5

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,28 @@ import org.apache.spark.sql.internal.SQLConf
4040
import org.apache.spark.sql.types._
4141

4242
/**
43-
* A trivial [[Analyzer]] with a dummy [[SessionCatalog]] and [[EmptyFunctionRegistry]].
43+
* Trivial [[Analyzer]]s with a dummy [[SessionCatalog]] and [[EmptyFunctionRegistry]].
4444
* Used for testing when all relations are already filled in and the analyzer needs only
4545
* to resolve attribute references.
4646
*/
47-
object SimpleAnalyzer extends Analyzer(
47+
sealed class BaseSimpleAnalyzer(caseSensitive: Boolean) extends Analyzer(
4848
new SessionCatalog(
4949
new InMemoryCatalog,
5050
EmptyFunctionRegistry,
51-
new SQLConf().copy(SQLConf.CASE_SENSITIVE -> true)) {
51+
new SQLConf().copy(SQLConf.CASE_SENSITIVE -> caseSensitive)) {
5252
override def createDatabase(dbDefinition: CatalogDatabase, ignoreIfExists: Boolean) {}
5353
},
54-
new SQLConf().copy(SQLConf.CASE_SENSITIVE -> true))
54+
new SQLConf().copy(SQLConf.CASE_SENSITIVE -> caseSensitive))
55+
56+
/**
57+
* A trivial analyzer which use case sensitive resolution.
58+
*/
59+
object SimpleAnalyzer extends BaseSimpleAnalyzer(true)
60+
61+
/**
62+
* A trivial analyzer which use case insensitive resolution.
63+
*/
64+
object SimpleCaseInsensitiveAnalyzer extends BaseSimpleAnalyzer(false)
5565

5666
/**
5767
* Provides a way to keep state during the analysis, this enables us to decouple the concerns
@@ -1189,7 +1199,7 @@ class Analyzer(
11891199

11901200
case f @ Filter(cond, child) if (!f.resolved || f.missingInput.nonEmpty) && child.resolved =>
11911201
val (newCond, newChild) = resolveExprsAndAddMissingAttrs(Seq(cond), child)
1192-
if (child.sameOutput(newChild)) {
1202+
if (child.output == newChild.output) {
11931203
f.copy(condition = newCond.head)
11941204
} else {
11951205
// Add missing attributes and then project them away.
@@ -2087,7 +2097,7 @@ class Analyzer(
20872097
// todo: It's hard to write a general rule to pull out nondeterministic expressions
20882098
// from LogicalPlan, currently we only do it for UnaryNode which has same output
20892099
// schema with its child.
2090-
case p: UnaryNode if p.sameOutput(p.child) && p.expressions.exists(!_.deterministic) =>
2100+
case p: UnaryNode if p.output == p.child.output && p.expressions.exists(!_.deterministic) =>
20912101
val nondeterToAttr = getNondeterToAttr(p.expressions)
20922102
val newPlan = p.transformExpressions { case e =>
20932103
nondeterToAttr.get(e).map(_.toAttribute).getOrElse(e)

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/dsl/package.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ package object dsl {
401401
def analyze: LogicalPlan =
402402
EliminateSubqueryAliases(analysis.SimpleAnalyzer.execute(logicalPlan))
403403

404+
def analyzeCaseInsensitive: LogicalPlan =
405+
EliminateSubqueryAliases(analysis.SimpleCaseInsensitiveAnalyzer.execute(logicalPlan))
406+
404407
def hint(name: String, parameters: Any*): LogicalPlan =
405408
UnresolvedHint(name, parameters, logicalPlan)
406409
}

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/RemoveRedundantAliasAndProjectSuite.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,11 @@ class RemoveRedundantAliasAndProjectSuite extends PlanTest with PredicateHelper
124124
val expected = Subquery(relation.select('a as "a", 'b).where('b < 10).select('a).analyze)
125125
comparePlans(optimized, expected)
126126
}
127+
128+
test("SPARK-25691: RemoveRedundantProject works also with different cases") {
129+
val relation = LocalRelation('a.int, 'b.int)
130+
val query = relation.select('A, 'b).analyzeCaseInsensitive
131+
val optimized = Optimize.execute(query)
132+
comparePlans(optimized, relation)
133+
}
127134
}

0 commit comments

Comments
 (0)