Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-50994][SQL] Perform RDD conversion under tracked execution #49678

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions sql/core/src/main/scala/org/apache/spark/sql/classic/Dataset.scala
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ class Dataset[T] private[sql](

/** @inheritdoc */
def reduce(func: (T, T) => T): T = withNewRDDExecutionId("reduce") {
rdd.reduce(func)
materializedRdd.reduce(func)
}

/** @inheritdoc */
Expand Down Expand Up @@ -1471,7 +1471,7 @@ class Dataset[T] private[sql](

/** @inheritdoc */
def foreachPartition(f: Iterator[T] => Unit): Unit = withNewRDDExecutionId("foreachPartition") {
rdd.foreachPartition(f)
materializedRdd.foreachPartition(f)
}

/** @inheritdoc */
Expand Down Expand Up @@ -1573,14 +1573,20 @@ class Dataset[T] private[sql](
sparkSession.sessionState.executePlan(deserialized)
}

/** @inheritdoc */
lazy val rdd: RDD[T] = {
private lazy val materializedRdd: RDD[T] = {
val objectType = exprEnc.deserializer.dataType
rddQueryExecution.toRdd.mapPartitions { rows =>
rows.map(_.get(0, objectType).asInstanceOf[T])
}
}

/** @inheritdoc */
lazy val rdd: RDD[T] = {
withNewRDDExecutionId("rdd") {
materializedRdd
}
}

/** @inheritdoc */
def toJavaRDD: JavaRDD[T] = rdd.toJavaRDD()

Expand Down
19 changes: 19 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2721,6 +2721,25 @@ class DataFrameSuite extends QueryTest
parameters = Map("name" -> ".whatever")
)
}

test("SPARK-50994: RDD conversion is performed with execution context") {
withSQLConf(SQLConf.CASE_SENSITIVE.key -> "true") {
withSQLConf(SQLConf.PARQUET_VECTORIZED_READER_ENABLED.key -> "false") {
withTempDir(dir => {
val dummyDF = Seq((1, 1.0), (2, 2.0), (3, 3.0), (1, 1.0)).toDF("a", "A")
dummyDF.write.format("parquet").mode("overwrite").save(dir.getCanonicalPath)

val df = spark.read.parquet(dir.getCanonicalPath)
val encoder = ExpressionEncoder(df.schema)
val deduplicated = df.dropDuplicates(Array("a"))
val df2 = deduplicated.flatMap(row => Seq(row))(encoder).rdd

val output = spark.createDataFrame(df2, df.schema)
checkAnswer(output, Seq(Row(1, 1.0), Row(2, 2.0), Row(3, 3.0)))
})
}
}
}
}

case class GroupByKey(a: Int, b: Int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2704,7 +2704,7 @@ class SQLQuerySuite extends SQLQuerySuiteBase with DisableAdaptiveExecutionSuite
checkAnswer(sql(s"SELECT id FROM $targetTable"),
Row(1) :: Row(2) :: Row(3) :: Nil)
spark.sparkContext.listenerBus.waitUntilEmpty()
assert(commands.size == 3)
assert(commands.size == 4)
assert(commands.head.nodeName == "Execute CreateHiveTableAsSelectCommand")

val v1WriteCommand = commands(1)
Expand Down
Loading