2

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?

2 Answers 2

3

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>.

Sign up to request clarification or add additional context in comments.

Comments

-1

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));
                    }

1 Comment

Your reply is not relevant to the question. You have explained how to add values from multiple records to a list, but the question is why I am getting error when using getArray() method for array data types.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.