Search in sources :

Example 1 with Concept

use of com.bakdata.conquery.models.datasets.concepts.Concept in project conquery by bakdata.

the class LoadingUtil method importConcepts.

public static void importConcepts(StandaloneSupport support, ArrayNode rawConcepts) throws JSONException, IOException {
    Dataset dataset = support.getDataset();
    List<Concept<?>> concepts = ConqueryTestSpec.parseSubTreeList(support, rawConcepts, Concept.class, c -> c.setDataset(support.getDataset()));
    for (Concept<?> concept : concepts) {
        support.getDatasetsProcessor().addConcept(dataset, concept);
    }
}
Also used : Concept(com.bakdata.conquery.models.datasets.concepts.Concept) Dataset(com.bakdata.conquery.models.datasets.Dataset)

Example 2 with Concept

use of com.bakdata.conquery.models.datasets.concepts.Concept in project conquery by bakdata.

the class CQConcept method createQueryPlan.

@Override
public QPNode createQueryPlan(QueryPlanContext context, ConceptQueryPlan plan) {
    final List<Aggregator<?>> conceptAggregators = createAggregators(plan, selects);
    List<QPNode> tableNodes = new ArrayList<>();
    for (CQTable table : tables) {
        List<FilterNode<?>> filters = table.getFilters().stream().map(FilterValue::createNode).collect(Collectors.toList());
        // add filter to children
        List<Aggregator<?>> aggregators = new ArrayList<>();
        aggregators.addAll(conceptAggregators);
        final List<Aggregator<?>> connectorAggregators = createAggregators(plan, table.getSelects());
        // Exists aggregators hold a reference to their parent FiltersNode so they need to be treated separately.
        // They also don't need aggregation as they simply imitate their reference.
        List<ExistsAggregator> existsAggregators = connectorAggregators.stream().filter(ExistsAggregator.class::isInstance).map(ExistsAggregator.class::cast).collect(Collectors.toList());
        aggregators.addAll(connectorAggregators);
        aggregators.removeIf(ExistsAggregator.class::isInstance);
        List<Aggregator<CDateSet>> eventDateUnionAggregators = aggregateEventDates ? List.of(new EventDateUnionAggregator(Set.of(table.getConnector().getTable()))) : Collections.emptyList();
        aggregators.addAll(eventDateUnionAggregators);
        final QPNode filtersNode = getConcept().createConceptQuery(context, filters, aggregators, eventDateUnionAggregators);
        // Link up the ExistsAggregators to the node
        existsAggregators.forEach(agg -> agg.setReference(filtersNode));
        // Select if matching secondaryId available
        final boolean hasSelectedSecondaryId = Arrays.stream(table.getConnector().getTable().getColumns()).map(Column::getSecondaryId).filter(Objects::nonNull).anyMatch(o -> Objects.equals(context.getSelectedSecondaryId(), o));
        final Column validityDateColumn = selectValidityDateColumn(table);
        final ConceptNode node = new ConceptNode(// TODO Don't set validity node, when no validity column exists. See workaround for this and remove it: https://github.com/bakdata/conquery/pull/1362
        new ValidityDateNode(validityDateColumn, filtersNode), elements, table, // if the node is excluded, don't pass it into the Node.
        !excludeFromSecondaryId && hasSelectedSecondaryId ? context.getSelectedSecondaryId() : null);
        tableNodes.add(node);
    }
    // We always merge on concept level
    final QPNode outNode = OrNode.of(tableNodes, aggregateEventDates ? DateAggregationAction.MERGE : DateAggregationAction.BLOCK);
    // Link concept-level Exists-select to outer node.
    conceptAggregators.stream().filter(aggregator -> aggregator instanceof ExistsAggregator).forEach(aggregator -> ((ExistsAggregator) aggregator).setReference(outNode));
    return outNode;
}
Also used : ConceptNode(com.bakdata.conquery.models.query.queryplan.specific.ConceptNode) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Arrays(java.util.Arrays) ConceptElement(com.bakdata.conquery.models.datasets.concepts.ConceptElement) EventDateUnionAggregator(com.bakdata.conquery.models.query.queryplan.aggregators.specific.EventDateUnionAggregator) NotEmpty(javax.validation.constraints.NotEmpty) Valid(javax.validation.Valid) JsonAlias(com.fasterxml.jackson.annotation.JsonAlias) Locale(java.util.Locale) QPNode(com.bakdata.conquery.models.query.queryplan.QPNode) ToString(lombok.ToString) CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) InternalOnly(com.bakdata.conquery.io.jackson.InternalOnly) ConceptQueryPlan(com.bakdata.conquery.models.query.queryplan.ConceptQueryPlan) NamespacedIdentifiableHolding(com.bakdata.conquery.models.query.NamespacedIdentifiableHolding) CPSType(com.bakdata.conquery.io.cps.CPSType) SelectResultInfo(com.bakdata.conquery.models.query.resultinfo.SelectResultInfo) NsIdRefCollection(com.bakdata.conquery.io.jackson.serializer.NsIdRefCollection) Concept(com.bakdata.conquery.models.datasets.concepts.Concept) Set(java.util.Set) ConceptNode(com.bakdata.conquery.models.query.queryplan.specific.ConceptNode) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) FilterValue(com.bakdata.conquery.apiv1.query.concept.filter.FilterValue) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) JsonManagedReference(com.fasterxml.jackson.annotation.JsonManagedReference) Column(com.bakdata.conquery.models.datasets.Column) Setter(lombok.Setter) Getter(lombok.Getter) NamespacedIdentifiable(com.bakdata.conquery.models.identifiable.ids.NamespacedIdentifiable) ArrayList(java.util.ArrayList) Select(com.bakdata.conquery.models.datasets.concepts.select.Select) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) DateAggregationMode(com.bakdata.conquery.models.query.DateAggregationMode) FilterNode(com.bakdata.conquery.models.query.queryplan.filter.FilterNode) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) DateAggregationAction(com.bakdata.conquery.models.query.queryplan.DateAggregationAction) ValidityDateNode(com.bakdata.conquery.models.query.queryplan.specific.ValidityDateNode) ExportForm(com.bakdata.conquery.apiv1.forms.export_form.ExportForm) QueryPlanContext(com.bakdata.conquery.models.query.QueryPlanContext) ValidationMethod(io.dropwizard.validation.ValidationMethod) QueryResolveContext(com.bakdata.conquery.models.query.QueryResolveContext) OrNode(com.bakdata.conquery.models.query.queryplan.specific.OrNode) Aggregator(com.bakdata.conquery.models.query.queryplan.aggregators.Aggregator) CQElement(com.bakdata.conquery.apiv1.query.CQElement) ExistsAggregator(com.bakdata.conquery.models.query.queryplan.aggregators.specific.ExistsAggregator) Collections(java.util.Collections) CDateSet(com.bakdata.conquery.models.common.CDateSet) QPNode(com.bakdata.conquery.models.query.queryplan.QPNode) CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) FilterNode(com.bakdata.conquery.models.query.queryplan.filter.FilterNode) EventDateUnionAggregator(com.bakdata.conquery.models.query.queryplan.aggregators.specific.EventDateUnionAggregator) ArrayList(java.util.ArrayList) EventDateUnionAggregator(com.bakdata.conquery.models.query.queryplan.aggregators.specific.EventDateUnionAggregator) Aggregator(com.bakdata.conquery.models.query.queryplan.aggregators.Aggregator) ExistsAggregator(com.bakdata.conquery.models.query.queryplan.aggregators.specific.ExistsAggregator) Column(com.bakdata.conquery.models.datasets.Column) ValidityDateNode(com.bakdata.conquery.models.query.queryplan.specific.ValidityDateNode) ExistsAggregator(com.bakdata.conquery.models.query.queryplan.aggregators.specific.ExistsAggregator)

