use of com.bakdata.conquery.models.query.results.MultilineEntityResult in project conquery by bakdata.
the class TableExportQueryPlan method execute.
@Override
public Optional<MultilineEntityResult> execute(QueryExecutionContext ctx, Entity entity) {
Optional<? extends EntityResult> result = subPlan.execute(ctx, entity);
if (result.isEmpty() || tables.isEmpty()) {
return Optional.empty();
}
List<Object[]> results = new ArrayList<>();
final int totalColumns = positions.values().stream().mapToInt(i -> i).max().getAsInt() + 1;
for (TableExportDescription exportDescription : tables) {
for (Bucket bucket : ctx.getEntityBucketsForTable(entity, exportDescription.getTable())) {
int entityId = entity.getId();
if (!bucket.containsEntity(entityId)) {
continue;
}
int start = bucket.getEntityStart(entityId);
int end = bucket.getEntityEnd(entityId);
for (int event = start; event < end; event++) {
// Export Full-table if it has no validity date.
if (exportDescription.getValidityDateColumn() != null && !bucket.eventIsContainedIn(event, exportDescription.getValidityDateColumn(), CDateSet.create(dateRange))) {
continue;
}
Object[] entry = new Object[totalColumns];
for (Column column : exportDescription.getTable().getColumns()) {
if (!bucket.has(event, column)) {
continue;
}
if (column.equals(exportDescription.getValidityDateColumn())) {
entry[0] = List.of(bucket.getAsDateRange(event, column));
} else {
entry[positions.get(column)] = bucket.createScriptValue(event, column);
}
}
results.add(entry);
}
}
}
return Optional.of(new MultilineEntityResult(entity.getId(), results));
}
use of com.bakdata.conquery.models.query.results.MultilineEntityResult in project conquery by bakdata.
the class FormQueryPlan method execute.
@Override
public Optional<MultilineEntityResult> execute(QueryExecutionContext ctx, Entity entity) {
if (!isOfInterest(entity)) {
// If the entity is not covered by the query generate a basic result line with constants but without features
return Optional.of(createResultForNotContained(entity, null));
}
List<Object[]> resultValues = new ArrayList<>(dateContexts.size());
for (DateContext dateContext : dateContexts) {
CDateSet dateRestriction = CDateSet.create(ctx.getDateRestriction());
dateRestriction.retainAll(dateContext.getDateRange());
// Reference the dates per sub-query, don't accumulate dates of all sub-queries
QueryExecutionContext innerContext = QueryUtils.determineDateAggregatorForContext(ctx, features::getValidityDateAggregator).withDateRestriction(dateRestriction);
features.init(ctx, entity);
Optional<SinglelineEntityResult> subResult = features.execute(innerContext, entity);
if (subResult.isEmpty()) {
resultValues.addAll(createResultForNotContained(entity, dateContext).listResultLines());
continue;
}
resultValues.addAll(ResultModifier.modify(subResult.get(), ResultModifier.existAggValuesSetterFor(features.getAggregators(), OptionalInt.of(0)).unaryAndThen(v -> addConstants(v, dateContext))).listResultLines());
}
return Optional.of(new MultilineEntityResult(entity.getId(), resultValues));
}
use of com.bakdata.conquery.models.query.results.MultilineEntityResult in project conquery by bakdata.
the class FormQueryPlan method createResultForNotContained.
private MultilineEntityResult createResultForNotContained(Entity entity, DateContext dateContext) {
List<Object[]> result = new ArrayList<>();
result.add(new Object[features.getAggregatorSize()]);
return ResultModifier.modify(new MultilineEntityResult(entity.getId(), result), ResultModifier.existAggValuesSetterFor(getAggregators(), OptionalInt.of(0)).unaryAndThen(v -> addConstants(v, dateContext)));
}
use of com.bakdata.conquery.models.query.results.MultilineEntityResult in project conquery by bakdata.
the class JacksonTest method testNonStrictNumbers.
@Test
public void testNonStrictNumbers() throws JSONException, IOException {
SerializationTestUtil.forType(Double.class).test(Double.NaN, null);
SerializationTestUtil.forType(Double.class).test(Double.NEGATIVE_INFINITY, null);
SerializationTestUtil.forType(Double.class).test(Double.POSITIVE_INFINITY, null);
SerializationTestUtil.forType(Double.class).test(Double.MAX_VALUE);
SerializationTestUtil.forType(Double.class).test(Double.MIN_VALUE);
SerializationTestUtil.forType(EntityResult.class).test(new MultilineEntityResult(4, List.of(new Object[] { 0, 1, 2 }, new Object[] { Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY })), new MultilineEntityResult(4, List.of(new Object[] { 0, 1, 2 }, new Object[] { null, null, null })));
}
use of com.bakdata.conquery.models.query.results.MultilineEntityResult in project conquery by bakdata.
the class EntityDateQueryPlan method execute.
@Override
public Optional<MultilineEntityResult> execute(QueryExecutionContext ctx, Entity entity) {
// Don't set the query date aggregator here because the subqueries should set their aggregator independently
// Execute the prerequisite query
Optional<EntityResult> preResult = query.execute(ctx, entity);
if (preResult.isEmpty()) {
return Optional.empty();
}
Optional<DateAggregator> validityDateAggregator = query.getValidityDateAggregator();
if (validityDateAggregator.isEmpty()) {
return Optional.empty();
}
final CDateSet aggregationResult = validityDateAggregator.get().createAggregationResult();
aggregationResult.retainAll(dateRestriction);
// Generate DateContexts in the provided resolutions
List<DateContext> contexts = new ArrayList<>();
for (CDateRange range : aggregationResult.asRanges()) {
contexts.addAll(DateContext.generateAbsoluteContexts(range, resolutionsAndAlignments));
}
FormQueryPlan resolutionQuery = new FormQueryPlan(contexts, features);
return resolutionQuery.execute(ctx, entity);
}
Aggregations