Search in sources :

Example 6 with Connector

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

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

the class TableExportQuery method createQueryPlan.

@Override
public TableExportQueryPlan createQueryPlan(QueryPlanContext context) {
    List<TableExportDescription> resolvedConnectors = new ArrayList<>();
    for (CQUnfilteredTable table : tables) {
        Connector connector = table.getTable();
        // if no dateColumn is provided, we use the default instead which is always the first one.
        // Set to null if none-available in the connector.
        final Column validityDateColumn = findValidityDateColumn(connector, table.getDateColumn());
        final TableExportDescription exportDescription = new TableExportDescription(connector.getTable(), validityDateColumn);
        resolvedConnectors.add(exportDescription);
    }
    return new TableExportQueryPlan(query.createQueryPlan(context), CDateRange.of(dateRange), resolvedConnectors, positions);
}
Also used : Connector(com.bakdata.conquery.models.datasets.concepts.Connector) CQUnfilteredTable(com.bakdata.conquery.apiv1.query.concept.filter.CQUnfilteredTable) Column(com.bakdata.conquery.models.datasets.Column) TableExportQueryPlan(com.bakdata.conquery.models.query.queryplan.TableExportQueryPlan) TableExportDescription(com.bakdata.conquery.models.query.queryplan.TableExportQueryPlan.TableExportDescription) ArrayList(java.util.ArrayList)

Example 8 with Connector

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

the class BucketManager method create.

public static BucketManager create(Worker worker, WorkerStorage storage, int entityBucketSize) {
    Int2ObjectMap<Entity> entities = new Int2ObjectAVLTreeMap<>();
    Map<Connector, Int2ObjectMap<Map<Bucket, CBlock>>> connectorCBlocks = new HashMap<>();
    Map<Table, Int2ObjectMap<List<Bucket>>> tableBuckets = new HashMap<>();
    IntArraySet assignedBucketNumbers = worker.getInfo().getIncludedBuckets();
    log.trace("Trying to load these buckets that map to: {}", assignedBucketNumbers);
    for (Bucket bucket : storage.getAllBuckets()) {
        if (!assignedBucketNumbers.contains(bucket.getBucket())) {
            log.warn("Found Bucket[{}] in Storage that does not belong to this Worker according to the Worker information.", bucket.getId());
        }
        registerBucket(bucket, entities, tableBuckets);
    }
    for (CBlock cBlock : storage.getAllCBlocks()) {
        registerCBlock(cBlock, connectorCBlocks);
    }
    return new BucketManager(worker.getJobManager(), storage, worker, entities, connectorCBlocks, tableBuckets, entityBucketSize);
}
Also used : Entity(com.bakdata.conquery.models.query.entity.Entity) ConceptTreeConnector(com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeConnector) Connector(com.bakdata.conquery.models.datasets.concepts.Connector) Table(com.bakdata.conquery.models.datasets.Table) HashMap(java.util.HashMap) Int2ObjectAVLTreeMap(it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) IntArraySet(it.unimi.dsi.fastutil.ints.IntArraySet)

Example 9 with Connector

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

the class FilterResolutionContainsTest method execute.

