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);
}
}
}
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;
}
Aggregations