Example 3 with Concept

use of com.bakdata.conquery.models.datasets.concepts.Concept in project conquery by bakdata.

the class AdminDatasetProcessor method deleteTable.

/**
 * Deletes a table if it has no dependents or not forced to do so.
 */
public synchronized List<ConceptId> deleteTable(Table table, boolean force) {
    final Namespace namespace = datasetRegistry.get(table.getDataset().getId());
    final List<Concept<?>> dependentConcepts = namespace.getStorage().getAllConcepts().stream().flatMap(c -> c.getConnectors().stream()).filter(con -> con.getTable().equals(table)).map(Connector::getConcept).collect(Collectors.toList());
    if (force || dependentConcepts.isEmpty()) {
        for (Concept<?> concept : dependentConcepts) {
            deleteConcept(concept);
        }
        namespace.getStorage().getAllImports().stream().filter(imp -> imp.getTable().equals(table)).forEach(this::deleteImport);
        namespace.getStorage().removeTable(table.getId());
        namespace.sendToAll(new RemoveTable(table));
    }
    return dependentConcepts.stream().map(Concept::getId).collect(Collectors.toList());
}
Also used : Concept(com.bakdata.conquery.models.datasets.concepts.Concept) RemoveConcept(com.bakdata.conquery.models.messages.namespaces.specific.RemoveConcept) UpdateConcept(com.bakdata.conquery.models.messages.namespaces.specific.UpdateConcept) Arrays(java.util.Arrays) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) SneakyThrows(lombok.SneakyThrows) RequiredArgsConstructor(lombok.RequiredArgsConstructor) EntityIdMap(com.bakdata.conquery.models.identifiable.mapping.EntityIdMap) Import(com.bakdata.conquery.models.datasets.Import) DictionaryId(com.bakdata.conquery.models.identifiable.ids.specific.DictionaryId) ConceptId(com.bakdata.conquery.models.identifiable.ids.specific.ConceptId) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId) InternalOnly(com.bakdata.conquery.io.jackson.InternalOnly) RemoveImportJob(com.bakdata.conquery.models.messages.namespaces.specific.RemoveImportJob) NonNull(lombok.NonNull) Table(com.bakdata.conquery.models.datasets.Table) Concept(com.bakdata.conquery.models.datasets.concepts.Concept) RemoveConcept(com.bakdata.conquery.models.messages.namespaces.specific.RemoveConcept) Set(java.util.Set) Validator(javax.validation.Validator) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) RemoveSecondaryId(com.bakdata.conquery.models.messages.namespaces.specific.RemoveSecondaryId) Dataset(com.bakdata.conquery.models.datasets.Dataset) Objects(java.util.Objects) SecondaryIdDescription(com.bakdata.conquery.models.datasets.SecondaryIdDescription) JobManager(com.bakdata.conquery.models.jobs.JobManager) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) Jackson(com.bakdata.conquery.io.jackson.Jackson) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) Column(com.bakdata.conquery.models.datasets.Column) Namespace(com.bakdata.conquery.models.worker.Namespace) RemoveTable(com.bakdata.conquery.models.messages.namespaces.specific.RemoveTable) Getter(lombok.Getter) AddWorker(com.bakdata.conquery.models.messages.network.specific.AddWorker) UpdateTable(com.bakdata.conquery.models.messages.namespaces.specific.UpdateTable) Connector(com.bakdata.conquery.models.datasets.concepts.Connector) UpdateSecondaryId(com.bakdata.conquery.models.messages.namespaces.specific.UpdateSecondaryId) NamespaceStorage(com.bakdata.conquery.io.storage.NamespaceStorage) IdMutex(com.bakdata.conquery.models.identifiable.IdMutex) TableId(com.bakdata.conquery.models.identifiable.ids.specific.TableId) CsvParser(com.univocity.parsers.csv.CsvParser) UpdateMatchingStatsMessage(com.bakdata.conquery.models.messages.namespaces.specific.UpdateMatchingStatsMessage) Identifiable(com.bakdata.conquery.models.identifiable.Identifiable) SimpleJob(com.bakdata.conquery.models.jobs.SimpleJob) ForbiddenException(javax.ws.rs.ForbiddenException) ImportJob(com.bakdata.conquery.models.jobs.ImportJob) IOException(java.io.IOException) ValidatorHelper(com.bakdata.conquery.models.exceptions.ValidatorHelper) UpdateConcept(com.bakdata.conquery.models.messages.namespaces.specific.UpdateConcept) ShardNodeInformation(com.bakdata.conquery.models.worker.ShardNodeInformation) StructureNode(com.bakdata.conquery.models.datasets.concepts.StructureNode) FilterSearch(com.bakdata.conquery.apiv1.FilterSearch) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) Collections(java.util.Collections) InputStream(java.io.InputStream) RemoveTable(com.bakdata.conquery.models.messages.namespaces.specific.RemoveTable) Namespace(com.bakdata.conquery.models.worker.Namespace)

