Skip to content

Support Spark 4.2#7570

Closed
pan3793 wants to merge 16 commits into
apache:masterfrom
pan3793:spark-4.2
Closed

Support Spark 4.2#7570
pan3793 wants to merge 16 commits into
apache:masterfrom
pan3793:spark-4.2

Conversation

@pan3793

@pan3793 pan3793 commented Jul 15, 2026

Copy link
Copy Markdown
Member

Why are the changes needed?

Spark 4.2.0 is released. This adds the spark-4.2 profile and the kyuubi-extension-spark-4-2 module, enabling Kyuubi to run on Spark 4.2.

What changes are proposed?

  • Add spark-4.2 Maven profile with the kyuubi-extension-spark-4-2 module. Lakehouse engines (Delta/Hudi/Paimon/Iceberg) fall back to 4.1 artifacts until native 4.2 support lands.
  • Adapt the engine UI and servlet adapter for Spark 4.2's Jetty 12 (ee10) / Servlet 6.0 upgrade.
  • Re-fork KyuubiEnsureRequirements and update MaxScanStrategy for Spark 4.2 physical plan API changes.
  • Add spark-4.2 CI matrix entries (normal + verify-on-spark-4.2-binary).

How was this patch tested?

Pass GHA.

Was this patch authored or co-authored using generative AI tooling?

Assisted-by: GLM 5.2

@github-actions github-actions Bot added kind:infra license, community building, project builds, asf infra related, etc. module:spark kind:build module:extensions module:authz labels Jul 15, 2026
@github-actions github-actions Bot added the kind:documentation Documentation is a feature! label Jul 15, 2026
pan3793 added 4 commits July 15, 2026 15:58
Spark 4.0 added a built-in session_user (alias for CurrentUser). Set
CurrentUserContext.CURRENT_USER to the session (proxy) user around query
execution so the built-in current_user/session_user/user functions return
the proxy user instead of the engine user. Skip registering the Kyuubi
session_user UDF on Spark 4.0+ since the built-in now handles it.
Spark 4.2 throws NullPointerException from DAGScheduler.cleanupQueryJobs
during System.exit cleanup when the engine crashes. Add it to the expected
error messages in the sync query causes engine crash test.
pan3793 added 9 commits July 15, 2026 16:56
Master apache#7552 already disables ANSI mode in DataMaskingTestBase.extraSparkConf,
so the duplicate in SparkSessionProvider is unnecessary.
SPARK-46050 (4.2.0) changed CatalogManager from a class to an interface,
breaking binary compatibility when compiled against Spark 3.5 and run
against Spark 4.2 (verify-on-spark-4.2-binary). Replace direct
spark.sessionState.catalogManager calls with reflective helpers in
SparkCatalogUtils.
invokeAs spreads Array[String] as varargs which causes IllegalArgumentException
from Method.invoke. Use Method.invoke directly for setCurrentNamespace to
avoid the varargs unwrapping issue.
Method.invoke wraps the target exception in InvocationTargetException,
which prevented the catch block in SparkSessionImpl from matching on the
cause's message (e.g. SCHEMA_NOT_FOUND). Unwrap before rethrowing.
SPARK-56369 (4.2.0) added withTable, withNamespace, withCurrentCatalogAndNamespace,
and makeQualifiedPath to QueryTestBase with public visibility, conflicting with
Kyuubi's protected definitions in kyuubi-spark-connector-hive tests. Rename the
Kyuubi methods to avoid the diamond inheritance conflict across Spark versions.
Spark 4.2.0 added a 22nd parameter multipartIdentifier: Option[Seq[String]]
to CatalogTable (SPARK-52729), so the reflective newCatalogTable could not
find a matching constructor and every createTable/insert path failed with
NoSuchMethodException. Add a leading reflective branch for the 22-argument
constructor, falling back to the 4.0 (21-arg) and 3.5 (20-arg) signatures.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds Spark 4.2 enablement to Apache Kyuubi by introducing a dedicated spark-4.2 build profile and a new Spark 4.2 SQL extension module, plus a set of compatibility updates for Spark 4.2’s Jetty 12 (ee10) / Servlet 6.0 changes and various Spark SQL internal API shifts.

Changes:

  • Add spark-4.2 Maven profile and new extensions/spark/kyuubi-extension-spark-4-2 module (tests + rules + parser + watchdog, etc.).
  • Update Spark engine UI / servlet adapter shims and Spark SQL engine logic for Spark 4.2 behavioral/API changes.
  • Extend CI matrix and documentation to include Spark 4.2.

