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 c701aa77499 HIVE-28766: EXECUTE IMMEDIATE with load data into table
query displays ERROR on the console. (Dayakar M, reviewed by Krisztian Kasa)
c701aa77499 is described below
commit c701aa77499affba353c13b2eb90ec9f6ce959a0
Author: Dayakar M <[email protected]>
AuthorDate: Tue Feb 25 17:38:06 2025 +0530
HIVE-28766: EXECUTE IMMEDIATE with load data into table query displays
ERROR on the console. (Dayakar M, reviewed by Krisztian Kasa)
* HIVE-28766: EXECUTE IMMEDIATE with load data into table query displays
ERROR on the console.
* Added missing test resources
---
data/files/hplsql.txt | 1 +
.../src/main/java/org/apache/hive/hplsql/Stmt.java | 14 ++++++++------
.../apache/hive/beeline/TestHplSqlViaBeeLine.java | 20 ++++++++++++++++++++
.../cli/operation/hplsql/HplSqlQueryExecutor.java | 10 ++++++----
4 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/data/files/hplsql.txt b/data/files/hplsql.txt
new file mode 100644
index 00000000000..0c41efbd7f9
--- /dev/null
+++ b/data/files/hplsql.txt
@@ -0,0 +1 @@
+100Bob
diff --git a/hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java
b/hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java
index ff70b2b9619..a39a60948d2 100644
--- a/hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java
+++ b/hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java
@@ -1088,14 +1088,16 @@ else if (trace) {
// Print the results
else {
int cols = query.columnCount();
- while(query.next()) {
- for(int i = 0; i < cols; i++) {
- if(i > 1) {
- console.print("\t");
+ if (cols > 0) {
+ while (query.next()) {
+ for (int i = 0; i < cols; i++) {
+ if (i > 1) {
+ console.print("\t");
+ }
+ console.print(query.column(i, String.class));
}
- console.print(query.column(i, String.class));
+ console.printLine("");
}
- console.printLine("");
}
}
} catch(QueryException e) {
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 0d3968cfee1..f1374663e9b 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
@@ -1376,6 +1376,26 @@ public void testCastHplSqlFunction() throws Throwable {
testScriptFile(SCRIPT_TEXT, args(), "1");
}
+ @Test
+ public void testExecuteImmediateLoadDataShouldNotThrowError() throws
Throwable {
+ String scriptText =
+ "DROP TABLE IF EXISTS result;\n" +
+ "CREATE TABLE result (id bigint, name string) stored as
textfile;\n" +
+ "EXECUTE IMMEDIATE 'load data local inpath
''../../data/files/hplsql.txt'' OVERWRITE INTO table result';";
+ // Inverted match, output should not have HPL/SQL error
+ testScriptFile(scriptText, args(), "^(.(?!(Error: Error running HPL/SQL
operation)))*$", OutStream.ERR);
+ }
+
+ @Test
+ public void testExecuteImmediateLoadData() throws Throwable {
+ String scriptText =
+ "DROP TABLE IF EXISTS result;\n" +
+ "CREATE TABLE result (id bigint, name string);\n" +
+ "EXECUTE IMMEDIATE 'load data local inpath
''../../data/files/hplsql.txt'' OVERWRITE INTO table result';\n" +
+ "SELECT * FROM result;";
+ testScriptFile(scriptText, args(), "100.*Bob");
+ }
+
private static List<String> args() {
return Arrays.asList("-d", BeeLine.BEELINE_DEFAULT_JDBC_DRIVER,
"-u", miniHS2.getBaseJdbcURL() + ";mode=hplsql", "-n", USER_NAME);
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 eae9107befe..94c0ab08577 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
@@ -74,11 +74,13 @@ public QueryResult executeQuery(String sql,
ParserRuleContext ctx) {
public Metadata metadata(OperationHandle operationHandle) {
try {
- TableSchema meta = hiveSession.getResultSetMetadata(operationHandle);
List<ColumnMeta> colMeta = new ArrayList<>();
- for (int i = 0; i < meta.getSize(); i++) {
- ColumnDescriptor col = meta.getColumnDescriptorAt(i);
- colMeta.add(new ColumnMeta(col.getName(), col.getTypeName(),
col.getType().toJavaSQLType()));
+ if (operationHandle.hasResultSet()) {
+ TableSchema meta = hiveSession.getResultSetMetadata(operationHandle);
+ for (int i = 0; i < meta.getSize(); i++) {
+ ColumnDescriptor col = meta.getColumnDescriptorAt(i);
+ colMeta.add(new ColumnMeta(col.getName(), col.getTypeName(),
col.getType().toJavaSQLType()));
+ }
}
return new Metadata(colMeta);
} catch (HiveSQLException e) {