我正在尝试使用Qubole SDK运行hive查询。虽然我能够作为string获得所需的结果,但为了更好地处理它,我希望按行访问它。类似于java对象的列表。
我获取数据的方法是:
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 .......我希望这个结果集以list的形式出现,我可以遍历它,而不是解析或标记字符串。
找不到任何库或类(如果有)。
发布于 2019-04-18 22:03:10
首先按\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
}https://stackoverflow.com/questions/55743801
复制相似问题