Search in sources :

Example 11 with Table

use of com.bakdata.conquery.models.datasets.Table 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 12 with Table

use of com.bakdata.conquery.models.datasets.Table in project conquery by bakdata.

the class AdminDatasetProcessor method deleteSecondaryId.

/**
 * Delete SecondaryId if it does not have any dependents.
 */
public synchronized void deleteSecondaryId(@NonNull SecondaryIdDescription secondaryId) {
    final Namespace namespace = datasetRegistry.get(secondaryId.getDataset().getId());
    // Before we commit this deletion, we check if this SecondaryId still has dependent Columns.
    final List<Column> dependents = namespace.getStorage().getTables().stream().map(Table::getColumns).flatMap(Arrays::stream).filter(column -> secondaryId.equals(column.getSecondaryId())).collect(Collectors.toList());
    if (!dependents.isEmpty()) {
        final Set<TableId> tables = dependents.stream().map(Column::getTable).map(Identifiable::getId).collect(Collectors.toSet());
        log.error("SecondaryId[{}] still present on {}", secondaryId, tables);
        throw new ForbiddenException(String.format("SecondaryId still has dependencies. %s", tables));
    }
    log.info("Deleting SecondaryId[{}]", secondaryId);
    namespace.getStorage().removeSecondaryId(secondaryId.getId());
    namespace.sendToAll(new RemoveSecondaryId(secondaryId));
}
Also used : 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) TableId(com.bakdata.conquery.models.identifiable.ids.specific.TableId) ForbiddenException(javax.ws.rs.ForbiddenException) RemoveSecondaryId(com.bakdata.conquery.models.messages.namespaces.specific.RemoveSecondaryId) Column(com.bakdata.conquery.models.datasets.Column) Arrays(java.util.Arrays) Namespace(com.bakdata.conquery.models.worker.Namespace)

Example 13 with Table

use of com.bakdata.conquery.models.datasets.Table in project conquery by bakdata.

the class AdminDatasetProcessor method deleteDataset.

/**
 * Delete dataset if it is empty.
 */
public synchronized void deleteDataset(Dataset dataset) {
    final Namespace namespace = datasetRegistry.get(dataset.getId());
    if (!namespace.getStorage().getTables().isEmpty()) {
        throw new WebApplicationException(String.format("Cannot delete dataset `%s`, because it still has tables: `%s`", dataset.getId(), namespace.getStorage().getTables().stream().map(Table::getId).map(Objects::toString).collect(Collectors.joining(","))), Response.Status.CONFLICT);
    }
    datasetRegistry.removeNamespace(dataset.getId());
}
Also used : Table(com.bakdata.conquery.models.datasets.Table) RemoveTable(com.bakdata.conquery.models.messages.namespaces.specific.RemoveTable) UpdateTable(com.bakdata.conquery.models.messages.namespaces.specific.UpdateTable) WebApplicationException(javax.ws.rs.WebApplicationException) Namespace(com.bakdata.conquery.models.worker.Namespace)

Example 14 with Table

use of com.bakdata.conquery.models.datasets.Table 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 15 with Table

use of com.bakdata.conquery.models.datasets.Table in project conquery by bakdata.

the class SerializationTests method bucketCompoundDateRange.

