Search in sources :

Example 11 with CQConcept

use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.

the class DefaultLabelTest method autoLabelConceptQuery.

@ParameterizedTest
@CsvSource({ "de,Concept", "en,Concept" })
void autoLabelConceptQuery(Locale locale, String autoLabel) {
    I18n.LOCALE.set(locale);
    CQConcept concept = makeCQConcept("Concept");
    ConceptQuery cq = new ConceptQuery(concept);
    ManagedQuery mQuery = cq.toManagedExecution(user, DATASET);
    mQuery.setLabel(mQuery.makeAutoLabel(getPrintSettings(locale)));
    assertThat(mQuery.getLabel()).isEqualTo(autoLabel + AUTO_LABEL_SUFFIX);
    assertThat(mQuery.getLabelWithoutAutoLabelSuffix()).isEqualTo(autoLabel);
}
Also used : CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with CQConcept

use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.

the class DefaultLabelTest method autoLabelConceptQueryFallback.

@ParameterizedTest
@CsvSource({ "de,Default-Concept", "en,Default-Concept" })
void autoLabelConceptQueryFallback(Locale locale, String autoLabel) {
    I18n.LOCALE.set(locale);
    CQConcept concept = new CQConcept();
    concept.setLabel(null);
    concept.setElements(List.of(CONCEPT));
    ConceptQuery cq = new ConceptQuery(concept);
    ManagedQuery mQuery = cq.toManagedExecution(user, DATASET);
    UUID uuid = UUID.randomUUID();
    mQuery.setQueryId(uuid);
    mQuery.setLabel(mQuery.makeAutoLabel(getPrintSettings(locale)));
    assertThat(mQuery.getLabel()).isEqualTo(autoLabel + AUTO_LABEL_SUFFIX);
    assertThat(mQuery.getLabelWithoutAutoLabelSuffix()).isEqualTo(autoLabel);
}
Also used : CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) UUID(java.util.UUID) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with CQConcept

use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.

the class DefaultLabelTest method autoLabelComplexQueryNullLabels.

@ParameterizedTest
@CsvSource({ "de,Hochgeladene-Liste Anfrage Default-Concept Concept2 Concept3", "en,Uploaded-List Query Default-Concept Concept2 Concept3" })
void autoLabelComplexQueryNullLabels(Locale locale, String autoLabel) {
    I18n.LOCALE.set(locale);
    final ManagedQuery managedQuery = new ManagedQuery(null, null, DATASET);
    managedQuery.setQueryId(UUID.randomUUID());
    CQAnd and = new CQAnd();
    CQConcept concept1 = new CQConcept();
    concept1.setLabel(null);
    concept1.setElements(List.of(CONCEPT));
    CQConcept concept2 = makeCQConcept("Concept2");
    CQConcept concept3 = makeCQConcept("Concept3");
    and.setChildren(List.of(new CQExternal(List.of(), new String[0][0]), new CQReusedQuery(managedQuery.getId()), concept1, concept2, concept3));
    ConceptQuery cq = new ConceptQuery(and);
    ManagedQuery mQuery = cq.toManagedExecution(user, DATASET);
    mQuery.setLabel(mQuery.makeAutoLabel(getPrintSettings(locale)));
    assertThat(mQuery.getLabel()).isEqualTo(autoLabel + AUTO_LABEL_SUFFIX);
    assertThat(mQuery.getLabelWithoutAutoLabelSuffix()).isEqualTo(autoLabel);
}
Also used : CQReusedQuery(com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) CQExternal(com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) CQAnd(com.bakdata.conquery.apiv1.query.concept.specific.CQAnd) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with CQConcept

use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.

the class FilteringConceptManipulator method consume.

