This is an automated email from the ASF dual-hosted git repository.
zhouyuan 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 664d1a5cb3 [GLUTEN-9003][VL] Count Delta's IncrementMetric natively
(#13165)
664d1a5cb3 is described below
commit 664d1a5cb3619cd8bf91509d4a60096014d0576a
Author: Mohammad Linjawi <[email protected]>
AuthorDate: Fri Nov 13 11:59:00 2026 +0300
[GLUTEN-9003][VL] Count Delta's IncrementMetric natively (#13165)
* [GLUTEN-9003][VL] Add native counter functions for Delta's IncrementMetric
---
.../util/delta-spark-ut/known-failures.txt | 179 --------
.../gluten/delta/IncrementMetricOffloadSuite.scala | 318 ++++++++++++++
.../gluten/delta/IncrementMetricOffloadSuite.scala | 1 +
.../gluten/backendsapi/velox/VeloxBackend.scala | 2 +
.../execution/DeltaFilterExecTransformer.scala | 61 ++-
.../execution/DeltaProjectExecTransformer.scala | 104 ++++-
.../execution/DeltaFilterExecTransformer.scala | 61 ++-
.../execution/DeltaProjectExecTransformer.scala | 104 ++++-
.../gluten/extension/DeltaPostTransformRules.scala | 47 ++-
.../gluten/extension/IncrementMetricOffload.scala | 132 ++++++
.../gluten/extension/OffloadDeltaFilter.scala | 10 +-
.../gluten/extension/OffloadDeltaProject.scala | 17 +-
.../org/apache/gluten/execution/DeltaSuite.scala | 457 ++++++++++++++++++++-
.../apache/spark/sql/GlutenDeltaTestUtils.scala} | 16 +-
14 files changed, 1258 insertions(+), 251 deletions(-)
diff --git a/.github/workflows/util/delta-spark-ut/known-failures.txt
b/.github/workflows/util/delta-spark-ut/known-failures.txt
index 333f26e7c0..99b64398b1 100644
--- a/.github/workflows/util/delta-spark-ut/known-failures.txt
+++ b/.github/workflows/util/delta-spark-ut/known-failures.txt
@@ -63,11 +63,6 @@ org.apache.spark.sql.delta.ConvertToDeltaSQLSuite#CONVERT
keeps NaN rows for fin
org.apache.spark.sql.delta.ConvertToDeltaScalaSuite#CONVERT keeps NaN rows for
finite-threshold predicate (NaN-excluding writer)
org.apache.spark.sql.delta.DeleteMetricsSuite#delete-metrics: delete one row
per file - Partitioned = false, cdfEnabled = false
org.apache.spark.sql.delta.DeleteMetricsSuite#delete-metrics: delete one row
per file - Partitioned = false, cdfEnabled = true
-org.apache.spark.sql.delta.DeltaCDCStreamDeletionVectorSuite#cdc streams with
noop merge
-org.apache.spark.sql.delta.DeltaCDCStreamSuite#cdc streams with noop merge
-org.apache.spark.sql.delta.DeltaCDCStreamWithCatalogManagedBatch100Suite#cdc
streams with noop merge
-org.apache.spark.sql.delta.DeltaCDCStreamWithCatalogManagedBatch1Suite#cdc
streams with noop merge
-org.apache.spark.sql.delta.DeltaCDCStreamWithCatalogManagedBatch2Suite#cdc
streams with noop merge
org.apache.spark.sql.delta.DeltaColumnMappingSuite#explicit id matching
org.apache.spark.sql.delta.DeltaDataFrameHadoopOptionsSuite#SC-86916: Delta
log cache should respect options
org.apache.spark.sql.delta.DeltaDataFrameHadoopOptionsSuite#SC-86916:
checkpoint should pick up Hadoop file system options
@@ -115,178 +110,30 @@
org.apache.spark.sql.delta.DeltaWithCatalogOwnedBatch1Suite#deleted files cause
org.apache.spark.sql.delta.DeltaWithCatalogOwnedBatch2Suite#SC-8810: skip
deleted file
org.apache.spark.sql.delta.DeltaWithCatalogOwnedBatch2Suite#SC-8810: skipping
deleted file still throws on corrupted file
org.apache.spark.sql.delta.DeltaWithCatalogOwnedBatch2Suite#deleted files
cause failure by default
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only delete all rows - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only delete all rows - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only delete all rows - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only delete all rows - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only with condition on delete and insert with no matching rows -
Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only with condition on delete and insert with no matching rows -
Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only with condition on delete and insert with no matching rows -
Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only with condition on delete and insert with no matching rows -
Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only with duplicates - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only with duplicates - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only with duplicates - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only with duplicates - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only with skipping - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only with skipping - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only with skipping - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only with skipping - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only without join - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only without join - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only without join - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only without join - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only without join with source with 1 row - Partitioned = false, CDF =
false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only without join with source with 1 row - Partitioned = false, CDF =
true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only without join with source with 1 row - Partitioned = true, CDF =
false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
delete-only without join with source with 1 row - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
insert-only with update/delete with unsatisfied conditions - Partitioned =
false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
insert-only with update/delete with unsatisfied conditions - Partitioned =
false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
insert-only with update/delete with unsatisfied conditions - Partitioned =
true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
insert-only with update/delete with unsatisfied conditions - Partitioned =
true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: match-only
- Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: match-only
- Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: match-only
- Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: match-only
- Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: match-only
with skipping - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: match-only
with skipping - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: match-only
with skipping - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: match-only
with skipping - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: match-only
with update/delete with unsatisfied conditions - Partitioned = false, CDF =
false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: match-only
with update/delete with unsatisfied conditions - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: match-only
with update/delete with unsatisfied conditions - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: match-only
with update/delete with unsatisfied conditions - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: not
matched by source update only - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: not
matched by source update only - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: not
matched by source update only - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: not
matched by source update only - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: replace
target with source - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: replace
target with source - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: replace
target with source - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: replace
target with source - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
update/delete/insert with some unsatisfied conditions - Partitioned = false,
CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
update/delete/insert with some unsatisfied conditions - Partitioned = false,
CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
update/delete/insert with some unsatisfied conditions - Partitioned = true, CDF
= false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics:
update/delete/insert with some unsatisfied conditions - Partitioned = true, CDF
= true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: upsert -
Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: upsert -
Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: upsert -
Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: upsert -
Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: upsert and
delete with conditions - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: upsert and
delete with conditions - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: upsert and
delete with conditions - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistorySuite#merge-metrics: upsert and
delete with conditions - Partitioned = true, CDF = true
org.apache.spark.sql.delta.DescribeDeltaHistorySuite#operation metrics - merge
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only delete all rows - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only delete all rows - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only delete all rows - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only delete all rows - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only with condition on delete and insert with no matching rows -
Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only with condition on delete and insert with no matching rows -
Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only with condition on delete and insert with no matching rows -
Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only with condition on delete and insert with no matching rows -
Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only with duplicates - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only with duplicates - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only with duplicates - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only with duplicates - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only with skipping - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only with skipping - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only with skipping - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only with skipping - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only without join - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only without join - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only without join - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only without join - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only without join with source with 1 row - Partitioned = false, CDF =
false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only without join with source with 1 row - Partitioned = false, CDF =
true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only without join with source with 1 row - Partitioned = true, CDF =
false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
delete-only without join with source with 1 row - Partitioned = true, CDF =
true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
insert-only with update/delete with unsatisfied conditions - Partitioned =
false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
insert-only with update/delete with unsatisfied conditions - Partitioned =
false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
insert-only with update/delete with unsatisfied conditions - Partitioned =
true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
insert-only with update/delete with unsatisfied conditions - Partitioned =
true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
match-only - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
match-only - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
match-only - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
match-only - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
match-only with skipping - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
match-only with skipping - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
match-only with skipping - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
match-only with skipping - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
match-only with update/delete with unsatisfied conditions - Partitioned =
false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
match-only with update/delete with unsatisfied conditions - Partitioned =
false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
match-only with update/delete with unsatisfied conditions - Partitioned =
true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
match-only with update/delete with unsatisfied conditions - Partitioned =
true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
not matched by source update only - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
not matched by source update only - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
not matched by source update only - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
not matched by source update only - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
replace target with source - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
replace target with source - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
replace target with source - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
replace target with source - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
update/delete/insert with some unsatisfied conditions - Partitioned = false,
CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
update/delete/insert with some unsatisfied conditions - Partitioned = false,
CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
update/delete/insert with some unsatisfied conditions - Partitioned = true,
CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
update/delete/insert with some unsatisfied conditions - Partitioned = true,
CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
upsert - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
upsert - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
upsert - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
upsert - Partitioned = true, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
upsert and delete with conditions - Partitioned = false, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
upsert and delete with conditions - Partitioned = false, CDF = true
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
upsert and delete with conditions - Partitioned = true, CDF = false
-org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#merge-metrics:
upsert and delete with conditions - Partitioned = true, CDF = true
org.apache.spark.sql.delta.DescribeDeltaHistoryWithCatalogOwnedBatch100Suite#operation
metrics - merge
org.apache.spark.sql.delta.FeatureEnablementConcurrencySuite#Enable column
mapping feature - txnInterleaved: true
org.apache.spark.sql.delta.FileSizeHistogramSuite#check CommitStats with
deletes
org.apache.spark.sql.delta.FileSizeHistogramSuite#histogram is re-calculated
when files are removed
org.apache.spark.sql.delta.HDFSLogStoreSuite#No AbstractFileSystem - end to
end test using data frame
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: ARRAY<BIGINT>,
targetType: ARRAY<INT> followAnsiEnabled: false, ansiEnabled: false,
storeAssignmentPolicy: ANSI
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: ARRAY<BIGINT>,
targetType: ARRAY<INT> followAnsiEnabled: false, ansiEnabled: true,
storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: ARRAY<BIGINT>,
targetType: ARRAY<INT> followAnsiEnabled: true, ansiEnabled: true,
storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: ARRAY<BIGINT>,
targetType: ARRAY<INT> followAnsiEnabled: true, ansiEnabled: true,
storeAssignmentPolicy: LEGACY
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: BIGINT, targetType:
DECIMAL(7,2) followAnsiEnabled: false, ansiEnabled: false,
storeAssignmentPolicy: ANSI
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: BIGINT, targetType:
DECIMAL(7,2) followAnsiEnabled: false, ansiEnabled: true,
storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: BIGINT, targetType:
DECIMAL(7,2) followAnsiEnabled: true, ansiEnabled: true, storeAssignmentPolicy:
ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: BIGINT, targetType:
DECIMAL(7,2) followAnsiEnabled: true, ansiEnabled: true, storeAssignmentPolicy:
LEGACY
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: BIGINT, targetType: INT
followAnsiEnabled: false, ansiEnabled: false, storeAssignmentPolicy: ANSI
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: BIGINT, targetType: INT
followAnsiEnabled: false, ansiEnabled: true, storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: BIGINT, targetType: INT
followAnsiEnabled: true, ansiEnabled: true, storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: BIGINT, targetType: INT
followAnsiEnabled: true, ansiEnabled: true, storeAssignmentPolicy: LEGACY
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: DECIMAL(3,1), targetType:
DECIMAL(3,2) followAnsiEnabled: false, ansiEnabled: false,
storeAssignmentPolicy: ANSI
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: DECIMAL(3,1), targetType:
DECIMAL(3,2) followAnsiEnabled: false, ansiEnabled: true,
storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: DECIMAL(3,1), targetType:
DECIMAL(3,2) followAnsiEnabled: true, ansiEnabled: true, storeAssignmentPolicy:
ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: DECIMAL(3,1), targetType:
DECIMAL(3,2) followAnsiEnabled: true, ansiEnabled: true, storeAssignmentPolicy:
LEGACY
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: DOUBLE, targetType:
BIGINT followAnsiEnabled: false, ansiEnabled: false, storeAssignmentPolicy: ANSI
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: DOUBLE, targetType:
BIGINT followAnsiEnabled: false, ansiEnabled: true, storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: DOUBLE, targetType:
BIGINT followAnsiEnabled: true, ansiEnabled: true, storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: DOUBLE, targetType:
BIGINT followAnsiEnabled: true, ansiEnabled: true, storeAssignmentPolicy: LEGACY
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: INT, targetType: SMALLINT
followAnsiEnabled: false, ansiEnabled: false, storeAssignmentPolicy: ANSI
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: INT, targetType: SMALLINT
followAnsiEnabled: false, ansiEnabled: true, storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: INT, targetType: SMALLINT
followAnsiEnabled: true, ansiEnabled: true, storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: INT, targetType: SMALLINT
followAnsiEnabled: true, ansiEnabled: true, storeAssignmentPolicy: LEGACY
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: INT, targetType: TINYINT
followAnsiEnabled: false, ansiEnabled: false, storeAssignmentPolicy: ANSI
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: INT, targetType: TINYINT
followAnsiEnabled: false, ansiEnabled: true, storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: INT, targetType: TINYINT
followAnsiEnabled: true, ansiEnabled: true, storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: INT, targetType: TINYINT
followAnsiEnabled: true, ansiEnabled: true, storeAssignmentPolicy: LEGACY
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: MAP<STRING, BIGINT>,
targetType: MAP<STRING, INT> followAnsiEnabled: false, ansiEnabled: false,
storeAssignmentPolicy: ANSI
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: MAP<STRING, BIGINT>,
targetType: MAP<STRING, INT> followAnsiEnabled: false, ansiEnabled: true,
storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: MAP<STRING, BIGINT>,
targetType: MAP<STRING, INT> followAnsiEnabled: true, ansiEnabled: true,
storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: MAP<STRING, BIGINT>,
targetType: MAP<STRING, INT> followAnsiEnabled: true, ansiEnabled: true,
storeAssignmentPolicy: LEGACY
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: STRING, targetType: INT
followAnsiEnabled: false, ansiEnabled: false, storeAssignmentPolicy: ANSI
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: STRING, targetType: INT
followAnsiEnabled: false, ansiEnabled: true, storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: STRING, targetType: INT
followAnsiEnabled: true, ansiEnabled: true, storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: STRING, targetType: INT
followAnsiEnabled: true, ansiEnabled: true, storeAssignmentPolicy: LEGACY
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: Struct<value:BIGINT>,
targetType: Struct<value:INT> followAnsiEnabled: false, ansiEnabled: false,
storeAssignmentPolicy: ANSI
-org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: Struct<value:BIGINT>,
targetType: Struct<value:INT> followAnsiEnabled: false, ansiEnabled: true,
storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: Struct<value:BIGINT>,
targetType: Struct<value:INT> followAnsiEnabled: true, ansiEnabled: true,
storeAssignmentPolicy: ANSI
org.apache.spark.sql.delta.ImplicitMergeCastingSuite#MERGE overflow in WHEN
MATCHED THEN UPDATE SET t.value = s.value sourceType: Struct<value:BIGINT>,
targetType: Struct<value:INT> followAnsiEnabled: true, ansiEnabled: true,
storeAssignmentPolicy: LEGACY
org.apache.spark.sql.delta.ImplicitStreamingMergeCastingSuite#Streaming MERGE
overflow sourceType: ARRAY<BIGINT>, targetType: ARRAY<INT> followAnsiEnabled:
true, ansiEnabled: true, storeAssignmentPolicy: ANSI
@@ -396,7 +243,6 @@
org.apache.spark.sql.delta.generatedsuites.delete.DeleteTempViewSQLPathBasedSuit
org.apache.spark.sql.delta.generatedsuites.delete.DeleteTempViewSQLPathBasedSuite#test
delete on temp view - nontrivial projection - SQL TempView
org.apache.spark.sql.delta.generatedsuites.delete.RowTrackingDeleteSuiteBaseCDCOnDVOffSuite#DELETE
with optimized writes preserves Row ID, isPartitioned=true
org.apache.spark.sql.delta.generatedsuites.delete.RowTrackingDeleteSuiteBaseDVOffSuite#DELETE
with optimized writes preserves Row ID, isPartitioned=true
-org.apache.spark.sql.delta.generatedsuites.merge.MergeCDCSQLPathBasedCDCOnSuite#merge
CDC - all conditions failed for all rows
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoDVsSQLPathBasedCDCOnDVsPredPushOffSuite#Merge
with DVs metrics - Incremental Updates
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoDVsSQLPathBasedCDCOnDVsPredPushOffSuite#Merge
with DVs metrics - delete entire file
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoDVsSQLPathBasedCDCOnDVsPredPushOffSuite#Verify
error is produced when paths are not joined correctly
@@ -414,40 +260,17 @@
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoExtendedSyntaxSQLInMem
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoExtendedSyntaxSQLInMemoryTableNameBasedSuite#extended
syntax - only conditional delete with multiple matches
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoExtendedSyntaxSQLInMemoryTableNameBasedSuite#extended
syntax - only conditional update with multiple matches
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoExtendedSyntaxSQLInMemoryTableNameBasedSuite#extended
syntax - only update with multiple matches
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoNotMatchedBySourceCDCPart2SQLNameBasedSuite#not
matched by source - all 3 clauses - no changes - isPartitioned: false -
cdcEnabled: true
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoNotMatchedBySourceCDCPart2SQLNameBasedSuite#not
matched by source - all 3 clauses - no changes - isPartitioned: true -
cdcEnabled: true
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoNotMatchedBySourceCDCPart2SQLPathBasedCDCOnSuite#not
matched by source - all 3 clauses - no changes - isPartitioned: false -
cdcEnabled: true
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoNotMatchedBySourceCDCPart2SQLPathBasedCDCOnSuite#not
matched by source - all 3 clauses - no changes - isPartitioned: true -
cdcEnabled: true
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoNotMatchedBySourceCDCPart2SQLPathBasedSuite#not
matched by source - all 3 clauses - no changes - isPartitioned: false -
cdcEnabled: true
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoNotMatchedBySourceCDCPart2SQLPathBasedSuite#not
matched by source - all 3 clauses - no changes - isPartitioned: true -
cdcEnabled: true
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoNotMatchedBySourceCDCPart2ScalaSuite#not
matched by source - all 3 clauses - no changes - isPartitioned: false -
cdcEnabled: true
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoNotMatchedBySourceCDCPart2ScalaSuite#not
matched by source - all 3 clauses - no changes - isPartitioned: true -
cdcEnabled: true
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSQLSQLNameBasedSuite#CTE
as a source in MERGE
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSQLSQLPathBasedCDCOnDVsPredPushOffSuite#CTE
as a source in MERGE
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSQLSQLPathBasedCDCOnDVsPredPushOnSuite#CTE
as a source in MERGE
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSQLSQLPathBasedCDCOnSuite#CTE
as a source in MERGE
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSQLSQLPathBasedDVsPredPushOffSuite#CTE
as a source in MERGE
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSQLSQLPathBasedDVsPredPushOnSuite#CTE
as a source in MERGE
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSQLSQLPathBasedSuite#CTE
as a source in MERGE
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLNameBasedSuite#data
skipping with matched predicates - with insert clause
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLNameBasedSuite#merge
with repartition - insert only merge
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLPathBasedCDCOnDVsPredPushOffSuite#data
skipping with matched predicates - with insert clause
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLPathBasedCDCOnDVsPredPushOffSuite#merge
with repartition - insert only merge
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLPathBasedCDCOnDVsPredPushOffSuite#merge
with repartition - partition on multiple columns
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLPathBasedCDCOnDVsPredPushOnSuite#data
skipping with matched predicates - with insert clause
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLPathBasedCDCOnDVsPredPushOnSuite#merge
with repartition - insert only merge
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLPathBasedCDCOnDVsPredPushOnSuite#merge
with repartition - partition on multiple columns
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLPathBasedCDCOnSuite#data
skipping with matched predicates - with insert clause
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLPathBasedCDCOnSuite#merge
with repartition - insert only merge
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLPathBasedDVsPredPushOffSuite#data
skipping with matched predicates - with insert clause
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLPathBasedDVsPredPushOffSuite#merge
with repartition - insert only merge
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLPathBasedDVsPredPushOffSuite#merge
with repartition - partition on multiple columns
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLPathBasedDVsPredPushOnSuite#data
skipping with matched predicates - with insert clause
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLPathBasedDVsPredPushOnSuite#merge
with repartition - insert only merge
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLPathBasedDVsPredPushOnSuite#merge
with repartition - partition on multiple columns
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLPathBasedSuite#data
skipping with matched predicates - with insert clause
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscSQLPathBasedSuite#merge
with repartition - insert only merge
-org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscScalaSuite#data
skipping with matched predicates - with insert clause
org.apache.spark.sql.delta.generatedsuites.merge.MergeIntoSuiteBaseMiscScalaSuite#merge
with repartition - insert only merge
org.apache.spark.sql.delta.generatedsuites.update.UpdateBaseTempViewSQLNameBasedSuite#test
update on temp view - nontrivial projection - Dataset TempView
org.apache.spark.sql.delta.generatedsuites.update.UpdateBaseTempViewSQLNameBasedSuite#test
update on temp view - nontrivial projection - SQL TempView
@@ -482,5 +305,3 @@
org.apache.spark.sql.delta.storage.dv.DeletionVectorWriteDurabilitySuite#a MERGE
org.apache.spark.sql.delta.storage.dv.DeletionVectorWriteDurabilitySuite#an
UPDATE whose deletion vector was never written does not corrupt the table
org.apache.spark.sql.delta.storage.dv.DeletionVectorWriteDurabilitySuite#control:
an ordinary write whose close fails does not commit
org.apache.spark.sql.delta.storage.dv.DeletionVectorWriteDurabilitySuite#the
kill-switch flag off does not apply the propagate-close fix
-org.apache.spark.sql.delta.test.DeltaV2CDCStreamDeletionVectorSuite#cdc
streams with noop merge
-org.apache.spark.sql.delta.test.DeltaV2CDCStreamSuite#cdc streams with noop
merge
diff --git
a/backends-velox/src-delta33/test/scala/org/apache/gluten/delta/IncrementMetricOffloadSuite.scala
b/backends-velox/src-delta33/test/scala/org/apache/gluten/delta/IncrementMetricOffloadSuite.scala
new file mode 100644
index 0000000000..5cc51eaf06
--- /dev/null
+++
b/backends-velox/src-delta33/test/scala/org/apache/gluten/delta/IncrementMetricOffloadSuite.scala
@@ -0,0 +1,318 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gluten.delta
+
+import org.apache.gluten.exception.GlutenNotSupportException
+import org.apache.gluten.execution.{DeltaFilterExecTransformer,
DeltaProjectExecTransformer}
+import org.apache.gluten.expression.IncrementMetricCall
+import org.apache.gluten.extension.IncrementMetricOffload
+
+import org.apache.spark.sql.catalyst.expressions.{Add, Alias, And,
ArrayFilter, ArrayTransform, AttributeReference, CaseWhen, Cast, Coalesce,
CreateArray, CreateNamedStruct, Divide, EqualNullSafe, EqualTo, Expression,
GreaterThan, If, IsNotNull, IsNull, LambdaFunction, Literal, NamedExpression,
NamedLambdaVariable, Not, Or}
+import org.apache.spark.sql.delta.metric.IncrementMetric
+import org.apache.spark.sql.execution.metric.SQLMetric
+import org.apache.spark.sql.types.{ArrayType, BooleanType, DoubleType,
IntegerType, StringType}
+
+import org.scalatest.funsuite.AnyFunSuite
+
+/**
+ * Delta's `IncrementMetric` needs either native evaluation counts or an
unconditional shape whose
+ * output row count is exact. Native counters are offloaded only below the
parents Delta's DML
+ * commands generate; any other parent can make the native count differ from
Spark's (GLUTEN-9003).
+ */
+class IncrementMetricOffloadSuite extends AnyFunSuite {
+
+ private val id = AttributeReference("id", IntegerType)()
+
+ private val nullableId = AttributeReference("nullable_id", IntegerType,
nullable = true)()
+
+ private def increment(child: Expression, metric: SQLMetric): IncrementMetric
=
+ IncrementMetric(child, metric)
+
+ private def newMetric(): SQLMetric = new SQLMetric("sum")
+
+ private def alias(child: Expression): NamedExpression = Alias(child, "col")()
+
+ test("an IncrementMetric at the root of a projection alias is offloadable") {
+ val metric = newMetric()
+ val projectList = Seq(id, alias(increment(Literal.TrueLiteral, metric)))
+ assert(IncrementMetricOffload.canOffloadProject(projectList,
nativeCounting = false))
+
+ val (stripped, metrics) =
+ DeltaProjectExecTransformer.stripIncrementMetrics(projectList,
nativeCounting = false)
+ assert(stripped.head eq id)
+ assert(stripped(1).asInstanceOf[Alias].child === Literal.TrueLiteral)
+ assert(stripped(1).exprId === projectList(1).exprId)
+ assert(metrics === Seq(("increment_metric", metric)))
+ }
+
+ test("a stack of IncrementMetric at the alias root is offloadable and keeps
every metric") {
+ val inner = newMetric()
+ val outer = newMetric()
+ val projectList = Seq(alias(increment(increment(Literal.FalseLiteral,
inner), outer)))
+ assert(IncrementMetricOffload.canOffloadProject(projectList,
nativeCounting = false))
+
+ val (stripped, metrics) =
+ DeltaProjectExecTransformer.stripIncrementMetrics(projectList,
nativeCounting = false)
+ assert(stripped.head.asInstanceOf[Alias].child === Literal.FalseLiteral)
+ assert(metrics.map(_._2) === Seq(outer, inner))
+ }
+
+ test("an IncrementMetric inside a CASE WHEN branch is not offloadable") {
+ // The shape MERGE generates: one counter per clause, the copied-row
counter in the else.
+ val updated = newMetric()
+ val copied = newMetric()
+ val rowDropped = CaseWhen(
+ Seq((EqualTo(id, Literal(1)), increment(Literal.FalseLiteral, updated))),
+ Some(increment(Literal.FalseLiteral, copied)))
+ val projectList = Seq(id, alias(rowDropped))
+ assert(!IncrementMetricOffload.canOffloadProject(projectList,
nativeCounting = false))
+ // A backend that counts natively supports CASE branches as named counter
function calls.
+ assert(IncrementMetricOffload.canOffloadProject(projectList,
nativeCounting = true))
+ intercept[GlutenNotSupportException] {
+ DeltaProjectExecTransformer.stripIncrementMetrics(projectList,
nativeCounting = false)
+ }
+ }
+
+ test("an IncrementMetric below the alias root stack is not offloadable") {
+ val projectList = Seq(
+ alias(
+ increment(
+ If(
+ GreaterThan(id, Literal(1)),
+ increment(Literal.TrueLiteral, newMetric()),
+ Literal(false)),
+ newMetric())))
+ assert(!IncrementMetricOffload.canOffloadProject(projectList,
nativeCounting = false))
+ intercept[GlutenNotSupportException] {
+ DeltaProjectExecTransformer.stripIncrementMetrics(projectList,
nativeCounting = false)
+ }
+ }
+
+ test("native counters inside AND or OR fall back") {
+ val counter = increment(Literal.TrueLiteral, newMetric())
+ val predicate = GreaterThan(id, Literal(1))
+ Seq[Expression](
+ And(counter, predicate),
+ Or(counter, predicate),
+ And(predicate, If(predicate, counter, Literal.FalseLiteral)),
+ increment(Or(predicate, counter), newMetric())
+ ).foreach {
+ expr =>
+ val projectList = Seq(alias(expr))
+ assert(!IncrementMetricOffload.canOffloadProject(projectList,
nativeCounting = true))
+ // The shape is rejected before any slot is assigned.
+ val error = intercept[GlutenNotSupportException] {
+ DeltaProjectExecTransformer.stripIncrementMetrics(projectList,
nativeCounting = true)
+ }
+ assert(error.getMessage ===
IncrementMetricOffload.nativeCounterPlacementReason)
+ }
+ }
+
+ test("native counters below any other parent fall back") {
+ def counter: Expression = increment(Literal(1), newMetric())
+ val x = NamedLambdaVariable("x", IntegerType, nullable = true)
+ val items = AttributeReference("items", ArrayType(IntegerType))()
+ val predicate = GreaterThan(id, Literal(1))
+ val shared = increment(Literal(1), newMetric())
+ Seq[Expression](
+ // Velox drops the rows where `nullable_id` is null before the counter
runs; Spark does not.
+ Add(counter, nullableId),
+ Add(increment(nullableId, newMetric()), nullableId),
+ // Spark skips the dividend when the divisor is zero; Velox evaluates it.
+ Divide(increment(Literal(1.0), newMetric()), Cast(id, DoubleType)),
+ // Velox merges identical inputs into one call; Spark evaluates the
second where the first
+ // is null.
+ Coalesce(Seq(shared, shared)),
+ // A lambda body is evaluated per element but missing from the exported
statistics.
+ ArrayTransform(items, LambdaFunction(increment(x, newMetric()), Seq(x))),
+ ArrayFilter(items, LambdaFunction(IsNotNull(increment(x, newMetric())),
Seq(x))),
+ // Conditions can be pruned by their branches; only branch values are
counted exactly.
+ If(increment(predicate, newMetric()), id, nullableId),
+ CaseWhen(Seq(increment(predicate, newMetric()) -> id), nullableId),
+ // A counter that is accepted on its own is still rejected below a
parent that is not.
+ CaseWhen(Seq(predicate -> Add(counter, nullableId)), counter)
+ ).foreach {
+ expr =>
+ val projectList = Seq(id, alias(expr))
+ assert(!IncrementMetricOffload.canOffloadProject(projectList,
nativeCounting = true), expr)
+ val error = intercept[GlutenNotSupportException] {
+ DeltaProjectExecTransformer.stripIncrementMetrics(projectList,
nativeCounting = true)
+ }
+ assert(error.getMessage ===
IncrementMetricOffload.nativeCounterPlacementReason)
+ }
+ }
+
+ test("native counting accepts every counter placement Delta DML generates") {
+ val sourcePresent = AttributeReference("_source_row_present_",
BooleanType)()
+ val targetPresent = AttributeReference("_target_row_present_",
BooleanType)()
+ val changeType = AttributeReference("_change_type", StringType)()
+ val predicate = GreaterThan(id, Literal(1))
+ def flag(value: Boolean): Expression = increment(Literal(value),
newMetric())
+ def stacked(value: Boolean): Expression = increment(flag(value),
newMetric())
+ // MERGE's _row_dropped_ column: the source/target dispatch, then one
value per clause.
+ val rowDropped = CaseWhen(
+ Seq(
+ IsNull(sourcePresent) -> If(predicate, stacked(true), flag(false)),
+ IsNull(targetPresent) -> CaseWhen(Seq(predicate -> flag(false)),
Literal.TrueLiteral)),
+ CaseWhen(
+ Seq(EqualTo(id, Literal(3)) -> stacked(true), predicate ->
stacked(false)),
+ flag(false))
+ )
+ def packed(dropped: Expression): Expression =
+ CreateArray(Seq(CreateNamedStruct(Seq(Literal("_row_dropped_"),
dropped))))
+ Seq[Expression](
+ // Source-row counters and the single clause of an insert-only MERGE: a
counter at the
+ // alias root, whatever it wraps.
+ flag(true),
+ increment(Add(nullableId, Literal(1)), newMetric()),
+ rowDropped,
+ // With change data feed on, the same column is packed into the change
rows Delta explodes.
+ CaseWhen(
+ Seq(
+ EqualNullSafe(changeType, Literal("insert")) -> packed(rowDropped),
+ EqualNullSafe(changeType, Literal("delete")) ->
packed(Not(rowDropped))),
+ packed(rowDropped)
+ )
+ ).foreach {
+ expr =>
+ val projectList = Seq(id, alias(expr))
+ assert(IncrementMetricOffload.canOffloadProject(projectList,
nativeCounting = true), expr)
+ val (rewritten, metrics) =
+ DeltaProjectExecTransformer.stripIncrementMetrics(projectList,
nativeCounting = true)
+ assert(rewritten.flatMap(_.collect { case m: IncrementMetric => m
}).isEmpty)
+ assert(metrics.nonEmpty)
+ }
+ }
+
+ test("a lambda function below a native counter stays offloadable") {
+ val x = NamedLambdaVariable("x", IntegerType, nullable = true)
+ val items = AttributeReference("items", ArrayType(IntegerType))()
+ val metric = newMetric()
+ val projectList =
+ Seq(alias(increment(
+ ArrayTransform(items, LambdaFunction(Add(x, Literal(1)), Seq(x))),
+ metric)))
+ assert(IncrementMetricOffload.canOffloadProject(projectList,
nativeCounting = true))
+ val (rewritten, metrics) =
+ DeltaProjectExecTransformer.stripIncrementMetrics(projectList,
nativeCounting = true)
+
assert(rewritten.head.asInstanceOf[Alias].child.isInstanceOf[IncrementMetricCall])
+ assert(metrics.map(_._1) === Seq("increment_metric_0"))
+ }
+
+ test("native counters around AND or OR remain offloadable") {
+ val predicate = GreaterThan(id, Literal(1))
+ Seq[Expression](And(predicate, predicate), Or(predicate,
predicate)).foreach {
+ expr =>
+ val projectList = Seq(alias(increment(expr, newMetric())))
+ assert(IncrementMetricOffload.canOffloadProject(projectList,
nativeCounting = true))
+ }
+ }
+
+ test("a project list without IncrementMetric is returned untouched") {
+ val projectList = Seq(id, alias(GreaterThan(id, Literal(1))))
+ assert(IncrementMetricOffload.canOffloadProject(projectList,
nativeCounting = false))
+ val (stripped, metrics) =
+ DeltaProjectExecTransformer.stripIncrementMetrics(projectList,
nativeCounting = false)
+ assert(stripped.zip(projectList).forall { case (a, b) => a eq b })
+ assert(metrics.isEmpty)
+ }
+
+ test("a filter on IncrementMetric over a literal true is offloadable") {
+ val touched = newMetric()
+ val condition = increment(Literal.TrueLiteral, touched)
+ assert(IncrementMetricOffload.canOffloadFilter(condition))
+ val (stripped, metrics) =
DeltaFilterExecTransformer.stripIncrementMetrics(condition)
+ assert(stripped === Literal.TrueLiteral)
+ assert(metrics === Seq(("increment_metric", touched)))
+
+ val stacked = increment(condition, newMetric())
+ assert(IncrementMetricOffload.canOffloadFilter(stacked))
+ assert(DeltaFilterExecTransformer.stripIncrementMetrics(stacked)._2.size
=== 2)
+ }
+
+ test("a filter on IncrementMetric over anything else is not offloadable") {
+ Seq[Expression](
+ increment(Literal.FalseLiteral, newMetric()),
+ increment(GreaterThan(id, Literal(1)), newMetric()),
+ And(increment(Literal.TrueLiteral, newMetric()), GreaterThan(id,
Literal(1)))
+ ).foreach {
+ condition => assert(!IncrementMetricOffload.canOffloadFilter(condition),
condition)
+ }
+ intercept[GlutenNotSupportException] {
+
DeltaFilterExecTransformer.stripIncrementMetrics(increment(Literal.FalseLiteral,
newMetric()))
+ }
+ }
+
+ test("native counting gives each distinct metric one slot, in order of first
appearance") {
+ val updated = newMetric()
+ val copied = newMetric()
+ val predicate = GreaterThan(id, Literal(1))
+ // `copied` appears twice: inside a branch and at another alias root. Both
calls share a slot.
+ val projectList = Seq(
+ id,
+ alias(CaseWhen(Seq(predicate -> increment(id, updated)), increment(id,
copied))),
+ alias(increment(Literal.TrueLiteral, copied)))
+ val (rewritten, metrics) =
+ DeltaProjectExecTransformer.stripIncrementMetrics(projectList,
nativeCounting = true)
+ assert(rewritten.head eq id)
+ val calls = rewritten.flatMap(_.collect { case call: IncrementMetricCall
=> call })
+ assert(calls.map(_.functionName) === Seq(
+ "increment_metric_0",
+ "increment_metric_1",
+ "increment_metric_1"))
+ assert(rewritten.flatMap(_.collect { case m: IncrementMetric => m
}).isEmpty)
+ assert(metrics.map(_._1) === Seq("increment_metric_0",
"increment_metric_1"))
+ assert(metrics.map(_._2).zip(Seq(updated, copied)).forall { case (a, b) =>
a eq b })
+ }
+
+ test("native counting does not need a metric name") {
+ // An accumulator that was never registered has no name; the slot stands
in for it.
+ val projectList = Seq(id, alias(increment(Literal.TrueLiteral,
newMetric())))
+ val (rewritten, metrics) =
+ DeltaProjectExecTransformer.stripIncrementMetrics(projectList,
nativeCounting = true)
+ assert(rewritten.head eq id)
+ assert(metrics.map(_._1) === Seq("increment_metric_0"))
+ val plain = Seq(id, alias(GreaterThan(id, Literal(1))))
+ val (untouched, none) =
+ DeltaProjectExecTransformer.stripIncrementMetrics(plain, nativeCounting
= true)
+ assert(untouched.zip(plain).forall { case (a, b) => a eq b })
+ assert(none.isEmpty)
+ }
+
+ test("native counting falls back above the slot limit") {
+ val projectList = (0 until IncrementMetricCall.maxCounters).map {
+ _ => alias(increment(Literal.TrueLiteral, newMetric()))
+ }
+ assert(
+ DeltaProjectExecTransformer
+ .stripIncrementMetrics(projectList, nativeCounting = true)
+ ._2
+ .size === IncrementMetricCall.maxCounters)
+ val oneTooMany = projectList :+ alias(increment(Literal.TrueLiteral,
newMetric()))
+ intercept[GlutenNotSupportException] {
+ DeltaProjectExecTransformer.stripIncrementMetrics(oneTooMany,
nativeCounting = true)
+ }
+ }
+
+ test("a filter condition without IncrementMetric is returned untouched") {
+ val condition = GreaterThan(id, Literal(1))
+ assert(!IncrementMetricOffload.canOffloadFilter(condition))
+ val (stripped, metrics) =
DeltaFilterExecTransformer.stripIncrementMetrics(condition)
+ assert(stripped eq condition)
+ assert(metrics.isEmpty)
+ }
+}
diff --git
a/backends-velox/src-delta4/test/scala/org/apache/gluten/delta/IncrementMetricOffloadSuite.scala
b/backends-velox/src-delta4/test/scala/org/apache/gluten/delta/IncrementMetricOffloadSuite.scala
new file mode 120000
index 0000000000..fa57f86f77
--- /dev/null
+++
b/backends-velox/src-delta4/test/scala/org/apache/gluten/delta/IncrementMetricOffloadSuite.scala
@@ -0,0 +1 @@
+../../../../../../../src-delta33/test/scala/org/apache/gluten/delta/IncrementMetricOffloadSuite.scala
\ No newline at end of file
diff --git
a/backends-velox/src/main/scala/org/apache/gluten/backendsapi/velox/VeloxBackend.scala
b/backends-velox/src/main/scala/org/apache/gluten/backendsapi/velox/VeloxBackend.scala
index 2e75321156..5f53fad323 100644
---
a/backends-velox/src/main/scala/org/apache/gluten/backendsapi/velox/VeloxBackend.scala
+++
b/backends-velox/src/main/scala/org/apache/gluten/backendsapi/velox/VeloxBackend.scala
@@ -91,6 +91,8 @@ object VeloxBackend {
}
object VeloxBackendSettings extends BackendSettingsApi {
+ override def supportNativeIncrementMetric(): Boolean = true
+
val SHUFFLE_SUPPORTED_CODEC = Set("lz4", "zstd")
val GLUTEN_VELOX_UDF_LIB_PATHS = VeloxBackend.CONF_PREFIX +
".udfLibraryPaths"
val GLUTEN_VELOX_DRIVER_UDF_LIB_PATHS = VeloxBackend.CONF_PREFIX +
".driver.udfLibraryPaths"
diff --git
a/gluten-delta/src-delta33/main/scala/org/apache/gluten/execution/DeltaFilterExecTransformer.scala
b/gluten-delta/src-delta33/main/scala/org/apache/gluten/execution/DeltaFilterExecTransformer.scala
index b71ff4ca4b..7c840f8986 100644
---
a/gluten-delta/src-delta33/main/scala/org/apache/gluten/execution/DeltaFilterExecTransformer.scala
+++
b/gluten-delta/src-delta33/main/scala/org/apache/gluten/execution/DeltaFilterExecTransformer.scala
@@ -17,29 +17,37 @@
package org.apache.gluten.execution
import org.apache.gluten.backendsapi.BackendsApiManager
+import org.apache.gluten.exception.GlutenNotSupportException
import org.apache.gluten.expression.{ConverterUtils, ExpressionConverter}
+import org.apache.gluten.extension.IncrementMetricOffload
import org.apache.gluten.metrics.MetricsUpdater
import org.apache.gluten.substrait.`type`.TypeBuilder
import org.apache.gluten.substrait.SubstraitContext
import org.apache.gluten.substrait.extensions.ExtensionBuilder
import org.apache.gluten.substrait.rel.{RelBuilder, RelNode}
-import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression}
+import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression,
Literal}
import org.apache.spark.sql.delta.metric.IncrementMetric
import org.apache.spark.sql.execution.SparkPlan
import org.apache.spark.sql.execution.metric.SQLMetric
+import org.apache.spark.sql.types.BooleanType
import scala.collection.JavaConverters._
+import scala.collection.mutable
case class DeltaFilterExecTransformer(condition: Expression, child: SparkPlan)
extends FilterExecTransformerBase(condition, child) {
- private var extraMetrics: Seq[(String, SQLMetric)] = Seq.empty
+ // The metrics carried by the IncrementMetric stack of the condition. The
stack wraps a literal
+ // true, so the filter keeps every row and the output row count equals the
evaluation count.
+ // Derived from the condition once, so validation and execution cannot
register a metric twice.
+ private lazy val incrementMetrics: Seq[(String, SQLMetric)] =
+ DeltaFilterExecTransformer.stripIncrementMetrics(condition)._2
override def metricsUpdater(): MetricsUpdater =
BackendsApiManager.getMetricsApiInstance.genFilterTransformerMetricsUpdater(
metrics,
- extraMetrics.toSeq)
+ incrementMetrics)
override def getRelNode(
context: SubstraitContext,
@@ -49,18 +57,10 @@ case class DeltaFilterExecTransformer(condition:
Expression, child: SparkPlan)
input: RelNode,
validation: Boolean): RelNode = {
assert(condExpr != null)
- val condExprNode = condExpr match {
- case IncrementMetric(child, metric) =>
- extraMetrics :+= (condExpr.prettyName, metric)
- ExpressionConverter
- .replaceWithExpressionTransformer(child, attributeSeq =
originalInputAttributes)
- .doTransform(context)
- case _ =>
- ExpressionConverter
- .replaceWithExpressionTransformer(condExpr, attributeSeq =
originalInputAttributes)
- .doTransform(context)
- }
-
+ val nativeCondition =
DeltaFilterExecTransformer.stripIncrementMetrics(condExpr)._1
+ val condExprNode = ExpressionConverter
+ .replaceWithExpressionTransformer(nativeCondition, attributeSeq =
originalInputAttributes)
+ .doTransform(context)
if (!validation) {
RelBuilder.makeFilterRel(input, condExprNode, context, operatorId)
} else {
@@ -78,3 +78,34 @@ case class DeltaFilterExecTransformer(condition: Expression,
child: SparkPlan)
override protected def withNewChildInternal(newChild: SparkPlan):
DeltaFilterExecTransformer =
copy(child = newChild)
}
+
+object DeltaFilterExecTransformer {
+
+ /**
+ * Removes the stack of [[IncrementMetric]] wrapping `condition` and returns
the condition that
+ * goes to the native filter together with the metrics that were removed.
+ *
+ * Only a stack over a literal `true` is accepted: any other condition drops
rows, so the output
+ * row count credited to the metrics would no longer be Spark's evaluation
count.
+ * [[org.apache.gluten.extension.OffloadDeltaFilter]] keeps such filters on
Spark, and this method
+ * refuses them so validation falls back if one slips through.
+ */
+ private[gluten] def stripIncrementMetrics(
+ condition: Expression): (Expression, Seq[(String, SQLMetric)]) = {
+ val metrics = mutable.ArrayBuffer.empty[(String, SQLMetric)]
+ var expr = condition
+ while (expr.isInstanceOf[IncrementMetric]) {
+ val increment = expr.asInstanceOf[IncrementMetric]
+ metrics += ((increment.prettyName, increment.metric))
+ expr = increment.child
+ }
+ if (metrics.nonEmpty) {
+ expr match {
+ case Literal(true, BooleanType) =>
+ case _ =>
+ throw new
GlutenNotSupportException(IncrementMetricOffload.conditionalFilterReason)
+ }
+ }
+ (expr, metrics.toSeq)
+ }
+}
diff --git
a/gluten-delta/src-delta33/main/scala/org/apache/gluten/execution/DeltaProjectExecTransformer.scala
b/gluten-delta/src-delta33/main/scala/org/apache/gluten/execution/DeltaProjectExecTransformer.scala
index dc709dad2d..0901f67876 100644
---
a/gluten-delta/src-delta33/main/scala/org/apache/gluten/execution/DeltaProjectExecTransformer.scala
+++
b/gluten-delta/src-delta33/main/scala/org/apache/gluten/execution/DeltaProjectExecTransformer.scala
@@ -17,14 +17,17 @@
package org.apache.gluten.execution
import org.apache.gluten.backendsapi.BackendsApiManager
-import org.apache.gluten.expression.{ConverterUtils, ExpressionConverter,
ExpressionTransformer}
+import org.apache.gluten.exception.GlutenNotSupportException
+import org.apache.gluten.expression.{ConverterUtils, ExpressionConverter,
ExpressionTransformer, IncrementMetricCall}
+import
org.apache.gluten.extension.DeltaPostTransformRules.containsIncrementMetricExpr
+import org.apache.gluten.extension.IncrementMetricOffload
import org.apache.gluten.metrics.MetricsUpdater
import org.apache.gluten.substrait.`type`.TypeBuilder
import org.apache.gluten.substrait.SubstraitContext
import org.apache.gluten.substrait.extensions.ExtensionBuilder
import org.apache.gluten.substrait.rel.{RelBuilder, RelNode}
-import org.apache.spark.sql.catalyst.expressions.{Alias, Attribute,
NamedExpression}
+import org.apache.spark.sql.catalyst.expressions.{Alias, Attribute,
Expression, NamedExpression}
import org.apache.spark.sql.delta.metric.IncrementMetric
import org.apache.spark.sql.execution.SparkPlan
import org.apache.spark.sql.execution.metric.SQLMetric
@@ -35,12 +38,20 @@ import scala.collection.mutable
case class DeltaProjectExecTransformer(projectList: Seq[NamedExpression],
child: SparkPlan)
extends ProjectExecTransformerBase(projectList, child) {
- private var extraMetrics = mutable.Seq.empty[(String, SQLMetric)]
+ // The metrics behind the project list's IncrementMetric expressions, keyed
the way the metrics
+ // updater credits them: by counter function name when the backend counts
natively, else by
+ // "increment_metric" for a stack at the root of an alias, evaluated once
per output row.
+ // Derived from the project list once, so validation and execution cannot
register a metric
+ // twice.
+ private lazy val incrementMetrics: Seq[(String, SQLMetric)] =
+ DeltaProjectExecTransformer
+ .stripIncrementMetrics(projectList,
IncrementMetricOffload.nativeCounting)
+ ._2
override def metricsUpdater(): MetricsUpdater =
BackendsApiManager.getMetricsApiInstance.genProjectTransformerMetricsUpdater(
metrics,
- extraMetrics.toSeq)
+ incrementMetrics)
override def getRelNode(
context: SubstraitContext,
@@ -49,7 +60,9 @@ case class DeltaProjectExecTransformer(projectList:
Seq[NamedExpression], child:
operatorId: Long,
input: RelNode,
validation: Boolean): RelNode = {
- val newProjectList = genNewProjectList(projectList)
+ val newProjectList = DeltaProjectExecTransformer
+ .stripIncrementMetrics(projectList,
IncrementMetricOffload.nativeCounting)
+ ._1
val columnarProjExprs: Seq[ExpressionTransformer] = ExpressionConverter
.replaceWithExpressionTransformer(newProjectList, attributeSeq =
originalInputAttributes)
val projExprNodeList = columnarProjExprs.map(_.doTransform(context)).asJava
@@ -76,17 +89,84 @@ case class DeltaProjectExecTransformer(projectList:
Seq[NamedExpression], child:
override protected def withNewChildInternal(newChild: SparkPlan):
DeltaProjectExecTransformer =
copy(child = newChild)
+}
+
+object DeltaProjectExecTransformer {
- def genNewProjectList(projectList: Seq[NamedExpression]):
Seq[NamedExpression] = {
- projectList.map {
+ /**
+ * Rewrites the project list for the backend and returns it together with
the metrics it carries,
+ * keyed the way the metrics updater credits them.
+ *
+ * With `nativeCounting`, every [[IncrementMetric]] becomes an
[[IncrementMetricCall]] on one of
+ * the backend's counter slots, one slot per distinct metric of the
projection, so the backend
+ * counts the rows it is evaluated on. A projection with more distinct
metrics than slots falls
+ * back, and so does a counter below a parent that
+ * [[org.apache.gluten.extension.IncrementMetricOffload.canOffloadProject]]
does not accept, such
+ * as `a + b`, `AND` or a lambda function.
+ *
+ * Without it, only the stack of [[IncrementMetric]] at the root of an alias
is removed and
+ * credited with the output row count. An [[IncrementMetric]] anywhere else
is evaluated only for
+ * some rows on Spark, so it cannot be represented by the output row count;
+ * [[org.apache.gluten.extension.OffloadDeltaProject]] keeps such projects
on Spark, and this
+ * method refuses them so validation falls back if one slips through.
+ */
+ private[gluten] def stripIncrementMetrics(
+ projectList: Seq[NamedExpression],
+ nativeCounting: Boolean): (Seq[NamedExpression], Seq[(String,
SQLMetric)]) = {
+ if (nativeCounting) {
+ if (!IncrementMetricOffload.canOffloadProject(projectList,
nativeCounting = true)) {
+ throw new
GlutenNotSupportException(IncrementMetricOffload.nativeCounterPlacementReason)
+ }
+ return rewriteToNativeCounters(projectList)
+ }
+ val metrics = mutable.ArrayBuffer.empty[(String, SQLMetric)]
+ val stripped = projectList.map {
case alias: Alias =>
- val newChild = alias.child.transformUp {
- case im @ IncrementMetric(child, metric) =>
- extraMetrics :+= (im.prettyName, metric)
- child
+ var expr: Expression = alias.child
+ while (expr.isInstanceOf[IncrementMetric]) {
+ val increment = expr.asInstanceOf[IncrementMetric]
+ metrics += ((increment.prettyName, increment.metric))
+ expr = increment.child
+ }
+ if (containsIncrementMetricExpr(expr)) {
+ throw new
GlutenNotSupportException(IncrementMetricOffload.conditionalProjectReason)
+ }
+ if (expr eq alias.child) alias else
alias.withNewChildren(Seq(expr)).asInstanceOf[Alias]
+ case other =>
+ if (containsIncrementMetricExpr(other)) {
+ throw new
GlutenNotSupportException(IncrementMetricOffload.conditionalProjectReason)
}
- Alias(child = newChild, name = alias.name)(alias.exprId)
+ other
+ }
+ (stripped, metrics.toSeq)
+ }
+
+ private def rewriteToNativeCounters(
+ projectList: Seq[NamedExpression]): (Seq[NamedExpression], Seq[(String,
SQLMetric)]) = {
+ // One slot per distinct metric, in order of first appearance. SQLMetric
has identity equality,
+ // so the same metric reached from several places shares its slot and the
backend sums the rows
+ // of every call to it, which is how Spark increments it too.
+ val slots = mutable.LinkedHashMap.empty[SQLMetric, String]
+ def toCall(expr: Expression): Expression = expr.transformUp {
+ case increment: IncrementMetric =>
+ val functionName = slots.getOrElseUpdate(
+ increment.metric, {
+ if (slots.size >= IncrementMetricCall.maxCounters) {
+ throw new GlutenNotSupportException(
+ s"More than ${IncrementMetricCall.maxCounters} distinct
metrics in one projection " +
+ "cannot be counted natively")
+ }
+ IncrementMetricCall.functionName(slots.size)
+ }
+ )
+ IncrementMetricCall(increment.child, functionName)
+ }
+ val rewritten = projectList.map {
+ case alias: Alias =>
+ val child = toCall(alias.child)
+ if (child eq alias.child) alias else
alias.withNewChildren(Seq(child)).asInstanceOf[Alias]
case other => other
}
+ (rewritten, slots.toSeq.map { case (metric, name) => (name, metric) })
}
}
diff --git
a/gluten-delta/src-delta4/main/scala/org/apache/gluten/execution/DeltaFilterExecTransformer.scala
b/gluten-delta/src-delta4/main/scala/org/apache/gluten/execution/DeltaFilterExecTransformer.scala
index b71ff4ca4b..7c840f8986 100644
---
a/gluten-delta/src-delta4/main/scala/org/apache/gluten/execution/DeltaFilterExecTransformer.scala
+++
b/gluten-delta/src-delta4/main/scala/org/apache/gluten/execution/DeltaFilterExecTransformer.scala
@@ -17,29 +17,37 @@
package org.apache.gluten.execution
import org.apache.gluten.backendsapi.BackendsApiManager
+import org.apache.gluten.exception.GlutenNotSupportException
import org.apache.gluten.expression.{ConverterUtils, ExpressionConverter}
+import org.apache.gluten.extension.IncrementMetricOffload
import org.apache.gluten.metrics.MetricsUpdater
import org.apache.gluten.substrait.`type`.TypeBuilder
import org.apache.gluten.substrait.SubstraitContext
import org.apache.gluten.substrait.extensions.ExtensionBuilder
import org.apache.gluten.substrait.rel.{RelBuilder, RelNode}
-import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression}
+import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression,
Literal}
import org.apache.spark.sql.delta.metric.IncrementMetric
import org.apache.spark.sql.execution.SparkPlan
import org.apache.spark.sql.execution.metric.SQLMetric
+import org.apache.spark.sql.types.BooleanType
import scala.collection.JavaConverters._
+import scala.collection.mutable
case class DeltaFilterExecTransformer(condition: Expression, child: SparkPlan)
extends FilterExecTransformerBase(condition, child) {
- private var extraMetrics: Seq[(String, SQLMetric)] = Seq.empty
+ // The metrics carried by the IncrementMetric stack of the condition. The
stack wraps a literal
+ // true, so the filter keeps every row and the output row count equals the
evaluation count.
+ // Derived from the condition once, so validation and execution cannot
register a metric twice.
+ private lazy val incrementMetrics: Seq[(String, SQLMetric)] =
+ DeltaFilterExecTransformer.stripIncrementMetrics(condition)._2
override def metricsUpdater(): MetricsUpdater =
BackendsApiManager.getMetricsApiInstance.genFilterTransformerMetricsUpdater(
metrics,
- extraMetrics.toSeq)
+ incrementMetrics)
override def getRelNode(
context: SubstraitContext,
@@ -49,18 +57,10 @@ case class DeltaFilterExecTransformer(condition:
Expression, child: SparkPlan)
input: RelNode,
validation: Boolean): RelNode = {
assert(condExpr != null)
- val condExprNode = condExpr match {
- case IncrementMetric(child, metric) =>
- extraMetrics :+= (condExpr.prettyName, metric)
- ExpressionConverter
- .replaceWithExpressionTransformer(child, attributeSeq =
originalInputAttributes)
- .doTransform(context)
- case _ =>
- ExpressionConverter
- .replaceWithExpressionTransformer(condExpr, attributeSeq =
originalInputAttributes)
- .doTransform(context)
- }
-
+ val nativeCondition =
DeltaFilterExecTransformer.stripIncrementMetrics(condExpr)._1
+ val condExprNode = ExpressionConverter
+ .replaceWithExpressionTransformer(nativeCondition, attributeSeq =
originalInputAttributes)
+ .doTransform(context)
if (!validation) {
RelBuilder.makeFilterRel(input, condExprNode, context, operatorId)
} else {
@@ -78,3 +78,34 @@ case class DeltaFilterExecTransformer(condition: Expression,
child: SparkPlan)
override protected def withNewChildInternal(newChild: SparkPlan):
DeltaFilterExecTransformer =
copy(child = newChild)
}
+
+object DeltaFilterExecTransformer {
+
+ /**
+ * Removes the stack of [[IncrementMetric]] wrapping `condition` and returns
the condition that
+ * goes to the native filter together with the metrics that were removed.
+ *
+ * Only a stack over a literal `true` is accepted: any other condition drops
rows, so the output
+ * row count credited to the metrics would no longer be Spark's evaluation
count.
+ * [[org.apache.gluten.extension.OffloadDeltaFilter]] keeps such filters on
Spark, and this method
+ * refuses them so validation falls back if one slips through.
+ */
+ private[gluten] def stripIncrementMetrics(
+ condition: Expression): (Expression, Seq[(String, SQLMetric)]) = {
+ val metrics = mutable.ArrayBuffer.empty[(String, SQLMetric)]
+ var expr = condition
+ while (expr.isInstanceOf[IncrementMetric]) {
+ val increment = expr.asInstanceOf[IncrementMetric]
+ metrics += ((increment.prettyName, increment.metric))
+ expr = increment.child
+ }
+ if (metrics.nonEmpty) {
+ expr match {
+ case Literal(true, BooleanType) =>
+ case _ =>
+ throw new
GlutenNotSupportException(IncrementMetricOffload.conditionalFilterReason)
+ }
+ }
+ (expr, metrics.toSeq)
+ }
+}
diff --git
a/gluten-delta/src-delta4/main/scala/org/apache/gluten/execution/DeltaProjectExecTransformer.scala
b/gluten-delta/src-delta4/main/scala/org/apache/gluten/execution/DeltaProjectExecTransformer.scala
index dc709dad2d..0901f67876 100644
---
a/gluten-delta/src-delta4/main/scala/org/apache/gluten/execution/DeltaProjectExecTransformer.scala
+++
b/gluten-delta/src-delta4/main/scala/org/apache/gluten/execution/DeltaProjectExecTransformer.scala
@@ -17,14 +17,17 @@
package org.apache.gluten.execution
import org.apache.gluten.backendsapi.BackendsApiManager
-import org.apache.gluten.expression.{ConverterUtils, ExpressionConverter,
ExpressionTransformer}
+import org.apache.gluten.exception.GlutenNotSupportException
+import org.apache.gluten.expression.{ConverterUtils, ExpressionConverter,
ExpressionTransformer, IncrementMetricCall}
+import
org.apache.gluten.extension.DeltaPostTransformRules.containsIncrementMetricExpr
+import org.apache.gluten.extension.IncrementMetricOffload
import org.apache.gluten.metrics.MetricsUpdater
import org.apache.gluten.substrait.`type`.TypeBuilder
import org.apache.gluten.substrait.SubstraitContext
import org.apache.gluten.substrait.extensions.ExtensionBuilder
import org.apache.gluten.substrait.rel.{RelBuilder, RelNode}
-import org.apache.spark.sql.catalyst.expressions.{Alias, Attribute,
NamedExpression}
+import org.apache.spark.sql.catalyst.expressions.{Alias, Attribute,
Expression, NamedExpression}
import org.apache.spark.sql.delta.metric.IncrementMetric
import org.apache.spark.sql.execution.SparkPlan
import org.apache.spark.sql.execution.metric.SQLMetric
@@ -35,12 +38,20 @@ import scala.collection.mutable
case class DeltaProjectExecTransformer(projectList: Seq[NamedExpression],
child: SparkPlan)
extends ProjectExecTransformerBase(projectList, child) {
- private var extraMetrics = mutable.Seq.empty[(String, SQLMetric)]
+ // The metrics behind the project list's IncrementMetric expressions, keyed
the way the metrics
+ // updater credits them: by counter function name when the backend counts
natively, else by
+ // "increment_metric" for a stack at the root of an alias, evaluated once
per output row.
+ // Derived from the project list once, so validation and execution cannot
register a metric
+ // twice.
+ private lazy val incrementMetrics: Seq[(String, SQLMetric)] =
+ DeltaProjectExecTransformer
+ .stripIncrementMetrics(projectList,
IncrementMetricOffload.nativeCounting)
+ ._2
override def metricsUpdater(): MetricsUpdater =
BackendsApiManager.getMetricsApiInstance.genProjectTransformerMetricsUpdater(
metrics,
- extraMetrics.toSeq)
+ incrementMetrics)
override def getRelNode(
context: SubstraitContext,
@@ -49,7 +60,9 @@ case class DeltaProjectExecTransformer(projectList:
Seq[NamedExpression], child:
operatorId: Long,
input: RelNode,
validation: Boolean): RelNode = {
- val newProjectList = genNewProjectList(projectList)
+ val newProjectList = DeltaProjectExecTransformer
+ .stripIncrementMetrics(projectList,
IncrementMetricOffload.nativeCounting)
+ ._1
val columnarProjExprs: Seq[ExpressionTransformer] = ExpressionConverter
.replaceWithExpressionTransformer(newProjectList, attributeSeq =
originalInputAttributes)
val projExprNodeList = columnarProjExprs.map(_.doTransform(context)).asJava
@@ -76,17 +89,84 @@ case class DeltaProjectExecTransformer(projectList:
Seq[NamedExpression], child:
override protected def withNewChildInternal(newChild: SparkPlan):
DeltaProjectExecTransformer =
copy(child = newChild)
+}
+
+object DeltaProjectExecTransformer {
- def genNewProjectList(projectList: Seq[NamedExpression]):
Seq[NamedExpression] = {
- projectList.map {
+ /**
+ * Rewrites the project list for the backend and returns it together with
the metrics it carries,
+ * keyed the way the metrics updater credits them.
+ *
+ * With `nativeCounting`, every [[IncrementMetric]] becomes an
[[IncrementMetricCall]] on one of
+ * the backend's counter slots, one slot per distinct metric of the
projection, so the backend
+ * counts the rows it is evaluated on. A projection with more distinct
metrics than slots falls
+ * back, and so does a counter below a parent that
+ * [[org.apache.gluten.extension.IncrementMetricOffload.canOffloadProject]]
does not accept, such
+ * as `a + b`, `AND` or a lambda function.
+ *
+ * Without it, only the stack of [[IncrementMetric]] at the root of an alias
is removed and
+ * credited with the output row count. An [[IncrementMetric]] anywhere else
is evaluated only for
+ * some rows on Spark, so it cannot be represented by the output row count;
+ * [[org.apache.gluten.extension.OffloadDeltaProject]] keeps such projects
on Spark, and this
+ * method refuses them so validation falls back if one slips through.
+ */
+ private[gluten] def stripIncrementMetrics(
+ projectList: Seq[NamedExpression],
+ nativeCounting: Boolean): (Seq[NamedExpression], Seq[(String,
SQLMetric)]) = {
+ if (nativeCounting) {
+ if (!IncrementMetricOffload.canOffloadProject(projectList,
nativeCounting = true)) {
+ throw new
GlutenNotSupportException(IncrementMetricOffload.nativeCounterPlacementReason)
+ }
+ return rewriteToNativeCounters(projectList)
+ }
+ val metrics = mutable.ArrayBuffer.empty[(String, SQLMetric)]
+ val stripped = projectList.map {
case alias: Alias =>
- val newChild = alias.child.transformUp {
- case im @ IncrementMetric(child, metric) =>
- extraMetrics :+= (im.prettyName, metric)
- child
+ var expr: Expression = alias.child
+ while (expr.isInstanceOf[IncrementMetric]) {
+ val increment = expr.asInstanceOf[IncrementMetric]
+ metrics += ((increment.prettyName, increment.metric))
+ expr = increment.child
+ }
+ if (containsIncrementMetricExpr(expr)) {
+ throw new
GlutenNotSupportException(IncrementMetricOffload.conditionalProjectReason)
+ }
+ if (expr eq alias.child) alias else
alias.withNewChildren(Seq(expr)).asInstanceOf[Alias]
+ case other =>
+ if (containsIncrementMetricExpr(other)) {
+ throw new
GlutenNotSupportException(IncrementMetricOffload.conditionalProjectReason)
}
- Alias(child = newChild, name = alias.name)(alias.exprId)
+ other
+ }
+ (stripped, metrics.toSeq)
+ }
+
+ private def rewriteToNativeCounters(
+ projectList: Seq[NamedExpression]): (Seq[NamedExpression], Seq[(String,
SQLMetric)]) = {
+ // One slot per distinct metric, in order of first appearance. SQLMetric
has identity equality,
+ // so the same metric reached from several places shares its slot and the
backend sums the rows
+ // of every call to it, which is how Spark increments it too.
+ val slots = mutable.LinkedHashMap.empty[SQLMetric, String]
+ def toCall(expr: Expression): Expression = expr.transformUp {
+ case increment: IncrementMetric =>
+ val functionName = slots.getOrElseUpdate(
+ increment.metric, {
+ if (slots.size >= IncrementMetricCall.maxCounters) {
+ throw new GlutenNotSupportException(
+ s"More than ${IncrementMetricCall.maxCounters} distinct
metrics in one projection " +
+ "cannot be counted natively")
+ }
+ IncrementMetricCall.functionName(slots.size)
+ }
+ )
+ IncrementMetricCall(increment.child, functionName)
+ }
+ val rewritten = projectList.map {
+ case alias: Alias =>
+ val child = toCall(alias.child)
+ if (child eq alias.child) alias else
alias.withNewChildren(Seq(child)).asInstanceOf[Alias]
case other => other
}
+ (rewritten, slots.toSeq.map { case (metric, name) => (name, metric) })
}
}
diff --git
a/gluten-delta/src/main/scala/org/apache/gluten/extension/DeltaPostTransformRules.scala
b/gluten-delta/src/main/scala/org/apache/gluten/extension/DeltaPostTransformRules.scala
index a6cfc42916..edbb0c0650 100644
---
a/gluten-delta/src/main/scala/org/apache/gluten/extension/DeltaPostTransformRules.scala
+++
b/gluten-delta/src/main/scala/org/apache/gluten/extension/DeltaPostTransformRules.scala
@@ -17,7 +17,7 @@
package org.apache.gluten.extension
import org.apache.gluten.backendsapi.BackendsApiManager
-import org.apache.gluten.execution.{DeltaScanTransformer,
FilterExecTransformerBase, ProjectExecTransformer}
+import org.apache.gluten.execution.{DeltaScanTransformer,
FilterExecTransformerBase, ProjectExecTransformer, ProjectExecTransformerBase}
import org.apache.gluten.extension.columnar.transition.RemoveTransitions
import org.apache.spark.sql.SparkSession
@@ -37,6 +37,7 @@ object DeltaPostTransformRules {
def rules: Seq[Rule[SparkPlan]] =
RemoveTransitions ::
deltaSpecificRules ::
+ incrementMetricParentsRule ::
Nil
/**
@@ -97,6 +98,50 @@ object DeltaPostTransformRules {
child.copy(output = p.output)
}
+ /**
+ * Keeps the trivial operators Delta stacks above a projection that stayed
on Spark for its
+ * `IncrementMetric` counters on Spark as well. MERGE writes through
+ * `filter(ROW_DROPPED_COL = false)` and a column drop above that
projection; offloading those two
+ * would only add a row-to-columnar transition in front of them and a second
columnar-to-row
+ * behind them, since the writer below is row based anyway.
+ *
+ * {{{
+ * Input: Output:
+ * ProjectExecTransformer (drop) ProjectExec (drop)
+ * +- FilterExecTransformer (dropped = false) +- FilterExec (dropped
= false)
+ * +- ProjectExec (CASE WHEN ... increment) +- ProjectExec (CASE
WHEN ... increment)
+ * }}}
+ */
+ val incrementMetricParentsRule: Rule[SparkPlan] = (plan: SparkPlan) => {
+ if (!plan.exists(isSparkIncrementMetricProject)) {
+ plan
+ } else {
+ plan.transformUp {
+ case filter: FilterExecTransformerBase if
staysOnSparkForIncrementMetric(filter.child) =>
+ FilterExec(filter.cond, filter.child)
+ case project: ProjectExecTransformerBase
+ if staysOnSparkForIncrementMetric(project.child) =>
+ ProjectExec(project.list, project.child)
+ }
+ }
+ }
+
+ private def isSparkIncrementMetricProject(plan: SparkPlan): Boolean = plan
match {
+ case ProjectExec(projectList, _) =>
projectList.exists(containsIncrementMetricExpr)
+ case _ => false
+ }
+
+ /**
+ * A Spark project or filter whose subtree, through Spark projects and
filters only, reaches a
+ * project carrying `IncrementMetric`.
+ */
+ private def staysOnSparkForIncrementMetric(plan: SparkPlan): Boolean = plan
match {
+ case project @ ProjectExec(_, child) =>
+ isSparkIncrementMetricProject(project) ||
staysOnSparkForIncrementMetric(child)
+ case FilterExec(_, child) => staysOnSparkForIncrementMetric(child)
+ case _ => false
+ }
+
/**
* Spark Delta injects synthetic deletion-vector predicates and columns into
the plan (via
* `PreprocessTableWithDVsStrategy`). Those drive the JVM reader path; for
the native Delta scan
diff --git
a/gluten-delta/src/main/scala/org/apache/gluten/extension/IncrementMetricOffload.scala
b/gluten-delta/src/main/scala/org/apache/gluten/extension/IncrementMetricOffload.scala
new file mode 100644
index 0000000000..6f36629f2a
--- /dev/null
+++
b/gluten-delta/src/main/scala/org/apache/gluten/extension/IncrementMetricOffload.scala
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gluten.extension
+
+import org.apache.gluten.backendsapi.BackendsApiManager
+import
org.apache.gluten.extension.DeltaPostTransformRules.containsIncrementMetricExpr
+
+import org.apache.spark.sql.catalyst.expressions.{Alias, CaseWhen,
CreateArray, CreateNamedStruct, Expression, If, Literal, NamedExpression, Not}
+import org.apache.spark.sql.types.BooleanType
+
+/**
+ * Decides whether a project or filter carrying Delta's `IncrementMetric` may
be offloaded.
+ *
+ * `IncrementMetric` adds one to a SQL metric every time it is evaluated and
returns its child.
+ * Without native counting the native side never evaluates it: the Delta
project and filter
+ * transformers strip it from the plan and the metrics updaters credit the
metric with the
+ * operator's output row count once the task finishes. That is exact only when
Spark would have
+ * evaluated the expression once per output row: at the root of a projection
alias, or as a filter
+ * condition that keeps every row. An `IncrementMetric` below a conditional
expression, which is
+ * where MERGE keeps the counter of every `WHEN` clause (`CASE WHEN clause
THEN increment ... ELSE
+ * increment(copied)`), fires for the rows that take its branch only.
Offloading it inflated those
+ * counters to the full row count, which corrupted the operation metrics of
every MERGE commit and,
+ * through `CDCReader.shouldSkipFileActionsInCommit`, produced phantom
change-data-feed rows for
+ * no-op merges (GLUTEN-9003).
+ *
+ * A backend that counts natively
+ *
([[org.apache.gluten.backendsapi.BackendSettingsApi.supportNativeIncrementMetric]])
evaluates
+ * each counter of a projection as one of its fixed pass-through slot functions
+ * ([[org.apache.gluten.expression.IncrementMetricCall]]) and reports how many
rows that function
+ * processed, which is the exact evaluation count: inside a `CASE WHEN` branch
only the rows that
+ * took the branch reach it. That holds only below the parents Delta's DML
commands put above a
+ * counter ([[countsLikeSpark]]); a counter below any other parent stays on
Spark. Other backends
+ * keep all conditional shapes on Spark. Filters are credited with their
output rows on every
+ * backend.
+ */
+object IncrementMetricOffload {
+
+ /** Delta's `IncrementMetric`, matched by name because Delta 2.4 (Spark 3.4)
has no such class. */
+ private[gluten] def isIncrementMetric(expr: Expression): Boolean = {
+ expr.prettyName == "increment_metric" && expr.children.size == 1
+ }
+
+ /** Removes a stack of `IncrementMetric` wrappers and returns the expression
they wrapped. */
+ private[gluten] def peelIncrementMetrics(expr: Expression): Expression = {
+ if (isIncrementMetric(expr)) peelIncrementMetrics(expr.children.head) else
expr
+ }
+
+ /** Whether the backend can count an expression's evaluations natively. */
+ def nativeCounting: Boolean =
BackendsApiManager.getSettings.supportNativeIncrementMetric()
+
+ /**
+ * Native counters can be offloaded when every `IncrementMetric` is reached
from its alias through
+ * parents Delta's DML commands generate ([[countsLikeSpark]]). Without
native counting, every
+ * `IncrementMetric` must sit at the root of its alias (a stack of them
counts as the root), so
+ * crediting it with the output row count is exact.
+ */
+ def canOffloadProject(projectList: Seq[NamedExpression], nativeCounting:
Boolean): Boolean = {
+ if (nativeCounting) {
+ projectList.forall(countsLikeSpark)
+ } else {
+ projectList.forall {
+ case alias: Alias =>
!containsIncrementMetricExpr(peelIncrementMetrics(alias.child))
+ case other => !containsIncrementMetricExpr(other)
+ }
+ }
+ }
+
+ /**
+ * Whether a native backend evaluates every `IncrementMetric` in `expr` on
the rows Spark does.
+ * That holds below the parents Delta's UPDATE, DELETE and MERGE put above a
counter: aliases,
+ * other counters, the values of `IF` and `CASE WHEN` (never their
conditions), `named_struct`,
+ * `array` and `NOT`. Each passes every row it receives to its
counter-bearing children, or routes
+ * rows to a branch the way Spark does. Under any other parent the counts
can differ: a
+ * null-intolerant function such as `a + b` lets Velox drop the rows where
another input is null
+ * before the counter runs, `AND` and `OR` reorder their operands, a lambda
body is missing from
+ * the exported statistics, Spark skips the dividend of a `divide` by zero
while Velox evaluates
+ * it, and Velox merges identical `coalesce` inputs into one call. The
subtree below a counter is
+ * unrestricted unless it holds another counter.
+ */
+ private def countsLikeSpark(expr: Expression): Boolean = expr match {
+ case e if !containsIncrementMetricExpr(e) => true
+ case e if isIncrementMetric(e) => countsLikeSpark(e.children.head)
+ case If(predicate, trueValue, falseValue) =>
+ !containsIncrementMetricExpr(predicate) && countsLikeSpark(trueValue) &&
+ countsLikeSpark(falseValue)
+ case CaseWhen(branches, elseValue) =>
+ branches.forall {
+ case (condition, value) => !containsIncrementMetricExpr(condition) &&
countsLikeSpark(value)
+ } && elseValue.forall(countsLikeSpark)
+ case _: Alias | _: CreateNamedStruct | _: CreateArray | _: Not =>
+ expr.children.forall(countsLikeSpark)
+ case _ => false
+ }
+
+ /**
+ * True when `condition` is a stack of `IncrementMetric` over a literal
`true`. Such a filter
+ * keeps every input row, so the operator's output rows equal Spark's
evaluation count.
+ */
+ def canOffloadFilter(condition: Expression): Boolean = {
+ isIncrementMetric(condition) && (peelIncrementMetrics(condition) match {
+ case Literal(true, BooleanType) => true
+ case _ => false
+ })
+ }
+
+ private[gluten] val conditionalProjectReason: String =
+ "IncrementMetric below a conditional expression must be evaluated by
Spark; the native " +
+ "project would credit it with every output row (GLUTEN-9003)"
+
+ private[gluten] val nativeCounterPlacementReason: String =
+ "IncrementMetric below a parent other than an alias, another
IncrementMetric, an IF or " +
+ "CASE WHEN value, named_struct, array or NOT must be evaluated by Spark;
native evaluation " +
+ "could count it on different rows (GLUTEN-9003)"
+
+ private[gluten] val conditionalFilterReason: String =
+ "IncrementMetric filter condition is not a literal true, so the native
filter's output rows " +
+ "would not match Spark's evaluation count (GLUTEN-9003)"
+}
diff --git
a/gluten-delta/src/main/scala/org/apache/gluten/extension/OffloadDeltaFilter.scala
b/gluten-delta/src/main/scala/org/apache/gluten/extension/OffloadDeltaFilter.scala
index 43147d3a1b..a62030d1cc 100644
---
a/gluten-delta/src/main/scala/org/apache/gluten/extension/OffloadDeltaFilter.scala
+++
b/gluten-delta/src/main/scala/org/apache/gluten/extension/OffloadDeltaFilter.scala
@@ -18,14 +18,20 @@ package org.apache.gluten.extension
import org.apache.gluten.execution.DeltaFilterExecTransformer
import
org.apache.gluten.extension.DeltaPostTransformRules.containsIncrementMetricExpr
+import org.apache.gluten.extension.columnar.FallbackTags
import org.apache.gluten.extension.columnar.offload.OffloadSingleNode
import org.apache.spark.sql.execution.{FilterExec, SparkPlan}
case class OffloadDeltaFilter() extends OffloadSingleNode {
override def offload(plan: SparkPlan): SparkPlan = plan match {
- case FilterExec(condition, child) if
containsIncrementMetricExpr(condition) =>
- DeltaFilterExecTransformer(condition, child)
+ case filter @ FilterExec(condition, child) if
containsIncrementMetricExpr(condition) =>
+ if (IncrementMetricOffload.canOffloadFilter(condition)) {
+ DeltaFilterExecTransformer(condition, child)
+ } else {
+ FallbackTags.add(filter,
IncrementMetricOffload.conditionalFilterReason)
+ filter
+ }
case p => p
}
}
diff --git
a/gluten-delta/src/main/scala/org/apache/gluten/extension/OffloadDeltaProject.scala
b/gluten-delta/src/main/scala/org/apache/gluten/extension/OffloadDeltaProject.scala
index e7787511e7..a914c85fa2 100644
---
a/gluten-delta/src/main/scala/org/apache/gluten/extension/OffloadDeltaProject.scala
+++
b/gluten-delta/src/main/scala/org/apache/gluten/extension/OffloadDeltaProject.scala
@@ -18,14 +18,27 @@ package org.apache.gluten.extension
import org.apache.gluten.execution.DeltaProjectExecTransformer
import
org.apache.gluten.extension.DeltaPostTransformRules.containsIncrementMetricExpr
+import org.apache.gluten.extension.columnar.FallbackTags
import org.apache.gluten.extension.columnar.offload.OffloadSingleNode
import org.apache.spark.sql.execution.{ProjectExec, SparkPlan}
case class OffloadDeltaProject() extends OffloadSingleNode {
override def offload(plan: SparkPlan): SparkPlan = plan match {
- case ProjectExec(projectList, child) if
projectList.exists(containsIncrementMetricExpr) =>
- DeltaProjectExecTransformer(projectList, child)
+ case project @ ProjectExec(projectList, child)
+ if projectList.exists(containsIncrementMetricExpr) =>
+ val nativeCounting = IncrementMetricOffload.nativeCounting
+ if (IncrementMetricOffload.canOffloadProject(projectList,
nativeCounting)) {
+ DeltaProjectExecTransformer(projectList, child)
+ } else {
+ val reason = if (nativeCounting) {
+ IncrementMetricOffload.nativeCounterPlacementReason
+ } else {
+ IncrementMetricOffload.conditionalProjectReason
+ }
+ FallbackTags.add(project, reason)
+ project
+ }
case p => p
}
}
diff --git
a/gluten-delta/src/test/scala/org/apache/gluten/execution/DeltaSuite.scala
b/gluten-delta/src/test/scala/org/apache/gluten/execution/DeltaSuite.scala
index acd61c76bd..51accc7705 100644
--- a/gluten-delta/src/test/scala/org/apache/gluten/execution/DeltaSuite.scala
+++ b/gluten-delta/src/test/scala/org/apache/gluten/execution/DeltaSuite.scala
@@ -16,12 +16,16 @@
*/
package org.apache.gluten.execution
+import org.apache.gluten.backendsapi.BackendsApiManager
import org.apache.gluten.extension.DeltaPostTransformRules
import org.apache.spark.SparkConf
-import org.apache.spark.sql.{DataFrame, Row}
+import org.apache.spark.scheduler.{SparkListener, SparkListenerEvent}
+import org.apache.spark.sql.{DataFrame, GlutenDeltaTestUtils, Row}
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.delta.DeltaLog
+import org.apache.spark.sql.execution.SparkPlanInfo
+import
org.apache.spark.sql.execution.ui.{SparkListenerSQLAdaptiveExecutionUpdate,
SparkListenerSQLExecutionStart}
import org.apache.spark.sql.types._
import org.apache.spark.util.SparkVersionUtil
@@ -1116,4 +1120,455 @@ abstract class DeltaSuite extends
WholeStageTransformerSuite {
assert(second eq third, "scanFilters should return the same cached
instance")
}
}
+
+ /** The operation metrics Delta recorded for the latest `operation` commit
of `table`. */
+ private def lastOperationMetrics(table: String, operation: String):
Map[String, String] = {
+ val row = spark
+ .sql(s"DESCRIBE HISTORY $table")
+ .filter(s"operation = '$operation'")
+ .orderBy(org.apache.spark.sql.functions.desc("version"))
+ .select("operationMetrics")
+ .head()
+ row.getMap[String, String](0).toMap
+ }
+
+ private def latestVersion(table: String, operation: String): Long = {
+ spark
+ .sql(s"DESCRIBE HISTORY $table")
+ .filter(s"operation = '$operation'")
+ .orderBy(org.apache.spark.sql.functions.desc("version"))
+ .select("version")
+ .head()
+ .getLong(0)
+ }
+
+ /**
+ * Runs `body` and returns the final physical plan of every SQL execution it
started, including
+ * the internal jobs of Delta commands, which never surface through a
returned DataFrame. Under
+ * adaptive execution the plan Gluten actually ran is the one in the last
plan update.
+ */
+ private def collectExecutedPlanInfos(body: => Unit): Seq[SparkPlanInfo] = {
+ val latest = new java.util.concurrent.ConcurrentHashMap[Long,
SparkPlanInfo]()
+ val listener = new SparkListener {
+ override def onOtherEvent(event: SparkListenerEvent): Unit = event match
{
+ case start: SparkListenerSQLExecutionStart =>
+ latest.put(start.executionId, start.sparkPlanInfo)
+ case update: SparkListenerSQLAdaptiveExecutionUpdate =>
+ latest.put(update.executionId, update.sparkPlanInfo)
+ case _ =>
+ }
+ }
+ // Queued events from setup would otherwise reach the newly registered
listener.
+ GlutenDeltaTestUtils.waitForListenerBus(spark.sparkContext)
+ spark.sparkContext.addSparkListener(listener)
+ try {
+ body
+ // Drain every execution's final plan update before inspecting the
captured plans.
+ GlutenDeltaTestUtils.waitForListenerBus(spark.sparkContext)
+ assert(!latest.isEmpty, "SQL execution events not seen")
+ } finally {
+ spark.sparkContext.removeSparkListener(listener)
+ }
+ latest.values().asScala.toSeq
+ }
+
+ /**
+ * MERGE's write projection: the per-column CASE WHENs over Delta's
row-present flags. Other
+ * projections carry CASE WHENs too, such as Delta 4.0's log replay, so the
flag is the marker.
+ */
+ private def isMergeWriteProjection(info: SparkPlanInfo): Boolean =
+ info.simpleString.contains("CASE WHEN") &&
info.simpleString.contains("_source_row_present_")
+
+ private def flattenPlanInfo(info: SparkPlanInfo): Seq[SparkPlanInfo] =
+ info +: info.children.flatMap(flattenPlanInfo)
+
+ /** The nodes above every node matching `target`, nearest first, excluding
the node itself. */
+ private def ancestorsOf(
+ info: SparkPlanInfo,
+ target: SparkPlanInfo => Boolean,
+ path: Seq[SparkPlanInfo] = Nil): Seq[SparkPlanInfo] = {
+ val here = if (target(info)) path else Nil
+ here ++ info.children.flatMap(ancestorsOf(_, target, info +: path))
+ }
+
+ test("delta: merge metrics count only the rows that take each clause") {
+ withTable("merge_metrics_target", "merge_metrics_source") {
+ import testImplicits._
+ // One target file, so the two unmatched rows are copied when it is
rewritten.
+ Seq((1, "t1"), (2, "t2"), (3, "t3"), (4, "t4"), (5, "t5"), (6, "t6"))
+ .toDF("id", "name")
+ .coalesce(1)
+ .write
+ .format("delta")
+ .saveAsTable("merge_metrics_target")
+ spark.sql("create table merge_metrics_source (id int, name string) using
delta")
+ spark.sql("""
+ |insert into merge_metrics_source values
+ |(3, 's3'), (4, 's4'), (5, 's5'), (6, 's6'), (7, 's7'), (8,
's8')
+ |""".stripMargin)
+ val plans = collectExecutedPlanInfos {
+ // Native counters need expression stats for correctness even when the
user disables
+ // diagnostic stats. The backend must preserve them after applying
user overrides.
+ withSQLConf(
+
"spark.gluten.sql.columnar.backend.velox.operator_track_expression_stats" ->
"false") {
+ spark.sql("""
+ |merge into merge_metrics_target t
+ |using merge_metrics_source s
+ |on t.id = s.id
+ |when matched and s.id = 3 then delete
+ |when matched then update set name = s.name
+ |when not matched then insert *
+ |""".stripMargin)
+ }
+ }
+ checkAnswer(
+ spark.sql("select * from merge_metrics_target order by id"),
+ Seq(
+ Row(1, "t1"),
+ Row(2, "t2"),
+ Row(4, "s4"),
+ Row(5, "s5"),
+ Row(6, "s6"),
+ Row(7, "s7"),
+ Row(8, "s8"))
+ )
+
+ // Every clause counter sits inside the CASE WHEN of the write
projection, so it counts
+ // only the rows that took its branch. Before GLUTEN-9003 each was
credited with all rows.
+ val metrics = lastOperationMetrics("merge_metrics_target", "MERGE")
+ // Delta 3 counts source rows through IncrementMetric; Delta 2.4 counts
them with a UDF
+ // whose evaluation count is not exact even on vanilla Spark (8 for
these 6 rows).
+ if (SparkVersionUtil.gteSpark35) {
+ assert(metrics("numSourceRows") === "6", metrics)
+ }
+ assert(metrics("numTargetRowsDeleted") === "1", metrics)
+ assert(metrics("numTargetRowsUpdated") === "3", metrics)
+ assert(metrics("numTargetRowsInserted") === "2", metrics)
+ assert(metrics("numTargetRowsCopied") === "2", metrics)
+
+ // A backend that counts natively offloads the write projection with its
CASE WHEN counters.
+ // Otherwise that projection stays on Spark while the unconditional
source-row counter is
+ // still offloaded. Delta 2.4 (Spark 3.4) counts through a UDF instead
of IncrementMetric,
+ // so there is no Delta transformer to look for there.
+ val nativeCounting =
BackendsApiManager.getSettings.supportNativeIncrementMetric()
+ if (SparkVersionUtil.gteSpark35 && nativeCounting) {
+ val nodes = plans.flatMap(flattenPlanInfo)
+ val nativeDeltaProjects = nodes.filter(_.nodeName ==
"DeltaProjectExecTransformer")
+ assert(
+ nativeDeltaProjects.exists(isMergeWriteProjection),
+ nodes.map(n => s"${n.nodeName}: ${n.simpleString}"))
+ assert(
+ !nodes.exists(n => n.nodeName == "Project" &&
isMergeWriteProjection(n)),
+ nodes.map(n => s"${n.nodeName}: ${n.simpleString}"))
+ } else if (SparkVersionUtil.gteSpark35) {
+ val nodes = plans.flatMap(flattenPlanInfo)
+ val nativeDeltaProjects = nodes.filter(_.nodeName ==
"DeltaProjectExecTransformer")
+ assert(nativeDeltaProjects.nonEmpty, nodes.map(_.nodeName).distinct)
+ assert(
+ nativeDeltaProjects.forall(!isMergeWriteProjection(_)),
+ nativeDeltaProjects.map(_.simpleString))
+ assert(
+ nodes.exists(n => n.nodeName == "Project" &&
isMergeWriteProjection(n)),
+ nodes.map(n => s"${n.nodeName}: ${n.simpleString}"))
+ // The filter and column drop Delta stacks above that projection stay
on Spark too, so
+ // nothing in the same stage converts its rows back into columnar
batches. The walk stops
+ // at the stage boundary: on Delta 4.0 the whole write query is nested
below a native sort
+ // and exchange that consume its rows regardless of this projection.
+ val boundaries =
+ Seq("WholeStageCodegen", "AdaptiveSparkPlan", "QueryStage",
"Exchange", "Shuffle")
+ val sameStage = plans.flatMap {
+ p =>
+ ancestorsOf(p, n => n.nodeName == "Project" &&
isMergeWriteProjection(n))
+ .takeWhile(n => !boundaries.exists(n.nodeName.contains))
+ }
+ assert(sameStage.nonEmpty,
plans.map(flattenPlanInfo(_).map(_.nodeName)))
+ assert(!sameStage.exists(_.nodeName == "RowToVeloxColumnar"),
sameStage.map(_.nodeName))
+ }
+ }
+ }
+
+ testWithMinSparkVersion(
+ "delta: operators above a merge write projection that stays on Spark stay
on Spark",
+ "3.5") {
+ // Blacklisting the native counter keeps every projection carrying
IncrementMetric on Spark, the
+ // way any other unsupported expression in MERGE's write projection would.
+ withSQLConf("spark.gluten.expression.blacklist" -> "increment_metric") {
+ withTable("fallback_merge_target", "fallback_merge_source") {
+ import testImplicits._
+ Seq((1, "t1"), (2, "t2"), (3, "t3"))
+ .toDF("id", "name")
+ .coalesce(1)
+ .write
+ .format("delta")
+ .saveAsTable("fallback_merge_target")
+ spark.sql("create table fallback_merge_source (id int, name string)
using delta")
+ spark.sql("insert into fallback_merge_source values (2, 's2'), (4,
's4')")
+ val plans = collectExecutedPlanInfos {
+ spark.sql("""
+ |merge into fallback_merge_target t
+ |using fallback_merge_source s
+ |on t.id = s.id
+ |when matched then update set name = s.name
+ |when not matched then insert *
+ |""".stripMargin)
+ }
+ checkAnswer(
+ spark.sql("select * from fallback_merge_target order by id"),
+ Seq(Row(1, "t1"), Row(2, "s2"), Row(3, "t3"), Row(4, "s4")))
+ val metrics = lastOperationMetrics("fallback_merge_target", "MERGE")
+ assert(metrics("numTargetRowsUpdated") === "1", metrics)
+ assert(metrics("numTargetRowsInserted") === "1", metrics)
+ assert(metrics("numTargetRowsCopied") === "2", metrics)
+
+ // The filter and column drop Delta stacks above the projection stay
in its Spark codegen
+ // stage instead of moving to a native stage behind a row-to-columnar
transition.
+ val writeProjection =
+ (n: SparkPlanInfo) => n.nodeName == "Project" &&
isMergeWriteProjection(n)
+ val nodes = plans.flatMap(flattenPlanInfo)
+ assert(nodes.exists(writeProjection), nodes.map(n => s"${n.nodeName}:
${n.simpleString}"))
+ val boundaries =
+ Seq("WholeStageCodegen", "AdaptiveSparkPlan", "QueryStage",
"Exchange", "Shuffle")
+ val sameStage = plans.flatMap {
+ p =>
+ ancestorsOf(p, writeProjection).takeWhile(n =>
!boundaries.exists(n.nodeName.contains))
+ }
+ assert(sameStage.headOption.map(_.nodeName).contains("Filter"),
sameStage.map(_.nodeName))
+ }
+ }
+ }
+
+ test("delta: no-op merge with change data feed produces no change rows") {
+ withTable("noop_merge_target", "noop_merge_source") {
+ spark.sql("""
+ |create table noop_merge_target (id int, name string) using
delta
+ |tblproperties ("delta.enableChangeDataFeed" = "true")
+ |""".stripMargin)
+ spark.sql("insert into noop_merge_target values (1, 'a'), (2, 'b')")
+ spark.sql("create table noop_merge_source (id int, name string) using
delta")
+ spark.sql("insert into noop_merge_source values (1, 'a'), (2, 'b')")
+ spark.sql("""
+ |merge into noop_merge_target t
+ |using noop_merge_source s
+ |on t.id = s.id
+ |when matched and t.name <> s.name then update set name =
s.name
+ |when not matched then insert *
+ |""".stripMargin)
+ checkAnswer(
+ spark.sql("select * from noop_merge_target order by id"),
+ Seq(Row(1, "a"), Row(2, "b")))
+
+ val metrics = lastOperationMetrics("noop_merge_target", "MERGE")
+ assert(metrics("numTargetRowsUpdated") === "0", metrics)
+ assert(metrics("numTargetRowsInserted") === "0", metrics)
+ assert(metrics("numTargetRowsDeleted") === "0", metrics)
+ assert(metrics("numTargetRowsCopied") === "2", metrics)
+
+ // Delta's CDC reader skips a MERGE commit only when these three
counters are all zero.
+ // Inflated counters made it read the rewritten file as real changes.
+ val mergeVersion = latestVersion("noop_merge_target", "MERGE")
+ val changes = spark.sql(s"select * from
table_changes('noop_merge_target', $mergeVersion)")
+ assert(changes.count() === 0, changes.collect().toSeq)
+ }
+ }
+
+ test("delta: merge with change data feed keeps exact metrics and change
rows") {
+ withTable("cdf_merge_target", "cdf_merge_source") {
+ spark.sql("""
+ |create table cdf_merge_target (id int, name string) using
delta
+ |tblproperties ("delta.enableChangeDataFeed" = "true")
+ |""".stripMargin)
+ spark.sql("insert into cdf_merge_target values (1, 'a'), (2, 'b'), (3,
'c'), (4, 'd')")
+ spark.sql("create table cdf_merge_source (id int, name string) using
delta")
+ spark.sql("insert into cdf_merge_source values (1, 'a'), (2, 'x'), (3,
'c'), (5, 'e')")
+ val plans = collectExecutedPlanInfos {
+ spark.sql("""
+ |merge into cdf_merge_target t
+ |using cdf_merge_source s
+ |on t.id = s.id
+ |when matched and s.id = 3 then delete
+ |when matched and t.name <> s.name then update set name =
s.name
+ |when not matched then insert *
+ |""".stripMargin)
+ }
+ checkAnswer(
+ spark.sql("select * from cdf_merge_target order by id"),
+ Seq(Row(1, "a"), Row(2, "x"), Row(4, "d"), Row(5, "e")))
+
+ // Row 1 matches without a clause taking it and row 4 has no source row:
both are copied.
+ val metrics = lastOperationMetrics("cdf_merge_target", "MERGE")
+ assert(metrics("numTargetRowsDeleted") === "1", metrics)
+ assert(metrics("numTargetRowsUpdated") === "1", metrics)
+ assert(metrics("numTargetRowsInserted") === "1", metrics)
+ assert(metrics("numTargetRowsCopied") === "2", metrics)
+
+ // With change data feed on, the counters sit inside the packed change
rows that Delta
+ // explodes above the write projection. Each change must appear exactly
once.
+ val mergeVersion = latestVersion("cdf_merge_target", "MERGE")
+ val changes = spark
+ .sql(s"""
+ |select _change_type, count(*) from
table_changes('cdf_merge_target', $mergeVersion)
+ |group by _change_type
+ |""".stripMargin)
+ .collect()
+ .map(r => r.getString(0) -> r.getLong(1))
+ .toMap
+ assert(
+ changes === Map(
+ "insert" -> 1L,
+ "update_preimage" -> 1L,
+ "update_postimage" -> 1L,
+ "delete" -> 1L),
+ changes)
+
+ if (SparkVersionUtil.gteSpark35) {
+ val nodes = plans.flatMap(flattenPlanInfo)
+ if (BackendsApiManager.getSettings.supportNativeIncrementMetric()) {
+ // The write projection and the explode chain above it stay in one
native stage, so no
+ // row-to-columnar transition sits between them.
+ val nativeDeltaProjects = nodes.filter(_.nodeName ==
"DeltaProjectExecTransformer")
+ assert(
+ nativeDeltaProjects.exists(isMergeWriteProjection),
+ nodes.map(n => s"${n.nodeName}: ${n.simpleString}"))
+ assert(
+ !nodes.exists(n => n.nodeName == "Project" &&
isMergeWriteProjection(n)),
+ nodes.map(n => s"${n.nodeName}: ${n.simpleString}"))
+ val boundaries =
+ Seq("WholeStageCodegen", "AdaptiveSparkPlan", "QueryStage",
"Exchange", "Shuffle")
+ val sameStage = plans.flatMap {
+ p =>
+ ancestorsOf(
+ p,
+ n => n.nodeName == "DeltaProjectExecTransformer" &&
isMergeWriteProjection(n))
+ .takeWhile(n => !boundaries.exists(n.nodeName.contains))
+ }
+ // Delta packs the change rows and explodes them twice, then unpacks
them.
+ assert(
+ sameStage.count(_.nodeName == "GenerateExecTransformer") == 2,
+ sameStage.map(_.nodeName))
+ } else {
+ // Without native counting the write projection stays on Spark.
Delta's explode chain
+ // above it is native, so this shape keeps one row-to-columnar
transition.
+ assert(
+ nodes.exists(n => n.nodeName == "Project" &&
isMergeWriteProjection(n)),
+ nodes.map(n => s"${n.nodeName}: ${n.simpleString}"))
+ }
+ }
+ }
+ }
+
+ testWithMinSparkVersion(
+ "delta: insert-only merge with change data feed counts inserts in every
evaluation mode",
+ "3.5") {
+ // Velox's simplified evaluation applies functions without counting the
rows they process. A
+ // plan with a native counter must keep the regular evaluation path after
user overrides, or the
+ // insert counter reads 0 and change data feed drops this commit's inserts.
+ Seq("false", "true").foreach {
+ simplified =>
+ withTable("insert_only_target", "insert_only_source") {
+ spark.sql("""
+ |create table insert_only_target (id int, name string)
using delta
+ |tblproperties ("delta.enableChangeDataFeed" = "true")
+ |""".stripMargin)
+ spark.sql("insert into insert_only_target values (1, 'a')")
+ spark.sql("create table insert_only_source (id int, name string)
using delta")
+ spark.sql("insert into insert_only_source values (1, 'x'), (2, 'b'),
(3, 'c')")
+ val plans = collectExecutedPlanInfos {
+ withSQLConf(
+ "spark.databricks.delta.merge.optimizeInsertOnlyMerge.enabled"
-> "true",
+
"spark.gluten.sql.columnar.backend.velox.expression.eval_simplified" ->
simplified
+ ) {
+ spark.sql("""
+ |merge into insert_only_target t
+ |using insert_only_source s
+ |on t.id = s.id
+ |when not matched then insert *
+ |""".stripMargin)
+ }
+ }
+ checkAnswer(
+ spark.sql("select * from insert_only_target order by id"),
+ Seq(Row(1, "a"), Row(2, "b"), Row(3, "c")))
+
+ // With a single insert clause, Delta 3.3 counts inserted rows with
an IncrementMetric at
+ // the root of the first output column's alias; Delta 4.x counts
them with a filter over a
+ // literal true, credited with its output rows.
+ val metrics = lastOperationMetrics("insert_only_target", "MERGE")
+ assert(metrics("numTargetRowsInserted") === "2", metrics)
+ assert(metrics("numTargetRowsUpdated") === "0", metrics)
+ assert(metrics("numTargetRowsDeleted") === "0", metrics)
+ // Delta 3.3 also evaluates the source-row counter once per source
file while it lists the
+ // files to scan, which Delta 4.x no longer does, so the count is
exact from Spark 4.0.
+ if (SparkVersionUtil.gteSpark40) {
+ assert(metrics("numSourceRows") === "3", metrics)
+ }
+
+ // Insert-only MERGE writes no change files: change data feed infers
the inserts from the
+ // commit's added files, and skips them when the three counters
above are all 0.
+ val mergeVersion = latestVersion("insert_only_target", "MERGE")
+ checkAnswer(
+ spark.sql(s"""
+ |select id, name, _change_type
+ |from table_changes('insert_only_target',
$mergeVersion, $mergeVersion)
+ |""".stripMargin),
+ Seq(Row(2, "b", "insert"), Row(3, "c", "insert"))
+ )
+
+ // Only a projection that carries IncrementMetric becomes a
DeltaProjectExecTransformer,
+ // and on Delta 3.3 this MERGE has one, so finding it in the
executed plan shows the
+ // counter ran natively.
+ if (
+ BackendsApiManager.getSettings.supportNativeIncrementMetric() &&
+ !SparkVersionUtil.gteSpark40
+ ) {
+ val nodes = plans.flatMap(flattenPlanInfo)
+ assert(
+ nodes.exists(_.nodeName == "DeltaProjectExecTransformer"),
+ s"eval_simplified=$simplified: " +
nodes.map(_.nodeName).distinct)
+ }
+ }
+ }
+ }
+
+ test("delta: delete and update metrics stay exact with and without deletion
vectors") {
+ withTempPath {
+ dir =>
+ val path = dir.getCanonicalPath
+ spark.range(10).coalesce(1).write.format("delta").save(path)
+ spark.sql(s"delete from delta.`$path` where id < 3")
+ val deleteMetrics = lastOperationMetrics(s"delta.`$path`", "DELETE")
+ assert(deleteMetrics("numDeletedRows") === "3", deleteMetrics)
+ assert(deleteMetrics("numCopiedRows") === "7", deleteMetrics)
+
+ spark.sql(s"update delta.`$path` set id = id + 100 where id >= 7")
+ val updateMetrics = lastOperationMetrics(s"delta.`$path`", "UPDATE")
+ assert(updateMetrics("numUpdatedRows") === "3", updateMetrics)
+ assert(updateMetrics("numCopiedRows") === "4", updateMetrics)
+ checkAnswer(
+ spark.sql(s"select id from delta.`$path` order by id"),
+ Seq(3L, 4L, 5L, 6L, 107L, 108L, 109L).map(Row(_)))
+ }
+ withTempPath {
+ dir =>
+ val path = dir.getCanonicalPath
+ spark.range(10).coalesce(1).write.format("delta").save(path)
+ spark.sql(
+ s"alter table delta.`$path` set tblproperties
('delta.enableDeletionVectors' = true)")
+ spark.sql(s"delete from delta.`$path` where id < 3")
+ val deleteMetrics = lastOperationMetrics(s"delta.`$path`", "DELETE")
+ assert(deleteMetrics("numDeletedRows") === "3", deleteMetrics)
+ // Delta 2.4 writes the deletion vector but does not report this
metric yet.
+ if (SparkVersionUtil.gteSpark35) {
+ assert(deleteMetrics("numDeletionVectorsAdded") === "1",
deleteMetrics)
+ }
+ assert(
+ DeltaLog.forTable(
+ spark,
+ path).update().allFiles.collect().exists(_.deletionVector != null),
+ "expected the DELETE to write a deletion vector instead of rewriting
the file"
+ )
+ checkAnswer(
+ spark.sql(s"select id from delta.`$path` order by id"),
+ Seq(3L, 4L, 5L, 6L, 7L, 8L, 9L).map(Row(_)))
+ }
+ }
}
diff --git
a/gluten-delta/src/main/scala/org/apache/gluten/extension/OffloadDeltaFilter.scala
b/gluten-delta/src/test/scala/org/apache/spark/sql/GlutenDeltaTestUtils.scala
similarity index 57%
copy from
gluten-delta/src/main/scala/org/apache/gluten/extension/OffloadDeltaFilter.scala
copy to
gluten-delta/src/test/scala/org/apache/spark/sql/GlutenDeltaTestUtils.scala
index 43147d3a1b..db16d047b2 100644
---
a/gluten-delta/src/main/scala/org/apache/gluten/extension/OffloadDeltaFilter.scala
+++
b/gluten-delta/src/test/scala/org/apache/spark/sql/GlutenDeltaTestUtils.scala
@@ -14,18 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.gluten.extension
+package org.apache.spark.sql
-import org.apache.gluten.execution.DeltaFilterExecTransformer
-import
org.apache.gluten.extension.DeltaPostTransformRules.containsIncrementMetricExpr
-import org.apache.gluten.extension.columnar.offload.OffloadSingleNode
+import org.apache.spark.SparkContext
-import org.apache.spark.sql.execution.{FilterExec, SparkPlan}
-
-case class OffloadDeltaFilter() extends OffloadSingleNode {
- override def offload(plan: SparkPlan): SparkPlan = plan match {
- case FilterExec(condition, child) if
containsIncrementMetricExpr(condition) =>
- DeltaFilterExecTransformer(condition, child)
- case p => p
- }
+object GlutenDeltaTestUtils {
+ def waitForListenerBus(sc: SparkContext): Unit =
sc.listenerBus.waitUntilEmpty(30000L)
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]