Search in sources :

Example 6 with CDateSet

use of com.bakdata.conquery.models.common.CDateSet in project conquery by bakdata.

the class CountQuartersOfDateRangeAggregator method acceptEvent.

@Override
public void acceptEvent(Bucket bucket, int event) {
    if (!bucket.has(event, getColumn())) {
        return;
    }
    final CDateSet set = CDateSet.create(bucket.getDateRange(event, getColumn()));
    set.retainAll(dateRestriction);
    for (CDateRange subRange : set.asRanges()) {
        // we can sensibly only look at real quarters.
        if (subRange.isOpen()) {
            continue;
        }
        addDateRange(subRange);
    }
}
Also used : CDateRange(com.bakdata.conquery.models.common.daterange.CDateRange) CDateSet(com.bakdata.conquery.models.common.CDateSet)

Example 7 with CDateSet

use of com.bakdata.conquery.models.common.CDateSet in project conquery by bakdata.

the class DateRestrictingNode method nextTable.

@Override
public void nextTable(QueryExecutionContext ctx, Table currentTable) {
    // if there was no date restriction we can just use the restriction CDateSet
    if (ctx.getDateRestriction().isAll()) {
        ctx = ctx.withDateRestriction(CDateSet.create(restriction));
    } else {
        CDateSet dateRestriction = CDateSet.create(ctx.getDateRestriction());
        dateRestriction.retainAll(restriction);
        ctx = ctx.withDateRestriction(dateRestriction);
    }
    super.nextTable(ctx, currentTable);
    preCurrentRow = ctx.getBucketManager().getEntityCBlocksForConnector(getEntity(), context.getConnector());
    validityDateColumn = context.getValidityDateColumn();
    if (validityDateColumn != null && !validityDateColumn.getType().isDateCompatible()) {
        throw new IllegalStateException("The validityDateColumn " + validityDateColumn + " is not a DATE TYPE");
    }
}
Also used : CDateSet(com.bakdata.conquery.models.common.CDateSet)

Example 8 with CDateSet

use of com.bakdata.conquery.models.common.CDateSet in project conquery by bakdata.

the class DateAggregator method createAggregationResult.

@Override
public CDateSet createAggregationResult() {
    final Set<CDateSet> all = new HashSet<>();
    children.forEach(s -> {
        CDateSet result = s.createAggregationResult();
        if (result != null) {
            all.add(result);
        }
    });
    // Repackage to get the results sorted. Might need some optimization.
    return action.aggregate(all);
}
Also used : CDateSet(com.bakdata.conquery.models.common.CDateSet) HashSet(java.util.HashSet)

Example 9 with CDateSet

use of com.bakdata.conquery.models.common.CDateSet in project conquery by bakdata.

the class DateReader method parseToCDateSet.

/**
 * Try and parse value to CDateSet using all available layouts, but starting at the last known successful one.
 */
public CDateSet parseToCDateSet(String value) {
    if (Strings.isNullOrEmpty(value)) {
        return null;
    }
    final int root = lastDateSetLayoutIndex.get();
    for (int offset = 0; offset < dateSetLayouts.size(); offset++) {
        final int index = (root + offset) % dateSetLayouts.size();
        final LocaleConfig.ListFormat sep = dateSetLayouts.get(index);
        try {
            final CDateSet result = sep.parse(value, this);
            lastDateSetLayoutIndex.set(index);
            return result;
        } catch (ParsingException e) {
            log.trace("Parsing failed for date set '{}' with pattern '{}'", value, sep, e);
        }
    }
    throw new ParsingException("None of the configured formats to parse the date set: " + value);
}
Also used : ParsingException(com.bakdata.conquery.models.exceptions.ParsingException) LocaleConfig(com.bakdata.conquery.models.config.LocaleConfig) CDateSet(com.bakdata.conquery.models.common.CDateSet)

Example 10 with CDateSet

use of com.bakdata.conquery.models.common.CDateSet in project conquery by bakdata.

the class TemporalQueryNode method isContained.

/**
 * Retrieves the {@link ConceptQueryPlan#getDateAggregator()} time of {@link #reference} and {@link #preceding}.
 * Then tests whether they match the specific criteria for inclusion.
 * If the criteria are met, the matching {@link CDateSet} is put into the @{@link SpecialDateUnion} node of the Queries associated QueryPlan.
 *
 * @return true, iff the Events match the specific criteria.
 */
@Override
public final boolean isContained() {
    if (!reference.isContained()) {
        return false;
    }
    CDateSet referenceDurations = dateAggregationAction.aggregate(getReference().getDateAggregators().stream().map(Aggregator::createAggregationResult).collect(Collectors.toSet()));
    // Create copy as we are mutating the set
    CDateSet precedingDurations = dateAggregationAction.aggregate(getPreceding().getDateAggregators().stream().map(Aggregator::createAggregationResult).collect(Collectors.toSet()));
    OptionalInt sampledReference = getReferenceSampler().sample(referenceDurations);
    if (sampledReference.isEmpty()) {
        return false;
    }
    matcher.removePreceding(precedingDurations, sampledReference.getAsInt());
    OptionalInt sampledPreceding = getPrecedingSampler().sample(precedingDurations);
    if (matcher.isContained(sampledReference, sampledPreceding)) {
        dateUnion.merge(referenceDurations);
        return true;
    }
    return false;
}
Also used : Aggregator(com.bakdata.conquery.models.query.queryplan.aggregators.Aggregator) OptionalInt(java.util.OptionalInt) CDateSet(com.bakdata.conquery.models.common.CDateSet)

Aggregations

CDateSet (com.bakdata.conquery.models.common.CDateSet)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)4 CDateRange (com.bakdata.conquery.models.common.daterange.CDateRange)3 DateContext (com.bakdata.conquery.models.forms.util.DateContext)3 Aggregator (com.bakdata.conquery.models.query.queryplan.aggregators.Aggregator)3 OptionalInt (java.util.OptionalInt)3 EntityResult (com.bakdata.conquery.models.query.results.EntityResult)2 MultilineEntityResult (com.bakdata.conquery.models.query.results.MultilineEntityResult)2 List (java.util.List)2 Getter (lombok.Getter)2 ExportForm (com.bakdata.conquery.apiv1.forms.export_form.ExportForm)1 CQElement (com.bakdata.conquery.apiv1.query.CQElement)1 CQTable (com.bakdata.conquery.apiv1.query.concept.filter.CQTable)1 FilterValue (com.bakdata.conquery.apiv1.query.concept.filter.FilterValue)1 CPSType (com.bakdata.conquery.io.cps.CPSType)1 InternalOnly (com.bakdata.conquery.io.jackson.InternalOnly)1 NsIdRefCollection (com.bakdata.conquery.io.jackson.serializer.NsIdRefCollection)1 LocaleConfig (com.bakdata.conquery.models.config.LocaleConfig)1