@Test
public void bucketCompoundDateRange() throws JSONException, IOException {
    Dataset dataset = new Dataset();
    dataset.setName("datasetName");
    Table table = new Table();
    Column startCol = new Column();
    startCol.setName("startCol");
    startCol.setType(MajorTypeId.DATE);
    startCol.setTable(table);
    Column endCol = new Column();
    endCol.setLabel("endLabel");
    endCol.setName("endCol");
    endCol.setType(MajorTypeId.DATE);
    endCol.setTable(table);
    Column compoundCol = new Column();
    compoundCol.setName("compoundCol");
    compoundCol.setType(MajorTypeId.DATE_RANGE);
    compoundCol.setTable(table);
    table.setColumns(new Column[] { startCol, endCol, compoundCol });
    table.setDataset(dataset);
    table.setName("tableName");
    Import imp = new Import(table);
    imp.setName("importTest");
    DateRangeTypeCompound compoundStore = new DateRangeTypeCompound(startCol.getName(), endCol.getName(), new BitSetStore(BitSet.valueOf(new byte[] { 0b1000 }), new BitSet(), 4));
    // 0b1000 is a binary representation of 8 so that the 4th is set to make sure that BitSet length is 4.
    ColumnStore startStore = new IntegerDateStore(new ShortArrayStore(new short[] { 1, 2, 3, 4 }, Short.MIN_VALUE));
    ColumnStore endStore = new IntegerDateStore(new ShortArrayStore(new short[] { 5, 6, 7, 8 }, Short.MIN_VALUE));
    Bucket bucket = new Bucket(0, 1, 4, new ColumnStore[] { startStore, endStore, compoundStore }, Collections.emptySet(), new int[0], new int[0], imp);
    compoundStore.setParent(bucket);
    CentralRegistry registry = new CentralRegistry();
    registry.register(dataset);
    registry.register(startCol);
    registry.register(endCol);
    registry.register(compoundCol);
    registry.register(table);
    registry.register(imp);
    registry.register(bucket);
    final Validator validator = Validators.newValidator();
    SerializationTestUtil.forType(Bucket.class).registry(registry).injectables(new Injectable() {

        @Override
        public MutableInjectableValues inject(MutableInjectableValues values) {
            return values.add(Validator.class, validator);
        }
    }).test(bucket);
}
Also used : Injectable(com.bakdata.conquery.io.jackson.Injectable) CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) Table(com.bakdata.conquery.models.datasets.Table) Import(com.bakdata.conquery.models.datasets.Import) BitSetStore(com.bakdata.conquery.models.events.stores.primitive.BitSetStore) Dataset(com.bakdata.conquery.models.datasets.Dataset) MutableInjectableValues(com.bakdata.conquery.io.jackson.MutableInjectableValues) BitSet(java.util.BitSet) ShortArrayStore(com.bakdata.conquery.models.events.stores.primitive.ShortArrayStore) DateRangeTypeCompound(com.bakdata.conquery.models.events.stores.specific.DateRangeTypeCompound) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) ColumnStore(com.bakdata.conquery.models.events.stores.root.ColumnStore) Column(com.bakdata.conquery.models.datasets.Column) Bucket(com.bakdata.conquery.models.events.Bucket) IntegerDateStore(com.bakdata.conquery.models.events.stores.primitive.IntegerDateStore) Validator(javax.validation.Validator) Test(org.junit.jupiter.api.Test) IdMapSerialisationTest(com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)

Aggregations

Table (com.bakdata.conquery.models.datasets.Table)22 Column (com.bakdata.conquery.models.datasets.Column)12 Dataset (com.bakdata.conquery.models.datasets.Dataset)11 CentralRegistry (com.bakdata.conquery.models.identifiable.CentralRegistry)8 Test (org.junit.jupiter.api.Test)8 Validator (javax.validation.Validator)7 Import (com.bakdata.conquery.models.datasets.Import)6 TreeConcept (com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept)6 CQTable (com.bakdata.conquery.apiv1.query.concept.filter.CQTable)5 ConceptTreeConnector (com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeConnector)5 Getter (lombok.Getter)5 Injectable (com.bakdata.conquery.io.jackson.Injectable)4 MutableInjectableValues (com.bakdata.conquery.io.jackson.MutableInjectableValues)4 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)4 Concept (com.bakdata.conquery.models.datasets.concepts.Concept)4 Connector (com.bakdata.conquery.models.datasets.concepts.Connector)4 Bucket (com.bakdata.conquery.models.events.Bucket)4 SneakyThrows (lombok.SneakyThrows)4 NamespaceStorage (com.bakdata.conquery.io.storage.NamespaceStorage)3 SecondaryIdDescription (com.bakdata.conquery.models.datasets.SecondaryIdDescription)3