This is an automated email from the ASF dual-hosted git repository.
jerryshao 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 9cb34602a7 [MINOR] fix(spark-connector): Avoid a deprecated
StringUtils call that breaks the Spark 4.1 build (#15105)
9cb34602a7 is described below
commit 9cb34602a77962bac7cac300e643a7665b4bf921
Author: Bharath Krishna <[email protected]>
AuthorDate: Wed Nov 18 22:03:52 2026 -0800
[MINOR] fix(spark-connector): Avoid a deprecated StringUtils call that
breaks the Spark 4.1 build (#15105)
### What changes were proposed in this pull request?
Replaces `StringUtils.startsWithIgnoreCase` in
`LanceRESTCatalogProvider` with a case-insensitive
`String.regionMatches` check, and adds a test for which properties count
as headers.
### Why are the changes needed?
#14755 added the call, and #13019 then added the Spark 4.1 connector,
which compiles `spark-common` against a commons-lang3 version that
deprecates it. With `-Werror`, `:spark-connector:spark-4.1:compileJava`
fails, so the build fails on main and on every open PR.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Compiled the Spark 3.5, 4.0 and 4.1 connectors, and ran
`TestLanceRESTCatalogProvider`, including the new test.
---------
Co-authored-by: Claude Sonnet 5.5 <[email protected]>
---
.../restcatalog/lance/LanceRESTCatalogProvider.java | 10 ++++++++--
.../restcatalog/lance/TestLanceRESTCatalogProvider.java | 15 +++++++++++++++
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git
a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/plugin/restcatalog/lance/LanceRESTCatalogProvider.java
b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/plugin/restcatalog/lance/LanceRESTCatalogProvider.java
index 69aebdd452..0587ae76c2 100644
---
a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/plugin/restcatalog/lance/LanceRESTCatalogProvider.java
+++
b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/plugin/restcatalog/lance/LanceRESTCatalogProvider.java
@@ -65,7 +65,7 @@ public class LanceRESTCatalogProvider implements
LakehouseRESTCatalogProvider {
Map<String, String> headers = new LinkedHashMap<>();
properties.forEach(
(key, value) -> {
- if (StringUtils.startsWithIgnoreCase(key, HEADER_PREFIX)) {
+ if (isHeaderProperty(key)) {
String headerName = key.substring(HEADER_PREFIX.length());
Preconditions.checkArgument(
headerName.matches("[!#$%&'*+.^_`|~0-9A-Za-z-]+"),
@@ -81,7 +81,7 @@ public class LanceRESTCatalogProvider implements
LakehouseRESTCatalogProvider {
canonicalKey);
}
});
- properties.keySet().removeIf(key -> StringUtils.startsWithIgnoreCase(key,
HEADER_PREFIX));
+ properties.keySet().removeIf(LanceRESTCatalogProvider::isHeaderProperty);
properties.putAll(headers);
}
@@ -167,6 +167,12 @@ public class LanceRESTCatalogProvider implements
LakehouseRESTCatalogProvider {
return new String[] {SPARK_EXTENSIONS};
}
+ // Avoid StringUtils.startsWithIgnoreCase: deprecated in the commons-lang3
version used by
+ // Spark 4.1, and the connector compiles with -Werror.
+ private static boolean isHeaderProperty(@Nullable String key) {
+ return key != null && key.regionMatches(true, 0, HEADER_PREFIX, 0,
HEADER_PREFIX.length());
+ }
+
/**
* The Lance client uses the raw response body as the exception message,
which is empty for most
* error responses, so fall back to the reason phrase and finally to an
explicit placeholder
diff --git
a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/plugin/restcatalog/lance/TestLanceRESTCatalogProvider.java
b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/plugin/restcatalog/lance/TestLanceRESTCatalogProvider.java
index c1e47ab000..eb28741b76 100644
---
a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/plugin/restcatalog/lance/TestLanceRESTCatalogProvider.java
+++
b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/plugin/restcatalog/lance/TestLanceRESTCatalogProvider.java
@@ -107,6 +107,21 @@ public class TestLanceRESTCatalogProvider {
assertTrue(rawQueries.get(0).contains("delimiter=%23"));
}
+ @Test
+ void testNormalizesOnlyHeaderPropertiesCaseInsensitively() {
+ Map<String, String> properties = new LinkedHashMap<>();
+ properties.put(null, "untouched");
+ properties.put("headers", "ordinary property");
+ properties.put("HEADERS.X-Test", "value");
+
+ new LanceRESTCatalogProvider().normalizeCatalogProperties(properties);
+
+ assertEquals("untouched", properties.get(null));
+ assertEquals("ordinary property", properties.get("headers"));
+ assertEquals("value", properties.get("headers.x-test"));
+ assertFalse(properties.containsKey("HEADERS.X-Test"));
+ }
+
@Test
void testDiscoverySendsOneAuthorizationValuePerPageForIdenticalHeaders() {
List<String> authorizationHeaders = new CopyOnWriteArrayList<>();