Search in sources :

Example 6 with Column

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

the class TableExportQuery method createResultInfos.

private static List<ResultInfo> createResultInfos(int size, Map<SecondaryIdDescription, Integer> secondaryIdPositions, Map<Column, Integer> positions) {
    ResultInfo[] infos = new ResultInfo[size];
    infos[0] = ConqueryConstants.DATES_INFO;
    for (Map.Entry<SecondaryIdDescription, Integer> e : secondaryIdPositions.entrySet()) {
        SecondaryIdDescription desc = e.getKey();
        Integer pos = e.getValue();
        infos[pos] = new SimpleResultInfo(desc.getLabel(), ResultType.IdT.INSTANCE);
    }
    for (Map.Entry<Column, Integer> entry : positions.entrySet()) {
        // 0 Position is date, already covered
        final int position = entry.getValue();
        // SecondaryIds are pulled to the front, already covered.
        final Column column = entry.getKey();
        if (position == 0 || column.getSecondaryId() != null) {
            continue;
        }
        infos[position] = new SimpleResultInfo(column.getTable().getLabel() + " " + column.getLabel(), ResultType.resolveResultType(column.getType()));
    }
    return List.of(infos);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SimpleResultInfo(com.bakdata.conquery.models.query.resultinfo.SimpleResultInfo) Column(com.bakdata.conquery.models.datasets.Column) SimpleResultInfo(com.bakdata.conquery.models.query.resultinfo.SimpleResultInfo) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) HashMap(java.util.HashMap) Map(java.util.Map) SecondaryIdDescription(com.bakdata.conquery.models.datasets.SecondaryIdDescription)

Example 7 with Column

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

the class PreprocessedHeader method assertMatch.

/**
 * Verify that the supplied table matches the preprocessed' data in shape.
 */
public void assertMatch(Table table) {
    StringJoiner errors = new StringJoiner("\n");
    if (table.getColumns().length != getColumns().length) {
        errors.add(String.format("Length=`%d` does not match table Length=`%d`", getColumns().length, table.getColumns().length));
    }
    final Map<String, MajorTypeId> typesByName = Arrays.stream(getColumns()).collect(Collectors.toMap(PPColumn::getName, PPColumn::getType));
    for (int i = 0; i < Math.min(table.getColumns().length, getColumns().length); i++) {
        final Column column = table.getColumns()[i];
        if (!typesByName.containsKey(column.getName())) {
            errors.add(String.format("Column[%s] is missing in Import.", column.getName()));
        } else if (!typesByName.get(column.getName()).equals(column.getType())) {
            errors.add(String.format("Column[%s] Types do not match %s != %s", column.getName(), typesByName.get(column.getName()), column.getType()));
        }
    }
    if (errors.length() != 0) {
        log.error(errors.toString());
        throw new IllegalArgumentException(String.format("Headers[%s.%s] do not match Table[%s]. More Info in Logs.", getTable(), getName(), table.getId()));
    }
}
Also used : Column(com.bakdata.conquery.models.datasets.Column) StringJoiner(java.util.StringJoiner) MajorTypeId(com.bakdata.conquery.models.events.MajorTypeId)

Example 8 with Column

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

the class SerializationTests method treeConcept.

