Search in sources :

Example 1 with SelectResultInfo

use of com.bakdata.conquery.models.query.resultinfo.SelectResultInfo in project conquery by bakdata.

the class ArrowResultGenerationTest method generateFieldsValue.

@Test
void generateFieldsValue() {
    List<ResultInfo> resultInfos = getResultTypes().stream().map(ResultTestUtil.TypedSelectDummy::new).map(select -> new SelectResultInfo(select, new CQConcept())).collect(Collectors.toList());
    List<Field> fields = generateFields(resultInfos, // Custom column namer so we don't require a dataset registry
    UNIQUE_NAMER);
    assertThat(fields).containsExactlyElementsOf(List.of(new Field("BOOLEAN", FieldType.nullable(ArrowType.Bool.INSTANCE), null), new Field("INTEGER", FieldType.nullable(new ArrowType.Int(32, true)), null), new Field("NUMERIC", FieldType.nullable(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)), null), new Field("CATEGORICAL", FieldType.nullable(new ArrowType.Utf8()), null), new Field("RESOLUTION", FieldType.nullable(new ArrowType.Utf8()), null), new Field("DATE", FieldType.nullable(new ArrowType.Date(DateUnit.DAY)), null), new Field("DATE_RANGE", FieldType.nullable(ArrowType.Struct.INSTANCE), List.of(new Field("min", FieldType.nullable(new ArrowType.Date(DateUnit.DAY)), null), new Field("max", FieldType.nullable(new ArrowType.Date(DateUnit.DAY)), null))), new Field("STRING", FieldType.nullable(new ArrowType.Utf8()), null), new Field("MONEY", FieldType.nullable(new ArrowType.Int(32, true)), null), new Field("LIST[BOOLEAN]", FieldType.nullable(ArrowType.List.INSTANCE), List.of(new Field("LIST[BOOLEAN]", FieldType.nullable(ArrowType.Bool.INSTANCE), null))), new Field("LIST[DATE_RANGE]", FieldType.nullable(ArrowType.List.INSTANCE), List.of(new Field("LIST[DATE_RANGE]", FieldType.nullable(ArrowType.Struct.INSTANCE), List.of(new Field("min", FieldType.nullable(new ArrowType.Date(DateUnit.DAY)), null), new Field("max", FieldType.nullable(new ArrowType.Date(DateUnit.DAY)), null))))), new Field("LIST[STRING]", FieldType.nullable(ArrowType.List.INSTANCE), List.of(new Field("LIST[STRING]", FieldType.nullable(new ArrowType.Utf8()), null)))));
}
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) Field(org.apache.arrow.vector.types.pojo.Field) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) SelectResultInfo(com.bakdata.conquery.models.query.resultinfo.SelectResultInfo) SelectResultInfo(com.bakdata.conquery.models.query.resultinfo.SelectResultInfo) CDate(com.bakdata.conquery.models.common.CDate) Test(org.junit.jupiter.api.Test)

Example 2 with SelectResultInfo

use of com.bakdata.conquery.models.query.resultinfo.SelectResultInfo in project conquery by bakdata.

the class DefaultColumnNameTest method checkCombinations.

@ParameterizedTest
@MethodSource("provideCombinations")
void checkCombinations(TestConcept concept, boolean hasCQConceptLabel, String expectedColumnName) {
    doAnswer(invocation -> {
        final ConceptId id = invocation.getArgument(0);
        if (!concept.getId().equals(id)) {
            throw new IllegalStateException("Expected the id " + concept.getId() + " but got " + id);
        }
        return concept;
    }).when(DATASET_REGISTRY).resolve(any());
    final CQConcept cqConcept = concept.createCQConcept(hasCQConceptLabel);
    final UniqueNamer uniqNamer = new UniqueNamer(SETTINGS);
    SelectResultInfo info = new SelectResultInfo(concept.extractSelect(cqConcept), cqConcept);
    assertThat(uniqNamer.getUniqueName(info)).isEqualTo(expectedColumnName);
}
Also used : UniqueNamer(com.bakdata.conquery.models.query.resultinfo.UniqueNamer) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) SelectResultInfo(com.bakdata.conquery.models.query.resultinfo.SelectResultInfo) ConceptId(com.bakdata.conquery.models.identifiable.ids.specific.ConceptId) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with SelectResultInfo

use of com.bakdata.conquery.models.query.resultinfo.SelectResultInfo 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)

Aggregations

CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)3 SelectResultInfo (com.bakdata.conquery.models.query.resultinfo.SelectResultInfo)3 ResultTestUtil (com.bakdata.conquery.io.result.ResultTestUtil)2 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)2 ResultType (com.bakdata.conquery.models.externalservice.ResultType)2 I18n (com.bakdata.conquery.models.i18n.I18n)2 EntityPrintId (com.bakdata.conquery.models.identifiable.mapping.EntityPrintId)2 ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)2 PrintSettings (com.bakdata.conquery.models.query.PrintSettings)2 ResultInfo (com.bakdata.conquery.models.query.resultinfo.ResultInfo)2 UniqueNamer (com.bakdata.conquery.models.query.resultinfo.UniqueNamer)2 EntityResult (com.bakdata.conquery.models.query.results.EntityResult)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Locale (java.util.Locale)2 StringJoiner (java.util.StringJoiner)2