use of com.bakdata.conquery.apiv1.query.concept.filter.CQUnfilteredTable in project conquery by bakdata.
the class TableExportQuery method resolve.
@Override
public void resolve(QueryResolveContext context) {
query.resolve(context);
// First is dates
AtomicInteger currentPosition = new AtomicInteger(1);
positions = new HashMap<>();
Map<SecondaryIdDescription, Integer> secondaryIdPositions = new HashMap<>();
// SecondaryIds are pulled to the front and grouped over all tables
tables.stream().map(cqUnfilteredTable -> cqUnfilteredTable.getTable().getTable().getColumns()).flatMap(Arrays::stream).map(Column::getSecondaryId).filter(Objects::nonNull).distinct().sorted(Comparator.comparing(SecondaryIdDescription::getLabel)).forEach(secondaryId -> secondaryIdPositions.put(secondaryId, currentPosition.getAndIncrement()));
for (CQUnfilteredTable table : tables) {
Connector connector = table.getTable();
final Column validityDateColumn = findValidityDateColumn(connector, table.getDateColumn());
if (validityDateColumn != null) {
positions.putIfAbsent(validityDateColumn, 0);
}
// Set column positions, set SecondaryId positions to precomputed ones.
for (Column column : connector.getTable().getColumns()) {
positions.computeIfAbsent(column, col -> col.getSecondaryId() != null ? secondaryIdPositions.get(col.getSecondaryId()) : currentPosition.getAndIncrement());
}
}
resultInfos = createResultInfos(currentPosition.get(), secondaryIdPositions, positions);
}
use of com.bakdata.conquery.apiv1.query.concept.filter.CQUnfilteredTable in project conquery by bakdata.
the class FullExportForm method createSubQueries.
@Override
public Map<String, List<ManagedQuery>> createSubQueries(DatasetRegistry datasets, User user, Dataset submittedDataset) {
// Forms are sent as an array of standard queries containing AND/OR of CQConcepts, we ignore everything and just convert the CQConcepts into CQUnfiltered for export.
final List<CQUnfilteredTable> unfilteredTables = tables.stream().flatMap(Visitable::stream).filter(CQConcept.class::isInstance).map(CQConcept.class::cast).flatMap(concept -> concept.getTables().stream()).map(table -> new CQUnfilteredTable(table.getConnector(), table.getDateColumn())).collect(Collectors.toList());
final TableExportQuery exportQuery = new TableExportQuery(queryGroup.getQuery());
exportQuery.setDateRange(getDateRange());
exportQuery.setTables(unfilteredTables);
final ManagedQuery managedQuery = new ManagedQuery(exportQuery, user, submittedDataset);
return Map.of(ConqueryConstants.SINGLE_RESULT_TABLE_NAME, List.of(managedQuery));
}
use of com.bakdata.conquery.apiv1.query.concept.filter.CQUnfilteredTable 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);
}
Aggregations