Search in sources :

Example 1 with CQUnfilteredTable

use of com.bakdata.conquery.apiv1.query.concept.filter.CQUnfilteredTable in project conquery by bakdata.

the class TableExportQuery method resolve.

@Override
public void resolve(QueryResolveContext context) {
    query.resolve(context);
    // First is dates
    AtomicInteger currentPosition = new AtomicInteger(1);
    positions = new HashMap<>();
    Map<SecondaryIdDescription, Integer> secondaryIdPositions = new HashMap<>();
    // SecondaryIds are pulled to the front and grouped over all tables
    tables.stream().map(cqUnfilteredTable -> cqUnfilteredTable.getTable().getTable().getColumns()).flatMap(Arrays::stream).map(Column::getSecondaryId).filter(Objects::nonNull).distinct().sorted(Comparator.comparing(SecondaryIdDescription::getLabel)).forEach(secondaryId -> secondaryIdPositions.put(secondaryId, currentPosition.getAndIncrement()));
    for (CQUnfilteredTable table : tables) {
        Connector connector = table.getTable();
        final Column validityDateColumn = findValidityDateColumn(connector, table.getDateColumn());
        if (validityDateColumn != null) {
            positions.putIfAbsent(validityDateColumn, 0);
        }
        // Set column positions, set SecondaryId positions to precomputed ones.
        for (Column column : connector.getTable().getColumns()) {
            positions.computeIfAbsent(column, col -> col.getSecondaryId() != null ? secondaryIdPositions.get(col.getSecondaryId()) : currentPosition.getAndIncrement());
        }
    }
    resultInfos = createResultInfos(currentPosition.get(), secondaryIdPositions, positions);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Connector(com.bakdata.conquery.models.datasets.concepts.Connector) CQUnfilteredTable(com.bakdata.conquery.apiv1.query.concept.filter.CQUnfilteredTable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) Column(com.bakdata.conquery.models.datasets.Column) SecondaryIdDescription(com.bakdata.conquery.models.datasets.SecondaryIdDescription)

Example 2 with CQUnfilteredTable

use of com.bakdata.conquery.apiv1.query.concept.filter.CQUnfilteredTable in project conquery by bakdata.

the class FullExportForm method createSubQueries.

@Override
public Map<String, List<ManagedQuery>> createSubQueries(DatasetRegistry datasets, User user, Dataset submittedDataset) {
    // Forms are sent as an array of standard queries containing AND/OR of CQConcepts, we ignore everything and just convert the CQConcepts into CQUnfiltered for export.
    final List<CQUnfilteredTable> unfilteredTables = tables.stream().flatMap(Visitable::stream).filter(CQConcept.class::isInstance).map(CQConcept.class::cast).flatMap(concept -> concept.getTables().stream()).map(table -> new CQUnfilteredTable(table.getConnector(), table.getDateColumn())).collect(Collectors.toList());
    final TableExportQuery exportQuery = new TableExportQuery(queryGroup.getQuery());
    exportQuery.setDateRange(getDateRange());
    exportQuery.setTables(unfilteredTables);
    final ManagedQuery managedQuery = new ManagedQuery(exportQuery, user, submittedDataset);
    return Map.of(ConqueryConstants.SINGLE_RESULT_TABLE_NAME, List.of(managedQuery));
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Setter(lombok.Setter) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) CQUnfilteredTable(com.bakdata.conquery.apiv1.query.concept.filter.CQUnfilteredTable) ManagedForm(com.bakdata.conquery.models.forms.managed.ManagedForm) Getter(lombok.Getter) ManagedInternalForm(com.bakdata.conquery.models.forms.managed.ManagedInternalForm) NotEmpty(javax.validation.constraints.NotEmpty) Valid(javax.validation.Valid) ManagedExecutionId(com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId) ManagedExecution(com.bakdata.conquery.models.execution.ManagedExecution) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) I18n(com.bakdata.conquery.models.i18n.I18n) QueryDescription(com.bakdata.conquery.apiv1.query.QueryDescription) ConqueryConstants(com.bakdata.conquery.ConqueryConstants) Nullable(javax.annotation.Nullable) Range(com.bakdata.conquery.models.common.Range) CPSType(com.bakdata.conquery.io.cps.CPSType) Visitable(com.bakdata.conquery.models.query.Visitable) Set(java.util.Set) Form(com.bakdata.conquery.apiv1.forms.Form) NotNull(javax.validation.constraints.NotNull) User(com.bakdata.conquery.models.auth.entities.User) Collectors(java.util.stream.Collectors) ExportFormC10n(com.bakdata.conquery.internationalization.ExportFormC10n) Dataset(com.bakdata.conquery.models.datasets.Dataset) Consumer(java.util.function.Consumer) List(java.util.List) TableExportQuery(com.bakdata.conquery.apiv1.query.TableExportQuery) C10N(c10n.C10N) QueryResolveContext(com.bakdata.conquery.models.query.QueryResolveContext) LocalDate(java.time.LocalDate) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) CQElement(com.bakdata.conquery.apiv1.query.CQElement) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) Collections(java.util.Collections) CQUnfilteredTable(com.bakdata.conquery.apiv1.query.concept.filter.CQUnfilteredTable) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) TableExportQuery(com.bakdata.conquery.apiv1.query.TableExportQuery) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery)