Example 4 with Concept

use of com.bakdata.conquery.models.datasets.concepts.Concept in project conquery by bakdata.

the class NamespacedStorage method decorateConceptStore.

private void decorateConceptStore(IdentifiableStore<Concept<?>> store) {
    store.onAdd(concept -> {
        if (concept.getDataset() != null && !concept.getDataset().equals(dataset.get())) {
            throw new IllegalStateException("Concept is not for this dataset.");
        }
        concept.setDataset(dataset.get());
        concept.initElements();
        concept.getSelects().forEach(centralRegistry::register);
        for (Connector connector : concept.getConnectors()) {
            centralRegistry.register(connector);
            connector.collectAllFilters().forEach(centralRegistry::register);
            connector.getSelects().forEach(centralRegistry::register);
            connector.getValidityDates().forEach(centralRegistry::register);
        }
        // add imports of table
        if (isRegisterImports()) {
            for (Import imp : getAllImports()) {
                for (Connector con : concept.getConnectors()) {
                    if (con.getTable().equals(imp.getTable())) {
                        con.addImport(imp);
                    }
                }
            }
        }
        if (concept instanceof TreeConcept) {
            ((TreeConcept) concept).getAllChildren().values().forEach(centralRegistry::register);
        }
    }).onRemove(concept -> {
        concept.getSelects().forEach(centralRegistry::remove);
        // see #146  remove from Dataset.concepts
        for (Connector connector : concept.getConnectors()) {
            connector.getSelects().forEach(centralRegistry::remove);
            connector.collectAllFilters().forEach(centralRegistry::remove);
            connector.getValidityDates().forEach(centralRegistry::remove);
            centralRegistry.remove(connector);
        }
        if (concept instanceof TreeConcept) {
            ((TreeConcept) concept).getAllChildren().values().forEach(centralRegistry::remove);
        }
    });
}
Also used : Dictionary(com.bakdata.conquery.models.dictionary.Dictionary) Getter(lombok.Getter) SneakyThrows(lombok.SneakyThrows) SecondaryIdDescriptionId(com.bakdata.conquery.models.identifiable.ids.specific.SecondaryIdDescriptionId) StoreFactory(com.bakdata.conquery.models.config.StoreFactory) Import(com.bakdata.conquery.models.datasets.Import) ArrayList(java.util.ArrayList) SingletonStore(com.bakdata.conquery.io.storage.xodus.stores.SingletonStore) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) Connector(com.bakdata.conquery.models.datasets.concepts.Connector) DictionaryId(com.bakdata.conquery.models.identifiable.ids.specific.DictionaryId) ConceptId(com.bakdata.conquery.models.identifiable.ids.specific.ConceptId) ToString(lombok.ToString) TableId(com.bakdata.conquery.models.identifiable.ids.specific.TableId) TreeConcept(com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept) Collection(java.util.Collection) Table(com.bakdata.conquery.models.datasets.Table) Concept(com.bakdata.conquery.models.datasets.concepts.Concept) Validator(javax.validation.Validator) IOException(java.io.IOException) ImportId(com.bakdata.conquery.models.identifiable.ids.specific.ImportId) Dataset(com.bakdata.conquery.models.datasets.Dataset) SecondaryIdDescription(com.bakdata.conquery.models.datasets.SecondaryIdDescription) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Column(com.bakdata.conquery.models.datasets.Column) Connector(com.bakdata.conquery.models.datasets.concepts.Connector) Import(com.bakdata.conquery.models.datasets.Import) TreeConcept(com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept)

