Search in sources :

Example 1 with SinglelineEntityResult

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));
}
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 2 with SinglelineEntityResult

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));
}
Also used : SinglelineEntityResult(com.bakdata.conquery.models.query.results.SinglelineEntityResult)

Aggregations

SinglelineEntityResult (com.bakdata.conquery.models.query.results.SinglelineEntityResult)2 CDateSet (com.bakdata.conquery.models.common.CDateSet)1 DateContext (com.bakdata.conquery.models.forms.util.DateContext)1 ResultModifier (com.bakdata.conquery.models.forms.util.ResultModifier)1 QueryExecutionContext (com.bakdata.conquery.models.query.QueryExecutionContext)1 Entity (com.bakdata.conquery.models.query.entity.Entity)1 ArrayConceptQueryPlan (com.bakdata.conquery.models.query.queryplan.ArrayConceptQueryPlan)1 QueryPlan (com.bakdata.conquery.models.query.queryplan.QueryPlan)1 Aggregator (com.bakdata.conquery.models.query.queryplan.aggregators.Aggregator)1 MultilineEntityResult (com.bakdata.conquery.models.query.results.MultilineEntityResult)1 QueryUtils (com.bakdata.conquery.util.QueryUtils)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 OptionalInt (java.util.OptionalInt)1 Getter (lombok.Getter)1