This is an automated email from the ASF dual-hosted git repository.

jshao 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 822871b4fe [#7416] fix(catalog-hive): Fix empty bypass key handling in 
HiveCatalogOperations (#7417)
822871b4fe is described below

commit 822871b4fed48a072f1fe2da62e61592cd145bb1
Author: liuxian <[email protected]>
AuthorDate: Wed Jun 18 00:13:10 2025 +0800

    [#7416] fix(catalog-hive): Fix empty bypass key handling in 
HiveCatalogOperations (#7417)
    
    ### What changes were proposed in this pull request?
    
    [#7416] feat(catalog-hive): Fix empty bypass key handling in
    HiveCatalogOperations
    
    ### Why are the changes needed?
    
    The current implementation doesn't check if the key after removing the
    bypass prefix is empty.
    This could lead to:
    Adding an empty key to the Hive configuration
    Potential unexpected behavior in the Hive client
    Difficult-to-debug issues where configuration values are not properly
    applied
    
    
    ### Does this PR introduce _any_ user-facing change?
    
    No
    
    ### How was this patch tested?
    
    Just run function testEmptyBypassKey in TestHiveCatalogOperations
    
    ---------
    
    Co-authored-by: liuxian131 <[email protected]>
---
 .../catalog/hive/HiveCatalogOperations.java          |  7 ++++++-
 .../catalog/hive/TestHiveCatalogOperations.java      | 20 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git 
a/catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/HiveCatalogOperations.java
 
b/catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/HiveCatalogOperations.java
index 902fce3779..43842677c8 100644
--- 
a/catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/HiveCatalogOperations.java
+++ 
b/catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/HiveCatalogOperations.java
@@ -150,7 +150,12 @@ public class HiveCatalogOperations implements 
CatalogOperations, SupportsSchemas
         (key, value) -> {
           if (key.startsWith(CATALOG_BYPASS_PREFIX)) {
             // Trim bypass prefix and pass it to hive conf
-            byPassConfig.put(key.substring(CATALOG_BYPASS_PREFIX.length()), 
value);
+            String hiveKey = key.substring(CATALOG_BYPASS_PREFIX.length());
+            if (!hiveKey.isEmpty()) {
+              byPassConfig.put(hiveKey, value);
+            } else {
+              LOG.warn("Ignoring invalid configuration key: {}", key);
+            }
           } else if (GRAVITINO_CONFIG_TO_HIVE.containsKey(key)) {
             gravitinoConfig.put(GRAVITINO_CONFIG_TO_HIVE.get(key), value);
           }
diff --git 
a/catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/TestHiveCatalogOperations.java
 
b/catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/TestHiveCatalogOperations.java
index 2c87bfd580..27260584b4 100644
--- 
a/catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/TestHiveCatalogOperations.java
+++ 
b/catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/TestHiveCatalogOperations.java
@@ -118,6 +118,26 @@ class TestHiveCatalogOperations {
     Assertions.assertEquals("v4", op.hiveConf.get("c.d"));
   }
 
+  @Test
+  void testEmptyBypassKey() {
+    Map<String, String> properties = Maps.newHashMap();
+    // Add a normal bypass configuration
+    properties.put(CATALOG_BYPASS_PREFIX + "mapreduce.job.reduces", "20");
+    // Add an empty bypass configuration
+    properties.put(CATALOG_BYPASS_PREFIX, "some-value");
+
+    HiveCatalogOperations hiveCatalogOperations = new HiveCatalogOperations();
+    hiveCatalogOperations.initialize(properties, null, 
HIVE_PROPERTIES_METADATA);
+
+    // Verify that the normal bypass configuration is correctly applied
+    String v = hiveCatalogOperations.hiveConf.get("mapreduce.job.reduces");
+    Assertions.assertEquals("20", v);
+
+    // Verify that the empty bypass configuration is not applied
+    // This will fail if the empty key is incorrectly added
+    Assertions.assertNull(hiveCatalogOperations.hiveConf.get(""));
+  }
+
   @Test
   void testTestConnection() throws TException, InterruptedException {
     HiveCatalogOperations op = new HiveCatalogOperations();

Reply via email to