use of com.bakdata.conquery.models.query.PrintSettings 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();
}
use of com.bakdata.conquery.models.query.PrintSettings in project conquery by bakdata.
the class ExcelResultRenderTest method writeAndRead.
@Test
void writeAndRead() throws IOException {
// Prepare every input data
PrintSettings printSettings = new PrintSettings(true, Locale.GERMAN, null, CONFIG, (cer) -> EntityPrintId.from(Integer.toString(cer.getEntityId()), Integer.toString(cer.getEntityId())), (selectInfo) -> selectInfo.getSelect().getLabel());
// The Shard nodes send Object[] but since Jackson is used for deserialization, nested collections are always a list because they are not further specialized
List<EntityResult> results = getTestEntityResults();
ManagedQuery mquery = new ManagedQuery(null, null, null) {
public List<ResultInfo> getResultInfos() {
return getResultTypes().stream().map(ResultTestUtil.TypedSelectDummy::new).map(select -> new SelectResultInfo(select, new CQConcept())).collect(Collectors.toList());
}
@Override
public Stream<EntityResult> streamResults() {
return results.stream();
}
};
// First we write to the buffer, than we read from it and parse it as TSV
ByteArrayOutputStream output = new ByteArrayOutputStream();
ExcelRenderer renderer = new ExcelRenderer(new ExcelConfig(), printSettings);
renderer.renderToStream(ResultTestUtil.ID_FIELDS, mquery, output);
InputStream inputStream = new ByteArrayInputStream(output.toByteArray());
List<String> computed = readComputed(inputStream, printSettings);
List<String> expected = generateExpectedTSV(results, mquery.getResultInfos(), printSettings);
log.info("Wrote and than read this excel data: {}", computed);
assertThat(computed).isNotEmpty();
assertThat(computed).isEqualTo(expected);
}
use of com.bakdata.conquery.models.query.PrintSettings in project conquery by bakdata.
the class ArrowResultGenerationTest method writeAndRead.
@Test
void writeAndRead() throws IOException {
// Initialize internationalization
I18n.init();
// Prepare every input data
PrintSettings printSettings = new PrintSettings(false, Locale.ROOT, null, CONFIG, (cer) -> EntityPrintId.from(Integer.toString(cer.getEntityId()), Integer.toString(cer.getEntityId())), (selectInfo) -> selectInfo.getSelect().getLabel());
// The Shard nodes send Object[] but since Jackson is used for deserialization, nested collections are always a list because they are not further specialized
List<EntityResult> results = getTestEntityResults();
ManagedQuery mquery = getTestQuery();
// First we write to the buffer, than we read from it and parse it as TSV
ByteArrayOutputStream output = new ByteArrayOutputStream();
renderToStream((root) -> new ArrowStreamWriter(root, new DictionaryProvider.MapDictionaryProvider(), output), printSettings, BATCH_SIZE, ResultTestUtil.ID_FIELDS, mquery.getResultInfos(), mquery.streamResults());
InputStream inputStream = new ByteArrayInputStream(output.toByteArray());
String computed = readTSV(inputStream);
assertThat(computed).isNotBlank();
assertThat(computed).isEqualTo(generateExpectedTSV(results, mquery.getResultInfos(), printSettings));
}
use of com.bakdata.conquery.models.query.PrintSettings in project conquery by bakdata.
the class FormTest method checkResults.
private void checkResults(StandaloneSupport standaloneSupport, ManagedForm managedForm, User user) throws IOException {
Map<String, List<ManagedQuery>> managedMapping = managedForm.getSubQueries();
IdPrinter idPrinter = standaloneSupport.getConfig().getFrontend().getQueryUpload().getIdPrinter(user, managedForm, standaloneSupport.getNamespace());
final ConqueryConfig config = standaloneSupport.getConfig();
PrintSettings PRINT_SETTINGS = new PrintSettings(false, Locale.ENGLISH, standaloneSupport.getDatasetsProcessor().getDatasetRegistry(), config, idPrinter::createId);
CsvLineStreamRenderer renderer = new CsvLineStreamRenderer(config.getCsv().createWriter(), PRINT_SETTINGS);
for (Map.Entry<String, List<ManagedQuery>> managed : managedMapping.entrySet()) {
List<ResultInfo> resultInfos = managed.getValue().get(0).getResultInfos();
log.info("{} CSV TESTING: {}", getLabel(), managed.getKey());
List<String> actual = renderer.toStream(config.getFrontend().getQueryUpload().getIdResultInfos(), resultInfos, managed.getValue().stream().flatMap(ManagedQuery::streamResults)).collect(Collectors.toList());
assertThat(actual).as("Checking result " + managed.getKey()).containsExactlyInAnyOrderElementsOf(In.stream(expectedCsv.get(managed.getKey()).stream()).withUTF8().readLines());
}
}
Aggregations