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 @@ -56,8 +56,9 @@ case class ExpandExec(
protected override def doExecute(): RDD[InternalRow] = {
val numOutputRows = longMetric("numOutputRows")

child.execute().mapPartitions { iter =>
child.execute().mapPartitionsWithIndexInternal { (index, iter) =>
val groups = projections.map(projection).toArray
groups.foreach(_.initialize(index))
new Iterator[InternalRow] {
private[this] var result: InternalRow = _
private[this] var idx = -1 // -1 means the initial state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.apache.spark.SparkRuntimeException
import org.apache.spark.sql.Row
import org.apache.spark.sql.connector.catalog.{Column, ColumnDefaultValue, TableChange, TableInfo}
import org.apache.spark.sql.connector.expressions.{GeneralScalarExpression, LiteralValue}
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.{IntegerType, StringType}

abstract class UpdateTableSuiteBase extends RowLevelOperationSuiteBase {
Expand Down Expand Up @@ -618,6 +619,25 @@ abstract class UpdateTableSuiteBase extends RowLevelOperationSuiteBase {
Row(2) :: Nil)
}

test("SPARK-53538: update with nondeterministic assignments and no wholestage codegen") {
val extraColCount = SQLConf.get.wholeStageMaxNumFields - 4
val schema = "pk INT NOT NULL, id INT, value DOUBLE, dep STRING, " +
((1 to extraColCount).map(i => s"col$i INT").mkString(", "))
val data = (1 to 3).map { i =>
s"""{ "pk": $i, "id": $i, "value": 2.0, "dep": "hr", """ +
((1 to extraColCount).map(j => s""""col$j": $i""").mkString(", ")) +
"}"
}.mkString("\n")
createAndInitTable(schema, data)

// rand() always generates values in [0, 1) range
sql(s"UPDATE $tableNameAsString SET value = rand() WHERE id <= 2")

checkAnswer(
sql(s"SELECT count(*) FROM $tableNameAsString WHERE value < 2.0"),
Row(2) :: Nil)
}

test("update with default values") {
val idDefault = new ColumnDefaultValue("42", LiteralValue(42, IntegerType))
val columns = Array(
Expand Down