Search in sources :

Example 6 with PrintSettings

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();
}
Also used : ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ArrowType(org.apache.arrow.vector.types.pojo.ArrowType) EntityResult(com.bakdata.conquery.models.query.results.EntityResult) ArrayList(java.util.ArrayList) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) EntityPrintId(com.bakdata.conquery.models.identifiable.mapping.EntityPrintId) ByteArrayInputStream(java.io.ByteArrayInputStream) FloatingPointPrecision(org.apache.arrow.vector.types.FloatingPointPrecision) ArrowRenderer(com.bakdata.conquery.io.result.arrow.ArrowRenderer) CDate(com.bakdata.conquery.models.common.CDate) Locale(java.util.Locale) I18n(com.bakdata.conquery.models.i18n.I18n) ArrowStreamReader(org.apache.arrow.vector.ipc.ArrowStreamReader) ResultType(com.bakdata.conquery.models.externalservice.ResultType) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) DictionaryProvider(org.apache.arrow.vector.dictionary.DictionaryProvider) UniqueNamer(com.bakdata.conquery.models.query.resultinfo.UniqueNamer) FieldVector(org.apache.arrow.vector.FieldVector) SelectResultInfo(com.bakdata.conquery.models.query.resultinfo.SelectResultInfo) NonNull(lombok.NonNull) VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) FieldType(org.apache.arrow.vector.types.pojo.FieldType) Collection(java.util.Collection) IOException(java.io.IOException) Field(org.apache.arrow.vector.types.pojo.Field) Collectors(java.util.stream.Collectors) ArrowStreamWriter(org.apache.arrow.vector.ipc.ArrowStreamWriter) JsonStringArrayList(org.apache.arrow.vector.util.JsonStringArrayList) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) ResultTestUtil(com.bakdata.conquery.io.result.ResultTestUtil) StringJoiner(java.util.StringJoiner) ROOT_ALLOCATOR(com.bakdata.conquery.io.result.arrow.ArrowUtil.ROOT_ALLOCATOR) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) DateUnit(org.apache.arrow.vector.types.DateUnit) InputStream(java.io.InputStream) NonNull(lombok.NonNull) Collection(java.util.Collection) ArrayList(java.util.ArrayList) JsonStringArrayList(org.apache.arrow.vector.util.JsonStringArrayList) List(java.util.List) ResultType(com.bakdata.conquery.models.externalservice.ResultType) StringJoiner(java.util.StringJoiner)

Example 7 with PrintSettings

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);
}
Also used : ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EntityResult(com.bakdata.conquery.models.query.results.EntityResult) ArrayList(java.util.ArrayList) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) EntityPrintId(com.bakdata.conquery.models.identifiable.mapping.EntityPrintId) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) DataFormatter(org.apache.poi.ss.usermodel.DataFormatter) Cell(org.apache.poi.ss.usermodel.Cell) I18n(com.bakdata.conquery.models.i18n.I18n) ResultType(com.bakdata.conquery.models.externalservice.ResultType) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) ResultTestUtil.getTestEntityResults(com.bakdata.conquery.io.result.ResultTestUtil.getTestEntityResults) SelectResultInfo(com.bakdata.conquery.models.query.resultinfo.SelectResultInfo) ResultTestUtil.getResultTypes(com.bakdata.conquery.io.result.ResultTestUtil.getResultTypes) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ExcelConfig(com.bakdata.conquery.models.config.ExcelConfig) Test(org.junit.jupiter.api.Test) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) ResultTestUtil(com.bakdata.conquery.io.result.ResultTestUtil) StringJoiner(java.util.StringJoiner) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) Row(org.apache.poi.ss.usermodel.Row) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) NotNull(org.jetbrains.annotations.NotNull) InputStream(java.io.InputStream) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EntityResult(com.bakdata.conquery.models.query.results.EntityResult) SelectResultInfo(com.bakdata.conquery.models.query.resultinfo.SelectResultInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) SelectResultInfo(com.bakdata.conquery.models.query.resultinfo.SelectResultInfo) ExcelConfig(com.bakdata.conquery.models.config.ExcelConfig) Test(org.junit.jupiter.api.Test)

Example 8 with PrintSettings

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));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EntityResult(com.bakdata.conquery.models.query.results.EntityResult) ArrowStreamWriter(org.apache.arrow.vector.ipc.ArrowStreamWriter) Test(org.junit.jupiter.api.Test)

Example 9 with 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());
    }
}
Also used : IdPrinter(com.bakdata.conquery.models.identifiable.mapping.IdPrinter) CsvLineStreamRenderer(com.bakdata.conquery.io.result.CsvLineStreamRenderer) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) List(java.util.List) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) Map(java.util.Map)

Aggregations

PrintSettings (com.bakdata.conquery.models.query.PrintSettings)9 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)7 ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)7 I18n (com.bakdata.conquery.models.i18n.I18n)6 ResultInfo (com.bakdata.conquery.models.query.resultinfo.ResultInfo)6 List (java.util.List)6 Locale (java.util.Locale)6 EntityResult (com.bakdata.conquery.models.query.results.EntityResult)5 ArrayList (java.util.ArrayList)5 Slf4j (lombok.extern.slf4j.Slf4j)5 Test (org.junit.jupiter.api.Test)5 IdPrinter (com.bakdata.conquery.models.identifiable.mapping.IdPrinter)4 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)3 ResultTestUtil (com.bakdata.conquery.io.result.ResultTestUtil)3 ResultUtil (com.bakdata.conquery.io.result.ResultUtil)3 ResultUtil.makeResponseWithFileName (com.bakdata.conquery.io.result.ResultUtil.makeResponseWithFileName)3 Subject (com.bakdata.conquery.models.auth.entities.Subject)3 Ability (com.bakdata.conquery.models.auth.permissions.Ability)3 Dataset (com.bakdata.conquery.models.datasets.Dataset)3 ManagedExecution (com.bakdata.conquery.models.execution.ManagedExecution)3