Search in sources :

Example 1 with Entity

use of com.bakdata.conquery.models.query.entity.Entity in project conquery by bakdata.

the class BucketManager method removeBucket.

public void removeBucket(Bucket bucket) {
    storage.getAllCBlocks().stream().filter(cblock -> cblock.getBucket().equals(bucket)).forEach(this::removeCBlock);
    for (int entityId : bucket.entities()) {
        final Entity entity = entities.get(entityId);
        if (entity == null) {
            continue;
        }
        if (isEntityEmpty(entity)) {
            entities.remove(entityId);
        }
    }
    tableToBuckets.getOrDefault(bucket.getTable(), Int2ObjectMaps.emptyMap()).getOrDefault(bucket.getBucket(), Collections.emptyList()).remove(bucket);
    storage.removeBucket(bucket.getId());
}
Also used : CBlockId(com.bakdata.conquery.models.identifiable.ids.specific.CBlockId) ConnectorId(com.bakdata.conquery.models.identifiable.ids.specific.ConnectorId) Getter(lombok.Getter) WorkerStorage(com.bakdata.conquery.io.storage.WorkerStorage) SneakyThrows(lombok.SneakyThrows) ConceptTreeConnector(com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeConnector) RequiredArgsConstructor(lombok.RequiredArgsConstructor) HashMap(java.util.HashMap) Import(com.bakdata.conquery.models.datasets.Import) ArrayList(java.util.ArrayList) Connector(com.bakdata.conquery.models.datasets.concepts.Connector) Worker(com.bakdata.conquery.models.worker.Worker) IdMutex(com.bakdata.conquery.models.identifiable.IdMutex) CalculateCBlocksJob(com.bakdata.conquery.models.jobs.CalculateCBlocksJob) Map(java.util.Map) Locked(com.bakdata.conquery.models.identifiable.IdMutex.Locked) TreeConcept(com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept) Int2ObjectMaps(it.unimi.dsi.fastutil.ints.Int2ObjectMaps) Collection(java.util.Collection) Table(com.bakdata.conquery.models.datasets.Table) Concept(com.bakdata.conquery.models.datasets.concepts.Concept) IntArraySet(it.unimi.dsi.fastutil.ints.IntArraySet) JobManager(com.bakdata.conquery.models.jobs.JobManager) Entity(com.bakdata.conquery.models.query.entity.Entity) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) Int2ObjectAVLTreeMap(it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap) Collections(java.util.Collections) Entity(com.bakdata.conquery.models.query.entity.Entity)

Example 2 with Entity

use of com.bakdata.conquery.models.query.entity.Entity in project conquery by bakdata.

the class TableExportQueryPlan method execute.

@Override
public Optional<MultilineEntityResult> execute(QueryExecutionContext ctx, Entity entity) {
    Optional<? extends EntityResult> result = subPlan.execute(ctx, entity);
    if (result.isEmpty() || tables.isEmpty()) {
        return Optional.empty();
    }
    List<Object[]> results = new ArrayList<>();
    final int totalColumns = positions.values().stream().mapToInt(i -> i).max().getAsInt() + 1;
    for (TableExportDescription exportDescription : tables) {
        for (Bucket bucket : ctx.getEntityBucketsForTable(entity, exportDescription.getTable())) {
            int entityId = entity.getId();
            if (!bucket.containsEntity(entityId)) {
                continue;
            }
            int start = bucket.getEntityStart(entityId);
            int end = bucket.getEntityEnd(entityId);
            for (int event = start; event < end; event++) {
                // Export Full-table if it has no validity date.
                if (exportDescription.getValidityDateColumn() != null && !bucket.eventIsContainedIn(event, exportDescription.getValidityDateColumn(), CDateSet.create(dateRange))) {
                    continue;
                }
                Object[] entry = new Object[totalColumns];
                for (Column column : exportDescription.getTable().getColumns()) {
                    if (!bucket.has(event, column)) {
                        continue;
                    }
                    if (column.equals(exportDescription.getValidityDateColumn())) {
                        entry[0] = List.of(bucket.getAsDateRange(event, column));
                    } else {
                        entry[positions.get(column)] = bucket.createScriptValue(event, column);
                    }
                }
                results.add(entry);
            }
        }
    }
    return Optional.of(new MultilineEntityResult(entity.getId(), results));
}
Also used : Bucket(com.bakdata.conquery.models.events.Bucket) Getter(lombok.Getter) Table(com.bakdata.conquery.models.datasets.Table) EntityResult(com.bakdata.conquery.models.query.results.EntityResult) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CDateRange(com.bakdata.conquery.models.common.daterange.CDateRange) MultilineEntityResult(com.bakdata.conquery.models.query.results.MultilineEntityResult) ArrayList(java.util.ArrayList) Entity(com.bakdata.conquery.models.query.entity.Entity) List(java.util.List) QueryExecutionContext(com.bakdata.conquery.models.query.QueryExecutionContext) Map(java.util.Map) Aggregator(com.bakdata.conquery.models.query.queryplan.aggregators.Aggregator) Optional(java.util.Optional) Nullable(javax.annotation.Nullable) CDateSet(com.bakdata.conquery.models.common.CDateSet) Column(com.bakdata.conquery.models.datasets.Column) Bucket(com.bakdata.conquery.models.events.Bucket) Column(com.bakdata.conquery.models.datasets.Column) ArrayList(java.util.ArrayList) MultilineEntityResult(com.bakdata.conquery.models.query.results.MultilineEntityResult)