@Override
public void execute(StandaloneSupport conquery) throws Exception {
    // read test sepcification
    String testJson = In.resource("/tests/query/MULTI_SELECT_DATE_RESTRICTION_OR_CONCEPT_QUERY/MULTI_SELECT_DATE_RESTRICTION_OR_CONCEPT_QUERY.test.json").withUTF8().readAll();
    DatasetId dataset = conquery.getDataset().getId();
    ConqueryTestSpec test = JsonIntegrationTest.readJson(dataset, testJson);
    ValidatorHelper.failOnError(log, conquery.getValidator().validate(test));
    test.importRequiredData(conquery);
    CSVConfig csvConf = conquery.getConfig().getCsv();
    FilterSearch.updateSearch(conquery.getNamespace().getNamespaces(), Collections.singleton(conquery.getNamespace().getDataset()), conquery.getDatasetsProcessor().getJobManager(), csvConf);
    conquery.waitUntilWorkDone();
    Concept<?> concept = conquery.getNamespace().getStorage().getAllConcepts().iterator().next();
    Connector connector = concept.getConnectors().iterator().next();
    AbstractSelectFilter<?> filter = (AbstractSelectFilter<?>) connector.getFilters().iterator().next();
    // Copy search csv from resources to tmp folder.
    final Path tmpCSv = Files.createTempFile("conquery_search", ".csv");
    Out.file(tmpCSv.toFile()).withUTF8().writeLines(lines);
    Files.write(tmpCSv, String.join(csvConf.getLineSeparator(), lines).getBytes(), StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
    filter.setSearchType(FilterSearch.FilterSearchType.CONTAINS);
    filter.setTemplate(new FilterTemplate(tmpCSv.toString(), Arrays.asList("HEADER"), "HEADER", "", ""));
    FilterSearch.createSourceSearch(filter, csvConf);
    assertThat(filter.getSourceSearch()).isNotNull();
    ConceptsProcessor processor = new ConceptsProcessor(conquery.getNamespace().getNamespaces());
    // from csv
    {
        ResolvedConceptsResult resolved = processor.resolveFilterValues(filter, List.of("a", "unknown"));
        // check the resolved values
        assertThat(resolved.getResolvedFilter().getValue().stream().map(FEValue::getValue)).containsExactlyInAnyOrder("a", "aaa", "aab", "baaa");
        assertThat(resolved.getUnknownCodes()).containsExactlyInAnyOrder("unknown");
    }
    // from column values
    {
        ResolvedConceptsResult resolved = processor.resolveFilterValues(filter, List.of("f", "unknown"));
        // check the resolved values
        assertThat(resolved.getResolvedFilter().getValue().stream().map(FEValue::getValue)).containsExactlyInAnyOrder("f");
        assertThat(resolved.getUnknownCodes()).containsExactlyInAnyOrder("unknown");
    }
}
Also used : Path(java.nio.file.Path) Connector(com.bakdata.conquery.models.datasets.concepts.Connector) AbstractSelectFilter(com.bakdata.conquery.models.datasets.concepts.filters.specific.AbstractSelectFilter) ConqueryTestSpec(com.bakdata.conquery.integration.json.ConqueryTestSpec) ConceptsProcessor(com.bakdata.conquery.resources.api.ConceptsProcessor) CSVConfig(com.bakdata.conquery.models.config.CSVConfig) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId) FilterTemplate(com.bakdata.conquery.apiv1.FilterTemplate) ResolvedConceptsResult(com.bakdata.conquery.resources.api.ConceptsProcessor.ResolvedConceptsResult)

Example 10 with Connector

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

the class ReusedQueryTest method execute.