Example 5 with Concept

use of com.bakdata.conquery.models.datasets.concepts.Concept in project conquery by bakdata.

the class ConceptUpdateAndDeletionTest method execute.

@Override
public void execute(String name, TestConquery testConquery) throws Exception {
    StandaloneSupport conquery = testConquery.getSupport(name);
    // Read two JSONs with different Trees
    final String testJson = In.resource("/tests/query/UPDATE_CONCEPT_TESTS/SIMPLE_TREECONCEPT_Query.json").withUTF8().readAll();
    final String testJson2 = In.resource("/tests/query/UPDATE_CONCEPT_TESTS/SIMPLE_TREECONCEPT_2_Query.json").withUTF8().readAll();
    final Dataset dataset = conquery.getDataset();
    final Namespace namespace = conquery.getNamespace();
    final ConceptId conceptId = ConceptId.Parser.INSTANCE.parse(dataset.getName(), "test_tree");
    final Concept<?> concept;
    final QueryTest test = (QueryTest) JsonIntegrationTest.readJson(dataset, testJson);
    final QueryTest test2 = (QueryTest) JsonIntegrationTest.readJson(dataset, testJson2);
    // Manually import data, so we can do our own work.
    {
        ValidatorHelper.failOnError(log, conquery.getValidator().validate(test));
        importSecondaryIds(conquery, test.getContent().getSecondaryIds());
        conquery.waitUntilWorkDone();
        LoadingUtil.importTables(conquery, test.getContent().getTables());
        conquery.waitUntilWorkDone();
        LoadingUtil.importConcepts(conquery, test.getRawConcepts());
        conquery.waitUntilWorkDone();
        assertThat(namespace.getStorage().getConcept(conceptId)).isNotNull();
        LoadingUtil.importTableContents(conquery, test.getContent().getTables());
        conquery.waitUntilWorkDone();
    }
    final Query query = IntegrationUtils.parseQuery(conquery, test.getRawQuery());
    // State before update.
    {
        log.info("Checking state before update");
        // Must contain the concept.
        assertThat(namespace.getStorage().getAllConcepts()).filteredOn(con -> con.getId().equals(conceptId)).isNotEmpty();
        assertThat(namespace.getStorage().getCentralRegistry().getOptional(conceptId)).isNotEmpty();
        for (ShardNode node : conquery.getShardNodes()) {
            for (Worker value : node.getWorkers().getWorkers().values()) {
                if (!value.getInfo().getDataset().equals(dataset.getId())) {
                    continue;
                }
                final ModificationShieldedWorkerStorage workerStorage = value.getStorage();
                assertThat(workerStorage.getCentralRegistry().getOptional(conceptId)).isNotEmpty();
                assertThat(workerStorage.getAllCBlocks()).describedAs("CBlocks for Worker %s", value.getInfo().getId()).filteredOn(cBlock -> cBlock.getConnector().getConcept().getId().equals(conceptId)).isNotEmpty();
            }
        }
        log.info("Executing query before update");
        IntegrationUtils.assertQueryResult(conquery, query, 1L, ExecutionState.DONE, conquery.getTestUser(), 201);
        conquery.waitUntilWorkDone();
        log.info("Query before update executed");
    }
    // Load a different concept with the same id (it has different children "C1" that are more than "A1")
    // To perform the update, the old concept will be deleted first and the new concept will be added. That means the deletion of concept is also covered here
    {
        log.info("Executing  update");
        LoadingUtil.updateConcepts(conquery, test2.getRawConcepts(), Response.Status.Family.SUCCESSFUL);
        conquery.waitUntilWorkDone();
        log.info("Update executed");
    }
    // Check state after update.
    {
        log.info("Checking state after update");
        // Must contain the concept now.
        assertThat(namespace.getStorage().getAllConcepts()).filteredOn(con -> con.getId().equals(conceptId)).isNotEmpty();
        assertThat(namespace.getStorage().getCentralRegistry().getOptional(conceptId)).isNotEmpty();
        for (ShardNode node : conquery.getShardNodes()) {
            for (Worker value : node.getWorkers().getWorkers().values()) {
                if (!value.getInfo().getDataset().equals(dataset.getId())) {
                    continue;
                }
                final ModificationShieldedWorkerStorage workerStorage = value.getStorage();
                assertThat(workerStorage.getCentralRegistry().getOptional(conceptId)).isNotEmpty();
                assertThat(workerStorage.getAllCBlocks()).describedAs("CBlocks for Worker %s", value.getInfo().getId()).filteredOn(cBlock -> cBlock.getConnector().getConcept().getId().equals(conceptId)).isNotEmpty();
            }
        }
        log.info("Executing query after update");
        // Assert that it now contains 2 instead of 1.
        IntegrationUtils.assertQueryResult(conquery, query, 2L, ExecutionState.DONE, conquery.getTestUser(), 201);
        conquery.waitUntilWorkDone();
        log.info("Query after update executed");
    }
    // new Conquery generated after restarting
    // StandaloneSupport conquery;
    // Restart conquery and assert again, that the data is correct.
    {
        testConquery.shutdown();
        // restart
        testConquery.beforeAll();
        conquery = testConquery.openDataset(dataset.getId());
        log.info("Checking state after re-start");
        {
            // Must contain the concept.
            assertThat(conquery.getNamespace().getStorage().getAllConcepts()).filteredOn(con -> con.getId().equals(conceptId)).isNotEmpty();
            assertThat(conquery.getNamespace().getStorage().getCentralRegistry().getOptional(conceptId)).isNotEmpty();
            for (ShardNode node : conquery.getShardNodes()) {
                for (Worker value : node.getWorkers().getWorkers().values()) {
                    if (!value.getInfo().getDataset().equals(dataset.getId())) {
                        continue;
                    }
                    final ModificationShieldedWorkerStorage workerStorage = value.getStorage();
                    assertThat(workerStorage.getCentralRegistry().getOptional(conceptId)).isNotEmpty();
                    assertThat(workerStorage.getAllCBlocks()).describedAs("CBlocks for Worker %s", value.getInfo().getId()).filteredOn(cBlock -> cBlock.getConnector().getConcept().getId().equals(conceptId)).isNotEmpty();
                }
            }
            log.info("Executing query after restart.");
            // Re-assert state.
            IntegrationUtils.assertQueryResult(conquery, query, 2L, ExecutionState.DONE, conquery.getTestUser(), 201);
            conquery.waitUntilWorkDone();
        }
    }
    // Delete the Concept.
    {
        log.info("Issuing deletion of import {}", conceptId);
        concept = Objects.requireNonNull(conquery.getNamespace().getStorage().getConcept(conceptId));
        conquery.getDatasetsProcessor().deleteConcept(concept);
        conquery.waitUntilWorkDone();
    }
    // Check state after deletion.
    {
        log.info("Checking state after deletion");
        // We've deleted the concept so it and it's associated cblock should be gone.
        assertThat(conquery.getNamespace().getStorage().getAllConcepts()).filteredOn(con -> con.getId().equals(conceptId)).isEmpty();
        assertThat(conquery.getNamespace().getStorage().getCentralRegistry().getOptional(conceptId)).isEmpty();
        assertThat(conquery.getShardNodes().stream().flatMap(node -> node.getWorkers().getWorkers().values().stream()).filter(worker -> worker.getInfo().getDataset().equals(dataset.getId())).map(Worker::getStorage)).noneMatch(workerStorage -> workerStorage.getConcept(conceptId) != null).noneMatch(workerStorage -> workerStorage.getAllCBlocks().stream().anyMatch(cBlock -> cBlock.getConnector().getConcept().getId().equals(conceptId)));
        log.info("Executing query after deletion (EXPECTING AN EXCEPTION IN THE LOGS!)");
        // Issue a query and assert that it is failing.
        IntegrationUtils.assertQueryResult(conquery, query, 0L, ExecutionState.FAILED, conquery.getTestUser(), 400);
    }
    // Restart conquery and assert again, that the state after deletion was maintained.
    {
        {
            testConquery.shutdown();
            // restart
            testConquery.beforeAll();
            conquery = testConquery.openDataset(dataset.getId());
        }
        // Check state after restart.
        {
            log.info("Checking state after restart");
            // We've deleted the concept so it and it's associated cblock should be gone.
            assertThat(conquery.getNamespace().getStorage().getAllConcepts()).filteredOn(con -> con.getId().equals(conceptId)).isEmpty();
            assertThat(conquery.getNamespace().getStorage().getCentralRegistry().getOptional(conceptId)).isEmpty();
            assertThat(conquery.getShardNodes().stream().flatMap(node -> node.getWorkers().getWorkers().values().stream()).filter(worker -> worker.getInfo().getDataset().equals(dataset.getId())).map(Worker::getStorage)).noneMatch(workerStorage -> workerStorage.getConcept(conceptId) != null).noneMatch(workerStorage -> workerStorage.getAllCBlocks().stream().anyMatch(cBlock -> cBlock.getConnector().getConcept().getId().equals(conceptId)));
            log.info("Executing query after restart (EXPECTING AN EXCEPTION IN THE LOGS!)");
            // Issue a query and assert that it is failing.
            IntegrationUtils.assertQueryResult(conquery, query, 0L, ExecutionState.FAILED, conquery.getTestUser(), 400);
        }
    }
}
Also used : IntegrationUtils(com.bakdata.conquery.integration.common.IntegrationUtils) ProgrammaticIntegrationTest(com.bakdata.conquery.integration.tests.ProgrammaticIntegrationTest) ExecutionState(com.bakdata.conquery.models.execution.ExecutionState) TestConquery(com.bakdata.conquery.util.support.TestConquery) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ShardNode(com.bakdata.conquery.commands.ShardNode) Concept(com.bakdata.conquery.models.datasets.concepts.Concept) QueryTest(com.bakdata.conquery.integration.json.QueryTest) LoadingUtil(com.bakdata.conquery.integration.common.LoadingUtil) StandaloneSupport(com.bakdata.conquery.util.support.StandaloneSupport) Dataset(com.bakdata.conquery.models.datasets.Dataset) ValidatorHelper(com.bakdata.conquery.models.exceptions.ValidatorHelper) Objects(java.util.Objects) Worker(com.bakdata.conquery.models.worker.Worker) Slf4j(lombok.extern.slf4j.Slf4j) Response(javax.ws.rs.core.Response) ModificationShieldedWorkerStorage(com.bakdata.conquery.io.storage.ModificationShieldedWorkerStorage) In(com.github.powerlibraries.io.In) ConceptId(com.bakdata.conquery.models.identifiable.ids.specific.ConceptId) JsonIntegrationTest(com.bakdata.conquery.integration.json.JsonIntegrationTest) Query(com.bakdata.conquery.apiv1.query.Query) LoadingUtil.importSecondaryIds(com.bakdata.conquery.integration.common.LoadingUtil.importSecondaryIds) Namespace(com.bakdata.conquery.models.worker.Namespace) Query(com.bakdata.conquery.apiv1.query.Query) QueryTest(com.bakdata.conquery.integration.json.QueryTest) ShardNode(com.bakdata.conquery.commands.ShardNode) Dataset(com.bakdata.conquery.models.datasets.Dataset) Worker(com.bakdata.conquery.models.worker.Worker) StandaloneSupport(com.bakdata.conquery.util.support.StandaloneSupport) Namespace(com.bakdata.conquery.models.worker.Namespace) ConceptId(com.bakdata.conquery.models.identifiable.ids.specific.ConceptId) ModificationShieldedWorkerStorage(com.bakdata.conquery.io.storage.ModificationShieldedWorkerStorage)