Reviewed changes

Copilot reviewed 83 out of 83 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
pom.xml Adds the spark-4.2 Maven profile and version/property overrides.
kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerConnectionSuite.scala Adjusts assertions for Spark 4.2 error-message variations.
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/ui/SparkUIUtils.scala Updates reflective UIUtils invocation for Spark 4.2 signature/Servlet changes.
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/ui/JavaxHttpServletRequest.scala Simplifies javax request adapter to minimal interface + raw underlying access.
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/ui/JakartaHttpServletRequest.scala Simplifies jakarta request adapter to minimal interface + raw underlying access.
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/ui/HttpServletRequestLike.scala Adds underlying to allow passing raw servlet requests to Spark internals.
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/ui/EngineTab.scala Adds Jetty 12 ee10 ServletContextHandler class resolution for Spark 4.2.
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/util/SparkCatalogUtils.scala Makes CatalogManager access reflective for Spark 4.2 binary-compat changes.
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/udf/KDFRegistry.scala Avoids registering session_user UDF on Spark 4+ due to built-in function.
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/session/SparkSessionImpl.scala Uses SparkCatalogUtils for namespace setting in Spark 4.2-compatible way.
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/SparkOperation.scala Propagates proxy user into Spark current user context for built-in user functions.
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/SetCurrentDatabase.scala Uses SparkCatalogUtils for namespace setting.
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/GetCurrentDatabase.scala Uses SparkCatalogUtils for namespace retrieval.
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/kyuubi/engine/spark/operation/GetCurrentCatalog.scala Uses SparkCatalogUtils for current catalog retrieval.
extensions/spark/kyuubi-spark-lineage/src/test/scala/org/apache/kyuubi/plugin/lineage/helper/SparkSQLLineageParserHelperSuite.scala Avoids Spark 4.2 analyzed-plan lazy transaction side effects in lineage tests.
extensions/spark/kyuubi-spark-lineage/README.md Marks Spark 4.2.x as supported for the lineage extension.
extensions/spark/kyuubi-spark-connector-hive/src/test/scala/org/apache/kyuubi/spark/connector/hive/KyuubiHiveTest.scala Renames test helper for clarity (withTabledropTableAfter).
extensions/spark/kyuubi-spark-connector-hive/src/test/scala/org/apache/kyuubi/spark/connector/hive/HiveQuerySuite.scala Updates callers to renamed test helpers.
extensions/spark/kyuubi-spark-connector-hive/src/test/scala/org/apache/kyuubi/spark/connector/hive/DynamicPartitionPruningSuite.scala Updates callers to renamed test helpers.
extensions/spark/kyuubi-spark-connector-hive/src/test/scala/org/apache/kyuubi/spark/connector/hive/command/ShowTablesSuite.scala Updates callers to renamed DDL test helpers.
extensions/spark/kyuubi-spark-connector-hive/src/test/scala/org/apache/kyuubi/spark/connector/hive/command/DDLCommandTestUtils.scala Renames namespace/catalog helper methods for clarity.
extensions/spark/kyuubi-spark-connector-hive/src/test/scala/org/apache/kyuubi/spark/connector/hive/command/CreateTableSuite.scala Updates callers to renamed helpers.
extensions/spark/kyuubi-spark-connector-hive/src/test/scala/org/apache/kyuubi/spark/connector/hive/command/CreateNamespaceSuite.scala Updates callers to renamed helpers.
extensions/spark/kyuubi-spark-connector-hive/src/main/scala/org/apache/kyuubi/spark/connector/hive/HiveTableCatalog.scala Updates CatalogTable construction path for Spark 4.2 signature changes.
extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/ranger/rowfiltering/RowFilteringForIcebergSuite.scala Tags Iceberg tests for exclusion in Spark 4.2 CI runs.
extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/ranger/datamasking/DataMaskingForIcebergSuite.scala Tags Iceberg tests for exclusion in Spark 4.2 CI runs.
extensions/spark/kyuubi-spark-authz/src/test/scala/org/apache/kyuubi/plugin/spark/authz/gen/FunctionCommands.scala Adapts RefreshFunctionCommand field extraction for Spark 4.2.
extensions/spark/kyuubi-spark-authz/src/main/resources/function_command_spec.json Adds identifier extraction entry for Spark 4.2 RefreshFunctionCommand.
extensions/spark/kyuubi-spark-authz/README.md Marks Spark 4.2.x as supported for the authz extension.
extensions/spark/kyuubi-extension-spark-4-2/src/test/scala/org/apache/spark/sql/ZorderCoreBenchmark.scala Adds Spark 4.2 zorder benchmark (example command currently needs updating).
extensions/spark/kyuubi-extension-spark-4-2/src/test/scala/org/apache/spark/sql/WatchDogSuite.scala Adds Spark 4.2 watchdog test coverage.
extensions/spark/kyuubi-extension-spark-4-2/src/test/scala/org/apache/spark/sql/ReportStatisticsDataSource.scala Adds a test datasource exposing reported statistics.
extensions/spark/kyuubi-extension-spark-4-2/src/test/scala/org/apache/spark/sql/ReportStatisticsAndPartitionAwareDataSource.scala Adds a test datasource exposing reported stats + partitioning.
extensions/spark/kyuubi-extension-spark-4-2/src/test/scala/org/apache/spark/sql/KyuubiSparkSQLExtensionTest.scala Provides Spark 4.2 SQL extension test harness.
extensions/spark/kyuubi-extension-spark-4-2/src/test/scala/org/apache/spark/sql/InsertShuffleNodeBeforeJoinSuite.scala Adds Spark 4.2 tests for shuffle injection before join.
extensions/spark/kyuubi-extension-spark-4-2/src/test/scala/org/apache/spark/sql/InjectResourceProfileSuite.scala Adds Spark 4.2 tests for custom resource profile injection.
extensions/spark/kyuubi-extension-spark-4-2/src/test/scala/org/apache/spark/sql/FinalStageResourceManagerSuite.scala Adds Spark 4.2 local-cluster test for final-stage resource manager.
extensions/spark/kyuubi-extension-spark-4-2/src/test/scala/org/apache/spark/sql/FinalStageConfigIsolationSuite.scala Adds Spark 4.2 tests for final-stage config isolation behavior.
extensions/spark/kyuubi-extension-spark-4-2/src/test/scala/org/apache/spark/sql/DynamicShufflePartitionsSuite.scala Adds Spark 4.2 tests for dynamic shuffle partition sizing.
extensions/spark/kyuubi-extension-spark-4-2/src/test/scala/org/apache/spark/sql/DropIgnoreNonexistentSuite.scala Adds Spark 4.2 tests for DROP ignore-nonexistent behavior changes.
extensions/spark/kyuubi-extension-spark-4-2/src/test/scala/org/apache/spark/sql/benchmark/KyuubiBenchmarkBase.scala Adds a benchmark helper for Spark 4.2 extension benchmarks.
extensions/spark/kyuubi-extension-spark-4-2/src/test/resources/log4j2-test.xml Adds test logging configuration for the new module.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/spark/sql/PruneFileSourcePartitionHelper.scala Adds helper for partition/data filter splitting used by watchdog strategy.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/spark/sql/InjectCustomResourceProfile.scala Adds Spark 4.2 rule to inject resource profile for final stages.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/spark/sql/hive/HiveSparkPlanHelper.scala Adds Spark 4.2 hive plan helper alias.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/spark/sql/FinalStageResourceManager.scala Adds Spark 4.2 final-stage executor-killing logic (issues found).
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/spark/sql/execution/CustomResourceProfileExec.scala Adds Spark 4.2 exec node to apply resource profiles (issue found).
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/zorder/Zorder.scala Adds Spark 4.2 zorder expression implementation.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/zorder/ResolveZorder.scala Adds analyzer rule to resolve zorder statements to commands.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/zorder/OptimizeZorderStatement.scala Adds logical plan node for zorder statement parsing.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/zorder/OptimizeZorderCommand.scala Adds runnable command for executing zorder writes (Hive-only).
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/zorder/InsertZorderBeforeWriting.scala Adds logical rewrite rules to inject zorder sort before writes.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/WriteUtils.scala Adds helper to detect write plans for rule gating.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/watchdog/MaxScanStrategy.scala Adds Spark 4.2 watchdog planner strategy for max partitions/filesize checks.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/watchdog/KyuubiWatchDogException.scala Adds Spark 4.2 watchdog exception types.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/watchdog/KyuubiUnsupportedOperationsCheck.scala Adds Spark 4.2 check to block script transformations when disabled.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/RemoveRebalanceShuffle.scala Adds Spark 4.2 AQE runtime optimizer rule to remove unnecessary rebalance shuffles.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/RebalanceBeforeWriting.scala Adds Spark 4.2 rules to inject rebalance partitions before writes.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/KyuubiSQLExtensionException.scala Adds Spark 4.2 extension exception type.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/KyuubiSQLConf.scala Adds Spark 4.2 extension configuration definitions (typo found).
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/KyuubiSparkSQLParser.scala Adds Spark 4.2 SQL parser wrapper for OPTIMIZE ZORDER support.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/KyuubiSparkSQLExtension.scala Registers Spark 4.2 parser/rules/strategies into SparkSessionExtensions.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/KyuubiSparkSQLAstBuilder.scala Adds AST builder for OPTIMIZE ZORDER statement construction.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/KyuubiQueryStagePreparation.scala Adds Spark 4.2 query-stage prep rules for final-stage config isolation.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/InsertShuffleNodeBeforeJoin.scala Adds Spark 4.2 shuffle injection rule to aid skew-join optimization.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/InferRebalanceAndSortOrders.scala Adds Spark 4.2 inference helper for rebalance/sort keys.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/DynamicShufflePartitions.scala Adds Spark 4.2 rule to adjust shuffle partitions based on input size.
extensions/spark/kyuubi-extension-spark-4-2/src/main/scala/org/apache/kyuubi/sql/DropIgnoreNonexistent.scala Adds Spark 4.2 logical rewrite for DROP ignore-nonexistent behavior.
extensions/spark/kyuubi-extension-spark-4-2/src/main/antlr4/org/apache/kyuubi/sql/KyuubiSparkSQL.g4 Adds Spark 4.2 SQL grammar for OPTIMIZE ... ZORDER parsing.
extensions/spark/kyuubi-extension-spark-4-2/pom.xml Adds new Spark 4.2 extension module build definition and test setup.
docs/quick_start/quick_start.rst Updates documented supported Spark range to include 4.2.
docs/extensions/engines/spark/rules.md Adds Spark 4.2 extension row to docs matrix.
dev/reformat Adds Spark 4.2 profile to formatting script profile list.
dev/kyuubi-codecov/pom.xml Adds Spark 4.2 profile dependencies for code coverage aggregation.
build/release/release.sh Adds release step to deploy Spark 4.2 extension artifact.
.github/workflows/style.yml Adds Spark 4.2 extension build to style workflow.
.github/workflows/master.yml Adds Spark 4.2 CI entries (issue found in verify-on-spark-4.2-binary).
.github/workflows/license.yml Adds Spark 4.2 profile to RAT/license check workflow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +100 to +101
rdd.withResources(resourceProfileBuilder.build())
rdd

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is copied from other version, cc @ulysses-you

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.

