Reputation: 628
I have a Hive table which has column with array data type. I am using JDBC to select rows from the table.
SELECT col1 FROM hive_table WHERE condition = 'condition'
After receiving the resultset, I am using res.getArray() method for the specific array field while looping through resultset.
Array arrayCol = res.getArray(1);
This is throwing a "Method not supported" error. Is it valid to use getArray() method for such queries executed on Hive table?
Upvotes: 2
Views: 1593
Reputation: 46
Unfortunately, no. You can see getArray() method is not implemented in ResultSet class for Hive JDBC. The actual class name is HiveBaseResultSet and the source code is located here.
Depends on what type of values the array holds, a client program need to decode its value by itself. For example, a column of type array<string> is encoded as a single String object like `["VALUE1","VALUE2",...,"VALUEN"]'. And we can use getString() method and freely re-construct any object of type Array<String> or List<String>.
Upvotes: 3
Reputation: 76
You can loop though the result set and add the column values to arraylist in java. See example below assuming that your table column is of String type.
List<String> list = new ArrayList<String>();
while (res.next()) {
list.add( res.getString(1));
}
Upvotes: -1