Example 3 with CQUnfilteredTable

use of com.bakdata.conquery.apiv1.query.concept.filter.CQUnfilteredTable in project conquery by bakdata.

the class TableExportQuery method createQueryPlan.

@Override
public TableExportQueryPlan createQueryPlan(QueryPlanContext context) {
    List<TableExportDescription> resolvedConnectors = new ArrayList<>();
    for (CQUnfilteredTable table : tables) {
        Connector connector = table.getTable();
        // if no dateColumn is provided, we use the default instead which is always the first one.
        // Set to null if none-available in the connector.
        final Column validityDateColumn = findValidityDateColumn(connector, table.getDateColumn());
        final TableExportDescription exportDescription = new TableExportDescription(connector.getTable(), validityDateColumn);
        resolvedConnectors.add(exportDescription);
    }
    return new TableExportQueryPlan(query.createQueryPlan(context), CDateRange.of(dateRange), resolvedConnectors, positions);
}
Also used : Connector(com.bakdata.conquery.models.datasets.concepts.Connector) CQUnfilteredTable(com.bakdata.conquery.apiv1.query.concept.filter.CQUnfilteredTable) Column(com.bakdata.conquery.models.datasets.Column) TableExportQueryPlan(com.bakdata.conquery.models.query.queryplan.TableExportQueryPlan) TableExportDescription(com.bakdata.conquery.models.query.queryplan.TableExportQueryPlan.TableExportDescription) ArrayList(java.util.ArrayList)

Aggregations

CQUnfilteredTable (com.bakdata.conquery.apiv1.query.concept.filter.CQUnfilteredTable)3 Column (com.bakdata.conquery.models.datasets.Column)2 Connector (com.bakdata.conquery.models.datasets.concepts.Connector)2 C10N (c10n.C10N)1 ConqueryConstants (com.bakdata.conquery.ConqueryConstants)1 Form (com.bakdata.conquery.apiv1.forms.Form)1 CQElement (com.bakdata.conquery.apiv1.query.CQElement)1 QueryDescription (com.bakdata.conquery.apiv1.query.QueryDescription)1 TableExportQuery (com.bakdata.conquery.apiv1.query.TableExportQuery)1 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)1 ExportFormC10n (com.bakdata.conquery.internationalization.ExportFormC10n)1 CPSType (com.bakdata.conquery.io.cps.CPSType)1 User (com.bakdata.conquery.models.auth.entities.User)1 Range (com.bakdata.conquery.models.common.Range)1 Dataset (com.bakdata.conquery.models.datasets.Dataset)1 SecondaryIdDescription (com.bakdata.conquery.models.datasets.SecondaryIdDescription)1 ManagedExecution (com.bakdata.conquery.models.execution.ManagedExecution)1 ManagedForm (com.bakdata.conquery.models.forms.managed.ManagedForm)1 ManagedInternalForm (com.bakdata.conquery.models.forms.managed.ManagedInternalForm)1 I18n (com.bakdata.conquery.models.i18n.I18n)1