Search in sources :

Example 1 with QueryExecutionContext

use of com.bakdata.conquery.models.query.QueryExecutionContext in project conquery by bakdata.

the class SecondaryIdQueryPlan method nextTable.

private void nextTable(QueryExecutionContext ctx, Table currentTable) {
    queryPlan.nextTable(ctx, currentTable);
    for (ConceptQueryPlan c : childPerKey.values()) {
        QueryExecutionContext context = QueryUtils.determineDateAggregatorForContext(ctx, c::getValidityDateAggregator);
        c.nextTable(context, currentTable);
    }
}
Also used : QueryExecutionContext(com.bakdata.conquery.models.query.QueryExecutionContext)

Example 2 with QueryExecutionContext

use of com.bakdata.conquery.models.query.QueryExecutionContext in project conquery by bakdata.

the class TableExportQueryPlan method execute.

@Override
public Optional<MultilineEntityResult> execute(QueryExecutionContext ctx, Entity entity) {
    Optional<? extends EntityResult> result = subPlan.execute(ctx, entity);
    if (result.isEmpty() || tables.isEmpty()) {
        return Optional.empty();
    }
    List<Object[]> results = new ArrayList<>();
    final int totalColumns = positions.values().stream().mapToInt(i -> i).max().getAsInt() + 1;
    for (TableExportDescription exportDescription : tables) {
        for (Bucket bucket : ctx.getEntityBucketsForTable(entity, exportDescription.getTable())) {
            int entityId = entity.getId();
            if (!bucket.containsEntity(entityId)) {
                continue;
            }
            int start = bucket.getEntityStart(entityId);
            int end = bucket.getEntityEnd(entityId);
            for (int event = start; event < end; event++) {
                // Export Full-table if it has no validity date.
                if (exportDescription.getValidityDateColumn() != null && !bucket.eventIsContainedIn(event, exportDescription.getValidityDateColumn(), CDateSet.create(dateRange))) {
                    continue;
                }
                Object[] entry = new Object[totalColumns];
                for (Column column : exportDescription.getTable().getColumns()) {
                    if (!bucket.has(event, column)) {
                        continue;
                    }
                    if (column.equals(exportDescription.getValidityDateColumn())) {
                        entry[0] = List.of(bucket.getAsDateRange(event, column));
                    } else {
                        entry[positions.get(column)] = bucket.createScriptValue(event, column);
                    }
                }
                results.add(entry);
            }
        }
    }
    return Optional.of(new MultilineEntityResult(entity.getId(), results));
}
Also used : Bucket(com.bakdata.conquery.models.events.Bucket) Getter(lombok.Getter) Table(com.bakdata.conquery.models.datasets.Table) EntityResult(com.bakdata.conquery.models.query.results.EntityResult) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CDateRange(com.bakdata.conquery.models.common.daterange.CDateRange) MultilineEntityResult(com.bakdata.conquery.models.query.results.MultilineEntityResult) ArrayList(java.util.ArrayList) Entity(com.bakdata.conquery.models.query.entity.Entity) List(java.util.List) QueryExecutionContext(com.bakdata.conquery.models.query.QueryExecutionContext) Map(java.util.Map) Aggregator(com.bakdata.conquery.models.query.queryplan.aggregators.Aggregator) Optional(java.util.Optional) Nullable(javax.annotation.Nullable) CDateSet(com.bakdata.conquery.models.common.CDateSet) Column(com.bakdata.conquery.models.datasets.Column) Bucket(com.bakdata.conquery.models.events.Bucket) Column(com.bakdata.conquery.models.datasets.Column) ArrayList(java.util.ArrayList) MultilineEntityResult(com.bakdata.conquery.models.query.results.MultilineEntityResult)

Example 3 with QueryExecutionContext

use of com.bakdata.conquery.models.query.QueryExecutionContext in project conquery by bakdata.

the class FormQueryPlan method execute.

