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

krisztiankasa 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 aafde76dc82 HIVE-28247: Execute immediate `select count(*) from tbl` 
throwing ClassCastException in hplsql mode. (Dayakar M, reviewed by Krisztian 
Kasa)
aafde76dc82 is described below

commit aafde76dc82762b7b276341ffb08983934560f17
Author: Dayakar M <[email protected]>
AuthorDate: Tue May 7 18:44:35 2024 +0530

    HIVE-28247: Execute immediate `select count(*) from tbl` throwing 
ClassCastException in hplsql mode. (Dayakar M, reviewed by Krisztian Kasa)
    
    Co-authored-by: mdayakar <[email protected]>
---
 .../apache/hive/beeline/TestHplSqlViaBeeLine.java    | 20 ++++++++++++++++++++
 .../cli/operation/hplsql/HplSqlQueryExecutor.java    |  2 ++
 2 files changed, 22 insertions(+)

diff --git 
a/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestHplSqlViaBeeLine.java
 
b/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestHplSqlViaBeeLine.java
index c4f2d7729b3..efe021e6598 100644
--- 
a/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestHplSqlViaBeeLine.java
+++ 
b/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestHplSqlViaBeeLine.java
@@ -1042,6 +1042,26 @@ public class TestHplSqlViaBeeLine {
     testScriptFile(SCRIPT_TEXT, args(), "Exit CONDITION Handler invoked.", 
OutStream.ERR);
   }
 
+  @Test
+  public void testExecuteImmediateSelectCountStatement() throws Throwable {
+    String SCRIPT_TEXT =
+        "DROP TABLE IF EXISTS result;\n" +
+            "CREATE TABLE result (s string);\n" +
+            "execute immediate 'SELECT count(*) from result';";
+    // Inverted match, output should not have NPE
+    testScriptFile(SCRIPT_TEXT, args(), "^(.(?!(ClassCastException)))*$", 
OutStream.ERR);
+  }
+
+  @Test
+  public void testExecuteSelectCountStatement() throws Throwable {
+    String SCRIPT_TEXT =
+        "DROP TABLE IF EXISTS result;\n" +
+            "CREATE TABLE result (s string);\n" +
+            "execute 'SELECT count(*) from result';";
+    // Inverted match, output should not have NPE
+    testScriptFile(SCRIPT_TEXT, args(), "^(.(?!(ClassCastException)))*$", 
OutStream.ERR);
+  }
+
   private static List<String> args() {
     return Arrays.asList("-d", BeeLine.BEELINE_DEFAULT_JDBC_DRIVER,
             "-u", miniHS2.getBaseJdbcURL() + ";mode=hplsql", "-n", userName);
diff --git 
a/service/src/java/org/apache/hive/service/cli/operation/hplsql/HplSqlQueryExecutor.java
 
b/service/src/java/org/apache/hive/service/cli/operation/hplsql/HplSqlQueryExecutor.java
index 9aa25d39c69..eae9107befe 100644
--- 
a/service/src/java/org/apache/hive/service/cli/operation/hplsql/HplSqlQueryExecutor.java
+++ 
b/service/src/java/org/apache/hive/service/cli/operation/hplsql/HplSqlQueryExecutor.java
@@ -137,6 +137,8 @@ public class HplSqlQueryExecutor implements QueryExecutor {
               return type.cast(((Number) current[columnIndex]).shortValue());
           if (type == Byte.class)
               return type.cast(((Number) current[columnIndex]).byteValue());
+          if (type == String.class)
+            return (T) String.valueOf(current[columnIndex]);
         }
         // RowSet can never return the HiveDecimal instances created on Hive 
side, nor its BigDecimal representation.
         // Instead, it gets converted into String object in 
ColumnBasedSet.addRow()...

Reply via email to