@Override
public void execute(String name, TestConquery testConquery) throws Exception {
    final StandaloneSupport conquery = testConquery.getSupport(name);
    final String testJson = In.resource("/tests/query/SECONDARY_ID_MIXED/SECONDARY_IDS_MIXED.test.json").withUTF8().readAll();
    final Dataset dataset = conquery.getDataset();
    final QueryTest test = (QueryTest) JsonIntegrationTest.readJson(dataset, testJson);
    // 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();
        LoadingUtil.importTableContents(conquery, test.getContent().getTables());
        conquery.waitUntilWorkDone();
    }
    final SecondaryIdQuery query = (SecondaryIdQuery) IntegrationUtils.parseQuery(conquery, test.getRawQuery());
    final ManagedExecutionId id = IntegrationUtils.assertQueryResult(conquery, query, 4L, ExecutionState.DONE, conquery.getTestUser(), 201);
    assertThat(id).isNotNull();
    final MetaStorage metaStorage = conquery.getMetaStorage();
    final ManagedQuery execution = (ManagedQuery) metaStorage.getExecution(id);
    // Normal reuse
    {
        final ConceptQuery reused = new ConceptQuery(new CQReusedQuery(execution.getId()));
        IntegrationUtils.assertQueryResult(conquery, reused, 2L, ExecutionState.DONE, conquery.getTestUser(), 201);
    }
    // Reuse by API
    {
        final URI reexecuteUri = HierarchyHelper.hierarchicalPath(conquery.defaultApiURIBuilder(), QueryResource.class, "reexecute").buildFromMap(Map.of(ResourceConstants.DATASET, conquery.getDataset().getName(), ResourceConstants.QUERY, execution.getId().toString()));
        final FullExecutionStatus status = conquery.getClient().target(reexecuteUri).request(MediaType.APPLICATION_JSON).post(Entity.entity(null, MediaType.APPLICATION_JSON_TYPE)).readEntity(FullExecutionStatus.class);
        assertThat(status.getStatus()).isIn(ExecutionState.RUNNING, ExecutionState.DONE);
    }
    // Reuse in SecondaryId
    {
        final SecondaryIdQuery reused = new SecondaryIdQuery();
        reused.setRoot(new CQReusedQuery(execution.getId()));
        reused.setSecondaryId(query.getSecondaryId());
        IntegrationUtils.assertQueryResult(conquery, reused, 4L, ExecutionState.DONE, conquery.getTestUser(), 201);
    }
    // Reuse in SecondaryId, but do exclude
    {
        final SecondaryIdQuery reused = new SecondaryIdQuery();
        final CQAnd root = new CQAnd();
        reused.setRoot(root);
        final CQReusedQuery reuse = new CQReusedQuery(execution.getId());
        reuse.setExcludeFromSecondaryId(true);
        // We select only a single event of the query by the exact filtering.
        final CQConcept cqConcept = new CQConcept();
        final ConceptId conceptId = new ConceptId(conquery.getDataset().getId(), "concept");
        final Concept<?> concept = conquery.getNamespaceStorage().getConcept(conceptId);
        cqConcept.setElements(List.of(concept));
        final CQTable cqTable = new CQTable();
        cqTable.setConcept(cqConcept);
        final CentralRegistry centralRegistry = conquery.getNamespaceStorage().getCentralRegistry();
        final Connector connector = centralRegistry.resolve(new ConnectorId(conceptId, "connector1"));
        cqTable.setConnector(connector);
        cqTable.setFilters(List.of(new FilterValue.CQRealRangeFilter((Filter<Range<BigDecimal>>) centralRegistry.resolve(new FilterId(connector.getId(), "filter")), new Range<>(BigDecimal.valueOf(1.01d), BigDecimal.valueOf(1.01d)))));
        cqConcept.setTables(List.of(cqTable));
        cqConcept.setExcludeFromSecondaryId(false);
        root.setChildren(List.of(reuse, cqConcept));
        reused.setSecondaryId(query.getSecondaryId());
        IntegrationUtils.assertQueryResult(conquery, reused, 1L, ExecutionState.DONE, conquery.getTestUser(), 201);
    }
    // Reuse Multiple times with different query types
    {
        final SecondaryIdQuery reused1 = new SecondaryIdQuery();
        reused1.setRoot(new CQReusedQuery(execution.getId()));
        reused1.setSecondaryId(query.getSecondaryId());
        final ManagedExecutionId reused1Id = IntegrationUtils.assertQueryResult(conquery, reused1, 4L, ExecutionState.DONE, conquery.getTestUser(), 201);
        final ManagedQuery execution1 = (ManagedQuery) metaStorage.getExecution(reused1Id);
        {
            final SecondaryIdQuery reused2 = new SecondaryIdQuery();
            reused2.setRoot(new CQReusedQuery(execution1.getId()));
            reused2.setSecondaryId(query.getSecondaryId());
            final ManagedExecutionId reused2Id = IntegrationUtils.assertQueryResult(conquery, reused2, 4L, ExecutionState.DONE, conquery.getTestUser(), 201);
            final ManagedQuery execution2 = (ManagedQuery) metaStorage.getExecution(reused2Id);
            assertThat(reused2Id).as("Query should be reused.").isEqualTo(reused1Id);
            // Now we change to ConceptQuery
            final ConceptQuery reused3 = new ConceptQuery(new CQReusedQuery(execution2.getId()));
            IntegrationUtils.assertQueryResult(conquery, reused3, 2L, ExecutionState.DONE, conquery.getTestUser(), 201);
        }
        {
            final SecondaryIdQuery reusedDiffId = new SecondaryIdQuery();
            reusedDiffId.setRoot(new CQReusedQuery(execution1.getId()));
            // ignored is a single global value and therefore the same as by-PID
            reusedDiffId.setSecondaryId(conquery.getNamespace().getStorage().getSecondaryId(new SecondaryIdDescriptionId(conquery.getDataset().getId(), "ignored")));
            final ManagedExecutionId executionId = IntegrationUtils.assertQueryResult(conquery, reusedDiffId, 2L, ExecutionState.DONE, conquery.getTestUser(), 201);
            assertThat(executionId).as("Query should NOT be reused.").isNotEqualTo(reused1Id);
        }
        {
            // Reuse by another user (create a copy of the actual query)
            final SecondaryIdQuery reused = new SecondaryIdQuery();
            reused.setRoot(new CQReusedQuery(execution.getId()));
            reused.setSecondaryId(query.getSecondaryId());
            User shareHolder = new User("shareholder", "ShareHolder", conquery.getMetaStorage());
            conquery.getMetaProcessor().addUser(shareHolder);
            shareHolder.addPermissions(Set.of(dataset.createPermission(Set.of(Ability.READ)), execution.createPermission(Set.of(Ability.READ))));
            ManagedExecutionId copyId = IntegrationUtils.assertQueryResult(conquery, reused, 4L, ExecutionState.DONE, shareHolder, 201);
            ManagedExecution<?> copy = metaStorage.getExecution(copyId);
            // Contentwise the label and tags should be the same
            assertThat(copy).usingRecursiveComparison().comparingOnlyFields("label", "tags").isEqualTo(execution);
            // However the Object holding the tags must be different, so the two are not linked here
            assertThat(copy.getTags()).isNotSameAs(execution.getTags());
            // And the ids must be different
            assertThat(copy.getId()).isNotSameAs(execution.getId());
        }
    }
}
Also used : Connector(com.bakdata.conquery.models.datasets.concepts.Connector) User(com.bakdata.conquery.models.auth.entities.User) CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) URI(java.net.URI) FilterId(com.bakdata.conquery.models.identifiable.ids.specific.FilterId) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) CQAnd(com.bakdata.conquery.apiv1.query.concept.specific.CQAnd) ConnectorId(com.bakdata.conquery.models.identifiable.ids.specific.ConnectorId) Concept(com.bakdata.conquery.models.datasets.concepts.Concept) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) SecondaryIdDescriptionId(com.bakdata.conquery.models.identifiable.ids.specific.SecondaryIdDescriptionId) CQReusedQuery(com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery) QueryTest(com.bakdata.conquery.integration.json.QueryTest) Dataset(com.bakdata.conquery.models.datasets.Dataset) Range(com.bakdata.conquery.models.common.Range) FullExecutionStatus(com.bakdata.conquery.apiv1.FullExecutionStatus) BigDecimal(java.math.BigDecimal) ConceptId(com.bakdata.conquery.models.identifiable.ids.specific.ConceptId) FilterValue(com.bakdata.conquery.apiv1.query.concept.filter.FilterValue) Filter(com.bakdata.conquery.models.datasets.concepts.filters.Filter) SecondaryIdQuery(com.bakdata.conquery.apiv1.query.SecondaryIdQuery) ManagedExecutionId(com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId) StandaloneSupport(com.bakdata.conquery.util.support.StandaloneSupport) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery)