public void consume(CQConcept concept, DatasetRegistry namespaces) {
    List<Select> selects = concept.getSelects();
    if (!selectBlockList.isEmpty()) {
        selects.removeIf(s -> selectBlockList.contains(s.getId()));
    } else if (!selectAllowList.isEmpty()) {
        selects.removeIf(s -> !selectAllowList.contains(s.getId()));
    }
    // Add default selects if none is present anymore
    if (selects.isEmpty()) {
        concept.setSelects(selectDefault.stream().map(namespaces::resolve).collect(Collectors.toList()));
    }
    // Handle tables
    List<CQTable> tables = concept.getTables();
    Iterator<CQTable> it = tables.iterator();
    while (it.hasNext()) {
        CQTable table = it.next();
        if (tableBlockList.contains(table.getConnector().getId())) {
            it.remove();
        }
        if (!tableAllowList.containsKey(table.getConnector().getId())) {
            it.remove();
        } else {
            // If table is allowlisted apply a table manipulator if one exist
            TableManipulator tableMan = tableAllowList.get(table.getConnector().getId());
            if (tableMan != null) {
                tableMan.consume(table, namespaces);
            }
        }
    }
    if (tables.isEmpty()) {
        throw new IllegalStateException(String.format("After filtering the tables of concept %s, no table was left in the concept. ConceptManipulator: %s", concept, this.toString()));
    }
}
Also used : ConnectorId(com.bakdata.conquery.models.identifiable.ids.specific.ConnectorId) Setter(lombok.Setter) Iterator(java.util.Iterator) Getter(lombok.Getter) Set(java.util.Set) Collectors(java.util.stream.Collectors) ConceptSelectId(com.bakdata.conquery.models.identifiable.ids.specific.ConceptSelectId) Connector(com.bakdata.conquery.models.datasets.concepts.Connector) List(java.util.List) Select(com.bakdata.conquery.models.datasets.concepts.select.Select) Builder(lombok.Builder) Map(java.util.Map) ToString(lombok.ToString) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) Collections(java.util.Collections) CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) Select(com.bakdata.conquery.models.datasets.concepts.select.Select)

Example 15 with CQConcept

use of com.bakdata.conquery.apiv1.query.concept.specific.CQConcept in project conquery by bakdata.

the class SecondaryIdQuery method resolve.

@Override
public void resolve(final QueryResolveContext context) {
    DateAggregationMode resolvedDateAggregationMode = dateAggregationMode;
    if (context.getDateAggregationMode() != null) {
        log.trace("Overriding date aggregation mode ({}) with mode from context ({})", dateAggregationMode, context.getDateAggregationMode());
        resolvedDateAggregationMode = context.getDateAggregationMode();
    }
    final QueryResolveContext resolvedContext = context.withDateAggregationMode(resolvedDateAggregationMode);
    this.query = new ConceptQuery(root);
    query.resolve(resolvedContext);
    withSecondaryId = new HashSet<>();
    withoutSecondaryId = new HashSet<>();
    // TODO FK: can we refactor this into methods of CQConcept?
    // partition tables by their holding of the requested SecondaryId.
    // This assumes that from the root, only ConceptNodes hold TableIds we are interested in.
    query.visit(queryElement -> {
        if (!(queryElement instanceof CQConcept)) {
            return;
        }
        final CQConcept concept = (CQConcept) queryElement;
        for (CQTable connector : concept.getTables()) {
            final Table table = connector.getConnector().getTable();
            final Column secondaryIdColumn = findSecondaryIdColumn(table);
            if (secondaryIdColumn != null && !concept.isExcludeFromSecondaryId()) {
                withSecondaryId.add(secondaryIdColumn);
            } else {
                withoutSecondaryId.add(table);
            }
        }
    });
    // If there are no tables with the secondaryId, we fail as that is user error.
    if (withSecondaryId.isEmpty()) {
        throw new ConqueryError.NoSecondaryIdSelectedError();
    }
}
Also used : CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) Table(com.bakdata.conquery.models.datasets.Table) Column(com.bakdata.conquery.models.datasets.Column) CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) DateAggregationMode(com.bakdata.conquery.models.query.DateAggregationMode) QueryResolveContext(com.bakdata.conquery.models.query.QueryResolveContext)

Aggregations

CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)18 ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)8 ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)7 CQTable (com.bakdata.conquery.apiv1.query.concept.filter.CQTable)6 Test (org.junit.jupiter.api.Test)6 Dataset (com.bakdata.conquery.models.datasets.Dataset)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 CQReusedQuery (com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 ExportForm (com.bakdata.conquery.apiv1.forms.export_form.ExportForm)3 CQAnd (com.bakdata.conquery.apiv1.query.concept.specific.CQAnd)3 CQExternal (com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal)3 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)3 ResultType (com.bakdata.conquery.models.externalservice.ResultType)3 I18n (com.bakdata.conquery.models.i18n.I18n)3 CentralRegistry (com.bakdata.conquery.models.identifiable.CentralRegistry)3 IdMapSerialisationTest (com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)3 UniqueNamer (com.bakdata.conquery.models.query.resultinfo.UniqueNamer)3 CsvSource (org.junit.jupiter.params.provider.CsvSource)3