This is an automated email from the ASF dual-hosted git repository.
LuciferYang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git
The following commit(s) were added to refs/heads/main by this push:
new 8290d545db [GLUTEN-13720][VL] Fix native Delta partitioned writes with
concurrent writers or presorted input (#13726)
8290d545db is described below
commit 8290d545dbd6f234e714925f04537c3ea98bd8a3
Author: YangJie <[email protected]>
AuthorDate: Thu Nov 26 08:36:02 2026 -0500
[GLUTEN-13720][VL] Fix native Delta partitioned writes with concurrent
writers or presorted input (#13726)
## What changes are proposed in this pull request?
Two partitioned-write failures of the native Delta writer (see the issue):
- On Delta 3.3, with `spark.sql.maxConcurrentOutputFileWriters > 0`,
unsorted input went to Spark's row-based concurrent writer, which can't read a
`BatchCarrierRow`. The writer now sorts by the partition columns and uses
`GlutenDynamicPartitionDataSingleWriter`, as with 0. On Delta 4,
`GlutenDeltaNativeWriteGate` already sends these writes to Delta's writer.
- On Delta 3.3 and 4, input already sorted by the partition columns handed
the empty-to-null project over a string partition column to the carrier-row
conversion as a bare transformer, which fails. The project now runs in a stage.
It turns "" into null, which can break up sorted partitions, so the writer now
sorts again unless only the last partition column goes through it and the input
sorts that column ASC NULLS FIRST or DESC NULLS LAST.
`VeloxDelta.md` drops the 3.5 concurrent-writer failure and updates the
`spark.sql.maxConcurrentOutputFileWriters` row.
Fixes #13720.
## How was this patch tested?
Added a test to the Delta 3.3 `DeltaNativeWriteSuite` that writes a
partitioned table with `maxConcurrentOutputFileWriters` 0 and 2, a string and
an int partition column, presorted and unsorted input, and an empty and a null
string value. It checks the rows and that the write stays native. The Delta 4
suite gets the same test without the concurrent-writer cases. Both suites also
get a test with one task and one row per batch that checks the committed files
per partition, and whether t [...]
## Was this patch authored or co-authored using generative AI tooling?
Yes. Generated-by: Claude claude-opus-5-5
---
.../delta/files/GlutenDeltaFileFormatWriter.scala | 103 +++++++++++----------
.../spark/sql/delta/DeltaNativeWriteSuite.scala | 80 +++++++++++++++-
.../delta/files/GlutenDeltaFileFormatWriter.scala | 42 +++++++--
.../spark/sql/delta/DeltaNativeWriteSuite.scala | 77 ++++++++++++++-
docs/backends/velox/get-started/VeloxDelta.md | 3 +-
5 files changed, 244 insertions(+), 61 deletions(-)
diff --git
a/backends-velox/src-delta33/main/scala/org/apache/spark/sql/delta/files/GlutenDeltaFileFormatWriter.scala
b/backends-velox/src-delta33/main/scala/org/apache/spark/sql/delta/files/GlutenDeltaFileFormatWriter.scala
index 1fcaa01a09..3c916adf11 100644
---
a/backends-velox/src-delta33/main/scala/org/apache/spark/sql/delta/files/GlutenDeltaFileFormatWriter.scala
+++
b/backends-velox/src-delta33/main/scala/org/apache/spark/sql/delta/files/GlutenDeltaFileFormatWriter.scala
@@ -230,9 +230,8 @@ object GlutenDeltaFileFormatWriter extends LoggingShims {
committer,
outputSpec,
requiredOrdering,
+ actualOrdering,
partitionColumns,
- sortColumns,
- orderingMatched,
isNativeWritable
)
}
@@ -247,46 +246,41 @@ object GlutenDeltaFileFormatWriter extends LoggingShims {
committer: FileCommitProtocol,
outputSpec: OutputSpec,
requiredOrdering: Seq[Expression],
+ actualOrdering: Seq[SortOrder],
partitionColumns: Seq[Attribute],
- sortColumns: Seq[Attribute],
- orderingMatched: Boolean,
writeOffloadable: Boolean): Set[String] = {
val projectList = V1WritesUtils.convertEmptyToNull(plan.output,
partitionColumns)
val empty2NullPlan =
if (projectList.nonEmpty) ProjectExecTransformer(projectList, plan) else
plan
writeAndCommit(job, description, committer) {
- val (planToExecute, concurrentOutputWriterSpec) = if (orderingMatched) {
- (empty2NullPlan, None)
+ def collapseStages(input: SparkPlan): SparkPlan =
+ GenerateTransformStageId()(
+ ColumnarCollapseTransformStages(new
GlutenConfig(sparkSession.sessionState.conf))(input))
+ // Spark's concurrent output writers read the partition values of every
row, which a
+ // BatchCarrierRow doesn't expose, so don't use them, and sort by
partition as when
+ // spark.sql.maxConcurrentOutputFileWriters is 0.
+ val planToExecute = if (isSortedAfterProject(requiredOrdering,
actualOrdering, projectList)) {
+ // The empty-to-null project is a bare transformer, which can't run
outside a stage.
+ if (projectList.nonEmpty) collapseStages(empty2NullPlan) else
empty2NullPlan
} else {
val sortPlan = createSortPlan(empty2NullPlan, requiredOrdering,
outputSpec)
- val concurrentOutputWriterSpec =
- createConcurrentOutputWriterSpec(sparkSession, sortPlan, sortColumns)
- if (concurrentOutputWriterSpec.isDefined) {
- (empty2NullPlan, concurrentOutputWriterSpec)
- } else {
- def addNativeSort(input: SparkPlan): SparkPlan = {
- val nativeSortPlan =
- SortExecTransformer(sortPlan.sortOrder, sortPlan.global, child =
input)
- val validationResult = nativeSortPlan.doValidate()
- assert(
- validationResult.ok(),
- s"Sort operation for Delta write is not offload-able:
${validationResult.reason()}")
- nativeSortPlan
- }
- val newPlan = sortPlan.child match {
- case wst @ WholeStageTransformer(wholeStageChild, _) =>
- wst.withNewChildren(Seq(addNativeSort(wholeStageChild)))
- case other if Convention.get(other).batchType == VeloxBatchType =>
- val nativeSortPlan = addNativeSort(other)
- val nativeSortPlanWithWst =
- GenerateTransformStageId()(ColumnarCollapseTransformStages(
- new
GlutenConfig(sparkSession.sessionState.conf))(nativeSortPlan))
- nativeSortPlanWithWst
- case other =>
- Transitions.toBatchPlan(sortPlan, VeloxBatchType)
- }
- (newPlan, None)
+ def addNativeSort(input: SparkPlan): SparkPlan = {
+ val nativeSortPlan =
+ SortExecTransformer(sortPlan.sortOrder, sortPlan.global, child =
input)
+ val validationResult = nativeSortPlan.doValidate()
+ assert(
+ validationResult.ok(),
+ s"Sort operation for Delta write is not offload-able:
${validationResult.reason()}")
+ nativeSortPlan
+ }
+ sortPlan.child match {
+ case wst @ WholeStageTransformer(wholeStageChild, _) =>
+ wst.withNewChildren(Seq(addNativeSort(wholeStageChild)))
+ case other if Convention.get(other).batchType == VeloxBatchType =>
+ collapseStages(addNativeSort(other))
+ case other =>
+ Transitions.toBatchPlan(sortPlan, VeloxBatchType)
}
}
@@ -325,7 +319,6 @@ object GlutenDeltaFileFormatWriter extends LoggingShims {
sparkAttemptNumber = taskContext.taskAttemptId().toInt &
Integer.MAX_VALUE,
committer,
iterator = iter,
- concurrentOutputWriterSpec = concurrentOutputWriterSpec,
partitionColumnToDataType
)
},
@@ -418,6 +411,30 @@ object GlutenDeltaFileFormatWriter extends LoggingShims {
SortExec(orderingExpr, global = false, child = plan)
}
+ /**
+ * Whether input sorted by `actualOrdering` is still sorted by
`requiredOrdering` after
+ * `projectList`, whose Empty2Null turns "" into null. With one such column,
the last required
+ * one, null and "" stay next to each other when the column is ASC NULLS
FIRST or DESC NULLS LAST.
+ * Otherwise the project can break up a partition: sorted (null, 1), (null,
2), ("", 1) becomes
+ * (null, 1), (null, 2), (null, 1).
+ */
+ private def isSortedAfterProject(
+ requiredOrdering: Seq[Expression],
+ actualOrdering: Seq[SortOrder],
+ projectList: Seq[NamedExpression]): Boolean = {
+ V1WritesUtils.isOrderingMatched(requiredOrdering, actualOrdering) &&
+ (projectList.collect { case Alias(Empty2Null(column), _) => column } match
{
+ case Seq() => true
+ case Seq(column) if
requiredOrdering.lastOption.exists(_.semanticEquals(column)) =>
+ val order = actualOrdering(requiredOrdering.length - 1)
+ (order.direction, order.nullOrdering) match {
+ case (Ascending, NullsFirst) | (Descending, NullsLast) => true
+ case _ => false
+ }
+ case _ => false
+ })
+ }
+
private def createConcurrentOutputWriterSpec(
sparkSession: SparkSession,
sortPlan: SortExec,
@@ -440,7 +457,6 @@ object GlutenDeltaFileFormatWriter extends LoggingShims {
sparkAttemptNumber: Int,
committer: FileCommitProtocol,
iterator: Iterator[InternalRow],
- concurrentOutputWriterSpec: Option[ConcurrentOutputWriterSpec],
partitionColumnToDataType: Map[String, DataType]): WriteTaskResult = {
val jobId = SparkHadoopWriterUtils.createJobID(jobTrackerID, sparkStageId)
@@ -476,20 +492,9 @@ object GlutenDeltaFileFormatWriter extends LoggingShims {
} else if (description.partitionColumns.isEmpty &&
description.bucketSpec.isEmpty) {
new SingleDirectoryDataWriter(description, taskAttemptContext,
committer)
} else {
- concurrentOutputWriterSpec match {
- case Some(spec) =>
- // TODO: Concurrent writer is not yet supported.
- new DynamicPartitionDataConcurrentWriter(
- description,
- taskAttemptContext,
- committer,
- spec
- )
- case _ =>
- // Columnar-based partition writer to divide the input batch by
partition values
- // and bucket IDs in advance.
- new GlutenDynamicPartitionDataSingleWriter(description,
taskAttemptContext, committer)
- }
+ // Columnar-based partition writer to divide the input batch by
partition values
+ // and bucket IDs in advance.
+ new GlutenDynamicPartitionDataSingleWriter(description,
taskAttemptContext, committer)
}
try {
diff --git
a/backends-velox/src-delta33/test/scala/org/apache/spark/sql/delta/DeltaNativeWriteSuite.scala
b/backends-velox/src-delta33/test/scala/org/apache/spark/sql/delta/DeltaNativeWriteSuite.scala
index 1cab51e3f8..f9e3e30051 100644
---
a/backends-velox/src-delta33/test/scala/org/apache/spark/sql/delta/DeltaNativeWriteSuite.scala
+++
b/backends-velox/src-delta33/test/scala/org/apache/spark/sql/delta/DeltaNativeWriteSuite.scala
@@ -18,8 +18,9 @@ package org.apache.spark.sql.delta
import org.apache.gluten.config.GlutenConfig
import org.apache.gluten.config.VeloxDeltaConfig
+import org.apache.gluten.execution.SortExecTransformer
-import org.apache.spark.sql.{DataFrame, Row}
+import org.apache.spark.sql.{Column, DataFrame, Row}
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.delta.actions.AddFile
import org.apache.spark.sql.delta.commands.optimize.OptimizeMetrics
@@ -441,6 +442,83 @@ class DeltaNativeWriteSuite extends DeltaSQLCommandTest {
}
}
+ test("native partitioned delta write with concurrent writers or presorted
input") {
+ // A string partition column goes through the project that turns empty
strings into nulls.
+ val rows =
+ Seq((1L, "a", 1), (2L, "b", 2), (3L, "a", 1), (4L, "c", 3), (5L, "", 4),
(6L, null, 4))
+ for {
+ maxWriters <- Seq("0", "2")
+ partitionColumn <- Seq("s", "p")
+ presorted <- Seq(false, true)
+ } {
+ val expected = rows.map {
+ case (id, "", p) if partitionColumn == "s" => Row(id, null, p)
+ case row => Row.fromTuple(row)
+ }
+ withNativeWriteOffloadConf {
+ withTempDir {
+ dir =>
+ val path = dir.getCanonicalPath
+ withSQLConf(SQLConf.MAX_CONCURRENT_OUTPUT_FILE_WRITERS.key ->
maxWriters) {
+ GlutenDeltaFileFormatWriter.clearExecutedPlanForTesting()
+ val df = rows.toDF("id", "s", "p")
+ val input = if (presorted)
df.sortWithinPartitions(partitionColumn) else df
+
input.write.format("delta").partitionBy(partitionColumn).save(path)
+ assert(!writerPlan.treeString.contains("ColumnarToRow"),
writerPlan)
+ // The writer sorts unsorted input; presorted input keeps the
user's sort only.
+ assert(writerPlan.collect { case s: SortExecTransformer => s
}.size == 1, writerPlan)
+ }
+ assert(
+ spark.read.format("delta").load(path).select("id", "s",
"p").orderBy("id")
+ .collect().toSeq == expected)
+ }
+ }
+ }
+ }
+
+ test("native delta write of input sorted before the empty-to-null project") {
+ def check(rows: Seq[(Long, String, Int)], partitionBy: Seq[String],
writerSorts: Boolean)(
+ sortBy: Column*): Unit = {
+ withNativeWriteOffloadConf {
+ withTempDir {
+ dir =>
+ val path = dir.getCanonicalPath
+ // One task and one row per batch, so a partition that comes back
after another
+ // partition gets a second file.
+ withSQLConf(GlutenConfig.COLUMNAR_MAX_BATCH_SIZE.key -> "1") {
+ GlutenDeltaFileFormatWriter.clearExecutedPlanForTesting()
+ spark.sparkContext
+ .parallelize(rows, 1)
+ .toDF("id", "s", "p")
+ .sortWithinPartitions(sortBy: _*)
+ .write
+ .format("delta")
+ .partitionBy(partitionBy: _*)
+ .save(path)
+ assert(!writerPlan.treeString.contains("ColumnarToRow"),
writerPlan)
+ }
+ val partitions = files(DeltaLog.forTable(spark,
path)).toSeq.map(_.partitionValues)
+ assert(partitions.size == 2 && partitions.distinct.size == 2,
partitions)
+ val sorts = writerPlan.collect { case s: SortExecTransformer => s }
+ assert(sorts.size == (if (writerSorts) 2 else 1), writerPlan)
+ }
+ }
+ }
+ // Empty2Null turns these into (null, 1), (null, 2), (null, 1), (null, 2).
+ val twoColumns = Seq((1L, null, 1), (2L, null, 2), (3L, "", 1), (4L, "",
2))
+ check(twoColumns, Seq("s", "p"), writerSorts = true)($"s", $"p")
+ val oneColumn = Seq((1L, "", 1), (2L, "a", 1), (3L, null, 1))
+ // These become null, "a", null.
+ check(oneColumn, Seq("s"), writerSorts = true)($"s".asc_nulls_last)
+ check(oneColumn, Seq("s"), writerSorts = true)($"s".desc_nulls_first)
+ // These stay grouped: null, null, "a" and "a", null, null.
+ check(oneColumn, Seq("s"), writerSorts = false)($"s")
+ check(oneColumn, Seq("s"), writerSorts = false)($"s".desc_nulls_last)
+ // The same with s after another partition column.
+ check(oneColumn, Seq("p", "s"), writerSorts = true)($"p",
$"s".asc_nulls_last)
+ check(oneColumn, Seq("p", "s"), writerSorts = false)($"p", $"s")
+ }
+
test("native delta write checks NOT NULL constraints on a partitioned
table") {
withNativeWriteOffloadConf {
withTempDir {
diff --git
a/backends-velox/src-delta4/main/scala/org/apache/spark/sql/delta/files/GlutenDeltaFileFormatWriter.scala
b/backends-velox/src-delta4/main/scala/org/apache/spark/sql/delta/files/GlutenDeltaFileFormatWriter.scala
index c159bd4e1f..c79f231ec3 100644
---
a/backends-velox/src-delta4/main/scala/org/apache/spark/sql/delta/files/GlutenDeltaFileFormatWriter.scala
+++
b/backends-velox/src-delta4/main/scala/org/apache/spark/sql/delta/files/GlutenDeltaFileFormatWriter.scala
@@ -241,9 +241,9 @@ object GlutenDeltaFileFormatWriter extends Logging {
committer,
outputSpec,
requiredOrdering,
+ actualOrdering,
partitionColumns,
sortColumns,
- orderingMatched,
isNativeWritable
)
}
@@ -258,16 +258,21 @@ object GlutenDeltaFileFormatWriter extends Logging {
committer: FileCommitProtocol,
outputSpec: OutputSpec,
requiredOrdering: Seq[Expression],
+ actualOrdering: Seq[SortOrder],
partitionColumns: Seq[Attribute],
sortColumns: Seq[Attribute],
- orderingMatched: Boolean,
writeOffloadable: Boolean): Set[String] = {
val projectList = V1WritesUtils.convertEmptyToNull(plan.output,
partitionColumns)
val empty2NullPlan = if (projectList.nonEmpty)
ProjectExecTransformer(projectList, plan) else plan
writeAndCommit(job, description, committer) {
- val (planToExecute, concurrentOutputWriterSpec) = if (orderingMatched) {
- (empty2NullPlan, None)
+ def collapseStages(input: SparkPlan): SparkPlan =
+ GenerateTransformStageId()(
+ ColumnarCollapseTransformStages(new
GlutenConfig(sparkSession.sessionState.conf))(input))
+ val sortedAfterProject = isSortedAfterProject(requiredOrdering,
actualOrdering, projectList)
+ val (planToExecute, concurrentOutputWriterSpec) = if
(sortedAfterProject) {
+ // The empty-to-null project is a bare transformer, which can't run
outside a stage.
+ (if (projectList.nonEmpty) collapseStages(empty2NullPlan) else
empty2NullPlan, None)
} else {
val sortPlan = createSortPlan(empty2NullPlan, requiredOrdering,
outputSpec)
val concurrentOutputWriterSpec =
@@ -286,10 +291,7 @@ object GlutenDeltaFileFormatWriter extends Logging {
case wst @ WholeStageTransformer(wholeStageChild, _) =>
wst.withNewChildren(Seq(addNativeSort(wholeStageChild)))
case other if Convention.get(other).batchType == VeloxBatchType =>
- val nativeSortPlan = addNativeSort(other)
- val nativeSortPlanWithWst =
- GenerateTransformStageId()(ColumnarCollapseTransformStages(new
GlutenConfig(sparkSession.sessionState.conf))(nativeSortPlan))
- nativeSortPlanWithWst
+ collapseStages(addNativeSort(other))
case other =>
Transitions.toBatchPlan(sortPlan, VeloxBatchType)
}
@@ -424,6 +426,30 @@ object GlutenDeltaFileFormatWriter extends Logging {
SortExec(orderingExpr, global = false, child = plan)
}
+ /**
+ * Whether input sorted by `actualOrdering` is still sorted by
`requiredOrdering` after
+ * `projectList`, whose Empty2Null turns "" into null. With one such column,
the last required
+ * one, null and "" stay next to each other when the column is ASC NULLS
FIRST or DESC NULLS
+ * LAST. Otherwise the project can break up a partition: sorted (null, 1),
(null, 2), ("", 1)
+ * becomes (null, 1), (null, 2), (null, 1).
+ */
+ private def isSortedAfterProject(
+ requiredOrdering: Seq[Expression],
+ actualOrdering: Seq[SortOrder],
+ projectList: Seq[NamedExpression]): Boolean = {
+ V1WritesUtils.isOrderingMatched(requiredOrdering, actualOrdering) &&
+ (projectList.collect { case Alias(Empty2Null(column), _) => column } match
{
+ case Seq() => true
+ case Seq(column) if
requiredOrdering.lastOption.exists(_.semanticEquals(column)) =>
+ val order = actualOrdering(requiredOrdering.length - 1)
+ (order.direction, order.nullOrdering) match {
+ case (Ascending, NullsFirst) | (Descending, NullsLast) => true
+ case _ => false
+ }
+ case _ => false
+ })
+ }
+
private def createConcurrentOutputWriterSpec(
sparkSession: SparkSession,
sortPlan: SortExec,
diff --git
a/backends-velox/src-delta4/test/scala/org/apache/spark/sql/delta/DeltaNativeWriteSuite.scala
b/backends-velox/src-delta4/test/scala/org/apache/spark/sql/delta/DeltaNativeWriteSuite.scala
index 855f599577..f4fec181b5 100644
---
a/backends-velox/src-delta4/test/scala/org/apache/spark/sql/delta/DeltaNativeWriteSuite.scala
+++
b/backends-velox/src-delta4/test/scala/org/apache/spark/sql/delta/DeltaNativeWriteSuite.scala
@@ -18,8 +18,9 @@ package org.apache.spark.sql.delta
import org.apache.gluten.config.GlutenConfig
import org.apache.gluten.config.VeloxDeltaConfig
+import org.apache.gluten.execution.SortExecTransformer
-import org.apache.spark.sql.{DataFrame, Row}
+import org.apache.spark.sql.{Column, DataFrame, Row}
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.delta.actions.AddFile
import org.apache.spark.sql.delta.commands.optimize.OptimizeMetrics
@@ -587,6 +588,80 @@ class DeltaNativeWriteSuite extends DeltaSQLCommandTest {
}
}
+ test("native partitioned delta write with presorted input") {
+ // A string partition column goes through the project that turns empty
strings into nulls.
+ val rows =
+ Seq((1L, "a", 1), (2L, "b", 2), (3L, "a", 1), (4L, "c", 3), (5L, "", 4),
(6L, null, 4))
+ for {
+ partitionColumn <- Seq("s", "p")
+ presorted <- Seq(false, true)
+ } {
+ val expected = rows.map {
+ case (id, "", p) if partitionColumn == "s" => Row(id, null, p)
+ case row => Row.fromTuple(row)
+ }
+ withNativeWriteOffloadConf {
+ withTempDir {
+ dir =>
+ val path = dir.getCanonicalPath
+ GlutenDeltaFileFormatWriter.clearExecutedPlanForTesting()
+ val df = rows.toDF("id", "s", "p")
+ val input = if (presorted)
df.sortWithinPartitions(partitionColumn) else df
+ input.write.format("delta").partitionBy(partitionColumn).save(path)
+ assert(!writerPlan.treeString.contains("ColumnarToRow"),
writerPlan)
+ // The writer sorts unsorted input; presorted input keeps the
user's sort only.
+ assert(writerPlan.collect { case s: SortExecTransformer => s
}.size == 1, writerPlan)
+ assert(
+ spark.read.format("delta").load(path).select("id", "s",
"p").orderBy("id")
+ .collect().toSeq == expected)
+ }
+ }
+ }
+ }
+
+ test("native delta write of input sorted before the empty-to-null project") {
+ def check(rows: Seq[(Long, String, Int)], partitionBy: Seq[String],
writerSorts: Boolean)(
+ sortBy: Column*): Unit = {
+ withNativeWriteOffloadConf {
+ withTempDir {
+ dir =>
+ val path = dir.getCanonicalPath
+ // One task and one row per batch, so a partition that comes back
after another
+ // partition gets a second file.
+ withSQLConf(GlutenConfig.COLUMNAR_MAX_BATCH_SIZE.key -> "1") {
+ GlutenDeltaFileFormatWriter.clearExecutedPlanForTesting()
+ spark.sparkContext
+ .parallelize(rows, 1)
+ .toDF("id", "s", "p")
+ .sortWithinPartitions(sortBy: _*)
+ .write
+ .format("delta")
+ .partitionBy(partitionBy: _*)
+ .save(path)
+ assert(!writerPlan.treeString.contains("ColumnarToRow"),
writerPlan)
+ }
+ val partitions = files(DeltaLog.forTable(spark,
path)).toSeq.map(_.partitionValues)
+ assert(partitions.size == 2 && partitions.distinct.size == 2,
partitions)
+ val sorts = writerPlan.collect { case s: SortExecTransformer => s }
+ assert(sorts.size == (if (writerSorts) 2 else 1), writerPlan)
+ }
+ }
+ }
+ // Empty2Null turns these into (null, 1), (null, 2), (null, 1), (null, 2).
+ val twoColumns = Seq((1L, null, 1), (2L, null, 2), (3L, "", 1), (4L, "",
2))
+ check(twoColumns, Seq("s", "p"), writerSorts = true)($"s", $"p")
+ val oneColumn = Seq((1L, "", 1), (2L, "a", 1), (3L, null, 1))
+ // These become null, "a", null.
+ check(oneColumn, Seq("s"), writerSorts = true)($"s".asc_nulls_last)
+ check(oneColumn, Seq("s"), writerSorts = true)($"s".desc_nulls_first)
+ // These stay grouped: null, null, "a" and "a", null, null.
+ check(oneColumn, Seq("s"), writerSorts = false)($"s")
+ check(oneColumn, Seq("s"), writerSorts = false)($"s".desc_nulls_last)
+ // The same with s after another partition column.
+ check(oneColumn, Seq("p", "s"), writerSorts = true)($"p",
$"s".asc_nulls_last)
+ check(oneColumn, Seq("p", "s"), writerSorts = false)($"p", $"s")
+ }
+
test("native delta write checks NOT NULL constraints on a partitioned
table") {
withNativeWriteOffloadConf {
withTempDir {
diff --git a/docs/backends/velox/get-started/VeloxDelta.md
b/docs/backends/velox/get-started/VeloxDelta.md
index 0f534e7292..3403af5696 100644
--- a/docs/backends/velox/get-started/VeloxDelta.md
+++ b/docs/backends/velox/get-started/VeloxDelta.md
@@ -455,7 +455,6 @@ These need native write on, unless a row says otherwise. On
Spark 4.x, many of t
| The `compression` option set to brotli or lzo fails the write. So does
`spark.sql.parquet.compression.codec` when the option is unset. The write fails
even with the Hadoop codec class on the classpath. Without that class, Delta's
writer fails too, and Spark does not ship it. | Exception | 3.5, from code.
Spark 4.x falls back | |
| The `compression` option or `spark.sql.parquet.compression.codec` set to
lz4_raw writes Snappy data into a `.lz4raw.parquet` file. | ResultMismatch |
3.5, from code. Spark 4.x falls back | |
| `maxRecordsPerFile` on an unpartitioned write counts rows but writes whole
batches. When the limit is smaller than a batch, the whole batch goes into one
file. The other files opened for that batch are 0-byte files that are not valid
Parquet. | ResultMismatch | 3.5, from code. Spark 4.x falls back | |
-| `spark.sql.maxConcurrentOutputFileWriters` above 0 makes a partitioned write
with unsorted input fail with `Underlying columnar data is inaccessible from
BatchCarrierRow`. | Exception | 3.5, from code. Spark 4.x falls back | |
| An unpartitioned native write whose first task gets no rows, for example a
write of an empty DataFrame, leaves a 0-byte file that is not valid Parquet.
Reading the table directory as plain Parquet can then fail with `is not a
Parquet file (length is too low: 0)`. With statistics on, the file stays on
disk until `VACUUM`. With `spark.databricks.delta.stats.collect=false`, Delta
commits it. The last two sentences are from code. | ResultMismatch | 3.5 and
4.x, seen on 4.1 | |
| A statistics aggregation that Velox cannot offload fails the write with
`ClassCastException`. With the default
`spark.gluten.sql.columnar.backend.velox.enableTimestampNtzValidation=false`,
the TIMESTAMP_NTZ case from the issue no longer fails on main. Tested on Spark
3.5, seen on 4.1, from code on 4.0. On Spark 3.5 with that option set to true,
the TIMESTAMP_NTZ case still fails (from code). | Exception | 3.5 and 4.x, from
code | [#12538](https://github.com/apache/gluten/issues/12538) |
@@ -533,7 +532,7 @@ A blank cell means unknown.
| spark.sql.ansi.enabled | true on Spark 4.x, false on 3.x | When true, every
query falls back unless `spark.gluten.sql.ansiFallback.enabled=false`. From
code. | ⚠️ |
| spark.sql.parquet.compression.codec | snappy | Codec for native writes when
the `compression` option is unset. On Spark 4.x, a codec Velox cannot write
makes the write fall back (from code). | ⚠️ |
| spark.sql.files.maxRecordsPerFile | 0 | Exact on partitioned native writes.
On unpartitioned tables, Spark 4.x falls back (from code); for Spark 3.5, see
[Write problems](#write-problems). | ⚠️ |
-| spark.sql.maxConcurrentOutputFileWriters | 0 | Above 0, partitioned native
writes with unsorted input fail on Spark 3.5 and fall back on Spark 4.x. From
code. | ⚠️ |
+| spark.sql.maxConcurrentOutputFileWriters | 0 | Above 0, partitioned native
writes on Spark 3.5 sort by the partition columns, as with 0, and the table
content is the same. On Spark 4.x they fall back. | ⚠️ |
| spark.sql.files.ignoreMissingFiles | false | Passed to Velox. Native scans
skip missing files when true. Tested on Spark 3.5 and 4.0, seen on 4.1, from
code on 3.4. | ✅ |
| spark.sql.parquet.mergeSchema | false | Spark's Parquet read option. When
true, Delta scans fall back. Delta Lake's `mergeSchema` write option is a
different setting (see [Write options](#write-options)). From code. | ❌ |
| spark.sql.parquet.outputTimestampType | INT96 | Ignored by native writes on
Spark 3.5. On Spark 4.x, writes with TIMESTAMP columns fall back unless it is
`TIMESTAMP_MICROS`. From code. See [Natively written
files](#natively-written-files). | ⚠️ |
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]