use of com.bakdata.conquery.models.datasets.concepts.select.Select 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;
}
use of com.bakdata.conquery.models.datasets.concepts.select.Select 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);
}
}
use of com.bakdata.conquery.models.datasets.concepts.select.Select 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()));
}
}
Aggregations