withResources will change the internal state, so its returned rdd same with the rdd.

sum += status.getSizeForBlock(i)
i += 1
}
executorToBlockSize.getOrElseUpdate(status.location.executorId, sum)

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.

it is a valid suggestion

// shuffle status.
// We should evict executors by their alive time first and retain all of executors which
// have better locality for shuffle block.
executorsWithRegistrationTs.toSeq.sortBy(_._2).foreach { case (id, _) =>

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.

it is a valid suggestion

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

since this is copied from spark 4.1, let's merge it as-is and do a bulk fix later

Comment thread .github/workflows/master.yml
Comment thread pom.xml Outdated
Comment thread pom.xml Outdated
// get the custom v2 session catalog or default spark_catalog
val sessionCatalog = invokeAs[AnyRef](catalogMgr, "v2SessionCatalog")
val defaultCatalog = catalogMgr.currentCatalog
val defaultCatalog = invokeAs[CatalogPlugin](catalogMgr, "currentCatalog")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why not use urrentCatalog method?

@pan3793 pan3793 Jul 16, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

to reuse catalogMgr and save a catalogManager(spark) call

if (spark.sessionState.catalogManager.isCatalogRegistered(catalog)) {
spark.sessionState.catalogManager.setCurrentCatalog(catalog)
if (isCatalogRegistered(spark, catalog)) {
invokeAs[Unit](

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

we don't have an existing setCurrentCatalog method like currentCatalog in this utility class

pan3793 and others added 3 commits July 16, 2026 19:41
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@wForget wForget left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @pan3793

@pan3793 pan3793 added this to the v1.12.0 milestone Jul 16, 2026
@pan3793 pan3793 closed this in 91bb98d Jul 16, 2026
@pan3793

pan3793 commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

thanks, merged to master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:build kind:documentation Documentation is a feature! kind:infra license, community building, project builds, asf infra related, etc. module:authz module:extensions module:server module:spark

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants