Search in sources :

Example 1 with SecondaryIdDescriptionId

use of com.bakdata.conquery.models.identifiable.ids.specific.SecondaryIdDescriptionId in project conquery by bakdata.

the class RequiredColumn method toColumn.

public Column toColumn(Table table, CentralRegistry storage) {
    Column col = new Column();
    col.setName(name);
    col.setType(type);
    col.setSharedDictionary(sharedDictionary);
    col.setTable(table);
    if (!Strings.isNullOrEmpty(secondaryId)) {
        final SecondaryIdDescription description = storage.resolve(new SecondaryIdDescriptionId(table.getDataset().getId(), secondaryId));
        col.setSecondaryId(description);
    }
    return col;
}
Also used : SecondaryIdDescriptionId(com.bakdata.conquery.models.identifiable.ids.specific.SecondaryIdDescriptionId) Column(com.bakdata.conquery.models.datasets.Column) SecondaryIdDescription(com.bakdata.conquery.models.datasets.SecondaryIdDescription)

Example 2 with SecondaryIdDescriptionId

use of com.bakdata.conquery.models.identifiable.ids.specific.SecondaryIdDescriptionId in project conquery by bakdata.

the class SecondaryIdEndpointTest method execute.

@Override
public void execute(StandaloneSupport conquery) throws Exception {
    final SecondaryIdDescription description = new SecondaryIdDescription();
    description.setDescription("description-DESCRIPTION");
    description.setName("description-NAME");
    description.setLabel("description-LABEL");
    final SecondaryIdDescriptionId id = new SecondaryIdDescriptionId(conquery.getDataset().getId(), description.getName());
    final Response post = uploadDescription(conquery, description);
    log.info("{}", post);
    assertThat(post).describedAs("Response = `%s`", post).returns(Response.Status.Family.SUCCESSFUL, response -> response.getStatusInfo().getFamily());
    {
        final Set<FESecondaryId> secondaryIds = fetchSecondaryIdDescriptions(conquery);
        log.info("{}", secondaryIds);
        description.setDataset(conquery.getDataset());
        assertThat(secondaryIds).extracting(FESecondaryId::getId).containsExactly(description.getId().toString());
        // Upload Table referencing SecondaryId
        {
            // Build data manually so content is minmal (ie no dataset prefixes etc)
            ObjectNode tableNode = Jackson.MAPPER.createObjectNode();
            tableNode.put("name", "table");
            ObjectNode columnNode = Jackson.MAPPER.createObjectNode();
            columnNode.put("name", "column");
            columnNode.put("type", MajorTypeId.INTEGER.name());
            columnNode.put("secondaryId", description.getId().toStringWithoutDataset());
            tableNode.put("columns", columnNode);
            final Response response = uploadTable(conquery, tableNode);
            assertThat(response.getStatusInfo().getFamily()).isEqualTo(Response.Status.Family.SUCCESSFUL);
        }
    }
    {
        final URI uri = HierarchyHelper.hierarchicalPath(conquery.defaultAdminURIBuilder(), DatasetsUIResource.class, "getDataset").buildFromMap(Map.of("dataset", conquery.getDataset().getName()));
        final Response actual = conquery.getClient().target(uri).request().get();
        assertThat(actual).returns(Response.Status.Family.SUCCESSFUL, response -> response.getStatusInfo().getFamily());
    }
    {
        // First one fails because table depends on it
        assertThat(deleteDescription(conquery, id)).returns(Response.Status.Family.CLIENT_ERROR, response -> response.getStatusInfo().getFamily());
        deleteTable(conquery, new TableId(conquery.getDataset().getId(), "table"));
        // We've deleted the table, now it should be successful
        assertThat(deleteDescription(conquery, id)).returns(Response.Status.Family.SUCCESSFUL, response -> response.getStatusInfo().getFamily());
        final Set<FESecondaryId> secondaryIds = fetchSecondaryIdDescriptions(conquery);
        log.info("{}", secondaryIds);
        assertThat(secondaryIds).isEmpty();
    }
}
Also used : Response(javax.ws.rs.core.Response) SecondaryIdDescriptionId(com.bakdata.conquery.models.identifiable.ids.specific.SecondaryIdDescriptionId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AdminTablesResource(com.bakdata.conquery.resources.admin.rest.AdminTablesResource) AdminDatasetResource(com.bakdata.conquery.resources.admin.rest.AdminDatasetResource) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MediaType(javax.ws.rs.core.MediaType) Map(java.util.Map) TableId(com.bakdata.conquery.models.identifiable.ids.specific.TableId) URI(java.net.URI) TypeReference(com.fasterxml.jackson.core.type.TypeReference) MajorTypeId(com.bakdata.conquery.models.events.MajorTypeId) IntegrationTest(com.bakdata.conquery.integration.IntegrationTest) ResourceConstants(com.bakdata.conquery.resources.ResourceConstants) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) DatasetsUIResource(com.bakdata.conquery.resources.admin.ui.DatasetsUIResource) FESecondaryId(com.bakdata.conquery.apiv1.frontend.FESecondaryId) Entity(javax.ws.rs.client.Entity) DatasetResource(com.bakdata.conquery.resources.api.DatasetResource) StandaloneSupport(com.bakdata.conquery.util.support.StandaloneSupport) SecondaryIdDescription(com.bakdata.conquery.models.datasets.SecondaryIdDescription) Slf4j(lombok.extern.slf4j.Slf4j) Response(javax.ws.rs.core.Response) Jackson(com.bakdata.conquery.io.jackson.Jackson) HierarchyHelper(com.bakdata.conquery.resources.hierarchies.HierarchyHelper) TableId(com.bakdata.conquery.models.identifiable.ids.specific.TableId) SecondaryIdDescriptionId(com.bakdata.conquery.models.identifiable.ids.specific.SecondaryIdDescriptionId) Set(java.util.Set) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FESecondaryId(com.bakdata.conquery.apiv1.frontend.FESecondaryId) URI(java.net.URI) SecondaryIdDescription(com.bakdata.conquery.models.datasets.SecondaryIdDescription)

Example 3 with SecondaryIdDescriptionId

use of com.bakdata.conquery.models.identifiable.ids.specific.SecondaryIdDescriptionId 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

SecondaryIdDescriptionId (com.bakdata.conquery.models.identifiable.ids.specific.SecondaryIdDescriptionId)3 SecondaryIdDescription (com.bakdata.conquery.models.datasets.SecondaryIdDescription)2 StandaloneSupport (com.bakdata.conquery.util.support.StandaloneSupport)2 URI (java.net.URI)2 FullExecutionStatus (com.bakdata.conquery.apiv1.FullExecutionStatus)1 FESecondaryId (com.bakdata.conquery.apiv1.frontend.FESecondaryId)1 ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)1 SecondaryIdQuery (com.bakdata.conquery.apiv1.query.SecondaryIdQuery)1 CQTable (com.bakdata.conquery.apiv1.query.concept.filter.CQTable)1 FilterValue (com.bakdata.conquery.apiv1.query.concept.filter.FilterValue)1 CQAnd (com.bakdata.conquery.apiv1.query.concept.specific.CQAnd)1 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)1 CQReusedQuery (com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery)1 IntegrationTest (com.bakdata.conquery.integration.IntegrationTest)1 QueryTest (com.bakdata.conquery.integration.json.QueryTest)1 Jackson (com.bakdata.conquery.io.jackson.Jackson)1 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)1 User (com.bakdata.conquery.models.auth.entities.User)1 Range (com.bakdata.conquery.models.common.Range)1 Column (com.bakdata.conquery.models.datasets.Column)1