Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ case class LocalRelation(output: Seq[Attribute], data: Seq[InternalRow] = Nil)
}
}

override def sameResult(plan: LogicalPlan): Boolean = plan match {
case LocalRelation(otherOutput, otherData) =>
otherOutput.map(_.dataType) == output.map(_.dataType) && otherData == data
case _ => false
override def sameResult(plan: LogicalPlan): Boolean = {
plan.canonicalized match {
case LocalRelation(otherOutput, otherData) =>
otherOutput.map(_.dataType) == output.map(_.dataType) && otherData == data
case _ => false
}
}

override lazy val statistics =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ private[sql] case class LogicalRDD(
override def newInstance(): LogicalRDD.this.type =
LogicalRDD(output.map(_.newInstance()), rdd)(session).asInstanceOf[this.type]

override def sameResult(plan: LogicalPlan): Boolean = plan match {
case LogicalRDD(_, otherRDD) => rdd.id == otherRDD.id
case _ => false
override def sameResult(plan: LogicalPlan): Boolean = {
plan.canonicalized match {
case LogicalRDD(_, otherRDD) => rdd.id == otherRDD.id
case _ => false
}
}

override protected def stringArgs: Iterator[Any] = Iterator(output)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ case class LogicalRelation(
com.google.common.base.Objects.hashCode(relation, output)
}

override def sameResult(otherPlan: LogicalPlan): Boolean = otherPlan match {
case LogicalRelation(otherRelation, _, _) => relation == otherRelation
case _ => false
override def sameResult(otherPlan: LogicalPlan): Boolean = {
otherPlan.canonicalized match {
case LogicalRelation(otherRelation, _, _) => relation == otherRelation
case _ => false
}
}

// When comparing two LogicalRelations from within LogicalPlan.sameResult, we only need
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,4 +552,15 @@ class CachedTableSuite extends QueryTest with SQLTestUtils with SharedSQLContext
selectStar,
Seq(Row(1, "1")))
}

test("SPARK-15915 Logical plans should use canonicalized plan when override sameResult") {
val localRelation = Seq(1, 2, 3).toDF()
localRelation.createOrReplaceTempView("localRelation")

spark.catalog.cacheTable("localRelation")
assert(
localRelation.queryExecution.withCachedData.collect {
case i: InMemoryRelation => i
}.size == 1)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private[hive] case class MetastoreRelation(

/** Only compare database and tablename, not alias. */
override def sameResult(plan: LogicalPlan): Boolean = {
plan match {
plan.canonicalized match {
case mr: MetastoreRelation =>
mr.databaseName == databaseName && mr.tableName == tableName
case _ => false
Expand Down