use of com.bakdata.conquery.models.externalservice.ResultType in project conquery by bakdata.
the class ArrowUtil method listField.
private static Field listField(ResultInfo info, @NonNull String uniqueName) {
if (!(info.getType() instanceof ResultType.ListT)) {
throw new IllegalStateException("Expected result type of " + ResultType.ListT.class.getName() + " but got " + info.getType().getClass().getName());
}
final ResultType elementType = ((ResultType.ListT) info.getType()).getElementType();
BiFunction<ResultInfo, String, Field> nestedFieldCreator = FIELD_MAP.getOrDefault(elementType.getClass(), ArrowUtil::stringField);
final Field nestedField = nestedFieldCreator.apply(info, uniqueName);
return new Field(uniqueName, FieldType.nullable(ArrowType.List.INSTANCE), List.of(nestedField));
}
use of com.bakdata.conquery.models.externalservice.ResultType in project conquery by bakdata.
the class CsvResultGenerationTest method generateExpectedCSV.
private String generateExpectedCSV(List<EntityResult> results, List<ResultInfo> resultInfos, PrintSettings settings) {
List<String> expected = new ArrayList<>();
expected.add(ResultTestUtil.ID_FIELDS.stream().map(info -> info.defaultColumnName(settings)).collect(Collectors.joining(",")) + "," + getResultTypes().stream().map(ResultType::typeInfo).collect(Collectors.joining(",")) + "\n");
results.stream().map(EntityResult.class::cast).forEach(res -> {
for (Object[] line : res.listResultLines()) {
StringJoiner valueJoiner = new StringJoiner(",");
valueJoiner.add(String.valueOf(res.getEntityId()));
valueJoiner.add(String.valueOf(res.getEntityId()));
for (int lIdx = 0; lIdx < line.length; lIdx++) {
Object val = line[lIdx];
if (val == null) {
valueJoiner.add("");
continue;
}
ResultInfo info = resultInfos.get(lIdx);
final String printVal = info.getType().printNullable(settings, val);
valueJoiner.add(printVal.contains(String.valueOf(CONFIG.getCsv().getDelimeter())) ? "\"" + printVal + "\"" : printVal);
}
expected.add(valueJoiner + "\n");
}
});
return expected.stream().collect(Collectors.joining());
}
use of com.bakdata.conquery.models.externalservice.ResultType in project conquery by bakdata.
the class ArrowResultGenerationTest method getPrintValue.
private static String getPrintValue(Object obj, ResultType type, PrintSettings settings) {
if (obj == null) {
return "null";
}
if (type.equals(ResultType.DateRangeT.INSTANCE)) {
// Special case for daterange in this test because it uses a StructVector, we rebuild the structural information
List<?> dr = (List<?>) obj;
StringBuilder sb = new StringBuilder();
sb.append("{");
final int min = (int) dr.get(0);
final int max = (int) dr.get(1);
// Handle cases where one of the limits is infinity
if (!CDate.isNegativeInfinity(min)) {
sb.append("\"min\":").append(min);
}
if (!CDate.isNegativeInfinity(min) && !CDate.isPositiveInfinity(max)) {
sb.append(",");
}
if (!CDate.isPositiveInfinity(max)) {
sb.append("\"max\":").append(max);
}
sb.append("}");
return sb.toString();
}
if (type.equals(ResultType.ResolutionT.INSTANCE)) {
return type.printNullable(settings, obj);
}
if (obj instanceof Collection) {
Collection<?> col = (Collection<?>) obj;
// Workaround: Arrow deserializes lists as a JsonStringArrayList which has a JSON String method
new StringJoiner(",", "[", "]");
@NonNull ResultType elemType = ((ResultType.ListT) type).getElementType();
return col.stream().map(v -> getPrintValue(v, elemType, settings)).collect(Collectors.joining(", ", "[", "]"));
}
return obj.toString();
}
Aggregations