Example 3 with Entity

use of com.bakdata.conquery.models.query.entity.Entity 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 4 with Entity

use of com.bakdata.conquery.models.query.entity.Entity in project conquery by bakdata.

the class FormQueryPlan method createResultForNotContained.

private MultilineEntityResult createResultForNotContained(Entity entity, DateContext dateContext) {
    List<Object[]> result = new ArrayList<>();
    result.add(new Object[features.getAggregatorSize()]);
    return ResultModifier.modify(new MultilineEntityResult(entity.getId(), result), ResultModifier.existAggValuesSetterFor(getAggregators(), OptionalInt.of(0)).unaryAndThen(v -> addConstants(v, dateContext)));
}
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) ArrayList(java.util.ArrayList) MultilineEntityResult(com.bakdata.conquery.models.query.results.MultilineEntityResult)

Example 5 with Entity

use of com.bakdata.conquery.models.query.entity.Entity in project conquery by bakdata.

the class SerializationTests method executionQueryJobError.

@Test
public void executionQueryJobError() throws JSONException, IOException {
    log.info("Beware, this test will print an ERROR message.");
    ConqueryError error = new ConqueryError.ExecutionJobErrorWrapper(new Entity(5), new ConqueryError.UnknownError(null));
    SerializationTestUtil.forType(ConqueryError.class).test(error);
}
Also used : Entity(com.bakdata.conquery.models.query.entity.Entity) ConqueryError(com.bakdata.conquery.models.error.ConqueryError) Test(org.junit.jupiter.api.Test) IdMapSerialisationTest(com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)

Aggregations

Entity (com.bakdata.conquery.models.query.entity.Entity)7 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Getter (lombok.Getter)4 CDateSet (com.bakdata.conquery.models.common.CDateSet)3 Table (com.bakdata.conquery.models.datasets.Table)3 QueryExecutionContext (com.bakdata.conquery.models.query.QueryExecutionContext)3 Aggregator (com.bakdata.conquery.models.query.queryplan.aggregators.Aggregator)3 MultilineEntityResult (com.bakdata.conquery.models.query.results.MultilineEntityResult)3 Optional (java.util.Optional)3 Connector (com.bakdata.conquery.models.datasets.concepts.Connector)2 ConceptTreeConnector (com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeConnector)2 Bucket (com.bakdata.conquery.models.events.Bucket)2 DateContext (com.bakdata.conquery.models.forms.util.DateContext)2 ResultModifier (com.bakdata.conquery.models.forms.util.ResultModifier)2 IdMutex (com.bakdata.conquery.models.identifiable.IdMutex)2 ArrayConceptQueryPlan (com.bakdata.conquery.models.query.queryplan.ArrayConceptQueryPlan)2 QueryPlan (com.bakdata.conquery.models.query.queryplan.QueryPlan)2 SinglelineEntityResult (com.bakdata.conquery.models.query.results.SinglelineEntityResult)2 QueryUtils (com.bakdata.conquery.util.QueryUtils)2