Skip to content

Commit

Permalink
HIVE-28766: EXECUTE IMMEDIATE with load data into table query display…
Browse files Browse the repository at this point in the history
…s 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
  • Loading branch information
mdayakar authored Feb 25, 2025
1 parent 92a5335 commit c701aa7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions data/files/hplsql.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
100Bob
14 changes: 8 additions & 6 deletions hplsql/src/main/java/org/apache/hive/hplsql/Stmt.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c701aa7

Please sign in to comment.