@Test
public void treeConcept() throws IOException, JSONException {
    Dataset dataset = new Dataset();
    dataset.setName("datasetName");
    TreeConcept concept = new TreeConcept();
    concept.setDataset(dataset);
    concept.setLabel("conceptLabel");
    concept.setName("conceptName");
    Table table = new Table();
    Column column = new Column();
    column.setLabel("colLabel");
    column.setName("colName");
    column.setType(MajorTypeId.STRING);
    column.setTable(table);
    Column dateColumn = new Column();
    dateColumn.setLabel("colLabel2");
    dateColumn.setName("colName2");
    dateColumn.setType(MajorTypeId.DATE);
    dateColumn.setTable(table);
    table.setColumns(new Column[] { column, dateColumn });
    table.setDataset(dataset);
    table.setLabel("tableLabel");
    table.setName("tableName");
    column.setTable(table);
    ConceptTreeConnector connector = new ConceptTreeConnector();
    connector.setConcept(concept);
    connector.setLabel("connLabel");
    connector.setName("connName");
    connector.setColumn(column);
    concept.setConnectors(List.of(connector));
    ValidityDate valDate = new ValidityDate();
    valDate.setColumn(dateColumn);
    valDate.setConnector(connector);
    valDate.setLabel("valLabel");
    valDate.setName("valName");
    connector.setValidityDates(List.of(valDate));
    CentralRegistry registry = new CentralRegistry();
    registry.register(dataset);
    registry.register(concept);
    registry.register(column);
    registry.register(dateColumn);
    registry.register(table);
    registry.register(connector);
    registry.register(valDate);
    final Validator validator = Validators.newValidator();
    concept.setValidator(validator);
    SerializationTestUtil.forType(TreeConcept.class).registry(registry).injectables(new Injectable() {

        @Override
        public MutableInjectableValues inject(MutableInjectableValues values) {
            return values.add(Validator.class, validator);
        }
    }).test(concept);
}
Also used : Injectable(com.bakdata.conquery.io.jackson.Injectable) ValidityDate(com.bakdata.conquery.models.datasets.concepts.ValidityDate) CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) Table(com.bakdata.conquery.models.datasets.Table) Column(com.bakdata.conquery.models.datasets.Column) Dataset(com.bakdata.conquery.models.datasets.Dataset) TreeConcept(com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept) MutableInjectableValues(com.bakdata.conquery.io.jackson.MutableInjectableValues) ConceptTreeConnector(com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeConnector) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) Validator(javax.validation.Validator) Test(org.junit.jupiter.api.Test) IdMapSerialisationTest(com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)

Example 9 with Column

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

the class SerializationTests method table.

@Test
public void table() throws JSONException, IOException {
    Dataset dataset = new Dataset();
    dataset.setName("datasetName");
    Table table = new Table();
    Column column = new Column();
    column.setLabel("colLabel");
    column.setName("colName");
    column.setType(MajorTypeId.STRING);
    column.setTable(table);
    table.setColumns(new Column[] { column });
    table.setDataset(dataset);
    table.setLabel("tableLabel");
    table.setName("tableName");
    CentralRegistry registry = new CentralRegistry();
    registry.register(dataset);
    registry.register(table);
    registry.register(column);
    final Validator validator = Validators.newValidator();
    SerializationTestUtil.forType(Table.class).registry(registry).injectables(new Injectable() {

        @Override
        public MutableInjectableValues inject(MutableInjectableValues values) {
            return values.add(Validator.class, validator);
        }
    }).test(table);
}
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) Column(com.bakdata.conquery.models.datasets.Column) Dataset(com.bakdata.conquery.models.datasets.Dataset) MutableInjectableValues(com.bakdata.conquery.io.jackson.MutableInjectableValues) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) Validator(javax.validation.Validator) Test(org.junit.jupiter.api.Test) IdMapSerialisationTest(com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)

Example 10 with Column

use of com.bakdata.conquery.models.datasets.Column 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)

Aggregations

Column (com.bakdata.conquery.models.datasets.Column)18 Table (com.bakdata.conquery.models.datasets.Table)10 Dataset (com.bakdata.conquery.models.datasets.Dataset)6 CQTable (com.bakdata.conquery.apiv1.query.concept.filter.CQTable)5 Validator (javax.validation.Validator)5 Injectable (com.bakdata.conquery.io.jackson.Injectable)4 MutableInjectableValues (com.bakdata.conquery.io.jackson.MutableInjectableValues)4 SecondaryIdDescription (com.bakdata.conquery.models.datasets.SecondaryIdDescription)4 CentralRegistry (com.bakdata.conquery.models.identifiable.CentralRegistry)4 Test (org.junit.jupiter.api.Test)4 Connector (com.bakdata.conquery.models.datasets.concepts.Connector)3 TreeConcept (com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept)3 IdMapSerialisationTest (com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)3 CQUnfilteredTable (com.bakdata.conquery.apiv1.query.concept.filter.CQUnfilteredTable)2 InternalOnly (com.bakdata.conquery.io.jackson.InternalOnly)2 CDateSet (com.bakdata.conquery.models.common.CDateSet)2 CDateRange (com.bakdata.conquery.models.common.daterange.CDateRange)2 Import (com.bakdata.conquery.models.datasets.Import)2 Concept (com.bakdata.conquery.models.datasets.concepts.Concept)2 ValidityDate (com.bakdata.conquery.models.datasets.concepts.ValidityDate)2