@Override
public Optional<MultilineEntityResult> execute(QueryExecutionContext ctx, Entity entity) {
    if (!isOfInterest(entity)) {
        // If the entity is not covered by the query generate a basic result line with constants but without features
        return Optional.of(createResultForNotContained(entity, null));
    }
    List<Object[]> resultValues = new ArrayList<>(dateContexts.size());
    for (DateContext dateContext : dateContexts) {
        CDateSet dateRestriction = CDateSet.create(ctx.getDateRestriction());
        dateRestriction.retainAll(dateContext.getDateRange());
        // Reference the dates per sub-query, don't accumulate dates of all sub-queries
        QueryExecutionContext innerContext = QueryUtils.determineDateAggregatorForContext(ctx, features::getValidityDateAggregator).withDateRestriction(dateRestriction);
        features.init(ctx, entity);
        Optional<SinglelineEntityResult> subResult = features.execute(innerContext, entity);
        if (subResult.isEmpty()) {
            resultValues.addAll(createResultForNotContained(entity, dateContext).listResultLines());
            continue;
        }
        resultValues.addAll(ResultModifier.modify(subResult.get(), ResultModifier.existAggValuesSetterFor(features.getAggregators(), OptionalInt.of(0)).unaryAndThen(v -> addConstants(v, dateContext))).listResultLines());
    }
    return Optional.of(new MultilineEntityResult(entity.getId(), resultValues));
}
Also used : Getter(lombok.Getter) SinglelineEntityResult(com.bakdata.conquery.models.query.results.SinglelineEntityResult) MultilineEntityResult(com.bakdata.conquery.models.query.results.MultilineEntityResult) OptionalInt(java.util.OptionalInt) ArrayConceptQueryPlan(com.bakdata.conquery.models.query.queryplan.ArrayConceptQueryPlan) ArrayList(java.util.ArrayList) Entity(com.bakdata.conquery.models.query.entity.Entity) List(java.util.List) DateContext(com.bakdata.conquery.models.forms.util.DateContext) QueryExecutionContext(com.bakdata.conquery.models.query.QueryExecutionContext) ResultModifier(com.bakdata.conquery.models.forms.util.ResultModifier) Aggregator(com.bakdata.conquery.models.query.queryplan.aggregators.Aggregator) QueryUtils(com.bakdata.conquery.util.QueryUtils) Optional(java.util.Optional) QueryPlan(com.bakdata.conquery.models.query.queryplan.QueryPlan) CDateSet(com.bakdata.conquery.models.common.CDateSet) QueryExecutionContext(com.bakdata.conquery.models.query.QueryExecutionContext) ArrayList(java.util.ArrayList) DateContext(com.bakdata.conquery.models.forms.util.DateContext) SinglelineEntityResult(com.bakdata.conquery.models.query.results.SinglelineEntityResult) MultilineEntityResult(com.bakdata.conquery.models.query.results.MultilineEntityResult) CDateSet(com.bakdata.conquery.models.common.CDateSet)

Example 4 with QueryExecutionContext

use of com.bakdata.conquery.models.query.QueryExecutionContext in project conquery by bakdata.

the class ExecuteForm method react.

