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 @@ -40,6 +40,7 @@ trait AliasAwareOutputExpression extends SQLConfHelper {
// more than `aliasCandidateLimit` attributes for an expression. In those cases the old logic
// handled only the last alias so we need to make sure that we give precedence to that.
// If the `outputExpressions` contain simple attributes we need to add those too to the map.
@transient
private lazy val aliasMap = {
val aliases = mutable.Map[Expression, mutable.ArrayBuffer[Attribute]]()
outputExpressions.reverse.foreach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ case class BatchScanExec(
applyPartialClustering: Boolean = false,
replicatePartitions: Boolean = false) extends DataSourceV2ScanExecBase {

@transient lazy val batch = scan.toBatch
@transient lazy val batch = if (scan == null) null else scan.toBatch

// TODO: unify the equal/hashCode implementation for all data source v2 query plans.
override def equals(other: Any): Boolean = other match {
case other: BatchScanExec =>
this.batch == other.batch && this.runtimeFilters == other.runtimeFilters &&
this.batch != null && this.batch == other.batch &&
Copy link
Contributor Author

@peter-toth peter-toth Mar 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to not consider BatchScanExecs equal when batch is not available.

this.runtimeFilters == other.runtimeFilters &&
this.commonPartitionValues == other.commonPartitionValues &&
this.replicatePartitions == other.replicatePartitions &&
this.applyPartialClustering == other.applyPartialClustering
Expand Down
16 changes: 16 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2679,4 +2679,20 @@ class SubquerySuite extends QueryTest
Row(8, 6))
}
}

test("SPARK-42745: Improved AliasAwareOutputExpression works with DSv2") {
withSQLConf(
SQLConf.USE_V1_SOURCE_LIST.key -> "") {
withTempPath { path =>
spark.range(0)
.write
.mode("overwrite")
.parquet(path.getCanonicalPath)
withTempView("t1") {
spark.read.parquet(path.toString).createOrReplaceTempView("t1")
checkAnswer(sql("select (select sum(id) from t1)"), Row(null))
}
}
}
}
}