Search in sources :

Example 1 with ResultInfo

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

the class AbstractQueryEngineTest method executeTest.

@Override
public void executeTest(StandaloneSupport standaloneSupport) throws IOException {
    Query query = getQuery();
    assertThat(standaloneSupport.getValidator().validate(query)).describedAs("Query Validation Errors").isEmpty();
    log.info("{} QUERY INIT", getLabel());
    final User testUser = standaloneSupport.getTestUser();
    final ManagedExecutionId executionId = IntegrationUtils.assertQueryResult(standaloneSupport, query, -1, ExecutionState.DONE, testUser, 201);
    final ManagedQuery execution = (ManagedQuery) standaloneSupport.getMetaStorage().getExecution(executionId);
    // check result info size
    List<ResultInfo> resultInfos = execution.getResultInfos();
    assertThat(execution.streamResults().flatMap(EntityResult::streamValues)).as("Should have same size as result infos").allSatisfy(v -> assertThat(v).hasSameSizeAs(resultInfos));
    // Get the actual response and compare with expected result.
    final Response csvResponse = standaloneSupport.getClient().target(HierarchyHelper.hierarchicalPath(standaloneSupport.defaultApiURIBuilder(), ResultCsvResource.class, "getAsCsv").buildFromMap(Map.of(DATASET, standaloneSupport.getDataset().getName(), QUERY, execution.getId().toString()))).queryParam("pretty", false).request(AdditionalMediaTypes.CSV).acceptLanguage(Locale.ENGLISH).get();
    List<String> actual = In.stream(((InputStream) csvResponse.getEntity())).readLines();
    ResourceFile expectedCsv = getExpectedCsv();
    List<String> expected = In.stream(expectedCsv.stream()).readLines();
    assertThat(actual).as("Results for %s are not as expected.", this).containsExactlyInAnyOrderElementsOf(expected);
    // check that getLastResultCount returns the correct size
    if (execution.streamResults().noneMatch(MultilineEntityResult.class::isInstance)) {
        assertThat(execution.getLastResultCount()).as("Result count for %s is not as expected.", this).isEqualTo(expected.size() - 1);
    }
    log.info("INTEGRATION TEST SUCCESSFUL {} {} on {} rows", getClass().getSimpleName(), this, expected.size());
}
Also used : Response(javax.ws.rs.core.Response) ResourceFile(com.bakdata.conquery.integration.common.ResourceFile) User(com.bakdata.conquery.models.auth.entities.User) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) Query(com.bakdata.conquery.apiv1.query.Query) ManagedExecutionId(com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) MultilineEntityResult(com.bakdata.conquery.models.query.results.MultilineEntityResult)

Example 2 with ResultInfo

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

the class ArrayConceptQuery method getResultInfos.

@Override
public List<ResultInfo> getResultInfos() {
    final List<ResultInfo> resultInfos = new ArrayList<>();
    ResultInfo dateInfo = ConqueryConstants.DATES_INFO;
    if (!DateAggregationMode.NONE.equals(getResolvedDateAggregationMode())) {
        // Add one DateInfo for the whole Query
        resultInfos.add(0, dateInfo);
    }
    int lastIndex = resultInfos.size();
    childQueries.forEach(q -> resultInfos.addAll(q.getResultInfos()));
    if (!resultInfos.isEmpty()) {
        // Remove DateInfo from each childQuery
        resultInfos.subList(lastIndex, resultInfos.size()).removeAll(List.of(dateInfo));
    }
    return resultInfos;
}
Also used : ArrayList(java.util.ArrayList) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo)

Example 3 with ResultInfo

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

the class TableExportQuery method createResultInfos.

private static List<ResultInfo> createResultInfos(int size, Map<SecondaryIdDescription, Integer> secondaryIdPositions, Map<Column, Integer> positions) {
    ResultInfo[] infos = new ResultInfo[size];
    infos[0] = ConqueryConstants.DATES_INFO;
    for (Map.Entry<SecondaryIdDescription, Integer> e : secondaryIdPositions.entrySet()) {
        SecondaryIdDescription desc = e.getKey();
        Integer pos = e.getValue();
        infos[pos] = new SimpleResultInfo(desc.getLabel(), ResultType.IdT.INSTANCE);
    }
    for (Map.Entry<Column, Integer> entry : positions.entrySet()) {
        // 0 Position is date, already covered
        final int position = entry.getValue();
        // SecondaryIds are pulled to the front, already covered.
        final Column column = entry.getKey();
        if (position == 0 || column.getSecondaryId() != null) {
            continue;
        }
        infos[position] = new SimpleResultInfo(column.getTable().getLabel() + " " + column.getLabel(), ResultType.resolveResultType(column.getType()));
    }
    return List.of(infos);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SimpleResultInfo(com.bakdata.conquery.models.query.resultinfo.SimpleResultInfo) Column(com.bakdata.conquery.models.datasets.Column) SimpleResultInfo(com.bakdata.conquery.models.query.resultinfo.SimpleResultInfo) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) HashMap(java.util.HashMap) Map(java.util.Map) SecondaryIdDescription(com.bakdata.conquery.models.datasets.SecondaryIdDescription)

