Skip to content

[DONT MERGE][GLUTEN-12569][VL] Add Spark 4.2 build profile and shim layer - #13052

Open
akshaytayal wants to merge 14 commits into
apache:mainfrom
akshaytayal:spark42-pr2.1-shim
Open

akshaytayal wants to merge 14 commits into
apache:mainfrom
akshaytayal:spark42-pr2.1-shim

Conversation

@akshaytayal

Copy link
Copy Markdown

What

Adds the Apache Spark 4.2 build profile (-Pspark-4.2) and the shims/spark42
layer, so Gluten can compile and run against Spark 4.2.0.

Part of the Spark 4.2 support effort (#12569). This is the shim layer; the
gluten-ut/spark42 unit-test module follows in separate PRs.

Details

  • New shims/spark42 module (Spark42Shims + SparkShimProvider) implementing
    the shim contract for Spark 4.2, including the SampleExec seed (SPARK-53564) and
    KeyGroupedPartitioning -> KeyedPartitioning (SPARK-53401) changes.
  • postDriverMetrics, SpecializedGetters.getBinaryView, columnar-vector,
    MemoryStream, PythonUDFRunner and BatchScan SPJ shims for Spark 4.2.
  • Rebased on current main: the stale PromotePrecision shim and
    widerDecimalType override are dropped (removed upstream in GLUTEN-12991 / [GLUTEN-12991][CORE] Remove the leftover PromotePrecision shim and its decimal rescale path #13002).

How was this patch tested

shims/common + shims/spark42 compile under -Pspark-4.2 -Pscala-2.13 -Pjava-17 -Pbackends-velox (BUILD SUCCESS). Full Spark 4.2 UT validation lands with the
gluten-ut/spark42 PRs.

MANOJ RAGUPATHY and others added 14 commits September 18, 2026 04:47
Spark 4.2 added parameters to three case classes, which silently breaks
positional extractor patterns:

- CharType gained a collation parameter.
- AppendDataExec / OverwriteByExpressionExec gained tableName and
  transaction.

Match on type (and on the named field where a value is needed) instead,
which is stable across all supported Spark versions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a4b4451c-d099-4965-871d-12781176d082
(cherry picked from commit b2a23c0)
Spark 4.2 hoisted checkAnswer, checkDataset, assertCached and friends out
of QueryTest into a new QueryTestBase trait, which SharedSparkSession now
mixes in. Because GlutenQueryTest declared its own copies of those
members, every suite mixing both inherited conflicting definitions.

Extending QueryTest (an abstract class up to 4.1, a trait in 4.2) makes
Gluten's versions genuine overrides on every supported Spark version, and
removes the duplicated-member conflict.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a4b4451c-d099-4965-871d-12781176d082
(cherry picked from commit a0c9f51)
- Spark 4.2 bumps Netty to 4.2.13, which removed
  PlatformDependent.allocateDirectNoCleaner. Use ByteBuffer.allocateDirect,
  which works on every supported version.
- Spark 4.2's spark-catalyst ships a patched copy of
  datasketches ResourceImpl, tripping the ban-duplicate-classes enforcer.
  Both artifacts are 'provided', so nothing extra is packaged; ignore it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a4b4451c-d099-4965-871d-12781176d082
(cherry picked from commit 5d4853d)
…rk 4.2

Spark 4.2 adds `getBinaryView` to `SpecializedGetters`, which makes
`PlaceholderRow` (and any other `InternalRowSparkCompatible` subclass) fail to
compile as non-abstract:

    BatchCarrierRow.scala:110: error: class PlaceholderRow needs to be abstract.
    Missing implementation for member of trait SpecializedGetters:
      def getBinaryView(x$1: Int): org.apache.spark.unsafe.types.BinaryView

Handled with the existing cross-version seam: `SpecializedGettersSparkCompatible`
gains a `getBinaryView` stub and `InternalRowSparkCompatible` overrides it. The
`Nothing` return type conforms to whichever concrete type the running Spark
version declares, so one definition covers the whole 3.x/4.x matrix -- exactly
how getVariant/getGeography/getGeometry are already handled.

Verified with clean builds (stale target/ classes previously masked this):
spark-3.4, spark-3.5, spark-4.0, spark-4.1 and spark-4.2 all BUILD SUCCESS.

(cherry picked from commit 7210d79)
Spark 4.2 moved postDriverMetrics to SupportsCustomDriverMetrics and made
the reported task metrics an explicit argument. Move doPostDriverMetrics
out of the version-agnostic BatchScanExecTransformer into each
BatchScanExecShim so the call site can differ per version.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8ae7d6bd-f561-417a-a635-40fe24dc67a5
Two Spark 4.2 renames that leak into version-agnostic code:

- SampleExec.seed became Option[Long], resolved lazily via resolvedSeed.
- KeyGroupedPartitioning was renamed to KeyedPartitioning.

Both are now hidden behind SparkShims (getSampleSeed,
isKeyGroupedPartitioning) so gluten-substrait and backends-velox stay
version-agnostic.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8ae7d6bd-f561-417a-a635-40fe24dc67a5
Adds the `spark-4.2` Maven profile and a `shims/spark42` module cloned from
`shims/spark41` with identifiers renamed. No behavioural change to existing
Spark versions: `spark-4.2` is opt-in and no other profile is touched.

- root pom.xml: new `spark-4.2` profile (spark.version 4.2.0, arrow 19.0.0 to
  track Spark 4.2's own Arrow, JDK 17+ / Scala 2.13 enforcers); `spark-4.2`
  added to the spark-version requireActiveProfile list.
- shims/pom.xml: `spark-4.2` profile activates module `spark42`.
- shims/spark42: 37 files, renamed spark41 -> spark42 / Spark41 -> Spark42.

Shim selection needs no hardcoded version: SparkShimDescriptor.DESCRIPTOR is
derived from the SPARK_COMPILE_VERSION build property.

This commit does not compile on its own; the Spark 4.2 source-incompatibilities
are fixed in the following commits so that each can be reverted independently.

(cherry picked from commit c4e06e1)
(cherry picked from commit f57b33e)
Implements the Spark 4.2 side of the shim contracts introduced earlier:
doPostDriverMetrics on BatchScanExecShim, plus getSampleSeed and
isKeyGroupedPartitioning on Spark42Shims.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8ae7d6bd-f561-417a-a635-40fe24dc67a5
(cherry picked from commit 464cfea)
Spark 4.2 replaced the storage-partitioned-join (SPJ) plumbing on
`BatchScanExec`:

- `StoragePartitionJoinParams` and the `KeyGroupedPartitionedScan` trait were
  removed; the constructor now takes `keyGroupedPartitioning: Option[Seq[Expression]]`.
- `KeyGroupedPartitioning` was replaced by `KeyedPartitioning`, which exposes
  `partitionKeys: Seq[InternalRowComparableWrapper]`, `keyOrdering`,
  `keyRowOrdering` and `toGrouped` instead of `partitionValues`/`expressions`.
- `filteredPartitions` became `Seq[Option[InputPartition]]`, runtime-filter
  pushdown moved to `PushDownUtils.pushRuntimeFilters`, and `postDriverMetrics`
  now requires the task-metrics argument.

Changes are confined to `shims/spark42`; `gluten-core`, `gluten-substrait` and
the backends are untouched. `Spark42Shims` and `BatchScanExecShim` keep the
exact signatures of their spark41 counterparts, so the `keyGroupedPartitioning`
propagation added in apache#12567 (ScanTransformerFactory) needs no change.

KNOWN LIMITATION (Spark 4.2 only, marked DEGRADED in the code):
`getCommonPartitionValues` returns `None`, and `orderPartitions` no longer
applies `joinKeyPositions`, `reducers` or partially-clustered replication.
Spark 4.2 moved these refinements off the scan node into
`EnsureRequirements`/`GroupPartitionsExec`, so there is no scan-level
equivalent to reproduce. The base fully-clustered SPJ path is unaffected.

This is currently unreachable: the only callers of `getCommonPartitionValues`
are `IcebergScanTransformer` and `PaimonScanTransformer`, and neither Iceberg
nor Paimon publishes Spark 4.2 artifacts yet (both 404 on Maven Central, vs 200
for their 4.1 builds); both profiles are also activeByDefault=false. Gluten
never populates `joinKeyPositions`/`reducers` anywhere. To be revisited when
Iceberg/Paimon ship Spark 4.2 support.

(cherry picked from commit 687d477)
(cherry picked from commit 15a9182)
Spark 4.2 reworked the columnar vector API:

- `WritableColumnVector` gains three abstract members —
  `putBytes(int,int,ByteBuffer,int)`, `putShortsFromIntsLittleEndian(...)` and
  `getBytesAsBinaryView(...)`. Added stub overrides to
  `WritableColumnVectorShim` following the file's existing style.
- `GeographyVal` and `GeometryVal` were removed in 4.2 and `ColumnVector`
  instead exposes `getBinaryView` (`ColumnVector.java:297`). `ArrowColumnarArray`
  drops the two geo overrides and delegates `getBinaryView` to `data`.

Verified against the 4.1.1 and 4.2.0 source trees: GeographyVal/GeometryVal
exist only in 4.1.1, BinaryView only in 4.2.0.

These are independent of the SPJ port and were masked until Scala compiled,
since scala-compile-first runs before javac.

(cherry picked from commit 4d14a83)
(cherry picked from commit 1e94dfc)
Spark 4.2 reworked `MemoryStream` factory overloads: the
`apply[A](numPartitions: Int)(encoder, sparkSession)` form no longer exists.
The remaining explicit-session overload is
`apply[A: Encoder](sparkSession: SparkSession, numPartitions: Int)`.

Switch the Spark 4.2 shim to that overload; the encoder is supplied by the
existing `A: Encoder` context bound.

(cherry picked from commit 252505b)
(cherry picked from commit 434b980)
Spark 4.2 dropped the trailing `profiler: Option[String]` parameter from both
`PythonUDFRunner.writeUDFs` overloads. Drop the `None` argument in the Spark
4.2 shim. `ArgumentMetadata` itself is unchanged between 4.1 and 4.2.

(cherry picked from commit 5b2558a)
(cherry picked from commit 5514f3d)
…ark42

The CI license-header check inspects newly added files. Replace the short
Apache form carried over from shims/spark41 with the canonical ASF header.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8ae7d6bd-f561-417a-a635-40fe24dc67a5
(cherry picked from commit c6eb1cc)
…lType shim

PromotePrecision and the decimal-rescale path (incl. SparkShims.widerDecimalType)
were removed from Gluten in GLUTEN-12991 (apache#13002). On current main the spark42
shim copies are unused, so remove the PromotePrecision shim class and the
Spark42Shims.widerDecimalType override (which now overrides nothing).
Copilot AI lite review requested due to automatic review settings September 18, 2026 05:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added CORE works for Gluten Core VELOX labels Sep 18, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@baibaichen baibaichen changed the title [GLUTEN-12569][VL] Add Spark 4.2 build profile and shim layer [DONT MERGE][GLUTEN-12569][VL] Add Spark 4.2 build profile and shim layer Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CORE works for Gluten Core VELOX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants