in thriftserver/session/src/main/java/org/apache/livy/thriftserver/session/ResultSet.java [85:119]
private String toHiveString(Object value, boolean quoteStrings) {
if (value == null) {
return null;
} else if (quoteStrings && value instanceof String) {
return "\"" + value + "\"";
} else if (value instanceof BigDecimal) {
return ((BigDecimal) value).stripTrailingZeros().toString();
} else if (value instanceof Map) {
return stream(new ScalaIterator<>(((Map<?,?>) value).iterator()))
.map(o -> toHiveString(o, true))
.sorted()
.collect(Collectors.joining(",", "{", "}"));
} else if (value instanceof Seq) {
return stream(new ScalaIterator<>(((Seq<?>) value).iterator()))
.map(o -> toHiveString(o, true))
.collect(Collectors.joining(",", "[", "]"));
} else if (value instanceof Tuple2) {
Tuple2 t = (Tuple2) value;
return String.format("%s:%s", toHiveString(t._1(), true), toHiveString(t._2(), true));
} else if (value instanceof Row) {
Row r = (Row) value;
final StructField[] fields = r.schema().fields();
final AtomicInteger idx = new AtomicInteger();
return stream(new ScalaIterator<>(r.toSeq().iterator()))
.map(o -> {
String fname = fields[idx.getAndIncrement()].name();
String fval = toHiveString(o, true);
return String.format("\"%s\":%s", fname, fval);
})
.collect(Collectors.joining(",", "{", "}"));
} else {
return value.toString();
}
}