use of com.bakdata.conquery.models.query.results.SinglelineEntityResult 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));
}
use of com.bakdata.conquery.models.query.results.SinglelineEntityResult in project conquery by bakdata.
the class ArrayConceptQueryPlan method execute.
@Override
public Optional<SinglelineEntityResult> execute(QueryExecutionContext ctx, Entity entity) {
// Only override if none has been set from a higher level
ctx = QueryUtils.determineDateAggregatorForContext(ctx, this::getValidityDateAggregator);
if (!isOfInterest(entity)) {
return Optional.empty();
}
Object[] resultValues = new Object[getAggregatorSize()];
// Start with 1 for aggregator values if dateSet needs to be added to the result
final int resultOffset = generateDateAggregation ? 1 : 0;
int resultInsertIdx = resultOffset;
boolean containedInChildQueries = false;
for (ConceptQueryPlan child : childPlans) {
Optional<SinglelineEntityResult> result = child.execute(ctx, entity);
if (result.isEmpty()) {
// The sub result was empty. Generate the necessary gapped columns in the result line
final Object[] applied = ResultModifier.existAggValuesSetterFor(child.getAggregators(), OptionalInt.of(0)).apply(new Object[child.getAggregatorSize()]);
// applied[0] is the child-queries DateUnion, which we don't copy.
int copyLength = applied.length - resultOffset;
System.arraycopy(applied, resultOffset, resultValues, resultInsertIdx, copyLength);
// Advance pointer for the result insertion by the number of currently handled
// aggregators.
resultInsertIdx = nextIndex(resultInsertIdx, child);
continue;
}
SinglelineEntityResult singleLineResult = result.get();
// Mark this result line as contained.
containedInChildQueries = true;
int copyLength = calculateCopyLength(singleLineResult);
System.arraycopy(singleLineResult.getValues(), resultOffset, resultValues, resultInsertIdx, copyLength);
// Advance pointer for the result insertion by the number of currently handled
// aggregators.
resultInsertIdx = nextIndex(resultInsertIdx, child);
}
if (!containedInChildQueries) {
// None of the subqueries contained an result
return Optional.empty();
}
if (generateDateAggregation) {
// Dateset was needed, add it to the front.
resultValues[VALIDITY_DATE_POSITION] = validityDateAggregator.createAggregationResult();
}
return Optional.of(new SinglelineEntityResult(entity.getId(), resultValues));
}
Aggregations