Aggregations

Connector (com.bakdata.conquery.models.datasets.concepts.Connector)10 ConqueryTestSpec (com.bakdata.conquery.integration.json.ConqueryTestSpec)4 Column (com.bakdata.conquery.models.datasets.Column)4 Dataset (com.bakdata.conquery.models.datasets.Dataset)4 DatasetId (com.bakdata.conquery.models.identifiable.ids.specific.DatasetId)4 FilterTemplate (com.bakdata.conquery.apiv1.FilterTemplate)3 SecondaryIdDescription (com.bakdata.conquery.models.datasets.SecondaryIdDescription)3 Table (com.bakdata.conquery.models.datasets.Table)3 Concept (com.bakdata.conquery.models.datasets.concepts.Concept)3 ConceptId (com.bakdata.conquery.models.identifiable.ids.specific.ConceptId)3 IOException (java.io.IOException)3 Getter (lombok.Getter)3 ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)2 CQTable (com.bakdata.conquery.apiv1.query.concept.filter.CQTable)2 CQUnfilteredTable (com.bakdata.conquery.apiv1.query.concept.filter.CQUnfilteredTable)2 FilterValue (com.bakdata.conquery.apiv1.query.concept.filter.FilterValue)2 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)2 Jackson (com.bakdata.conquery.io.jackson.Jackson)2 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)2 Range (com.bakdata.conquery.models.common.Range)2