Example 4 with ResultInfo

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

the class ExcelRenderer method writeBody.

private int writeBody(SXSSFSheet sheet, List<ResultInfo> infos, Stream<EntityResult> resultLines) {
    // Row 0 is the Header the data starts at 1
    final AtomicInteger currentRow = new AtomicInteger(1);
    final int writtenLines = resultLines.mapToInt(l -> this.writeRowsForEntity(infos, l, currentRow, cfg, sheet)).sum();
    // The result was shorter than the number of rows to track, so we auto size here explicitly
    if (writtenLines < config.getLastRowToAutosize()) {
        setColumnWidthsAndUntrack(sheet);
    }
    return writtenLines;
}
Also used : ExcelSheetNameC10n(com.bakdata.conquery.internationalization.ExcelSheetNameC10n) SneakyThrows(lombok.SneakyThrows) EntityResult(com.bakdata.conquery.models.query.results.EntityResult) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) CellReference(org.apache.poi.ss.util.CellReference) ArrayList(java.util.ArrayList) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) BigDecimal(java.math.BigDecimal) ManagedExecution(com.bakdata.conquery.models.execution.ManagedExecution) CDate(com.bakdata.conquery.models.common.CDate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Cell(org.apache.poi.ss.usermodel.Cell) SXSSFSheet(org.apache.poi.xssf.streaming.SXSSFSheet) I18n(com.bakdata.conquery.models.i18n.I18n) CTTableColumns(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumns) CTTableColumn(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn) ResultType(com.bakdata.conquery.models.externalservice.ResultType) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) CTTableStyleInfo(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyleInfo) UniqueNamer(com.bakdata.conquery.models.query.resultinfo.UniqueNamer) OutputStream(java.io.OutputStream) XSSFTable(org.apache.poi.xssf.usermodel.XSSFTable) ImmutableMap(com.google.common.collect.ImmutableMap) IOException(java.io.IOException) User(com.bakdata.conquery.models.auth.entities.User) SingleTableResult(com.bakdata.conquery.models.query.SingleTableResult) ExcelConfig(com.bakdata.conquery.models.config.ExcelConfig) List(java.util.List) AreaReference(org.apache.poi.ss.util.AreaReference) Stream(java.util.stream.Stream) CTTable(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable) C10N(c10n.C10N) Row(org.apache.poi.ss.usermodel.Row) POIXMLProperties(org.apache.poi.ooxml.POIXMLProperties) CellStyle(org.apache.poi.ss.usermodel.CellStyle) NotNull(org.jetbrains.annotations.NotNull) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 5 with ResultInfo

use of com.bakdata.conquery.models.query.resultinfo.ResultInfo 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));
}
Also used : Field(org.apache.arrow.vector.types.pojo.Field) ResultType(com.bakdata.conquery.models.externalservice.ResultType) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo)

Aggregations

ResultInfo (com.bakdata.conquery.models.query.resultinfo.ResultInfo)17 ArrayList (java.util.ArrayList)10 ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)6 PrintSettings (com.bakdata.conquery.models.query.PrintSettings)6 List (java.util.List)6 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)5 ResultType (com.bakdata.conquery.models.externalservice.ResultType)5 I18n (com.bakdata.conquery.models.i18n.I18n)5 Locale (java.util.Locale)5 SelectResultInfo (com.bakdata.conquery.models.query.resultinfo.SelectResultInfo)4 UniqueNamer (com.bakdata.conquery.models.query.resultinfo.UniqueNamer)4 EntityResult (com.bakdata.conquery.models.query.results.EntityResult)4 StringJoiner (java.util.StringJoiner)4 Slf4j (lombok.extern.slf4j.Slf4j)4 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)3 ResultTestUtil (com.bakdata.conquery.io.result.ResultTestUtil)3 EntityPrintId (com.bakdata.conquery.models.identifiable.mapping.EntityPrintId)3 IOException (java.io.IOException)3 Stream (java.util.stream.Stream)3 Cell (org.apache.poi.ss.usermodel.Cell)3