Skip to content

Commit

Permalink
narrow down to view only
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaido91 committed Oct 15, 2018
1 parent 64aafc5 commit c4aaa8d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,18 @@ import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types._

/**
* Trivial [[Analyzer]]s with a dummy [[SessionCatalog]] and [[EmptyFunctionRegistry]].
* A trivial [[Analyzer]] with a dummy [[SessionCatalog]] and [[EmptyFunctionRegistry]].
* Used for testing when all relations are already filled in and the analyzer needs only
* to resolve attribute references.
*/
sealed class BaseSimpleAnalyzer(caseSensitive: Boolean) extends Analyzer(
object SimpleAnalyzer extends Analyzer(
new SessionCatalog(
new InMemoryCatalog,
EmptyFunctionRegistry,
new SQLConf().copy(SQLConf.CASE_SENSITIVE -> caseSensitive)) {
new SQLConf().copy(SQLConf.CASE_SENSITIVE -> true)) {
override def createDatabase(dbDefinition: CatalogDatabase, ignoreIfExists: Boolean) {}
},
new SQLConf().copy(SQLConf.CASE_SENSITIVE -> caseSensitive))

/**
* A trivial analyzer which use case sensitive resolution.
*/
object SimpleAnalyzer extends BaseSimpleAnalyzer(true)

/**
* A trivial analyzer which use case insensitive resolution.
*/
object SimpleCaseInsensitiveAnalyzer extends BaseSimpleAnalyzer(false)
new SQLConf().copy(SQLConf.CASE_SENSITIVE -> true))

/**
* Provides a way to keep state during the analysis, this enables us to decouple the concerns
Expand Down Expand Up @@ -1189,7 +1179,7 @@ class Analyzer(
if (!s.resolved || s.missingInput.nonEmpty) && child.resolved =>
val (newOrder, newChild) = resolveExprsAndAddMissingAttrs(order, child)
val ordering = newOrder.map(_.asInstanceOf[SortOrder])
if (child.sameOutput(newChild)) {
if (child.output == newChild.output) {
s.copy(order = ordering)
} else {
// Add missing attributes and then project them away.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,6 @@ package object dsl {
def analyze: LogicalPlan =
EliminateSubqueryAliases(analysis.SimpleAnalyzer.execute(logicalPlan))

def analyzeCaseInsensitive: LogicalPlan =
EliminateSubqueryAliases(analysis.SimpleCaseInsensitiveAnalyzer.execute(logicalPlan))

def hint(name: String, parameters: Any*): LogicalPlan =
UnresolvedHint(name, parameters, logicalPlan)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ object RemoveRedundantAliases extends Rule[LogicalPlan] {
*/
object RemoveRedundantProject extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan = plan transform {
case p @ Project(_, child) if p.sameOutput(child) => child
case p @ Project(_, child) if p.output == child.output => child
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,4 @@ class RemoveRedundantAliasAndProjectSuite extends PlanTest with PredicateHelper
val expected = Subquery(relation.select('a as "a", 'b).where('b < 10).select('a).analyze)
comparePlans(optimized, expected)
}

test("SPARK-25691: RemoveRedundantProject works also with different cases") {
val relation = LocalRelation('a.int, 'b.int)
val query = relation.select('A, 'b).analyzeCaseInsensitive
val optimized = Optimize.execute(query)
comparePlans(optimized, relation)
}
}

0 comments on commit c4aaa8d

Please sign in to comment.