Aggregations

Concept (com.bakdata.conquery.models.datasets.concepts.Concept)9 Dataset (com.bakdata.conquery.models.datasets.Dataset)7 ConceptId (com.bakdata.conquery.models.identifiable.ids.specific.ConceptId)4 Column (com.bakdata.conquery.models.datasets.Column)3 ConceptElement (com.bakdata.conquery.models.datasets.concepts.ConceptElement)3 Connector (com.bakdata.conquery.models.datasets.concepts.Connector)3 List (java.util.List)3 Slf4j (lombok.extern.slf4j.Slf4j)3 CQTable (com.bakdata.conquery.apiv1.query.concept.filter.CQTable)2 FilterValue (com.bakdata.conquery.apiv1.query.concept.filter.FilterValue)2 QueryTest (com.bakdata.conquery.integration.json.QueryTest)2 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)2 Import (com.bakdata.conquery.models.datasets.Import)2 SecondaryIdDescription (com.bakdata.conquery.models.datasets.SecondaryIdDescription)2 Table (com.bakdata.conquery.models.datasets.Table)2 ValidatorHelper (com.bakdata.conquery.models.exceptions.ValidatorHelper)2 CentralRegistry (com.bakdata.conquery.models.identifiable.CentralRegistry)2 DictionaryId (com.bakdata.conquery.models.identifiable.ids.specific.DictionaryId)2 SecondaryIdDescriptionId (com.bakdata.conquery.models.identifiable.ids.specific.SecondaryIdDescriptionId)2 TableId (com.bakdata.conquery.models.identifiable.ids.specific.TableId)2