1

我正在尝试使用Qubole SDKhive运行查询。虽然我能够获得所需的结果,但为了更好地处理它,我希望逐行访问它。类似于 java 对象列表的东西。string

获取数据的方式是:

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

控制台给出如下输出:

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

我希望以列表的形式设置这个结果集,我可以对其进行迭代,而不是解析或标记一堆字符串。

如果存在,则无法找到任何库或类。

4

1 回答 1

0

首先拆分字符串\r\n,然后\t像这样:

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


            }
于 2019-04-18T14:03:10.130 回答