Search in sources :

Example 6 with QueryDescription

use of com.bakdata.conquery.apiv1.query.QueryDescription in project conquery by bakdata.

the class ManagedExecution method setAdditionalFieldsForStatusWithSource.

/**
 * Sets additional fields of an {@link ExecutionStatus} when a more specific status is requested.
 */
protected void setAdditionalFieldsForStatusWithSource(Subject subject, FullExecutionStatus status) {
    QueryDescription query = getSubmitted();
    NamespacedIdentifiableCollector namespacesIdCollector = new NamespacedIdentifiableCollector();
    query.visit(namespacesIdCollector);
    final Set<Concept> concepts = namespacesIdCollector.getIdentifiables().stream().filter(ConceptElement.class::isInstance).map(ConceptElement.class::cast).map(ConceptElement::getConcept).collect(Collectors.toSet());
    boolean canExpand = subject.isPermittedAll(concepts, Ability.READ);
    status.setCanExpand(canExpand);
    status.setQuery(canExpand ? getSubmitted() : null);
}
Also used : Concept(com.bakdata.conquery.models.datasets.concepts.Concept) NamespacedIdentifiableCollector(com.bakdata.conquery.util.QueryUtils.NamespacedIdentifiableCollector) ConceptElement(com.bakdata.conquery.models.datasets.concepts.ConceptElement) QueryDescription(com.bakdata.conquery.apiv1.query.QueryDescription)

Example 7 with QueryDescription

use of com.bakdata.conquery.apiv1.query.QueryDescription in project conquery by bakdata.

the class QueryProcessor method tryReuse.

/**
 * Determine if the submitted query does reuse ONLY another query and restart that instead of creating another one.
 */
private ManagedExecution<?> tryReuse(QueryDescription query, ManagedExecutionId executionId, DatasetRegistry datasetRegistry, ConqueryConfig config, ExecutionManager executionManager, User user) {
    ManagedExecution<?> execution = datasetRegistry.getMetaRegistry().resolve(executionId);
    if (execution == null) {
        return null;
    }
    // Direct reuse only works if the queries are of the same type (As reuse reconstructs the Query for different types)
    if (!query.getClass().equals(execution.getSubmitted().getClass())) {
        return null;
    }
    // If SecondaryIds differ from selected and prior, we cannot reuse them.
    if (query instanceof SecondaryIdQuery) {
        final SecondaryIdDescription selectedSecondaryId = ((SecondaryIdQuery) query).getSecondaryId();
        final SecondaryIdDescription reusedSecondaryId = ((SecondaryIdQuery) execution.getSubmitted()).getSecondaryId();
        if (!selectedSecondaryId.equals(reusedSecondaryId)) {
            return null;
        }
    }
    // If the user is not the owner of the execution, we definitely create a new Execution, so the owner can cancel it
    if (!user.isOwner(execution)) {
        final ManagedExecution<?> newExecution = executionManager.createExecution(datasetRegistry, execution.getSubmitted(), user, execution.getDataset());
        newExecution.setLabel(execution.getLabel());
        newExecution.setTags(execution.getTags().clone());
        storage.updateExecution(newExecution);
        execution = newExecution;
    }
    ExecutionState state = execution.getState();
    if (state.equals(ExecutionState.RUNNING)) {
        log.trace("The Execution[{}] was already started and its state is: {}", execution.getId(), state);
        return execution;
    }
    log.trace("Re-executing Query {}", execution);
    executionManager.execute(datasetRegistry, execution, config);
    return execution;
}
Also used : ExecutionState(com.bakdata.conquery.models.execution.ExecutionState) SecondaryIdQuery(com.bakdata.conquery.apiv1.query.SecondaryIdQuery) SecondaryIdDescription(com.bakdata.conquery.models.datasets.SecondaryIdDescription)

Aggregations

QueryDescription (com.bakdata.conquery.apiv1.query.QueryDescription)6 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)5 User (com.bakdata.conquery.models.auth.entities.User)5 Dataset (com.bakdata.conquery.models.datasets.Dataset)5 Slf4j (lombok.extern.slf4j.Slf4j)5 ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)4 CQReusedQuery (com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery)4 ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)4 SecondaryIdQuery (com.bakdata.conquery.apiv1.query.SecondaryIdQuery)3 Jackson (com.bakdata.conquery.io.jackson.Jackson)3 StoreMappings (com.bakdata.conquery.io.storage.StoreMappings)3 IterationStatistic (com.bakdata.conquery.io.storage.xodus.stores.SerializingStore.IterationStatistic)3 ExecutionState (com.bakdata.conquery.models.execution.ExecutionState)3 NamespacedIdentifiableCollector (com.bakdata.conquery.util.QueryUtils.NamespacedIdentifiableCollector)3 Query (com.bakdata.conquery.apiv1.query.Query)2 CQExternal (com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal)2 Subject (com.bakdata.conquery.models.auth.entities.Subject)2 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)2 XodusStoreFactory (com.bakdata.conquery.models.config.XodusStoreFactory)2 ManagedExecution (com.bakdata.conquery.models.execution.ManagedExecution)2