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

ayushsaxena pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git


The following commit(s) were added to refs/heads/master by this push:
     new 01e262cd3f2 HIVE-28057: Iceberg: Branches with non-lowercase 
characters can't be accessed. (#5068). (Ayush Saxena, reviewed by Denys 
Kuzmenko)
01e262cd3f2 is described below

commit 01e262cd3f259a7ecb4b23e789ff1c189ab2de68
Author: Ayush Saxena <[email protected]>
AuthorDate: Fri Feb 9 12:01:56 2024 +0530

    HIVE-28057: Iceberg: Branches with non-lowercase characters can't be 
accessed. (#5068). (Ayush Saxena, reviewed by Denys Kuzmenko)
---
 .../iceberg/mr/hive/TestHiveIcebergBranchOperation.java    | 14 ++++++++++++++
 .../java/org/apache/hadoop/hive/ql/metadata/HiveUtils.java |  8 ++++++++
 .../org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java  |  2 +-
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git 
a/iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergBranchOperation.java
 
b/iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergBranchOperation.java
index d892a72b822..9f88bae3496 100644
--- 
a/iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergBranchOperation.java
+++ 
b/iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergBranchOperation.java
@@ -238,4 +238,18 @@ public class TestHiveIcebergBranchOperation extends 
HiveIcebergStorageHandlerWit
             "ALTER TABLE customers CREATE BRANCH %s FOR TAG AS OF %s", 
branchName2, branchName1)))
         
.isInstanceOf(IllegalArgumentException.class).hasMessageEndingWith("does not 
exist");
   }
+
+  @Test
+  public void testCreateBranchWithNonLowerCase() throws InterruptedException, 
IOException {
+    Table table =
+        testTables.createTableWithVersions(shell, "customers", 
HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA,
+            fileFormat, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS, 
2);
+
+    String branchName = "test_Branch_1";
+    Long snapshotId = table.history().get(0).snapshotId();
+    shell.executeStatement(
+        String.format("ALTER TABLE customers CREATE BRANCH %s FOR 
SYSTEM_VERSION AS OF %d", branchName, snapshotId));
+    // Select with non-lower case branch name shouldn't throw exception.
+    shell.executeStatement(String.format("SELECT * FROM 
default.customers.branch_%s", branchName));
+  }
 }
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveUtils.java 
b/ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveUtils.java
index d1d197ebece..ae8849b8528 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveUtils.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveUtils.java
@@ -468,4 +468,12 @@ public final class HiveUtils {
     Matcher ref = TAG.matcher(refName);
     return ref.matches();
   }
+
+  public static String getLowerCaseTableName(String refName) {
+    String[] refParts = refName.split("\\.");
+    if (refParts.length == 3 && SNAPSHOT_REF.matcher(refParts[2]).matches()) {
+      return (refParts[0] + "." + refParts[1]).toLowerCase() + "." + 
refParts[2];
+    }
+    return refName.toLowerCase();
+  }
 }
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java 
b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
index 5b84437ecef..9bc8e03d164 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
@@ -1137,7 +1137,7 @@ public class SemanticAnalyzer extends 
BaseSemanticAnalyzer {
 
     ASTNode tableTree = (ASTNode) (tabref.getChild(0));
 
-    String tabIdName = getUnescapedName(tableTree).toLowerCase();
+    String tabIdName = 
HiveUtils.getLowerCaseTableName(getUnescapedName(tableTree));
 
     String alias = findSimpleTableName(tabref, aliasIndex);
 

Reply via email to