use of com.bakdata.conquery.models.query.QueryPlanContext in project conquery by bakdata.
the class CQConcept method createQueryPlan.
@Override
public QPNode createQueryPlan(QueryPlanContext context, ConceptQueryPlan plan) {
final List<Aggregator<?>> conceptAggregators = createAggregators(plan, selects);
List<QPNode> tableNodes = new ArrayList<>();
for (CQTable table : tables) {
List<FilterNode<?>> filters = table.getFilters().stream().map(FilterValue::createNode).collect(Collectors.toList());
// add filter to children
List<Aggregator<?>> aggregators = new ArrayList<>();
aggregators.addAll(conceptAggregators);
final List<Aggregator<?>> connectorAggregators = createAggregators(plan, table.getSelects());
// Exists aggregators hold a reference to their parent FiltersNode so they need to be treated separately.
// They also don't need aggregation as they simply imitate their reference.
List<ExistsAggregator> existsAggregators = connectorAggregators.stream().filter(ExistsAggregator.class::isInstance).map(ExistsAggregator.class::cast).collect(Collectors.toList());
aggregators.addAll(connectorAggregators);
aggregators.removeIf(ExistsAggregator.class::isInstance);
List<Aggregator<CDateSet>> eventDateUnionAggregators = aggregateEventDates ? List.of(new EventDateUnionAggregator(Set.of(table.getConnector().getTable()))) : Collections.emptyList();
aggregators.addAll(eventDateUnionAggregators);
final QPNode filtersNode = getConcept().createConceptQuery(context, filters, aggregators, eventDateUnionAggregators);
// Link up the ExistsAggregators to the node
existsAggregators.forEach(agg -> agg.setReference(filtersNode));
// Select if matching secondaryId available
final boolean hasSelectedSecondaryId = Arrays.stream(table.getConnector().getTable().getColumns()).map(Column::getSecondaryId).filter(Objects::nonNull).anyMatch(o -> Objects.equals(context.getSelectedSecondaryId(), o));
final Column validityDateColumn = selectValidityDateColumn(table);
final ConceptNode node = new ConceptNode(// TODO Don't set validity node, when no validity column exists. See workaround for this and remove it: https://github.com/bakdata/conquery/pull/1362
new ValidityDateNode(validityDateColumn, filtersNode), elements, table, // if the node is excluded, don't pass it into the Node.
!excludeFromSecondaryId && hasSelectedSecondaryId ? context.getSelectedSecondaryId() : null);
tableNodes.add(node);
}
// We always merge on concept level
final QPNode outNode = OrNode.of(tableNodes, aggregateEventDates ? DateAggregationAction.MERGE : DateAggregationAction.BLOCK);
// Link concept-level Exists-select to outer node.
conceptAggregators.stream().filter(aggregator -> aggregator instanceof ExistsAggregator).forEach(aggregator -> ((ExistsAggregator) aggregator).setReference(outNode));
return outNode;
}
use of com.bakdata.conquery.models.query.QueryPlanContext 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;
}
}
}
use of com.bakdata.conquery.models.query.QueryPlanContext 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);
}
Aggregations