Search in sources :

Example 1 with CQTable

use of com.bakdata.conquery.apiv1.query.concept.filter.CQTable in project conquery by bakdata.

the class FilterTest method parseQuery.

private Query parseQuery(StandaloneSupport support) throws JSONException, IOException {
    rawFilterValue.put("filter", support.getDataset().getName() + ".concept.connector.filter");
    FilterValue<?> result = parseSubTree(support, rawFilterValue, Jackson.MAPPER.getTypeFactory().constructType(FilterValue.class));
    CQTable cqTable = new CQTable();
    cqTable.setFilters(Collections.singletonList(result));
    cqTable.setConnector(connector);
    CQConcept cqConcept = new CQConcept();
    cqTable.setConcept(cqConcept);
    cqConcept.setElements(Collections.singletonList(concept));
    cqConcept.setTables(Collections.singletonList(cqTable));
    if (dateRange != null) {
        CQDateRestriction restriction = new CQDateRestriction();
        restriction.setDateRange(dateRange);
        restriction.setChild(cqConcept);
        return new ConceptQuery(restriction);
    }
    return new ConceptQuery(cqConcept);
}
Also used : CQDateRestriction(com.bakdata.conquery.apiv1.query.concept.specific.CQDateRestriction) CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) FilterValue(com.bakdata.conquery.apiv1.query.concept.filter.FilterValue)

Example 2 with CQTable

use of com.bakdata.conquery.apiv1.query.concept.filter.CQTable 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 CQTable

use of com.bakdata.conquery.apiv1.query.concept.filter.CQTable in project conquery by bakdata.

the class SerializationTests method testFormQuery.

@Test
public void testFormQuery() throws IOException, JSONException {
    CQConcept concept = new CQConcept();
    final TreeConcept testConcept = new TreeConcept();
    Dataset dataset = new Dataset();
    dataset.setName("testDataset");
    testConcept.setDataset(dataset);
    testConcept.setName("concept");
    final ConceptTreeConnector connector = new ConceptTreeConnector();
    connector.setConcept(testConcept);
    connector.setName("connector1");
    testConcept.setConnectors(List.of(connector));
    concept.setElements(Collections.singletonList(testConcept));
    CQTable[] tables = { new CQTable() };
    connector.setTable(new Table());
    tables[0].setConnector(connector);
    tables[0].setConcept(concept);
    concept.setTables(Arrays.asList(tables));
    ConceptQuery subQuery = new ConceptQuery(concept);
    CQOr features = new CQOr();
    features.setChildren(Collections.singletonList(concept));
    AbsoluteFormQuery query = new AbsoluteFormQuery(subQuery, CDateRange.exactly(LocalDate.now()).toSimpleRange(), ArrayConceptQuery.createFromFeatures(Collections.singletonList(features)), List.of(ExportForm.ResolutionAndAlignment.of(Resolution.COMPLETE, Alignment.NO_ALIGN), ExportForm.ResolutionAndAlignment.of(Resolution.QUARTERS, Alignment.QUARTER)));
    CentralRegistry centralRegistry = new CentralRegistry();
    centralRegistry.register(dataset);
    centralRegistry.register(testConcept);
    centralRegistry.register(connector);
    SerializationTestUtil.forType(AbsoluteFormQuery.class).registry(centralRegistry).test(query);
}
Also used : CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) Table(com.bakdata.conquery.models.datasets.Table) Dataset(com.bakdata.conquery.models.datasets.Dataset) TreeConcept(com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept) CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) ConceptTreeConnector(com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeConnector) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) ArrayConceptQuery(com.bakdata.conquery.apiv1.query.ArrayConceptQuery) AbsoluteFormQuery(com.bakdata.conquery.models.forms.managed.AbsoluteFormQuery) CQOr(com.bakdata.conquery.apiv1.query.concept.specific.CQOr) Test(org.junit.jupiter.api.Test) IdMapSerialisationTest(com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)

Example 4 with CQTable

use of com.bakdata.conquery.apiv1.query.concept.filter.CQTable in project conquery by bakdata.

the class SerializationTests method cqConcept.

@Test
public void cqConcept() throws JSONException, IOException {
    final Dataset dataset = new Dataset();
    dataset.setName("dataset");
    final TreeConcept concept = new TreeConcept();
    concept.setName("concept");
    concept.setDataset(dataset);
    final ConceptTreeConnector connector = new ConceptTreeConnector();
    connector.setConcept(concept);
    concept.setConnectors(List.of(connector));
    final CQConcept cqConcept = new CQConcept();
    cqConcept.setElements(List.of(concept));
    cqConcept.setLabel("Label");
    final CQTable cqTable = new CQTable();
    cqTable.setConnector(connector);
    cqTable.setFilters(List.of());
    cqTable.setConcept(cqConcept);
    cqConcept.setTables(List.of(cqTable));
    final CentralRegistry registry = new CentralRegistry();
    registry.register(dataset);
    registry.register(concept);
    registry.register(connector);
    SerializationTestUtil.forType(CQConcept.class).registry(registry).test(cqConcept);
}
Also used : Dataset(com.bakdata.conquery.models.datasets.Dataset) TreeConcept(com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept) CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) ConceptTreeConnector(com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeConnector) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) Test(org.junit.jupiter.api.Test) IdMapSerialisationTest(com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)

Example 5 with CQTable

use of com.bakdata.conquery.apiv1.query.concept.filter.CQTable in project conquery by bakdata.

the class CQConcept method setDefaultExists.

@Override
public void setDefaultExists() {
    boolean allTablesEmpty = getTables().stream().map(CQTable::getSelects).allMatch(List::isEmpty);
    if (!(getSelects().isEmpty() && (tables.isEmpty() || allTablesEmpty))) {
        // Don't fill if there are any selects on concept level or on any table level
        return;
    }
    List<Select> cSelects = new ArrayList<>(getSelects());
    cSelects.addAll(getConcept().getDefaultSelects());
    setSelects(cSelects);
    for (CQTable t : getTables()) {
        List<Select> conSelects = new ArrayList<>(t.getSelects());
        conSelects.addAll(t.getConnector().getDefaultSelects());
        t.setSelects(conSelects);
    }
}
Also used : CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) Select(com.bakdata.conquery.models.datasets.concepts.select.Select) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

CQTable (com.bakdata.conquery.apiv1.query.concept.filter.CQTable)8 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)6 ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)3 FilterValue (com.bakdata.conquery.apiv1.query.concept.filter.FilterValue)3 Dataset (com.bakdata.conquery.models.datasets.Dataset)3 Select (com.bakdata.conquery.models.datasets.concepts.select.Select)3 CentralRegistry (com.bakdata.conquery.models.identifiable.CentralRegistry)3 Column (com.bakdata.conquery.models.datasets.Column)2 Table (com.bakdata.conquery.models.datasets.Table)2 Concept (com.bakdata.conquery.models.datasets.concepts.Concept)2 Connector (com.bakdata.conquery.models.datasets.concepts.Connector)2 ConceptTreeConnector (com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeConnector)2 TreeConcept (com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept)2 IdMapSerialisationTest (com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)2 ConnectorId (com.bakdata.conquery.models.identifiable.ids.specific.ConnectorId)2 DateAggregationMode (com.bakdata.conquery.models.query.DateAggregationMode)2 QueryResolveContext (com.bakdata.conquery.models.query.QueryResolveContext)2 List (java.util.List)2 Test (org.junit.jupiter.api.Test)2 FullExecutionStatus (com.bakdata.conquery.apiv1.FullExecutionStatus)1