Search in sources :

Example 6 with QueryExecutionContext

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

the class SecondaryIdQueryPlan method executeQueriesWithSecondaryId.

private void executeQueriesWithSecondaryId(QueryExecutionContext ctx, Entity entity, Column secondaryIdColumnId) {
    QueryExecutionContext ctxWithPhase = ctx.withActiveSecondaryId(getSecondaryId());
    Table currentTable = secondaryIdColumnId.getTable();
    nextTable(ctxWithPhase, currentTable);
    final List<Bucket> tableBuckets = ctx.getBucketManager().getEntityBucketsForTable(entity, currentTable);
    for (Bucket bucket : tableBuckets) {
        int entityId = entity.getId();
        nextBlock(bucket);
        if (!bucket.containsEntity(entityId)) {
            continue;
        }
        if (!isOfInterest(bucket)) {
            continue;
        }
        int start = bucket.getEntityStart(entityId);
        int end = bucket.getEntityEnd(entityId);
        for (int event = start; event < end; event++) {
            // we ignore events with no value in the secondaryIdColumn
            if (!bucket.has(event, secondaryIdColumnId)) {
                continue;
            }
            String key = ((String) bucket.createScriptValue(event, secondaryIdColumnId));
            final ConceptQueryPlan plan = childPerKey.computeIfAbsent(key, k -> createChild(ctxWithPhase, bucket));
            plan.nextEvent(bucket, event);
        }
    }
}
Also used : Table(com.bakdata.conquery.models.datasets.Table) QueryExecutionContext(com.bakdata.conquery.models.query.QueryExecutionContext) Bucket(com.bakdata.conquery.models.events.Bucket)

Example 7 with QueryExecutionContext

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

the class SecondaryIdQueryPlan method createChild.

/**
 * if a new distinct secondaryId was found we create a new clone of the ConceptQueryPlan
 * and bring it up to speed
 */
private ConceptQueryPlan createChild(QueryExecutionContext currentContext, Bucket currentBucket) {
    ConceptQueryPlan plan;
    // Try to reuse old child plan first before allocating new ones
    if ((plan = childPlanReusePool.poll()) == null) {
        plan = query.createQueryPlan(queryPlanContext.withSelectedSecondaryId(secondaryId));
    }
    final QueryExecutionContext context = QueryUtils.determineDateAggregatorForContext(currentContext, plan::getValidityDateAggregator);
    plan.init(context, queryPlan.getEntity());
    plan.nextTable(context, currentBucket.getTable());
    plan.isOfInterest(currentBucket);
    plan.nextBlock(currentBucket);
    return plan;
}
Also used : QueryExecutionContext(com.bakdata.conquery.models.query.QueryExecutionContext)

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