1

Am trying to run a hive query using Qubole SDK. Though am able to get the desired result as string, in order to better process it, am looking to access this row-wise. Something like a list of java objects.

The way am getting the data is:

CommandResponse commandResponse = client.command().hive().query(query).invoke().get();
ResultLatch resultLatch = new ResultLatch(client, commandResponse.getId());
ResultValue resultValue = resultLatch.awaitResult();
System.out.println(resultValue.getResults());

And the console gives an output like:

"val1"  "val2"  "val3"  "val4"
........ some more set of values .......

I was looking to have this result set in the form of list which I can iterate over instead of parsing or tokenizing the bunch of strings.

Unable to find any library or class if its there.

roger_that
  • 9,493
  • 18
  • 66
  • 102

1 Answers1

0

Split string by \r\n first, then by \t like this:

import org.apache.commons.lang3.StringUtils;

...

private static String convertNulls(String s) {
    \\Use this function to convert blanks, null and \\N to''
    return StringUtils.isBlank(s) | 
       s.equalsIgnoreCase("null") | 
        s.equalsIgnoreCase("\\N") ? "" : s;
}

...

inputStr=resultValue.getResults();

if (!StringUtils.isBlank(inputStr)) {
            for (String row: inputStr.split("\r\n")) { //split rows
                String[] s = row.split("\t");          //split columns

                //Do what you want here with s 
                //Use convertNulls method to convert all NULLs variations to empty strings
                //Or load some ArrayList or Map, etc


            }
leftjoin
  • 36,950
  • 8
  • 57
  • 116