This is an automated email from the ASF dual-hosted git repository.
diqiu50 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new 68b58d1408 [#13018] feat(spark-connector): Add Spark 4.1 support
(#13019)
68b58d1408 is described below
commit 68b58d14081f6bbe13900868f271290e87eef8f9
Author: YangJie <[email protected]>
AuthorDate: Wed Nov 18 20:47:41 2026 -0500
[#13018] feat(spark-connector): Add Spark 4.1 support (#13019)
### What changes were proposed in this pull request?
Adds `spark-connector/v4.1`, a copy of `v4.0` on Spark 4.1.3 and Iceberg
1.11.0. Beyond the copy:
- Iceberg's 4.1 `SparkTable` and Spark 4.1's `JDBCTable` and
`JDBCScanBuilder` have different constructors, so three shared wrappers
call their superclass through per-line base classes under
`spark-common/src/main/spark35`, `spark40` and `spark41`.
- Iceberg's 4.1 extensions read a branch (the `branch` option or WAP) by
renaming the relation to `<table>.branch_<name>`, which Spark 4.1 loads
again. The 4.1 catalog loads it as that branch, checking `SELECT_TABLE`
on `<table>`.
- With an internal conf on, Spark 4.1 can push a JDBC join past
`SparkJdbcPushDownPolicy`. Joins between Gravitino JDBC tables now stay
in Spark.
- The 4.1 catalog implements `ProcedureCatalog.listProcedures`, which
Spark 4.1 added. Iceberg's 4.1 module raises `IllegalArgumentException`
for a dropped branch or tag, so the 4.1 ITs override the expected type.
Shared-tree edits the 4.1 compile forced (a `NotNull` annotation,
deprecated helpers, narrower suppressions) keep 3.5 and 4.0 behavior
unchanged.
### Why are the changes needed?
Spark 4.1 is released and users on it have no connector build. Iceberg
1.11.0 publishes an `iceberg-spark-runtime` for 4.1 and none for 4.2, so
4.1 is the newest line the connector can support.
Fix: #13018
### Does this PR introduce _any_ user-facing change?
Two new published artifacts, `gravitino-spark-4.1_2.13` and
`gravitino-spark-connector-runtime-4.1_2.13`. No new properties or APIs.
Paimon is unavailable on 4.1, as it is on 4.0. On 4.1,
`<db>.<table>.branch_<name>` reads that branch, as Iceberg's own catalog
does; 3.5 and 4.0 still reject the name. Unlike Iceberg's catalog,
writes and deletes through that name fail, and `<db>.<table>.tag_<name>`
is still rejected. Joins between two Gravitino JDBC tables stay in Spark
even with `spark.sql.optimizer.datasourceV2JoinPushdown=true`.
### How was this patch tested?
- `TestGravitinoIcebergCatalogSpark41`: a `branch_` name loads that
branch after the Gravitino privilege check and refuses Spark writes and
deletes, a denied check never reaches Iceberg, and other names under a
two-level namespace, such as `db.t.tag_v1`, are still rejected.
- `TestSparkJdbcScanBuilderJoinPushDown`: two stock builders over one
source count as joinable, and the Gravitino builder does not.
- `SparkIcebergCatalogIT.testIcebergBranchReads`, run on all three
lines: reads with the `branch` option and with a WAP branch return the
branch rows, and `TRUNCATE TABLE <table>.branch_<name>` fails and leaves
main unchanged.
---------
Co-authored-by: Claude Code <[email protected]>
---
.github/trivy/README.md | 2 +-
.../workflows/backend-integration-test-action.yml | 4 +-
.github/workflows/cve-scan.yml | 12 +-
.../workflows/spark-integration-test-action.yml | 6 +-
.../workflows/trino-integration-test-action.yml | 4 +-
.../workflows/trino-multi-version-test-action.yml | 4 +-
build.gradle.kts | 8 +-
dev/docker/spark-connectors/README.md | 4 +-
docs/expression.md | 2 +-
docs/how-to-build.md | 2 +-
docs/spark-connector/spark-catalog-iceberg.md | 1 +
docs/spark-connector/spark-catalog-paimon.md | 5 +-
docs/spark-connector/spark-connector.md | 6 +-
gradle/libs.versions.toml | 1 +
settings.gradle.kts | 3 +
.../spark/connector/SparkTableChangeConverter.java | 10 +-
.../connector/iceberg/IcebergRestOAuthConfig.java | 11 +-
.../spark/connector/iceberg/SparkIcebergTable.java | 15 +-
.../spark/connector/jdbc/SparkJdbcScanBuilder.java | 4 +-
.../spark/connector/jdbc/SparkJdbcTable.java | 4 +-
.../utils/HiveGravitinoOperationOperator.java | 5 +-
.../connector/iceberg/SparkIcebergTableBase.java | 52 ++++++
.../connector/jdbc/SparkJdbcScanBuilderBase.java | 39 +++++
.../spark/connector/jdbc/SparkJdbcTableBase.java | 41 +++++
.../connector/iceberg/SparkIcebergTableBase.java | 52 ++++++
.../connector/jdbc/SparkJdbcScanBuilderBase.java | 39 +++++
.../spark/connector/jdbc/SparkJdbcTableBase.java | 41 +++++
.../connector/iceberg/SparkIcebergTableBase.java | 106 +++++++++++++
.../connector/jdbc/SparkJdbcScanBuilderBase.java | 60 +++++++
.../spark/connector/jdbc/SparkJdbcTableBase.java | 42 +++++
.../authorization/TestRequiredPrivilegesCheck.java | 6 +-
.../catalog/TestBaseCatalogAuthorization.java | 32 ++--
.../catalog/TestTransformTableChange.java | 25 +--
.../test/iceberg/SparkIcebergCatalogIT.java | 59 ++++++-
.../jdbc/TestSparkJdbcPushDownPolicy.java | 24 +--
spark-connector/v4.0/spark/build.gradle.kts | 6 +-
.../v4.1/spark-runtime/build.gradle.kts | 66 ++++++++
.../{v4.0 => v4.1}/spark/build.gradle.kts | 20 +--
...avitinoAuthorizationSparkSessionExtensions.java | 41 +++++
.../glue/GravitinoGlueCatalogSpark41.java | 22 +++
.../hive/GravitinoHiveCatalogSpark41.java | 22 +++
.../iceberg/GravitinoIcebergCatalogSpark41.java | 125 +++++++++++++++
.../jdbc/GravitinoJdbcCatalogSpark41.java | 22 +++
.../GravitinoPostgreSqlCatalogSpark41.java | 31 ++++
.../connector/plugin/GravitinoSparkPlugin.java | 66 ++++++++
.../TestGravitinoIcebergCatalogSpark41.java | 174 +++++++++++++++++++++
.../test/authorization/SparkAuthorizationIT41.java | 22 +++
.../authorization/SparkJwksAuthorizationIT41.java | 22 +++
.../test/hive/SparkHiveCatalogIT41.java | 35 +++++
.../iceberg/IcebergMetadataColumnsSpark41.java | 54 +++++++
.../SparkIcebergCatalogHiveBackendIT41.java | 47 ++++++
.../SparkIcebergCatalogRestBackendIT41.java | 40 +++++
.../SparkIcebergCatalogRestRoutingIT41.java | 41 +++++
.../test/jdbc/SparkJdbcMysqlCatalogIT41.java | 35 +++++
.../test/jdbc/SparkJdbcPostgreSqlCatalogIT41.java | 35 +++++
.../jdbc/TestSparkJdbcScanBuilderJoinPushDown.java | 79 ++++++++++
.../connector/plugin/TestGravitinoSparkPlugin.java | 36 +++++
.../spark/src/test/resources/log4j2.properties | 47 ++++++
58 files changed, 1719 insertions(+), 100 deletions(-)
diff --git a/.github/trivy/README.md b/.github/trivy/README.md
index 6f1941f684..8d37358426 100644
--- a/.github/trivy/README.md
+++ b/.github/trivy/README.md
@@ -27,7 +27,7 @@ Each artifact is a separate target, so a finding is
attributed to the artifact u
| Job | Built with | Targets |
| --- | --- | --- |
| Server packages | `compileDistribution`, `compileIcebergRESTServer`,
`compileLanceRESTServer` | `server-distribution`, `iceberg-rest-server`,
`lance-rest-server` |
-| Shaded jars | `shadowJar` of each module | the nine `*-bundle` jars,
`client-java-runtime`, `filesystem-hadoop3-runtime`, `jobs`,
`flink-runtime-{1.19,1.20,2.1,2.2}`, `spark-runtime-3.5_2.12`,
`spark-runtime-3.5_2.13`, `spark-runtime-4.0` |
+| Shaded jars | `shadowJar` of each module | the nine `*-bundle` jars,
`client-java-runtime`, `filesystem-hadoop3-runtime`, `jobs`,
`flink-runtime-{1.19,1.20,2.1,2.2}`, `spark-runtime-3.5_2.12`,
`spark-runtime-3.5_2.13`, `spark-runtime-4.0`, `spark-runtime-4.1` |
| Trino connectors | `copyRuntimeLibs` of each version range |
`trino-connector-{469-472,473-477,478-479,480,481,482-483}` |
| Lock files | none | `mcp-server` (`mcp-server/uv.lock`), `web`
(`web/web/pnpm-lock.yaml`), `web-v2` (`web-v2/web/pnpm-lock.yaml`),
`client-python` (see below) |
diff --git a/.github/workflows/backend-integration-test-action.yml
b/.github/workflows/backend-integration-test-action.yml
index dd9c8018fd..221dbc4518 100644
--- a/.github/workflows/backend-integration-test-action.yml
+++ b/.github/workflows/backend-integration-test-action.yml
@@ -108,8 +108,8 @@ jobs:
-x :flink-connector:flink-1.20:test -x
:flink-connector:flink-runtime-1.20:test \
-x :flink-connector:flink-2.1:test -x
:flink-connector:flink-runtime-2.1:test \
-x :flink-connector:flink-2.2:test -x
:flink-connector:flink-runtime-2.2:test \
- -x :spark-connector:spark-3.5:test -x
:spark-connector:spark-4.0:test \
- -x :spark-connector:spark-runtime-3.5:test -x
:spark-connector:spark-runtime-4.0:test \
+ -x :spark-connector:spark-3.5:test -x
:spark-connector:spark-4.0:test -x :spark-connector:spark-4.1:test \
+ -x :spark-connector:spark-runtime-3.5:test -x
:spark-connector:spark-runtime-4.0:test -x
:spark-connector:spark-runtime-4.1:test \
-x :trino-connector:integration-test:test \
-x :iceberg:iceberg-rest-trino-it:test \
-x :plugins:idp-basic:test \
diff --git a/.github/workflows/cve-scan.yml b/.github/workflows/cve-scan.yml
index 544600f50f..c389cfbc7c 100644
--- a/.github/workflows/cve-scan.yml
+++ b/.github/workflows/cve-scan.yml
@@ -133,7 +133,7 @@ jobs:
if: github.event_name != 'schedule' || github.repository ==
'apache/gravitino'
needs: trivy-db
runs-on: ubuntu-latest
- timeout-minutes: 90
+ timeout-minutes: 95
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #
v7.0.1
with:
@@ -161,8 +161,9 @@ jobs:
:maintenance:jobs:shadowJar \
:flink-connector:flink-runtime-1.19:shadowJar
:flink-connector:flink-runtime-1.20:shadowJar \
:flink-connector:flink-runtime-2.1:shadowJar
:flink-connector:flink-runtime-2.2:shadowJar \
- :spark-connector:spark-runtime-3.5:shadowJar
:spark-connector:spark-runtime-4.0:shadowJar
- # The Spark 3.5 runtime is also released for Scala 2.13. Spark 4.0 is
Scala 2.13 only.
+ :spark-connector:spark-runtime-3.5:shadowJar
:spark-connector:spark-runtime-4.0:shadowJar \
+ :spark-connector:spark-runtime-4.1:shadowJar
+ # The Spark 3.5 runtime is also released for Scala 2.13. Spark 4.0 and
4.1 are Scala 2.13 only.
- name: Build the Spark 3.5 runtime for Scala 2.13
run: ./gradlew -PskipWeb=true -PscalaVersion=2.13
:spark-connector:spark-runtime-3.5:shadowJar
# Every jar is staged even if another one cannot be found, and the step
fails at the end. The
@@ -184,12 +185,13 @@ jobs:
stage spark-runtime-3.5_2.12
'spark-connector/v3.5/spark-runtime/build/libs/gravitino-spark-connector-runtime-3.5_2.12-*.jar'
stage spark-runtime-3.5_2.13
'spark-connector/v3.5/spark-runtime/build/libs/gravitino-spark-connector-runtime-3.5_2.13-*.jar'
stage spark-runtime-4.0
'spark-connector/v4.0/spark-runtime/build/libs/gravitino-spark-connector-runtime-4.0_2.13-*.jar'
+ stage spark-runtime-4.1
'spark-connector/v4.1/spark-runtime/build/libs/gravitino-spark-connector-runtime-4.1_2.13-*.jar'
exit "${rc}"
# Runs after a failed Stage step too, but not when the build already
failed.
- # 19 targets x 3m scan limit = 57m at most (a jar takes well under a
minute).
+ # 20 targets x 3m scan limit = 60m at most (a jar takes well under a
minute).
- name: Scan
if: ${{ !cancelled() && steps.stage.conclusion != 'skipped' }}
- timeout-minutes: 60
+ timeout-minutes: 65
env:
TRIVY_SCAN_TIMEOUT: 3m
run: .github/trivy/scan.sh scan-all "${TARGET_DIR}"
diff --git a/.github/workflows/spark-integration-test-action.yml
b/.github/workflows/spark-integration-test-action.yml
index f45f8df06a..1bf2496470 100644
--- a/.github/workflows/spark-integration-test-action.yml
+++ b/.github/workflows/spark-integration-test-action.yml
@@ -88,10 +88,11 @@ jobs:
id: integrationTest
run: |
./gradlew -PskipTests -PtestMode=${{ inputs.test-mode }}
-PscalaVersion=${{ inputs.scala-version }} -PskipDockerTests=false
-PskipWeb=true :spark-connector:spark-3.5:test --tests
"org.apache.gravitino.spark.connector.integration.test.**"
- # Spark 4 is Scala 2.13 only, so its module ignores -PscalaVersion.
Guard on 2.12 so that
- # adding a 2.13 entry to the matrix later does not run the Spark 4
suite twice.
+ # The Spark 4 modules are Scala 2.13 only, so they ignore
-PscalaVersion. Guard on 2.12 so
+ # that adding a 2.13 entry to the matrix later does not run those
suites twice.
if [ "${{ inputs.scala-version }}" == "2.12" ]; then
./gradlew -PskipTests -PtestMode=${{ inputs.test-mode }}
-PskipDockerTests=false -PskipWeb=true :spark-connector:spark-4.0:test --tests
"org.apache.gravitino.spark.connector.integration.test.**"
+ ./gradlew -PskipTests -PtestMode=${{ inputs.test-mode }}
-PskipDockerTests=false -PskipWeb=true :spark-connector:spark-4.1:test --tests
"org.apache.gravitino.spark.connector.integration.test.**"
fi
- name: Upload integrate tests reports
@@ -103,5 +104,6 @@ jobs:
build/reports
spark-connector/v3.5/spark/build/spark-3.5-integration-test.log
spark-connector/v4.0/spark/build/spark-4.0-integration-test.log
+ spark-connector/v4.1/spark/build/spark-4.1-integration-test.log
distribution/package/logs/*.out
distribution/package/logs/*.log
diff --git a/.github/workflows/trino-integration-test-action.yml
b/.github/workflows/trino-integration-test-action.yml
index dafa86e7e2..bdbea2fbb2 100644
--- a/.github/workflows/trino-integration-test-action.yml
+++ b/.github/workflows/trino-integration-test-action.yml
@@ -77,8 +77,8 @@ jobs:
-x :flink-connector:flink-runtime-2.1:build \
-x :flink-connector:flink-2.2:build \
-x :flink-connector:flink-runtime-2.2:build \
- -x :spark-connector:spark-3.5:build -x
:spark-connector:spark-4.0:build \
- -x :spark-connector:spark-runtime-3.5:build -x
:spark-connector:spark-runtime-4.0:build \
+ -x :spark-connector:spark-3.5:build -x
:spark-connector:spark-4.0:build -x :spark-connector:spark-4.1:build \
+ -x :spark-connector:spark-runtime-3.5:build -x
:spark-connector:spark-runtime-4.0:build -x
:spark-connector:spark-runtime-4.1:build \
-x :mcp-server:build -x :lineage:build \
-x :maintenance:optimizer:build -x :maintenance:jobs:build \
-x :lance:lance-common:build -x :lance:lance-rest-server:build
diff --git a/.github/workflows/trino-multi-version-test-action.yml
b/.github/workflows/trino-multi-version-test-action.yml
index 7e83e8c14a..c8fef4092e 100644
--- a/.github/workflows/trino-multi-version-test-action.yml
+++ b/.github/workflows/trino-multi-version-test-action.yml
@@ -35,8 +35,8 @@ jobs:
-x :flink-connector:flink-runtime-2.1:build \
-x :flink-connector:flink-2.2:build \
-x :flink-connector:flink-runtime-2.2:build \
- -x :spark-connector:spark-3.5:build -x
:spark-connector:spark-4.0:build \
- -x :spark-connector:spark-runtime-3.5:build -x
:spark-connector:spark-runtime-4.0:build \
+ -x :spark-connector:spark-3.5:build -x
:spark-connector:spark-4.0:build -x :spark-connector:spark-4.1:build \
+ -x :spark-connector:spark-runtime-3.5:build -x
:spark-connector:spark-runtime-4.0:build -x
:spark-connector:spark-runtime-4.1:build \
-x :mcp-server:build -x :lineage:build \
-x :maintenance:optimizer:build -x :maintenance:jobs:build \
-x :lance:lance-common:build -x :lance:lance-rest-server:build
diff --git a/build.gradle.kts b/build.gradle.kts
index 553275c762..6546c150d3 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -767,7 +767,9 @@ subprojects {
// though the rest of :spark-connector (3.x) stays on Java 8.
val jdk17OnlyProjectPaths = setOf(
":spark-connector:spark-4.0",
- ":spark-connector:spark-runtime-4.0"
+ ":spark-connector:spark-runtime-4.0",
+ ":spark-connector:spark-4.1",
+ ":spark-connector:spark-runtime-4.1"
)
fun compatibleWithJDK8(project: Project): Boolean {
@@ -946,6 +948,7 @@ subprojects {
":catalogs:catalog-lakehouse-paimon" to listOf("paimon"),
":spark-connector:spark-3.5" to listOf("iceberg"),
":spark-connector:spark-4.0" to listOf("iceberg"),
+ ":spark-connector:spark-4.1" to listOf("iceberg"),
":server-common" to listOf("hadoop"),
":iceberg:iceberg-common" to listOf("iceberg"),
":iceberg:iceberg-rest-server" to listOf("iceberg"),
@@ -962,7 +965,8 @@ subprojects {
// SparkTransformConverter's Iceberg-derived findWidth method is private
and absent from Javadoc.
sourceNotices.set(
when (project.path) {
- ":spark-connector:spark-3.5", ":spark-connector:spark-4.0" ->
sourceNoticeNames.filterNot { it == "iceberg" }
+ ":spark-connector:spark-3.5", ":spark-connector:spark-4.0",
":spark-connector:spark-4.1" ->
+ sourceNoticeNames.filterNot { it == "iceberg" }
else -> sourceNoticeNames
}
)
diff --git a/dev/docker/spark-connectors/README.md
b/dev/docker/spark-connectors/README.md
index fa9cbc849f..852e69fec8 100644
--- a/dev/docker/spark-connectors/README.md
+++ b/dev/docker/spark-connectors/README.md
@@ -61,8 +61,8 @@ version, or keep it lower.
Each Spark version / Scala variant ships as its own directory under
`/connectors` (named `spark-<major>_<scala>`). Across the project Spark 3.3 is
-Scala 2.12 only; Spark 3.4 and later add Scala 2.13; Spark 4.0 is Scala 2.13
-only. The exact set baked into an image depends on the Gravitino source branch
+Scala 2.12 only; Spark 3.4 and later add Scala 2.13; Spark 4.0 and later are
+Scala 2.13 only. The exact set baked into an image depends on the Gravitino
source branch
it was built from; list them with:
```bash
diff --git a/docs/expression.md b/docs/expression.md
index e9eb5c4818..fd9ab9bb39 100644
--- a/docs/expression.md
+++ b/docs/expression.md
@@ -61,7 +61,7 @@ An LTZ literal assigned to an NTZ column keeps the local
fields produced by Spar
an NTZ literal assigned to an LTZ column is interpreted in the Spark session
zone before it is sent
as an instant. DATE defaults assigned to timestamp columns become midnight in
the Spark session
zone for LTZ targets, or local midnight for NTZ targets. String defaults for
timestamp columns are
-explicitly rejected in both Spark 3.5 and 4.0; use a `TIMESTAMP_LTZ` or
`TIMESTAMP_NTZ` literal instead
+explicitly rejected in Spark 3.5, 4.0 and 4.1; use a `TIMESTAMP_LTZ` or
`TIMESTAMP_NTZ` literal instead
of relying on implicit database conversion. Date and string defaults for
non-timestamp columns
retain their literal values and types.
diff --git a/docs/how-to-build.md b/docs/how-to-build.md
index 7643c786ce..cb65e084ea 100644
--- a/docs/how-to-build.md
+++ b/docs/how-to-build.md
@@ -79,7 +79,7 @@ Gravitino builds from source on Linux and macOS natively, and
on Windows through
This creates
`gravitino-spark-connector-runtime-{sparkVersion}_{scalaVersion}-{version}.jar`
under the `spark-connector/v3.5/spark-runtime/build/libs` directory. Replace
`2.12` with `2.13` to build against a different Scala version. The default
Scala version is `2.12` if `-PscalaVersion` is not specified.
- Replace `spark-runtime-3.5` with `spark-runtime-4.0` for Spark 4. Spark 4 is
Scala 2.13 only, so that module ignores `-PscalaVersion` and always builds
against 2.13.
+ Replace `spark-runtime-3.5` with `spark-runtime-4.0` or `spark-runtime-4.1`
for Spark 4. Spark 4 is Scala 2.13 only, so those modules ignore
`-PscalaVersion` and always build against 2.13.
:::note
The first time you build the project, downloading the dependencies may take
a while.
diff --git a/docs/spark-connector/spark-catalog-iceberg.md
b/docs/spark-connector/spark-catalog-iceberg.md
index a6ec29c666..173d41f09e 100644
--- a/docs/spark-connector/spark-catalog-iceberg.md
+++ b/docs/spark-connector/spark-catalog-iceberg.md
@@ -20,6 +20,7 @@ Spark clients use a different Iceberg version than the
Gravitino server (1.11.0)
|---------------|----------------|-----------------|---------------------------------------------------------|-----------------------------------------------------------------------------------|
| 3.5 | 2.12 or 2.13 | 1.11.0 |
`iceberg-spark-runtime-3.5_${scala-version}-1.11.0.jar` |
`gravitino-spark-connector-runtime-3.5_${scala-version}-${gravitino-version}.jar`
|
| 4.0 | 2.13 | 1.11.0 |
`iceberg-spark-runtime-4.0_2.13-1.11.0.jar` |
`gravitino-spark-connector-runtime-4.0_2.13-${gravitino-version}.jar`
|
+| 4.1 | 2.13 | 1.11.0 |
`iceberg-spark-runtime-4.1_2.13-1.11.0.jar` |
`gravitino-spark-connector-runtime-4.1_2.13-${gravitino-version}.jar`
|
Replace `${scala-version}` with `2.12` or `2.13`, and `${gravitino-version}`
with your Gravitino release version.
diff --git a/docs/spark-connector/spark-catalog-paimon.md
b/docs/spark-connector/spark-catalog-paimon.md
index d947b9730e..24b49ea8cd 100644
--- a/docs/spark-connector/spark-catalog-paimon.md
+++ b/docs/spark-connector/spark-catalog-paimon.md
@@ -16,8 +16,9 @@ The Apache Gravitino Spark connector offers the capability to
read and write Pai
:::info
The Paimon catalog is available on Spark 3.5 only. Paimon first published
`paimon-spark-4.0` in
-Paimon 1.3.0, above the version Gravitino currently depends on, so the Spark 4
connector builds
-without the Paimon classes.
+Paimon 1.3.0, above the version Gravitino currently depends on, and has
published no
+`paimon-spark-4.1` in any release so far, so the Spark 4 connectors build
without the Paimon
+classes.
:::
## Capabilities
diff --git a/docs/spark-connector/spark-connector.md
b/docs/spark-connector/spark-connector.md
index c0d48952f6..9f8195fc44 100644
--- a/docs/spark-connector/spark-connector.md
+++ b/docs/spark-connector/spark-connector.md
@@ -18,13 +18,13 @@ The Apache Gravitino Spark connector leverages the Spark
DataSourceV2 interface
## Requirement
-* Spark 3.5 or 4.0
+* Spark 3.5, 4.0 or 4.1
* Scala 2.12 or 2.13 on Spark 3.5; Spark 4 is Scala 2.13 only
* JDK 8, 11 or 17 on Spark 3.5; Spark 4 requires JDK 17
## Usage
-1. [Build](../how-to-build.md) or download the package matching your Spark
minor version and Scala version
([gravitino-spark-connector-runtime-3.5_2.12](https://mvnrepository.com/artifact/org.apache.gravitino/gravitino-spark-connector-runtime-3.5_2.12),
[gravitino-spark-connector-runtime-3.5_2.13](https://mvnrepository.com/artifact/org.apache.gravitino/gravitino-spark-connector-runtime-3.5_2.13),
[gravitino-spark-connector-runtime-4.0_2.13](https://mvnrepository.com/artifact/org.apache.g
[...]
+1. [Build](../how-to-build.md) or download the package matching your Spark
minor version and Scala version
([gravitino-spark-connector-runtime-3.5_2.12](https://mvnrepository.com/artifact/org.apache.gravitino/gravitino-spark-connector-runtime-3.5_2.12),
[gravitino-spark-connector-runtime-3.5_2.13](https://mvnrepository.com/artifact/org.apache.gravitino/gravitino-spark-connector-runtime-3.5_2.13),
[gravitino-spark-connector-runtime-4.0_2.13](https://mvnrepository.com/artifact/org.apache.g
[...]
2. Configure the Spark session to use the Gravitino spark connector.
| Property | Type | Default Value |
Description
| Required |
@@ -180,7 +180,7 @@ could return different results:
- Date parts other than year, quarter, month, day, hour, and minute, such as
`second()` or
`weekofyear()`. The source can compute them differently.
- Filters with a `TIMESTAMP_NTZ` literal, when the JDBC dialect cannot write
it in SQL. The
- PostgreSQL dialect in Spark 3.5 has this limit. Spark 4.0 does not.
+ PostgreSQL dialect in Spark 3.5 has this limit. Spark 4 does not.
- Value-dependent aggregates on timestamp columns whose JDBC reader type
differs from the type Spark shows. An
example is PostgreSQL `timestamptz` on Spark 3.5 with
`preferTimestampNTZ=true`.
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 35c1940dc5..f9606604f4 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -85,6 +85,7 @@ datastrato-iceberg = "1.13.0"
experimental-iceberg-git-commit = "e6118db078e09d960600c3c302e0f220457cb388"
iceberg4spark35 = "1.11.0"
iceberg4spark40 = "1.11.0"
+iceberg4spark41 = "1.11.0"
paimon = '1.2.0'
# spark34 is pinned by modules other than the Spark connector for their own
tests, so it stays
# after the connector dropped 3.4; it says nothing about connector support.
diff --git a/settings.gradle.kts b/settings.gradle.kts
index ba36b7f0f5..37a2779cac 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -119,6 +119,9 @@ project(":spark-connector:spark-runtime-3.5").projectDir =
file("spark-connector
include("spark-connector:spark-4.0", "spark-connector:spark-runtime-4.0")
project(":spark-connector:spark-4.0").projectDir =
file("spark-connector/v4.0/spark")
project(":spark-connector:spark-runtime-4.0").projectDir =
file("spark-connector/v4.0/spark-runtime")
+include("spark-connector:spark-4.1", "spark-connector:spark-runtime-4.1")
+project(":spark-connector:spark-4.1").projectDir =
file("spark-connector/v4.1/spark")
+project(":spark-connector:spark-runtime-4.1").projectDir =
file("spark-connector/v4.1/spark-runtime")
include("web:web", "web:integration-test")
include("web-v2:web", "web-v2:integration-test")
include("docs")
diff --git
a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/SparkTableChangeConverter.java
b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/SparkTableChangeConverter.java
index 49bb456831..5c08b80901 100644
---
a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/SparkTableChangeConverter.java
+++
b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/SparkTableChangeConverter.java
@@ -154,12 +154,14 @@ public class SparkTableChangeConverter {
} else if (change instanceof TableChange.UpdateColumnDefaultValue) {
TableChange.UpdateColumnDefaultValue updateColumnDefaultValue =
(TableChange.UpdateColumnDefaultValue) change;
+ // Spark 4.1 deprecates newDefaultValue in favour of newCurrentDefault,
which Spark 3.5 and
+ // 4.0's UpdateColumnDefaultValue does not declare. Scoped to this
declaration so the rest of
+ // the method keeps the -Werror deprecation gate.
+ @SuppressWarnings("deprecation")
+ String newDefaultValue = updateColumnDefaultValue.newDefaultValue();
return org.apache.gravitino.rel.TableChange.updateColumnDefaultValue(
updateColumnDefaultValue.fieldNames(),
- convertDefaultValue(
- updateColumnDefaultValue.newDefaultValue(),
- updateColumnDefaultValue.fieldNames(),
- columns));
+ convertDefaultValue(newDefaultValue,
updateColumnDefaultValue.fieldNames(), columns));
} else {
throw new UnsupportedOperationException(
String.format("Unsupported table change %s",
change.getClass().getName()));
diff --git
a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/iceberg/IcebergRestOAuthConfig.java
b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/iceberg/IcebergRestOAuthConfig.java
index 540ba982b2..ff4a2f3035 100644
---
a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/iceberg/IcebergRestOAuthConfig.java
+++
b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/iceberg/IcebergRestOAuthConfig.java
@@ -85,7 +85,7 @@ class IcebergRestOAuthConfig {
return applyBasicCredentials(sparkConf, result);
}
boolean hasExplicitLegacyOAuth2 =
- StringUtils.equalsIgnoreCase(explicitAuthType, AUTH_TYPE_OAUTH2)
+ AUTH_TYPE_OAUTH2.equalsIgnoreCase(explicitAuthType)
||
result.keySet().stream().anyMatch(OAUTH2_TRIGGER_PROPERTIES::contains);
// An explicit legacy OAuth2 configuration already decides how IRC is
authenticated.
if (!hasExplicitLegacyOAuth2) {
@@ -178,7 +178,14 @@ class IcebergRestOAuthConfig {
}
}
+ // Hand-rolled rather than StringUtils.removeEnd/removeStart: commons-lang3
deprecates both in
+ // 3.19.0, which the Spark 4.1 build resolves, and -Werror makes that a
compile error. Their
+ // replacement, Strings.CS, does not exist in the 3.12.0 the Spark 3.5 build
resolves, so no
+ // named helper compiles on every supported line.
private static String joinUri(String serverUri, String tokenPath) {
- return StringUtils.removeEnd(serverUri, "/") + "/" +
StringUtils.removeStart(tokenPath, "/");
+ String base =
+ serverUri.endsWith("/") ? serverUri.substring(0, serverUri.length() -
1) : serverUri;
+ String path = tokenPath.startsWith("/") ? tokenPath.substring(1) :
tokenPath;
+ return base + "/" + path;
}
}
diff --git
a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/iceberg/SparkIcebergTable.java
b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/iceberg/SparkIcebergTable.java
index 0cffbda3a0..58dd1eebab 100644
---
a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/iceberg/SparkIcebergTable.java
+++
b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/iceberg/SparkIcebergTable.java
@@ -19,7 +19,6 @@
package org.apache.gravitino.spark.connector.iceberg;
-import java.lang.reflect.Field;
import java.util.Map;
import org.apache.gravitino.rel.Table;
import org.apache.gravitino.spark.connector.PropertiesConverter;
@@ -38,7 +37,7 @@ import org.apache.spark.sql.util.CaseInsensitiveStringMap;
* For spark-connector in Iceberg, it explicitly uses SparkTable to identify
whether it is an Apache
* Iceberg table, so the SparkIcebergTable must extend SparkTable.
*/
-public class SparkIcebergTable extends SparkTable {
+public class SparkIcebergTable extends SparkIcebergTableBase {
private GravitinoTableInfoHelper gravitinoTableInfoHelper;
private org.apache.spark.sql.connector.catalog.Table sparkTable;
@@ -51,7 +50,7 @@ public class SparkIcebergTable extends SparkTable {
PropertiesConverter propertiesConverter,
SparkTransformConverter sparkTransformConverter,
SparkTypeConverter sparkTypeConverter) {
- super(sparkTable.table(), !isCacheEnabled(sparkCatalog));
+ super(sparkTable, sparkCatalog);
this.gravitinoTableInfoHelper =
new GravitinoTableInfoHelper(
true,
@@ -92,14 +91,4 @@ public class SparkIcebergTable extends SparkTable {
public ScanBuilder newScanBuilder(CaseInsensitiveStringMap options) {
return ((SparkTable) sparkTable).newScanBuilder(options);
}
-
- private static boolean isCacheEnabled(SparkCatalog sparkCatalog) {
- try {
- Field cacheEnabled =
sparkCatalog.getClass().getDeclaredField("cacheEnabled");
- cacheEnabled.setAccessible(true);
- return cacheEnabled.getBoolean(sparkCatalog);
- } catch (NoSuchFieldException | IllegalAccessException e) {
- throw new RuntimeException("Failed to get cacheEnabled field from
SparkCatalog", e);
- }
- }
}
diff --git
a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/SparkJdbcScanBuilder.java
b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/SparkJdbcScanBuilder.java
index 21c6da5d32..085db9b34c 100644
---
a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/SparkJdbcScanBuilder.java
+++
b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/SparkJdbcScanBuilder.java
@@ -35,12 +35,12 @@ import
org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCScanBuilder;
* different semantics. Other predicates, aggregates, Top-N, limits, and
offsets are pushed as
* usual.
*/
-public class SparkJdbcScanBuilder extends JDBCScanBuilder {
+public class SparkJdbcScanBuilder extends SparkJdbcScanBuilderBase {
private final transient SparkJdbcPushDownPolicy policy;
SparkJdbcScanBuilder(JDBCScanBuilder delegate, SparkJdbcPushDownPolicy
policy) {
- super(delegate.session(), delegate.schema(), delegate.jdbcOptions());
+ super(delegate);
this.policy = policy;
}
diff --git
a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTable.java
b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTable.java
index ce62e4d718..baaeaa5378 100644
---
a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTable.java
+++
b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTable.java
@@ -43,7 +43,7 @@ import org.apache.spark.sql.types.StructField;
import org.apache.spark.sql.types.StructType;
import org.apache.spark.sql.util.CaseInsensitiveStringMap;
-public class SparkJdbcTable extends JDBCTable {
+public class SparkJdbcTable extends SparkJdbcTableBase {
private final GravitinoTableInfoHelper gravitinoTableInfoHelper;
private final Table gravitinoTable;
@@ -58,7 +58,7 @@ public class SparkJdbcTable extends JDBCTable {
PropertiesConverter propertiesConverter,
SparkTransformConverter sparkTransformConverter,
SparkTypeConverter sparkTypeConverter) {
- super(identifier, jdbcTable.schema(), jdbcTable.jdbcOptions());
+ super(identifier, jdbcTable);
this.gravitinoTable = gravitinoTable;
this.gravitinoTableInfoHelper =
new GravitinoTableInfoHelper(
diff --git
a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/utils/HiveGravitinoOperationOperator.java
b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/utils/HiveGravitinoOperationOperator.java
index ec3eadfbb1..97d387d440 100644
---
a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/utils/HiveGravitinoOperationOperator.java
+++
b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/utils/HiveGravitinoOperationOperator.java
@@ -37,7 +37,6 @@ import
org.apache.spark.sql.catalyst.expressions.GenericInternalRow;
import org.apache.spark.sql.types.DataType;
import org.apache.spark.sql.types.StructField;
import org.apache.spark.sql.types.StructType;
-import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -147,7 +146,7 @@ public class HiveGravitinoOperationOperator {
return new GenericInternalRow(values);
}
- private @NotNull String getHivePartitionName(
+ private String getHivePartitionName(
String[] names, InternalRow ident, StructType partitionSchema) {
StringBuilder partitionName = new StringBuilder();
Preconditions.checkArgument(names != null, "Partition column names must
not be null");
@@ -167,7 +166,7 @@ public class HiveGravitinoOperationOperator {
return partitionName.toString();
}
- private @NotNull String getHivePartitionName(InternalRow ident, StructType
partitionSchema) {
+ private String getHivePartitionName(InternalRow ident, StructType
partitionSchema) {
StringBuilder partitionName = new StringBuilder();
int numFields = ident.numFields();
for (int i = 0; i < numFields; i++) {
diff --git
a/spark-connector/spark-common/src/main/spark35/org/apache/gravitino/spark/connector/iceberg/SparkIcebergTableBase.java
b/spark-connector/spark-common/src/main/spark35/org/apache/gravitino/spark/connector/iceberg/SparkIcebergTableBase.java
new file mode 100644
index 0000000000..642a91e3ae
--- /dev/null
+++
b/spark-connector/spark-common/src/main/spark35/org/apache/gravitino/spark/connector/iceberg/SparkIcebergTableBase.java
@@ -0,0 +1,52 @@
+/*
+ * 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.gravitino.spark.connector.iceberg;
+
+import java.lang.reflect.Field;
+import org.apache.iceberg.spark.SparkCatalog;
+import org.apache.iceberg.spark.source.SparkTable;
+
+/**
+ * Carries the Iceberg constructor call for {@link SparkIcebergTable}. Iceberg
publishes one Spark
+ * module per Spark line and their {@code SparkTable} constructors differ, so
each line has its own
+ * copy of this class while the table itself stays shared.
+ */
+public abstract class SparkIcebergTableBase extends SparkTable {
+
+ /**
+ * Creates the Iceberg table this wrapper stands in for.
+ *
+ * @param sparkTable the Iceberg table Spark loaded
+ * @param sparkCatalog the Iceberg catalog that loaded it, read for its
cache setting
+ */
+ protected SparkIcebergTableBase(SparkTable sparkTable, SparkCatalog
sparkCatalog) {
+ super(sparkTable.table(), !isCacheEnabled(sparkCatalog));
+ }
+
+ private static boolean isCacheEnabled(SparkCatalog sparkCatalog) {
+ try {
+ Field cacheEnabled =
sparkCatalog.getClass().getDeclaredField("cacheEnabled");
+ cacheEnabled.setAccessible(true);
+ return cacheEnabled.getBoolean(sparkCatalog);
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ throw new RuntimeException("Failed to get cacheEnabled field from
SparkCatalog", e);
+ }
+ }
+}
diff --git
a/spark-connector/spark-common/src/main/spark35/org/apache/gravitino/spark/connector/jdbc/SparkJdbcScanBuilderBase.java
b/spark-connector/spark-common/src/main/spark35/org/apache/gravitino/spark/connector/jdbc/SparkJdbcScanBuilderBase.java
new file mode 100644
index 0000000000..e17980163a
--- /dev/null
+++
b/spark-connector/spark-common/src/main/spark35/org/apache/gravitino/spark/connector/jdbc/SparkJdbcScanBuilderBase.java
@@ -0,0 +1,39 @@
+/*
+ * 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.gravitino.spark.connector.jdbc;
+
+import org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCScanBuilder;
+
+/**
+ * Carries the {@code JDBCScanBuilder} constructor call for {@link
SparkJdbcScanBuilder}. Spark 4.1
+ * added a fourth constructor parameter, so each Spark line has its own copy
of this class while the
+ * scan builder itself stays shared.
+ */
+public abstract class SparkJdbcScanBuilderBase extends JDBCScanBuilder {
+
+ /**
+ * Creates a scan builder for the same table and options as {@code delegate}.
+ *
+ * @param delegate the scan builder Spark created
+ */
+ protected SparkJdbcScanBuilderBase(JDBCScanBuilder delegate) {
+ super(delegate.session(), delegate.schema(), delegate.jdbcOptions());
+ }
+}
diff --git
a/spark-connector/spark-common/src/main/spark35/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTableBase.java
b/spark-connector/spark-common/src/main/spark35/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTableBase.java
new file mode 100644
index 0000000000..6d9e131cc2
--- /dev/null
+++
b/spark-connector/spark-common/src/main/spark35/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTableBase.java
@@ -0,0 +1,41 @@
+/*
+ * 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.gravitino.spark.connector.jdbc;
+
+import org.apache.spark.sql.connector.catalog.Identifier;
+import org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCTable;
+
+/**
+ * Carries the {@code JDBCTable} constructor call for {@link SparkJdbcTable}.
Spark 4.1 added a
+ * fourth constructor parameter, so each Spark line has its own copy of this
class while the table
+ * itself stays shared.
+ */
+public abstract class SparkJdbcTableBase extends JDBCTable {
+
+ /**
+ * Creates the JDBC table this wrapper stands in for.
+ *
+ * @param identifier the table identifier
+ * @param jdbcTable the JDBC table Spark loaded
+ */
+ protected SparkJdbcTableBase(Identifier identifier, JDBCTable jdbcTable) {
+ super(identifier, jdbcTable.schema(), jdbcTable.jdbcOptions());
+ }
+}
diff --git
a/spark-connector/spark-common/src/main/spark40/org/apache/gravitino/spark/connector/iceberg/SparkIcebergTableBase.java
b/spark-connector/spark-common/src/main/spark40/org/apache/gravitino/spark/connector/iceberg/SparkIcebergTableBase.java
new file mode 100644
index 0000000000..642a91e3ae
--- /dev/null
+++
b/spark-connector/spark-common/src/main/spark40/org/apache/gravitino/spark/connector/iceberg/SparkIcebergTableBase.java
@@ -0,0 +1,52 @@
+/*
+ * 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.gravitino.spark.connector.iceberg;
+
+import java.lang.reflect.Field;
+import org.apache.iceberg.spark.SparkCatalog;
+import org.apache.iceberg.spark.source.SparkTable;
+
+/**
+ * Carries the Iceberg constructor call for {@link SparkIcebergTable}. Iceberg
publishes one Spark
+ * module per Spark line and their {@code SparkTable} constructors differ, so
each line has its own
+ * copy of this class while the table itself stays shared.
+ */
+public abstract class SparkIcebergTableBase extends SparkTable {
+
+ /**
+ * Creates the Iceberg table this wrapper stands in for.
+ *
+ * @param sparkTable the Iceberg table Spark loaded
+ * @param sparkCatalog the Iceberg catalog that loaded it, read for its
cache setting
+ */
+ protected SparkIcebergTableBase(SparkTable sparkTable, SparkCatalog
sparkCatalog) {
+ super(sparkTable.table(), !isCacheEnabled(sparkCatalog));
+ }
+
+ private static boolean isCacheEnabled(SparkCatalog sparkCatalog) {
+ try {
+ Field cacheEnabled =
sparkCatalog.getClass().getDeclaredField("cacheEnabled");
+ cacheEnabled.setAccessible(true);
+ return cacheEnabled.getBoolean(sparkCatalog);
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ throw new RuntimeException("Failed to get cacheEnabled field from
SparkCatalog", e);
+ }
+ }
+}
diff --git
a/spark-connector/spark-common/src/main/spark40/org/apache/gravitino/spark/connector/jdbc/SparkJdbcScanBuilderBase.java
b/spark-connector/spark-common/src/main/spark40/org/apache/gravitino/spark/connector/jdbc/SparkJdbcScanBuilderBase.java
new file mode 100644
index 0000000000..e17980163a
--- /dev/null
+++
b/spark-connector/spark-common/src/main/spark40/org/apache/gravitino/spark/connector/jdbc/SparkJdbcScanBuilderBase.java
@@ -0,0 +1,39 @@
+/*
+ * 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.gravitino.spark.connector.jdbc;
+
+import org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCScanBuilder;
+
+/**
+ * Carries the {@code JDBCScanBuilder} constructor call for {@link
SparkJdbcScanBuilder}. Spark 4.1
+ * added a fourth constructor parameter, so each Spark line has its own copy
of this class while the
+ * scan builder itself stays shared.
+ */
+public abstract class SparkJdbcScanBuilderBase extends JDBCScanBuilder {
+
+ /**
+ * Creates a scan builder for the same table and options as {@code delegate}.
+ *
+ * @param delegate the scan builder Spark created
+ */
+ protected SparkJdbcScanBuilderBase(JDBCScanBuilder delegate) {
+ super(delegate.session(), delegate.schema(), delegate.jdbcOptions());
+ }
+}
diff --git
a/spark-connector/spark-common/src/main/spark40/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTableBase.java
b/spark-connector/spark-common/src/main/spark40/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTableBase.java
new file mode 100644
index 0000000000..6d9e131cc2
--- /dev/null
+++
b/spark-connector/spark-common/src/main/spark40/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTableBase.java
@@ -0,0 +1,41 @@
+/*
+ * 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.gravitino.spark.connector.jdbc;
+
+import org.apache.spark.sql.connector.catalog.Identifier;
+import org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCTable;
+
+/**
+ * Carries the {@code JDBCTable} constructor call for {@link SparkJdbcTable}.
Spark 4.1 added a
+ * fourth constructor parameter, so each Spark line has its own copy of this
class while the table
+ * itself stays shared.
+ */
+public abstract class SparkJdbcTableBase extends JDBCTable {
+
+ /**
+ * Creates the JDBC table this wrapper stands in for.
+ *
+ * @param identifier the table identifier
+ * @param jdbcTable the JDBC table Spark loaded
+ */
+ protected SparkJdbcTableBase(Identifier identifier, JDBCTable jdbcTable) {
+ super(identifier, jdbcTable.schema(), jdbcTable.jdbcOptions());
+ }
+}
diff --git
a/spark-connector/spark-common/src/main/spark41/org/apache/gravitino/spark/connector/iceberg/SparkIcebergTableBase.java
b/spark-connector/spark-common/src/main/spark41/org/apache/gravitino/spark/connector/iceberg/SparkIcebergTableBase.java
new file mode 100644
index 0000000000..5a447e6d0a
--- /dev/null
+++
b/spark-connector/spark-common/src/main/spark41/org/apache/gravitino/spark/connector/iceberg/SparkIcebergTableBase.java
@@ -0,0 +1,106 @@
+/*
+ * 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.gravitino.spark.connector.iceberg;
+
+import org.apache.iceberg.spark.SparkCatalog;
+import org.apache.iceberg.spark.source.SparkTable;
+import org.apache.spark.sql.connector.expressions.filter.Predicate;
+import org.apache.spark.sql.connector.write.LogicalWriteInfo;
+import org.apache.spark.sql.connector.write.RowLevelOperationBuilder;
+import org.apache.spark.sql.connector.write.RowLevelOperationInfo;
+import org.apache.spark.sql.connector.write.WriteBuilder;
+
+/**
+ * Carries the Iceberg constructor call for {@link SparkIcebergTable}. Iceberg
publishes one Spark
+ * module per Spark line and their {@code SparkTable} constructors differ, so
each line has its own
+ * copy of this class while the table itself stays shared.
+ */
+public abstract class SparkIcebergTableBase extends SparkTable {
+
+ private final SparkTable sparkTable;
+
+ /**
+ * Creates the Iceberg table this wrapper stands in for.
+ *
+ * @param sparkTable the Iceberg table Spark loaded
+ * @param sparkCatalog the Iceberg catalog that loaded it, unused on this
Spark line
+ */
+ protected SparkIcebergTableBase(SparkTable sparkTable, SparkCatalog
sparkCatalog) {
+ // Iceberg's Spark 4.1 module publishes only SparkTable(Table). The
earlier lines pass an
+ // eager-refresh flag derived from the catalog's cacheEnabled field; 4.1
has no such parameter.
+ super(sparkTable.table());
+ this.sparkTable = sparkTable;
+ }
+
+ // The constructor above always builds the main branch, while the loaded
table can be a branch
+ // (see GravitinoIcebergCatalogSpark41#loadTable). Iceberg's ResolveBranch
reads branch() to
+ // decide whether the relation still has to be switched to the requested
branch.
+
+ @Override
+ public String branch() {
+ return sparkTable.branch();
+ }
+
+ @Override
+ public Long snapshotId() {
+ return sparkTable.snapshotId();
+ }
+
+ @Override
+ public String version() {
+ return sparkTable.version();
+ }
+
+ // The inherited write and delete methods ignore the branch the table was
loaded for, so a table
+ // loaded for a branch refuses them instead of writing elsewhere.
+
+ @Override
+ public WriteBuilder newWriteBuilder(LogicalWriteInfo info) {
+ rejectWriteToBranch();
+ return super.newWriteBuilder(info);
+ }
+
+ @Override
+ public RowLevelOperationBuilder
newRowLevelOperationBuilder(RowLevelOperationInfo info) {
+ rejectWriteToBranch();
+ return super.newRowLevelOperationBuilder(info);
+ }
+
+ @Override
+ public boolean canDeleteWhere(Predicate[] predicates) {
+ rejectWriteToBranch();
+ return super.canDeleteWhere(predicates);
+ }
+
+ @Override
+ public void deleteWhere(Predicate[] predicates) {
+ rejectWriteToBranch();
+ super.deleteWhere(predicates);
+ }
+
+ private void rejectWriteToBranch() {
+ if (sparkTable.branch() != null) {
+ throw new UnsupportedOperationException(
+ String.format(
+ "Cannot write to %s through a table loaded for branch %s",
+ name(), sparkTable.branch()));
+ }
+ }
+}
diff --git
a/spark-connector/spark-common/src/main/spark41/org/apache/gravitino/spark/connector/jdbc/SparkJdbcScanBuilderBase.java
b/spark-connector/spark-common/src/main/spark41/org/apache/gravitino/spark/connector/jdbc/SparkJdbcScanBuilderBase.java
new file mode 100644
index 0000000000..03890c6da6
--- /dev/null
+++
b/spark-connector/spark-common/src/main/spark41/org/apache/gravitino/spark/connector/jdbc/SparkJdbcScanBuilderBase.java
@@ -0,0 +1,60 @@
+/*
+ * 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.gravitino.spark.connector.jdbc;
+
+import org.apache.spark.sql.connector.read.SupportsPushDownJoin;
+import org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCScanBuilder;
+
+/**
+ * Carries the {@code JDBCScanBuilder} constructor call for {@link
SparkJdbcScanBuilder}. Spark 4.1
+ * added a fourth constructor parameter, so each Spark line has its own copy
of this class while the
+ * scan builder itself stays shared. Spark 4.1 also added join pushdown, which
this copy turns off
+ * when the builder is the left side of the join, the side Spark asks.
+ */
+public abstract class SparkJdbcScanBuilderBase extends JDBCScanBuilder {
+
+ /**
+ * Creates a scan builder for the same table and options as {@code delegate}.
+ *
+ * @param delegate the scan builder Spark created
+ */
+ protected SparkJdbcScanBuilderBase(JDBCScanBuilder delegate) {
+ // Spark 4.1 added the additionalMetrics parameter; forward what the
delegate reports.
+ super(
+ delegate.session(),
+ delegate.schema(),
+ delegate.jdbcOptions(),
+ delegate.additionalMetrics());
+ }
+
+ /**
+ * Keeps joins with this builder on the left in Spark. Spark 4.1 can push a
join of two tables of
+ * the same JDBC source. It compiles the join condition without {@link
SparkJdbcPushDownPolicy},
+ * and the left table's policy, which knows only that table's columns, then
decides on aggregates
+ * and Top-N over both tables.
+ *
+ * @param other the scan builder of the other side of the join
+ * @return false
+ */
+ @Override
+ public boolean isOtherSideCompatibleForJoin(SupportsPushDownJoin other) {
+ return false;
+ }
+}
diff --git
a/spark-connector/spark-common/src/main/spark41/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTableBase.java
b/spark-connector/spark-common/src/main/spark41/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTableBase.java
new file mode 100644
index 0000000000..67224badba
--- /dev/null
+++
b/spark-connector/spark-common/src/main/spark41/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTableBase.java
@@ -0,0 +1,42 @@
+/*
+ * 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.gravitino.spark.connector.jdbc;
+
+import org.apache.spark.sql.connector.catalog.Identifier;
+import org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCTable;
+
+/**
+ * Carries the {@code JDBCTable} constructor call for {@link SparkJdbcTable}.
Spark 4.1 added a
+ * fourth constructor parameter, so each Spark line has its own copy of this
class while the table
+ * itself stays shared.
+ */
+public abstract class SparkJdbcTableBase extends JDBCTable {
+
+ /**
+ * Creates the JDBC table this wrapper stands in for.
+ *
+ * @param identifier the table identifier
+ * @param jdbcTable the JDBC table Spark loaded
+ */
+ protected SparkJdbcTableBase(Identifier identifier, JDBCTable jdbcTable) {
+ // Spark 4.1 added the additionalMetrics parameter; forward what the
loaded table reports.
+ super(identifier, jdbcTable.schema(), jdbcTable.jdbcOptions(),
jdbcTable.additionalMetrics());
+ }
+}
diff --git
a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/authorization/TestRequiredPrivilegesCheck.java
b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/authorization/TestRequiredPrivilegesCheck.java
index 6d21bf31ca..658c20f855 100644
---
a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/authorization/TestRequiredPrivilegesCheck.java
+++
b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/authorization/TestRequiredPrivilegesCheck.java
@@ -34,7 +34,6 @@ import org.apache.spark.sql.connector.catalog.SupportsRead;
import org.apache.spark.sql.connector.catalog.SupportsWrite;
import org.apache.spark.sql.connector.catalog.Table;
import org.apache.spark.sql.execution.datasources.v2.DataSourceV2Relation;
-import org.apache.spark.sql.util.CaseInsensitiveStringMap;
import org.junit.jupiter.api.Test;
import scala.collection.JavaConverters;
@@ -51,8 +50,9 @@ public class TestRequiredPrivilegesCheck {
}
private static LogicalPlan relation(Table table) {
- return DataSourceV2Relation.create(
- table, scala.Option.empty(), scala.Option.empty(),
CaseInsensitiveStringMap.empty());
+ // The three-argument overload passes empty options and exists on every
supported Spark line;
+ // Spark 4.1 added a defaulted fifth parameter to the overload that takes
options.
+ return DataSourceV2Relation.create(table, scala.Option.empty(),
scala.Option.empty());
}
@Test
diff --git
a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestBaseCatalogAuthorization.java
b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestBaseCatalogAuthorization.java
index 589152f551..c4e982b048 100644
---
a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestBaseCatalogAuthorization.java
+++
b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestBaseCatalogAuthorization.java
@@ -184,7 +184,7 @@ public class TestBaseCatalogAuthorization {
() ->
catalog.alterTable(
identifier,
- TableChange.updateColumnDefaultValue(
+ updateColumnDefaultValue(
new String[] {"ts"}, "TIMESTAMP_LTZ '2026-11-04
12:34:56.123456'")));
return null;
});
@@ -209,7 +209,7 @@ public class TestBaseCatalogAuthorization {
() ->
catalog.alterTable(
identifier,
- TableChange.updateColumnDefaultValue(new String[] {"ts"},
sql),
+ updateColumnDefaultValue(new String[] {"ts"}, sql),
TableChange.updateColumnType(new String[] {"ts"},
DataTypes.TimestampNTZType)));
Assertions.assertTrue(error.getMessage().contains("cannot be combined"));
Mockito.verifyNoInteractions(gravitinoTableCatalog, sparkCatalog);
@@ -229,7 +229,7 @@ public class TestBaseCatalogAuthorization {
ForbiddenException.class,
() ->
catalog.alterTable(
- identifier, TableChange.updateColumnDefaultValue(new
String[] {"ts"}, sql))));
+ identifier, updateColumnDefaultValue(new String[] {"ts"},
sql))));
verify(gravitinoTableCatalog).loadTable(gravitinoIdentifier);
Mockito.verifyNoMoreInteractions(gravitinoTableCatalog);
Mockito.verifyNoInteractions(sparkCatalog);
@@ -252,8 +252,7 @@ public class TestBaseCatalogAuthorization {
() ->
catalog.alterTable(
identifier,
- TableChange.updateColumnDefaultValue(
- new String[] {"ts"}, "DATE '2026-11-04'")));
+ updateColumnDefaultValue(new String[] {"ts"}, "DATE
'2026-11-04'")));
return null;
});
ArgumentCaptor<org.apache.gravitino.rel.TableChange> change =
@@ -281,8 +280,7 @@ public class TestBaseCatalogAuthorization {
() ->
catalog.alterTable(
identifier,
- TableChange.updateColumnDefaultValue(
- new String[] {"ts"}, "'2026-11-04 12:34:56.123456'")));
+ updateColumnDefaultValue(new String[] {"ts"}, "'2026-11-04
12:34:56.123456'")));
Assertions.assertTrue(error.getMessage().contains("TIMESTAMP_LTZ or
TIMESTAMP_NTZ"));
verify(gravitinoTableCatalog).loadTable(gravitinoIdentifier);
Mockito.verifyNoMoreInteractions(gravitinoTableCatalog);
@@ -293,7 +291,7 @@ public class TestBaseCatalogAuthorization {
void testNumericDefaultDoesNotReadSchema() throws Exception {
Identifier identifier = Identifier.of(new String[] {"schema"}, "table_a");
NameIdentifier gravitinoIdentifier = NameIdentifier.of("schema",
"table_a");
- catalog.alterTable(identifier, TableChange.updateColumnDefaultValue(new
String[] {"ts"}, "42"));
+ catalog.alterTable(identifier, updateColumnDefaultValue(new String[]
{"ts"}, "42"));
verify(gravitinoTableCatalog,
Mockito.never()).loadTable(gravitinoIdentifier);
}
@@ -311,12 +309,10 @@ public class TestBaseCatalogAuthorization {
});
catalog.alterTable(
identifier,
- TableChange.updateColumnDefaultValue(
- new String[] {"ts"}, "TIMESTAMP_NTZ '2026-11-04 12:34:00'"),
- TableChange.updateColumnDefaultValue(
- new String[] {"ts"}, "TIMESTAMP_NTZ '2026-11-04 00:00:00'"),
- TableChange.updateColumnDefaultValue(new String[] {"ts"}, "DATE
'2026-11-04'"),
- TableChange.updateColumnDefaultValue(new String[] {"label"},
"'label'"));
+ updateColumnDefaultValue(new String[] {"ts"}, "TIMESTAMP_NTZ
'2026-11-04 12:34:00'"),
+ updateColumnDefaultValue(new String[] {"ts"}, "TIMESTAMP_NTZ
'2026-11-04 00:00:00'"),
+ updateColumnDefaultValue(new String[] {"ts"}, "DATE '2026-11-04'"),
+ updateColumnDefaultValue(new String[] {"label"}, "'label'"));
verify(gravitinoTableCatalog).loadTable(gravitinoIdentifier);
verify(table).columns();
}
@@ -369,4 +365,12 @@ public class TestBaseCatalogAuthorization {
return mock(SparkTransformConverter.class);
}
}
+
+ // Spark 4.1 deprecates the String form of updateColumnDefaultValue; the
DefaultValue form that
+ // replaces it does not exist on Spark 3.5 or 4.0. Scoped to this helper so
the rest of the class
+ // keeps the -Werror deprecation gate.
+ @SuppressWarnings("deprecation")
+ private static TableChange updateColumnDefaultValue(String[] fieldNames,
String sql) {
+ return TableChange.updateColumnDefaultValue(fieldNames, sql);
+ }
}
diff --git
a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestTransformTableChange.java
b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestTransformTableChange.java
index ba3688b28a..09701b5abc 100644
---
a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestTransformTableChange.java
+++
b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestTransformTableChange.java
@@ -72,8 +72,7 @@ public class TestTransformTableChange {
String[] fieldNames = new String[] {"col"};
String defaultValue = "'col_default_value'";
TableChange.UpdateColumnDefaultValue sparkChange =
- (TableChange.UpdateColumnDefaultValue)
- TableChange.updateColumnDefaultValue(fieldNames, defaultValue);
+ (TableChange.UpdateColumnDefaultValue)
updateColumnDefaultValue(fieldNames, defaultValue);
org.apache.gravitino.rel.TableChange gravitinoChange =
sparkTableChangeConverter.toGravitinoTableChange(
@@ -102,7 +101,7 @@ public class TestTransformTableChange {
UnsupportedOperationException.class,
() ->
sparkTableChangeConverter.toGravitinoTableChange(
- TableChange.updateColumnDefaultValue(new String[] {"col"},
"")));
+ updateColumnDefaultValue(new String[] {"col"}, "")));
Assertions.assertEquals("DROP DEFAULT is not supported by Gravitino",
exception.getMessage());
for (String expression :
new String[] {
@@ -119,7 +118,7 @@ public class TestTransformTableChange {
IllegalArgumentException.class,
() ->
sparkTableChangeConverter.toGravitinoTableChange(
- TableChange.updateColumnDefaultValue(new String[] {"col"},
expression)));
+ updateColumnDefaultValue(new String[] {"col"}, expression)));
}
}
@@ -310,7 +309,7 @@ public class TestTransformTableChange {
IllegalArgumentException.class,
() ->
sparkTableChangeConverter.toGravitinoTableChange(
- TableChange.updateColumnDefaultValue(new String[]
{"col"}, sql),
+ updateColumnDefaultValue(new String[] {"col"}, sql),
() -> new Column[] {Column.of("col", target, null)}));
Assertions.assertTrue(error.getMessage().contains("col"));
Assertions.assertTrue(error.getMessage().contains("TIMESTAMP_LTZ or
TIMESTAMP_NTZ"));
@@ -336,7 +335,7 @@ public class TestTransformTableChange {
org.apache.gravitino.rel.TableChange.UpdateColumnDefaultValue converted =
(org.apache.gravitino.rel.TableChange.UpdateColumnDefaultValue)
sparkTableChangeConverter.toGravitinoTableChange(
- TableChange.updateColumnDefaultValue(
+ updateColumnDefaultValue(
new String[] {"parent", "ts"}, "TIMESTAMP_NTZ '2026-11-04
12:34:00'"),
() -> columns);
Assertions.assertEquals(
@@ -347,7 +346,7 @@ public class TestTransformTableChange {
IllegalArgumentException.class,
() ->
sparkTableChangeConverter.toGravitinoTableChange(
- TableChange.updateColumnDefaultValue(path, "TIMESTAMP_NTZ
'2026-11-04 12:34:00'"),
+ updateColumnDefaultValue(path, "TIMESTAMP_NTZ '2026-11-04
12:34:00'"),
() -> columns));
}
}
@@ -359,7 +358,7 @@ public class TestTransformTableChange {
IllegalArgumentException.class,
() ->
sparkTableChangeConverter.toGravitinoTableChange(
- TableChange.updateColumnDefaultValue(new String[] {"col"},
sql)));
+ updateColumnDefaultValue(new String[] {"col"}, sql)));
Assertions.assertThrows(
IllegalArgumentException.class,
() -> assertDefault("TIMESTAMP '2026-11-04 12:34:56'",
Literals.stringLiteral("unused")));
@@ -615,7 +614,7 @@ public class TestTransformTableChange {
org.apache.gravitino.rel.TableChange.UpdateColumnDefaultValue converted =
(org.apache.gravitino.rel.TableChange.UpdateColumnDefaultValue)
sparkTableChangeConverter.toGravitinoTableChange(
- TableChange.updateColumnDefaultValue(new String[] {"col"},
sql),
+ updateColumnDefaultValue(new String[] {"col"}, sql),
() -> new Column[] {Column.of("col", ((Literal<?>)
expected).dataType(), null)});
Assertions.assertEquals(expected, converted.getNewDefaultValue());
return converted.getNewDefaultValue();
@@ -632,4 +631,12 @@ public class TestTransformTableChange {
return null;
});
}
+
+ // Spark 4.1 deprecates the String form of updateColumnDefaultValue; the
DefaultValue form that
+ // replaces it does not exist on Spark 3.5 or 4.0. Scoped to this helper so
the rest of the class
+ // keeps the -Werror deprecation gate.
+ @SuppressWarnings("deprecation")
+ private static TableChange updateColumnDefaultValue(String[] fieldNames,
String sql) {
+ return TableChange.updateColumnDefaultValue(fieldNames, sql);
+ }
}
diff --git
a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/integration/test/iceberg/SparkIcebergCatalogIT.java
b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/integration/test/iceberg/SparkIcebergCatalogIT.java
index f94f1fe850..501239c124 100644
---
a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/integration/test/iceberg/SparkIcebergCatalogIT.java
+++
b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/integration/test/iceberg/SparkIcebergCatalogIT.java
@@ -373,6 +373,7 @@ public abstract class SparkIcebergCatalogIT extends
SparkCommonIT {
void testIcebergSQLExtensions() throws NoSuchTableException {
testIcebergPartitionFieldOperations();
testIcebergBranchOperations();
+ testIcebergBranchReads();
testIcebergTagOperations();
testIcebergIdentifierOperations();
testIcebergDistributionAndOrderingOperations();
@@ -903,10 +904,52 @@ public abstract class SparkIcebergCatalogIT extends
SparkCommonIT {
// drop branch
sql(String.format("ALTER TABLE %s DROP BRANCH `%s`", tableName, branch1));
Assertions.assertThrows(
- ValidationException.class,
+ unknownVersionException(),
() -> sql(String.format("SELECT * FROM %s VERSION AS OF '%s'",
tableName, branch1)));
}
+ // Iceberg's Spark 4.1 module resolves the branch read option and the WAP
branch in an analyzer
+ // rule that renames the relation to <table>.branch_<name>, and Spark 4.1
loads that name from
+ // the catalog again before the query runs.
+ private void testIcebergBranchReads() {
+ String tableName = "test_iceberg_branch_reads";
+ String branch = "audit";
+ dropTableIfExists(tableName);
+ createSimpleTable(tableName);
+ sql(String.format("INSERT INTO %s VALUES(1, '1', 1);", tableName));
+ sql(String.format("ALTER TABLE %s CREATE BRANCH `%s`", tableName, branch));
+ sql(String.format("INSERT INTO %s VALUES(2, '2', 2);", tableName));
+
+ List<String> branchData =
+ getSparkSession()
+ .read()
+ .option("branch", branch)
+ .table(tableName)
+ .orderBy("id")
+ .collectAsList()
+ .stream()
+ .map(row -> row.mkString(","))
+ .collect(Collectors.toList());
+ Assertions.assertEquals(ImmutableList.of("1,1,1"), branchData);
+
+ sql(String.format("ALTER TABLE %s SET TBLPROPERTIES
('write.wap.enabled'='true')", tableName));
+ sql(String.format("SET spark.wap.branch=%s", branch));
+ try {
+ Assertions.assertEquals(ImmutableList.of("1,1,1"),
getTableData(tableName));
+ } finally {
+ sql("RESET spark.wap.branch");
+ }
+ // A branch_ name reads the branch on Spark 4.1 but must not let a write
reach main.
+ Assertions.assertThrows(
+ Exception.class,
+ () ->
+ sql(
+ String.format(
+ "TRUNCATE TABLE %s.%s.branch_%s", getDefaultDatabase(),
tableName, branch)));
+ Assertions.assertEquals(
+ "1,1,1;2,2,2", String.join(";",
getQueryData(getSelectAllSqlWithOrder(tableName, "id"))));
+ }
+
private void testIcebergTagOperations() throws NoSuchTableException {
String tableName = "test_iceberg_tags";
String tag1 = "tag1";
@@ -950,7 +993,7 @@ public abstract class SparkIcebergCatalogIT extends
SparkCommonIT {
// drop tag
sql(String.format("ALTER TABLE %s DROP TAG `%s`", tableName, tag1));
Assertions.assertThrows(
- ValidationException.class,
+ unknownVersionException(),
() -> sql(String.format("SELECT * FROM %s VERSION AS OF '%s'",
tableName, tag1)));
}
@@ -1116,6 +1159,18 @@ public abstract class SparkIcebergCatalogIT extends
SparkCommonIT {
Assertions.assertEquals("1,1,1;1,1,1;1,1,1;1,1,1", String.join(";",
queryResult));
}
+ /**
+ * The exception a query against a branch or tag that no longer exists
raises. Iceberg makes this
+ * check with {@code ValidationException.check} in {@code SparkCatalog} up
to its Spark 4.0
+ * module, and with {@code Preconditions.checkArgument} in {@code
SparkTable} from its Spark 4.1
+ * one.
+ *
+ * @return the exception class this Spark line raises
+ */
+ protected Class<? extends Throwable> unknownVersionException() {
+ return ValidationException.class;
+ }
+
protected SparkMetadataColumnInfo[] getIcebergMetadataColumns() {
return new SparkMetadataColumnInfo[] {
new SparkMetadataColumnInfo("_spec_id", DataTypes.IntegerType, false),
diff --git
a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestSparkJdbcPushDownPolicy.java
b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestSparkJdbcPushDownPolicy.java
index d20565a174..6e3f548491 100644
---
a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestSparkJdbcPushDownPolicy.java
+++
b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestSparkJdbcPushDownPolicy.java
@@ -21,6 +21,7 @@ package org.apache.gravitino.spark.connector.jdbc;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.time.LocalDateTime;
import java.util.Arrays;
@@ -146,11 +147,7 @@ public class TestSparkJdbcPushDownPolicy {
.updated("driver", "org.postgresql.Driver")
.updated("pushDownPredicate", "true")
.updated("pushDownLimit", "true"));
- SparkJdbcScanBuilder builder =
- new SparkJdbcScanBuilder(
- new JDBCScanBuilder(
- mock(SparkSession.class, RETURNS_DEEP_STUBS), sparkSchema(),
options),
- policy);
+ SparkJdbcScanBuilder builder = new
SparkJdbcScanBuilder(jdbcScanBuilder(options), policy);
Predicate safe = eq(col("id"), lit(1, DataTypes.IntegerType));
Predicate unsafe = eq(col("s"), lit("a", DataTypes.StringType));
@@ -224,11 +221,7 @@ public class TestSparkJdbcPushDownPolicy {
.updated("dbtable", "t")
.updated("driver", "org.postgresql.Driver")
.updated("pushDownPredicate", "false"));
- SparkJdbcScanBuilder builder =
- new SparkJdbcScanBuilder(
- new JDBCScanBuilder(
- mock(SparkSession.class, RETURNS_DEEP_STUBS), sparkSchema(),
options),
- policy());
+ SparkJdbcScanBuilder builder = new
SparkJdbcScanBuilder(jdbcScanBuilder(options), policy());
Predicate prefilter = eq(col("s"), lit("a", DataTypes.StringType));
Predicate numeric = eq(col("id"), lit(1, DataTypes.IntegerType));
Predicate[] residual = builder.pushPredicates(new Predicate[] {prefilter,
numeric});
@@ -316,6 +309,17 @@ public class TestSparkJdbcPushDownPolicy {
}
}
+ // JDBCScanBuilder's constructor gained a parameter in Spark 4.1, so stub
the accessors that
+ // SparkJdbcScanBuilder copies from its delegate instead of calling the
constructor here.
+ private static JDBCScanBuilder jdbcScanBuilder(JDBCOptions options) {
+ JDBCScanBuilder delegate = mock(JDBCScanBuilder.class);
+ SparkSession session = mock(SparkSession.class, RETURNS_DEEP_STUBS);
+ when(delegate.session()).thenReturn(session);
+ when(delegate.schema()).thenReturn(sparkSchema());
+ when(delegate.jdbcOptions()).thenReturn(options);
+ return delegate;
+ }
+
private static SparkJdbcPushDownPolicy policy() {
return policy(URL);
}
diff --git a/spark-connector/v4.0/spark/build.gradle.kts
b/spark-connector/v4.0/spark/build.gradle.kts
index 1aa122f1ec..0b80f57171 100644
--- a/spark-connector/v4.0/spark/build.gradle.kts
+++ b/spark-connector/v4.0/spark/build.gradle.kts
@@ -45,8 +45,9 @@ val jakartaValidationVersion: String = "2.0.2"
val artifactName =
"${rootProject.name}-spark-${sparkMajorVersion}_$scalaVersion"
// The connector's shared sources are compiled here rather than consumed as a
jar, so that every
-// supported Spark version builds them against its own API. Everything a Spark
4 build needs its own
-// copy of lives in this module's own src/main/java, so no flavor directory is
composed in.
+// supported Spark version builds them against its own API. The spark40
directory holds the shared
+// classes whose superclass constructor differs on this line; everything else
this build needs its
+// own copy of lives in src/main/java.
val sparkCommonDir =
project(":spark-connector").projectDir.resolve("spark-common")
sourceSets {
@@ -55,6 +56,7 @@ sourceSets {
setSrcDirs(
listOf(
"$sparkCommonDir/src/main/java",
+ "$sparkCommonDir/src/main/spark40",
"src/main/java"
)
)
diff --git a/spark-connector/v4.1/spark-runtime/build.gradle.kts
b/spark-connector/v4.1/spark-runtime/build.gradle.kts
new file mode 100644
index 0000000000..f5f985772e
--- /dev/null
+++ b/spark-connector/v4.1/spark-runtime/build.gradle.kts
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
+
+plugins {
+ `maven-publish`
+ id("java")
+ alias(libs.plugins.shadow)
+}
+
+// Spark 4 is Scala 2.13 only.
+val scalaVersion: String = "2.13"
+val sparkVersion: String = libs.versions.spark41.get()
+val sparkMajorVersion: String = sparkVersion.substringBeforeLast(".")
+val kyuubiVersion: String = libs.versions.kyuubi4spark.get()
+val baseName =
"${rootProject.name}-spark-connector-runtime-${sparkMajorVersion}_$scalaVersion"
+
+dependencies {
+ implementation(project(":clients:client-java-runtime", configuration =
"shadow"))
+ implementation(project(":spark-connector:spark-4.1"))
+
implementation("org.apache.kyuubi:kyuubi-spark-connector-hive_$scalaVersion:$kyuubiVersion")
+}
+
+tasks.withType<ShadowJar>(ShadowJar::class.java) {
+ isZip64 = true
+ configurations = listOf(project.configurations.runtimeClasspath.get())
+ archiveFileName.set("$baseName-$version.jar")
+ archiveClassifier.set("")
+
+ exclude("org/slf4j/**")
+
+ // Relocate dependencies to avoid conflicts
+ relocate("com.google", "org.apache.gravitino.shaded.com.google")
+ relocate("google", "org.apache.gravitino.shaded.google")
+ relocate("org.apache.hc", "org.apache.gravitino.shaded.org.apache.hc")
+ relocate("com.github.benmanes.caffeine",
"org.apache.gravitino.shaded.com.github.benmanes.caffeine")
+}
+
+publishing {
+ publications {
+ withType<MavenPublication>().configureEach {
+ artifactId = baseName
+ }
+ }
+}
+
+tasks.jar {
+ dependsOn(tasks.named("shadowJar"))
+ archiveClassifier.set("empty")
+}
diff --git a/spark-connector/v4.0/spark/build.gradle.kts
b/spark-connector/v4.1/spark/build.gradle.kts
similarity index 93%
copy from spark-connector/v4.0/spark/build.gradle.kts
copy to spark-connector/v4.1/spark/build.gradle.kts
index 1aa122f1ec..90653f35de 100644
--- a/spark-connector/v4.0/spark/build.gradle.kts
+++ b/spark-connector/v4.1/spark/build.gradle.kts
@@ -31,9 +31,9 @@ repositories {
// Spark 4 is Scala 2.13 only.
val scalaVersion: String = "2.13"
-val sparkVersion: String = libs.versions.spark40.get()
+val sparkVersion: String = libs.versions.spark41.get()
val sparkMajorVersion: String = sparkVersion.substringBeforeLast(".")
-val icebergVersion: String = libs.versions.iceberg4spark40.get()
+val icebergVersion: String = libs.versions.iceberg4spark41.get()
val kyuubiVersion: String = libs.versions.kyuubi4spark.get()
val scalaCollectionCompatVersion: String =
libs.versions.scala.collection.compat.get()
val jerseyVersion: String = libs.versions.jersey.get()
@@ -45,8 +45,9 @@ val jakartaValidationVersion: String = "2.0.2"
val artifactName =
"${rootProject.name}-spark-${sparkMajorVersion}_$scalaVersion"
// The connector's shared sources are compiled here rather than consumed as a
jar, so that every
-// supported Spark version builds them against its own API. Everything a Spark
4 build needs its own
-// copy of lives in this module's own src/main/java, so no flavor directory is
composed in.
+// supported Spark version builds them against its own API. The spark41
directory holds the shared
+// classes whose superclass constructor differs on this line; everything else
this build needs its
+// own copy of lives in src/main/java.
val sparkCommonDir =
project(":spark-connector").projectDir.resolve("spark-common")
sourceSets {
@@ -55,6 +56,7 @@ sourceSets {
setSrcDirs(
listOf(
"$sparkCommonDir/src/main/java",
+ "$sparkCommonDir/src/main/spark41",
"src/main/java"
)
)
@@ -78,11 +80,11 @@ sourceSets {
}
}
-// Paimon publishes no paimon-spark-4.x artifact at the version this
repository pins, so the Paimon
-// classes stay out of the Spark 4 builds. They live in
spark-common/src/main/spark35 and are not on
-// this module's source path; the shared tests that exercise them are excluded
here. The two shared
-// test utilities that mention Paimon reach it by simple class name and
provider string, so they need
-// no exclusion.
+// Paimon publishes no paimon-spark-4.1 artifact at the versions released so
far, so the Paimon
+// classes stay out of this build. They live in spark-common/src/main/spark35
and are not on this
+// module's source path; the shared tests that exercise them are excluded
here. The two shared test
+// utilities that mention Paimon reach it by simple class name and provider
string, so they need no
+// exclusion.
sourceSets {
named("test") {
java {
diff --git
a/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/authorization/GravitinoAuthorizationSparkSessionExtensions.java
b/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/authorization/GravitinoAuthorizationSparkSessionExtensions.java
new file mode 100644
index 0000000000..8dce471b30
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/authorization/GravitinoAuthorizationSparkSessionExtensions.java
@@ -0,0 +1,41 @@
+/*
+ * 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.gravitino.spark.connector.authorization;
+
+import org.apache.spark.sql.SparkSessionExtensions;
+import scala.Function1;
+
+/**
+ * Registers Gravitino authorization checks with a Spark session.
+ *
+ * <p>Post-hoc resolution runs after every relation is resolved but before
checkAnalysis, so all
+ * denied tables are reported together rather than failing on the first
resolution error. The
+ * denials are read from the analyzed plan itself, so no session state is
carried between queries
+ * and no parser wrapper is needed.
+ */
+public class GravitinoAuthorizationSparkSessionExtensions
+ implements Function1<SparkSessionExtensions, Void> {
+
+ @Override
+ public Void apply(SparkSessionExtensions extensions) {
+ extensions.injectPostHocResolutionRule(session -> new
RequiredPrivilegesCheck());
+ return null;
+ }
+}
diff --git
a/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/glue/GravitinoGlueCatalogSpark41.java
b/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/glue/GravitinoGlueCatalogSpark41.java
new file mode 100644
index 0000000000..c7aad2d04a
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/glue/GravitinoGlueCatalogSpark41.java
@@ -0,0 +1,22 @@
+/*
+ * 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.gravitino.spark.connector.glue;
+
+/** Spark 4.1 specific Gravitino Glue catalog implementation. */
+public class GravitinoGlueCatalogSpark41 extends GravitinoGlueCatalog {}
diff --git
a/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/hive/GravitinoHiveCatalogSpark41.java
b/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/hive/GravitinoHiveCatalogSpark41.java
new file mode 100644
index 0000000000..748f0e4438
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/hive/GravitinoHiveCatalogSpark41.java
@@ -0,0 +1,22 @@
+/*
+ * 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.gravitino.spark.connector.hive;
+
+/** Spark 4.1 specific Gravitino Hive catalog implementation. */
+public class GravitinoHiveCatalogSpark41 extends GravitinoHiveCatalog {}
diff --git
a/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/iceberg/GravitinoIcebergCatalogSpark41.java
b/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/iceberg/GravitinoIcebergCatalogSpark41.java
new file mode 100644
index 0000000000..4d0660cbb9
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/iceberg/GravitinoIcebergCatalogSpark41.java
@@ -0,0 +1,125 @@
+/*
+ * 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.gravitino.spark.connector.iceberg;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.gravitino.rel.Table;
+import org.apache.iceberg.spark.procedures.SparkProcedures;
+import org.apache.iceberg.spark.source.SparkTable;
+import org.apache.spark.sql.catalyst.analysis.NoSuchTableException;
+import org.apache.spark.sql.connector.catalog.Identifier;
+import org.apache.spark.sql.connector.catalog.ProcedureCatalog;
+import org.apache.spark.sql.connector.catalog.procedures.UnboundProcedure;
+
+/**
+ * Spark 4.1 specific Gravitino Iceberg catalog implementation. {@link
ProcedureCatalog} is declared
+ * here rather than in the shared base because Spark 4 moved the procedure
types out of Iceberg's
+ * package into its own and changed {@code loadProcedure} to return {@link
UnboundProcedure}.
+ */
+public class GravitinoIcebergCatalogSpark41 extends GravitinoIcebergCatalog
+ implements ProcedureCatalog {
+
+ private static final Pattern BRANCH_SELECTOR =
Pattern.compile("branch_(.*)");
+
+ /**
+ * Also loads {@code <database>.<table>.branch_<name>} as that branch of the
table. Iceberg's
+ * Spark 4.1 extensions resolve the {@code branch} read option and the WAP
branch by renaming the
+ * relation this way, and Spark 4.1 loads the relation again by that name
before running the
+ * query. A query that names {@code <database>.<table>.branch_<name>}
directly reads the branch
+ * the same way; the loaded table refuses Spark writes and deletes.
+ *
+ * @param ident the table identifier
+ * @return the loaded table
+ * @throws NoSuchTableException if the table does not exist
+ */
+ @Override
+ public org.apache.spark.sql.connector.catalog.Table loadTable(Identifier
ident)
+ throws NoSuchTableException {
+ Matcher branch = BRANCH_SELECTOR.matcher(ident.name());
+ if (ident.namespace().length != 2 || !branch.matches()) {
+ return super.loadTable(ident);
+ }
+ Identifier tableIdent =
+ Identifier.of(new String[] {ident.namespace()[0]},
ident.namespace()[1]);
+ // A denied table throws here rather than returning
AuthorizationTable.deny: when Spark loads
+ // the relation again, it would report the placeholder only as a changed
table id.
+ Table gravitinoTable = loadGravitinoTable(tableIdent);
+ SparkTable sparkTable = (SparkTable) loadSparkTable(tableIdent);
+ return createSparkTable(
+ tableIdent,
+ gravitinoTable,
+ SparkTable.create(sparkTable.table(), branch.group(1)),
+ sparkCatalog,
+ propertiesConverter,
+ sparkTransformConverter,
+ getSparkTypeConverter());
+ }
+
+ /**
+ * Procedures validate that the catalog registered with Spark's
catalogManager is the same one
+ * passed to the {@code ProcedureBuilder} that invokes loadProcedure(). Pass
this catalog rather
+ * than the internal Spark catalog to satisfy that check.
+ */
+ @Override
+ public UnboundProcedure loadProcedure(Identifier identifier) {
+ String[] namespace = identifier.namespace();
+ String name = identifier.name();
+
+ try {
+ if (isSystemNamespace(namespace)) {
+ SparkProcedures.ProcedureBuilder builder =
SparkProcedures.newBuilder(name);
+ if (builder != null) {
+ return builder.withTableCatalog(this).build();
+ }
+ }
+ } catch (NoSuchMethodException
+ | IllegalAccessException
+ | InvocationTargetException
+ | ClassNotFoundException e) {
+ throw new RuntimeException("Failed to load Iceberg Procedure " +
identifier, e);
+ }
+
+ // Spark 4 ships no NoSuchProcedureException: it wraps whatever
loadProcedure throws in
+ // FAILED_TO_LOAD_ROUTINE unless the exception is already a
SparkThrowable. Iceberg's own
+ // BaseCatalog throws a plain RuntimeException here for the same reason,
so match it.
+ throw new RuntimeException("Procedure does not exist: " + identifier);
+ }
+
+ /** Spark 4.1 added this method to {@code ProcedureCatalog}; Spark 4.0 has
no equivalent. */
+ @Override
+ public Identifier[] listProcedures(String[] namespace) {
+ try {
+ if (isSystemNamespace(namespace)) {
+ return SparkProcedures.names().stream()
+ .map(name -> Identifier.of(namespace, name))
+ .toArray(Identifier[]::new);
+ }
+ } catch (NoSuchMethodException
+ | IllegalAccessException
+ | InvocationTargetException
+ | ClassNotFoundException e) {
+ throw new RuntimeException(
+ "Failed to list Iceberg Procedures under " +
Arrays.toString(namespace), e);
+ }
+ return new Identifier[0];
+ }
+}
diff --git
a/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/jdbc/GravitinoJdbcCatalogSpark41.java
b/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/jdbc/GravitinoJdbcCatalogSpark41.java
new file mode 100644
index 0000000000..bcc51f8b25
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/jdbc/GravitinoJdbcCatalogSpark41.java
@@ -0,0 +1,22 @@
+/*
+ * 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.gravitino.spark.connector.jdbc;
+
+/** Spark 4.1 specific Gravitino JDBC catalog implementation. */
+public class GravitinoJdbcCatalogSpark41 extends GravitinoJdbcCatalog {}
diff --git
a/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/jdbc/postgresql/GravitinoPostgreSqlCatalogSpark41.java
b/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/jdbc/postgresql/GravitinoPostgreSqlCatalogSpark41.java
new file mode 100644
index 0000000000..8a2afc5d49
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/jdbc/postgresql/GravitinoPostgreSqlCatalogSpark41.java
@@ -0,0 +1,31 @@
+/*
+ * 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.gravitino.spark.connector.jdbc.postgresql;
+
+import org.apache.gravitino.spark.connector.PropertiesConverter;
+import org.apache.gravitino.spark.connector.jdbc.GravitinoJdbcCatalog;
+import org.apache.gravitino.spark.connector.jdbc.JdbcPropertiesConverter;
+
+/** Spark 4.1 specific Gravitino PostgreSQL catalog implementation. */
+public class GravitinoPostgreSqlCatalogSpark41 extends GravitinoJdbcCatalog {
+ @Override
+ protected PropertiesConverter getPropertiesConverter() {
+ return JdbcPropertiesConverter.getNoTablePropertiesInstance();
+ }
+}
diff --git
a/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/plugin/GravitinoSparkPlugin.java
b/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/plugin/GravitinoSparkPlugin.java
new file mode 100644
index 0000000000..50cea1c486
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/main/java/org/apache/gravitino/spark/connector/plugin/GravitinoSparkPlugin.java
@@ -0,0 +1,66 @@
+/*
+ * 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.gravitino.spark.connector.plugin;
+
+import
org.apache.gravitino.spark.connector.authorization.GravitinoAuthorizationSparkSessionExtensions;
+import org.apache.gravitino.spark.connector.catalog.SparkCatalogKind;
+import org.apache.gravitino.spark.connector.glue.GravitinoGlueCatalogSpark41;
+import org.apache.gravitino.spark.connector.hive.GravitinoHiveCatalogSpark41;
+import
org.apache.gravitino.spark.connector.iceberg.GravitinoIcebergCatalogSpark41;
+import org.apache.gravitino.spark.connector.jdbc.GravitinoJdbcCatalogSpark41;
+import
org.apache.gravitino.spark.connector.jdbc.postgresql.GravitinoPostgreSqlCatalogSpark41;
+import org.apache.spark.api.plugin.DriverPlugin;
+import org.apache.spark.api.plugin.ExecutorPlugin;
+import org.apache.spark.api.plugin.SparkPlugin;
+
+/**
+ * The entrypoint for Apache Gravitino Spark connector on Spark 4.1.
+ *
+ * <p>Every supported Spark version has a class of this name in this package,
which is what users
+ * name in {@code spark.plugins}. Each one binds the classes its own Spark
version needs, as
+ * compile-time class references, so a renamed or missing class fails the
build rather than the
+ * session, and a jar can only bind classes it actually contains.
+ *
+ * <p>No Paimon catalog is bound: Paimon publishes no {@code paimon-spark-4.1}
artifact at the
+ * versions released so far, so the Spark 4.1 build has no Paimon catalog to
name.
+ */
+public class GravitinoSparkPlugin implements SparkPlugin {
+
+ @Override
+ public DriverPlugin driverPlugin() {
+ return new GravitinoDriverPlugin(bindings());
+ }
+
+ @Override
+ public ExecutorPlugin executorPlugin() {
+ return null;
+ }
+
+ private static SparkBindings bindings() {
+ return SparkBindings.builder()
+
.authorizationExtension(GravitinoAuthorizationSparkSessionExtensions.class)
+ .catalog(SparkCatalogKind.HIVE, GravitinoHiveCatalogSpark41.class)
+ .catalog(SparkCatalogKind.LAKEHOUSE_ICEBERG,
GravitinoIcebergCatalogSpark41.class)
+ .catalog(SparkCatalogKind.GLUE, GravitinoGlueCatalogSpark41.class)
+ .catalog(SparkCatalogKind.JDBC, GravitinoJdbcCatalogSpark41.class)
+ .catalog(SparkCatalogKind.JDBC_POSTGRESQL,
GravitinoPostgreSqlCatalogSpark41.class)
+ .build();
+ }
+}
diff --git
a/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/iceberg/TestGravitinoIcebergCatalogSpark41.java
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/iceberg/TestGravitinoIcebergCatalogSpark41.java
new file mode 100644
index 0000000000..f41e7b29e4
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/iceberg/TestGravitinoIcebergCatalogSpark41.java
@@ -0,0 +1,174 @@
+/*
+ * 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.gravitino.spark.connector.iceberg;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import org.apache.gravitino.Catalog;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.authorization.Privilege;
+import org.apache.gravitino.client.GravitinoClient;
+import org.apache.gravitino.exceptions.ForbiddenException;
+import org.apache.gravitino.rel.Table;
+import org.apache.gravitino.rel.TableCatalog;
+import org.apache.gravitino.spark.connector.catalog.GravitinoCatalogManager;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.SnapshotRef;
+import org.apache.iceberg.spark.SparkCatalog;
+import org.apache.iceberg.spark.source.SparkTable;
+import org.apache.iceberg.types.Types;
+import org.apache.spark.SparkConf;
+import org.apache.spark.sql.connector.catalog.Identifier;
+import org.apache.spark.sql.connector.expressions.filter.Predicate;
+import org.apache.spark.sql.connector.write.LogicalWriteInfo;
+import org.apache.spark.sql.connector.write.RowLevelOperationInfo;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+public class TestGravitinoIcebergCatalogSpark41 {
+
+ private static final Identifier TABLE = Identifier.of(new String[] {"db"},
"t");
+ // The name Iceberg's ResolveBranch gives a relation that reads branch
"audit" of db.t.
+ private static final Identifier AUDIT_BRANCH =
+ Identifier.of(new String[] {"db", "t"}, "branch_audit");
+
+ private TableCatalog gravitinoTableCatalog;
+ private SparkCatalog sparkCatalog;
+ private TestCatalog catalog;
+
+ @BeforeAll
+ void initCatalogManager() {
+ GravitinoCatalogManager.create(
+ new SparkConf(false), "user", identity -> mock(GravitinoClient.class));
+ }
+
+ @AfterAll
+ void closeCatalogManager() {
+ GravitinoCatalogManager.get().close();
+ }
+
+ @BeforeEach
+ void setUp() {
+ Catalog gravitinoCatalog = mock(Catalog.class);
+ gravitinoTableCatalog = mock(TableCatalog.class);
+ when(gravitinoCatalog.asTableCatalog()).thenReturn(gravitinoTableCatalog);
+ sparkCatalog = mock(SparkCatalog.class);
+ catalog = new TestCatalog(gravitinoCatalog, sparkCatalog);
+ }
+
+ @Test
+ void testBranchSelectorLoadsTheBranchOfTheTable() throws Exception {
+ SparkIcebergTable loaded = loadAuditBranch();
+
+ assertEquals("db.t", loaded.name());
+ // ResolveBranch switches the relation to the branch again unless branch()
reports it.
+ assertEquals("audit", loaded.branch());
+ assertEquals(2L, loaded.snapshotId());
+ verify(sparkCatalog).loadTable(TABLE);
+ }
+
+ @Test
+ void testTableLoadedByBranchNameRefusesWrites() throws Exception {
+ SparkIcebergTable loaded = loadAuditBranch();
+
+ assertThrows(
+ UnsupportedOperationException.class,
+ () -> loaded.newWriteBuilder(mock(LogicalWriteInfo.class)));
+ assertThrows(
+ UnsupportedOperationException.class,
+ () ->
loaded.newRowLevelOperationBuilder(mock(RowLevelOperationInfo.class)));
+ assertThrows(UnsupportedOperationException.class, loaded::truncateTable);
+ assertThrows(UnsupportedOperationException.class, () ->
loaded.deleteWhere(new Predicate[0]));
+ }
+
+ @Test
+ void testDeniedBranchSelectorDoesNotLoadTheIcebergTable() {
+ when(gravitinoTableCatalog.loadTable(
+ NameIdentifier.of("db", "t"),
ImmutableSet.of(Privilege.Name.SELECT_TABLE)))
+ .thenThrow(new ForbiddenException("denied"));
+
+ assertThrows(ForbiddenException.class, () ->
catalog.loadTable(AUDIT_BRANCH));
+ verifyNoInteractions(sparkCatalog);
+ }
+
+ @Test
+ void testOtherMultiLevelNamesAreStillRejected() {
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> catalog.loadTable(Identifier.of(new String[] {"db", "t"},
"tag_v1")));
+ verifyNoInteractions(gravitinoTableCatalog, sparkCatalog);
+ }
+
+ private SparkIcebergTable loadAuditBranch() throws Exception {
+ Table gravitinoTable = mock(Table.class);
+ when(gravitinoTableCatalog.loadTable(
+ NameIdentifier.of("db", "t"),
ImmutableSet.of(Privilege.Name.SELECT_TABLE)))
+ .thenReturn(gravitinoTable);
+ Snapshot main = snapshot(1L);
+ Snapshot audit = snapshot(2L);
+ org.apache.iceberg.Table icebergTable =
mock(org.apache.iceberg.Table.class);
+ when(icebergTable.schema())
+ .thenReturn(new Schema(Types.NestedField.required(1, "id",
Types.IntegerType.get())));
+ when(icebergTable.currentSnapshot()).thenReturn(main);
+ when(icebergTable.snapshot("audit")).thenReturn(audit);
+ when(icebergTable.refs())
+ .thenReturn(ImmutableMap.of("audit",
SnapshotRef.branchBuilder(2L).build()));
+ when(icebergTable.properties()).thenReturn(ImmutableMap.of());
+ when(gravitinoTable.name()).thenReturn("t");
+ SparkTable sparkTable = mock(SparkTable.class);
+ when(sparkTable.table()).thenReturn(icebergTable);
+ when(sparkCatalog.loadTable(TABLE)).thenReturn(sparkTable);
+ return assertInstanceOf(SparkIcebergTable.class,
catalog.loadTable(AUDIT_BRANCH));
+ }
+
+ private static Snapshot snapshot(long id) {
+ Snapshot snapshot = mock(Snapshot.class);
+ when(snapshot.snapshotId()).thenReturn(id);
+ return snapshot;
+ }
+
+ private static class TestCatalog extends GravitinoIcebergCatalogSpark41 {
+
+ private final Catalog gravitinoCatalog;
+
+ private TestCatalog(Catalog gravitinoCatalog, SparkCatalog sparkCatalog) {
+ this.gravitinoCatalog = gravitinoCatalog;
+ this.sparkCatalog = sparkCatalog;
+ }
+
+ @Override
+ protected Catalog gravitinoCatalog() {
+ return gravitinoCatalog;
+ }
+ }
+}
diff --git
a/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/authorization/SparkAuthorizationIT41.java
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/authorization/SparkAuthorizationIT41.java
new file mode 100644
index 0000000000..06980758b4
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/authorization/SparkAuthorizationIT41.java
@@ -0,0 +1,22 @@
+/*
+ * 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.gravitino.spark.connector.integration.test.authorization;
+
+/** Spark 4.1 authorization integration tests. */
+public class SparkAuthorizationIT41 extends SparkAuthorizationIT {}
diff --git
a/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/authorization/SparkJwksAuthorizationIT41.java
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/authorization/SparkJwksAuthorizationIT41.java
new file mode 100644
index 0000000000..0bdcc87423
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/authorization/SparkJwksAuthorizationIT41.java
@@ -0,0 +1,22 @@
+/*
+ * 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.gravitino.spark.connector.integration.test.authorization;
+
+/** Spark 4.1 authorization integration tests against a JWKS-backed Gravitino
server. */
+public class SparkJwksAuthorizationIT41 extends SparkJwksAuthorizationIT {}
diff --git
a/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/hive/SparkHiveCatalogIT41.java
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/hive/SparkHiveCatalogIT41.java
new file mode 100644
index 0000000000..560095bff4
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/hive/SparkHiveCatalogIT41.java
@@ -0,0 +1,35 @@
+/*
+ * 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.gravitino.spark.connector.integration.test.hive;
+
+import org.apache.gravitino.spark.connector.hive.GravitinoHiveCatalogSpark41;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class SparkHiveCatalogIT41 extends SparkHiveCatalogIT {
+ @Test
+ void testCatalogClassName() {
+ String catalogClass =
+ getSparkSession()
+ .sessionState()
+ .conf()
+ .getConfString("spark.sql.catalog." + getCatalogName());
+ Assertions.assertEquals(GravitinoHiveCatalogSpark41.class.getName(),
catalogClass);
+ }
+}
diff --git
a/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/iceberg/IcebergMetadataColumnsSpark41.java
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/iceberg/IcebergMetadataColumnsSpark41.java
new file mode 100644
index 0000000000..8439ca499d
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/iceberg/IcebergMetadataColumnsSpark41.java
@@ -0,0 +1,54 @@
+/*
+ * 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.gravitino.spark.connector.integration.test.iceberg;
+
+import
org.apache.gravitino.spark.connector.integration.test.util.SparkMetadataColumnInfo;
+import org.apache.spark.sql.types.DataTypes;
+import org.apache.spark.sql.types.StructField;
+
+/**
+ * The metadata columns Iceberg reports from its Spark 4.1 module, which
differ from its 3.5 one.
+ *
+ * <p>The row-lineage columns ({@code _row_id}, {@code
_last_updated_sequence_number}) only show up
+ * for tables that support row lineage, meaning format version 3 and above,
while the 3.5 module
+ * reports them unconditionally; these ITs create format version 2 tables,
Iceberg's default. {@code
+ * _spec_id} is also nullable here and non-nullable on 3.5.
+ *
+ * <p>Every Iceberg IT on this line needs the same answer, and the two
backends inherit from
+ * different shared bases, so it lives here rather than being overridden twice.
+ */
+final class IcebergMetadataColumnsSpark41 {
+
+ private IcebergMetadataColumnsSpark41() {}
+
+ /** Returns a fresh array each call: the shared ITs mutate entries of it in
place. */
+ static SparkMetadataColumnInfo[] newMetadataColumns() {
+ return new SparkMetadataColumnInfo[] {
+ new SparkMetadataColumnInfo("_spec_id", DataTypes.IntegerType, true),
+ new SparkMetadataColumnInfo(
+ "_partition",
+ DataTypes.createStructType(
+ new StructField[] {DataTypes.createStructField("name",
DataTypes.StringType, true)}),
+ true),
+ new SparkMetadataColumnInfo("_file", DataTypes.StringType, false),
+ new SparkMetadataColumnInfo("_pos", DataTypes.LongType, false),
+ new SparkMetadataColumnInfo("_deleted", DataTypes.BooleanType, false)
+ };
+ }
+}
diff --git
a/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/iceberg/SparkIcebergCatalogHiveBackendIT41.java
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/iceberg/SparkIcebergCatalogHiveBackendIT41.java
new file mode 100644
index 0000000000..8b540d545b
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/iceberg/SparkIcebergCatalogHiveBackendIT41.java
@@ -0,0 +1,47 @@
+/*
+ * 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.gravitino.spark.connector.integration.test.iceberg;
+
+import
org.apache.gravitino.spark.connector.iceberg.GravitinoIcebergCatalogSpark41;
+import
org.apache.gravitino.spark.connector.integration.test.util.SparkMetadataColumnInfo;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class SparkIcebergCatalogHiveBackendIT41 extends
SparkIcebergCatalogHiveBackendIT {
+
+ @Test
+ void testCatalogClassName() {
+ String catalogClass =
+ getSparkSession()
+ .sessionState()
+ .conf()
+ .getConfString("spark.sql.catalog." + getCatalogName());
+ Assertions.assertEquals(GravitinoIcebergCatalogSpark41.class.getName(),
catalogClass);
+ }
+
+ @Override
+ protected SparkMetadataColumnInfo[] getIcebergMetadataColumns() {
+ return IcebergMetadataColumnsSpark41.newMetadataColumns();
+ }
+
+ @Override
+ protected Class<? extends Throwable> unknownVersionException() {
+ return IllegalArgumentException.class;
+ }
+}
diff --git
a/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/iceberg/SparkIcebergCatalogRestBackendIT41.java
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/iceberg/SparkIcebergCatalogRestBackendIT41.java
new file mode 100644
index 0000000000..b206130471
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/iceberg/SparkIcebergCatalogRestBackendIT41.java
@@ -0,0 +1,40 @@
+/*
+ * 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.gravitino.spark.connector.integration.test.iceberg;
+
+import
org.apache.gravitino.spark.connector.integration.test.util.SparkMetadataColumnInfo;
+import org.junit.jupiter.api.condition.DisabledIf;
+
+/**
+ * Runs the shared Iceberg suite against the Iceberg REST backend on Spark
4.1. The base is disabled
+ * in embedded mode; repeating the condition here matches what the 3.5
subclass does.
+ */
+@DisabledIf("org.apache.gravitino.integration.test.util.ITUtils#isEmbedded")
+public class SparkIcebergCatalogRestBackendIT41 extends
SparkIcebergCatalogRestBackendIT {
+
+ @Override
+ protected SparkMetadataColumnInfo[] getIcebergMetadataColumns() {
+ return IcebergMetadataColumnsSpark41.newMetadataColumns();
+ }
+
+ @Override
+ protected Class<? extends Throwable> unknownVersionException() {
+ return IllegalArgumentException.class;
+ }
+}
diff --git
a/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/iceberg/SparkIcebergCatalogRestRoutingIT41.java
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/iceberg/SparkIcebergCatalogRestRoutingIT41.java
new file mode 100644
index 0000000000..281a0be9cd
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/iceberg/SparkIcebergCatalogRestRoutingIT41.java
@@ -0,0 +1,41 @@
+/*
+ * 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.gravitino.spark.connector.integration.test.iceberg;
+
+import
org.apache.gravitino.spark.connector.integration.test.util.SparkMetadataColumnInfo;
+import org.junit.jupiter.api.condition.DisabledIf;
+
+/**
+ * Runs the shared Iceberg suite against a Hive-backed catalog routed through
the Iceberg REST
+ * server on Spark 4.1. The base is disabled in embedded mode; repeating the
condition here matches
+ * what the 3.5 subclass does.
+ */
+@DisabledIf("org.apache.gravitino.integration.test.util.ITUtils#isEmbedded")
+public class SparkIcebergCatalogRestRoutingIT41 extends
SparkIcebergCatalogRestRoutingIT {
+
+ @Override
+ protected SparkMetadataColumnInfo[] getIcebergMetadataColumns() {
+ return IcebergMetadataColumnsSpark41.newMetadataColumns();
+ }
+
+ @Override
+ protected Class<? extends Throwable> unknownVersionException() {
+ return IllegalArgumentException.class;
+ }
+}
diff --git
a/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/jdbc/SparkJdbcMysqlCatalogIT41.java
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/jdbc/SparkJdbcMysqlCatalogIT41.java
new file mode 100644
index 0000000000..d45c747d1c
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/jdbc/SparkJdbcMysqlCatalogIT41.java
@@ -0,0 +1,35 @@
+/*
+ * 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.gravitino.spark.connector.integration.test.jdbc;
+
+import org.apache.gravitino.spark.connector.jdbc.GravitinoJdbcCatalogSpark41;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class SparkJdbcMysqlCatalogIT41 extends SparkJdbcMysqlCatalogIT {
+ @Test
+ void testCatalogClassName() {
+ String catalogClass =
+ getSparkSession()
+ .sessionState()
+ .conf()
+ .getConfString("spark.sql.catalog." + getCatalogName());
+ Assertions.assertEquals(GravitinoJdbcCatalogSpark41.class.getName(),
catalogClass);
+ }
+}
diff --git
a/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/jdbc/SparkJdbcPostgreSqlCatalogIT41.java
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/jdbc/SparkJdbcPostgreSqlCatalogIT41.java
new file mode 100644
index 0000000000..103de44fe8
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/integration/test/jdbc/SparkJdbcPostgreSqlCatalogIT41.java
@@ -0,0 +1,35 @@
+/*
+ * 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.gravitino.spark.connector.integration.test.jdbc;
+
+import
org.apache.gravitino.spark.connector.jdbc.postgresql.GravitinoPostgreSqlCatalogSpark41;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class SparkJdbcPostgreSqlCatalogIT41 extends
SparkJdbcPostgreSqlCatalogIT {
+ @Test
+ void testCatalogClassName() {
+ String catalogClass =
+ getSparkSession()
+ .sessionState()
+ .conf()
+ .getConfString("spark.sql.catalog." + getCatalogName());
+ Assertions.assertEquals(GravitinoPostgreSqlCatalogSpark41.class.getName(),
catalogClass);
+ }
+}
diff --git
a/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestSparkJdbcScanBuilderJoinPushDown.java
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestSparkJdbcScanBuilderJoinPushDown.java
new file mode 100644
index 0000000000..4801facf18
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestSparkJdbcScanBuilderJoinPushDown.java
@@ -0,0 +1,79 @@
+/*
+ * 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.gravitino.spark.connector.jdbc;
+
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+
+import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.types.Types;
+import org.apache.spark.sql.SparkSession;
+import org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions;
+import org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCScanBuilder;
+import org.apache.spark.sql.execution.metric.SQLMetric;
+import org.apache.spark.sql.jdbc.JdbcDialects;
+import org.apache.spark.sql.types.DataTypes;
+import org.apache.spark.sql.types.StructType;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import scala.collection.immutable.HashMap;
+
+public class TestSparkJdbcScanBuilderJoinPushDown {
+
+ private static final String URL = "jdbc:postgresql://localhost/test";
+ private static final StructType SCHEMA =
+ new StructType().add("id", DataTypes.IntegerType).add("s",
DataTypes.StringType);
+
+ @Test
+ void testJoinsOfGravitinoTablesStayInSpark() {
+ JDBCScanBuilder left = jdbcScanBuilder("a");
+ JDBCScanBuilder right = jdbcScanBuilder("b");
+ // Spark's own builders accept each other as join sides: both read the
same PostgreSQL source.
+ Assertions.assertTrue(left.isOtherSideCompatibleForJoin(right));
+
+ SparkJdbcPushDownPolicy policy =
+ new SparkJdbcPushDownPolicy(
+ new Column[] {
+ Column.of("id", Types.IntegerType.get()), Column.of("s",
Types.StringType.get())
+ },
+ SCHEMA,
+ SCHEMA,
+ JdbcDialects.get(URL),
+ URL);
+ SparkJdbcScanBuilder gravitinoLeft = new SparkJdbcScanBuilder(left,
policy);
+ Assertions.assertFalse(
+ gravitinoLeft.isOtherSideCompatibleForJoin(new
SparkJdbcScanBuilder(right, policy)));
+ Assertions.assertFalse(gravitinoLeft.isOtherSideCompatibleForJoin(right));
+ }
+
+ private static JDBCScanBuilder jdbcScanBuilder(String table) {
+ JDBCOptions options =
+ new JDBCOptions(
+ new HashMap<String, String>()
+ .updated("url", URL)
+ .updated("dbtable", table)
+ .updated("driver", "org.postgresql.Driver"));
+ return new JDBCScanBuilder(
+ mock(SparkSession.class, RETURNS_DEEP_STUBS),
+ SCHEMA,
+ options,
+ new HashMap<String, SQLMetric>());
+ }
+}
diff --git
a/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/plugin/TestGravitinoSparkPlugin.java
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/plugin/TestGravitinoSparkPlugin.java
new file mode 100644
index 0000000000..e7577f662b
--- /dev/null
+++
b/spark-connector/v4.1/spark/src/test/java/org/apache/gravitino/spark/connector/plugin/TestGravitinoSparkPlugin.java
@@ -0,0 +1,36 @@
+/*
+ * 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.gravitino.spark.connector.plugin;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests that this module's bindings are complete. Constructing the driver
plugin runs {@code
+ * SparkBindings.build()}, whose Preconditions reject a missing binding, so a
catalog this module
+ * forgot to bind fails here rather than at session startup.
+ */
+public class TestGravitinoSparkPlugin {
+
+ @Test
+ void testTheBindingsThisModuleDeclaresAreComplete() {
+ Assertions.assertNotNull(new GravitinoSparkPlugin().driverPlugin());
+ }
+}
diff --git a/spark-connector/v4.1/spark/src/test/resources/log4j2.properties
b/spark-connector/v4.1/spark/src/test/resources/log4j2.properties
new file mode 100644
index 0000000000..4f72cf653a
--- /dev/null
+++ b/spark-connector/v4.1/spark/src/test/resources/log4j2.properties
@@ -0,0 +1,47 @@
+#
+# 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.
+#
+
+# Set to debug or trace if log4j initialization is failing
+status = info
+
+# Name of the configuration
+name = ConsoleLogConfig
+
+# Console appender configuration
+appender.console.type = Console
+appender.console.name = consoleLogger
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L -
%m%n
+
+# Log files location
+property.logPath =
${sys:gravitino.log.path:-integration-test/build/integration-test.log}
+
+# File appender configuration
+appender.file.type = File
+appender.file.name = fileLogger
+appender.file.fileName = ${logPath}
+appender.file.layout.type = PatternLayout
+appender.file.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L -
%m%n
+
+# Root logger level
+rootLogger.level = info
+
+# Root logger referring to console and file appenders
+rootLogger.appenderRef.stdout.ref = consoleLogger
+rootLogger.appenderRef.file.ref = fileLogger