@Override
public void react(Worker worker) throws Exception {
    log.info("Started Form {}", formId);
    // Execution might have been cancelled before so we uncancel it here.
    final QueryExecutor queryExecutor = worker.getQueryExecutor();
    queryExecutor.unsetQueryCancelled(formId);
    // Execute all plans.
    for (Entry<ManagedExecutionId, Query> entry : queries.entrySet()) {
        final Query query = entry.getValue();
        ShardResult result = createResult(worker, entry.getKey());
        // Before we start the query, we create it once to test if it will succeed before creating it multiple times for evaluation per core.
        try {
            query.createQueryPlan(new QueryPlanContext(worker));
        } catch (Exception e) {
            ConqueryError err = asConqueryError(e);
            log.warn("Failed to create query plans for {}.", formId, err);
            queryExecutor.sendFailureToManagerNode(result, err);
            return;
        }
        final QueryExecutionContext subQueryContext = new QueryExecutionContext(formId, queryExecutor, worker.getStorage(), worker.getBucketManager());
        if (!queryExecutor.execute(query, subQueryContext, result)) {
            return;
        }
    }
}
Also used : ConqueryError.asConqueryError(com.bakdata.conquery.models.error.ConqueryError.asConqueryError) ConqueryError(com.bakdata.conquery.models.error.ConqueryError) Query(com.bakdata.conquery.apiv1.query.Query) QueryExecutionContext(com.bakdata.conquery.models.query.QueryExecutionContext) QueryExecutor(com.bakdata.conquery.models.query.QueryExecutor) ManagedExecutionId(com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId) FormShardResult(com.bakdata.conquery.models.query.results.FormShardResult) ShardResult(com.bakdata.conquery.models.query.results.ShardResult) QueryPlanContext(com.bakdata.conquery.models.query.QueryPlanContext)

Example 5 with QueryExecutionContext

use of com.bakdata.conquery.models.query.QueryExecutionContext in project conquery by bakdata.

the class ExecuteQuery method react.

@Override
public void react(Worker worker) throws Exception {
    final ManagedExecutionId executionId = id;
    log.info("Started {} {}", query.getClass().getSimpleName(), executionId);
    // Execution might have been cancelled before so we uncancel it here.
    final QueryExecutor queryExecutor = worker.getQueryExecutor();
    queryExecutor.unsetQueryCancelled(executionId);
    final ShardResult result = createShardResult(worker);
    // Before we start the query, we create it once to test if it will succeed before creating it multiple times for evaluation per core.
    try {
        query.createQueryPlan(new QueryPlanContext(worker));
    } catch (Exception e) {
        ConqueryError err = asConqueryError(e);
        log.warn("Failed to create query plans for {}.", executionId, err);
        queryExecutor.sendFailureToManagerNode(result, err);
        return;
    }
    final QueryExecutionContext executionContext = new QueryExecutionContext(executionId, queryExecutor, worker.getStorage(), worker.getBucketManager());
    queryExecutor.execute(query, executionContext, result);
}
Also used : ConqueryError.asConqueryError(com.bakdata.conquery.models.error.ConqueryError.asConqueryError) ConqueryError(com.bakdata.conquery.models.error.ConqueryError) QueryExecutionContext(com.bakdata.conquery.models.query.QueryExecutionContext) QueryExecutor(com.bakdata.conquery.models.query.QueryExecutor) ManagedExecutionId(com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId) ShardResult(com.bakdata.conquery.models.query.results.ShardResult) QueryPlanContext(com.bakdata.conquery.models.query.QueryPlanContext)

Aggregations

QueryExecutionContext (com.bakdata.conquery.models.query.QueryExecutionContext)7 CDateSet (com.bakdata.conquery.models.common.CDateSet)2 Table (com.bakdata.conquery.models.datasets.Table)2 ConqueryError (com.bakdata.conquery.models.error.ConqueryError)2 ConqueryError.asConqueryError (com.bakdata.conquery.models.error.ConqueryError.asConqueryError)2 Bucket (com.bakdata.conquery.models.events.Bucket)2 ManagedExecutionId (com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId)2 QueryExecutor (com.bakdata.conquery.models.query.QueryExecutor)2 QueryPlanContext (com.bakdata.conquery.models.query.QueryPlanContext)2 Entity (com.bakdata.conquery.models.query.entity.Entity)2 Aggregator (com.bakdata.conquery.models.query.queryplan.aggregators.Aggregator)2 MultilineEntityResult (com.bakdata.conquery.models.query.results.MultilineEntityResult)2 ShardResult (com.bakdata.conquery.models.query.results.ShardResult)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2 Getter (lombok.Getter)2 Query (com.bakdata.conquery.apiv1.query.Query)1 CDateRange (com.bakdata.conquery.models.common.daterange.CDateRange)1 Column (com.bakdata.conquery.models.datasets.Column)1