use of com.bakdata.conquery.models.datasets.Table in project conquery by bakdata.
the class CBlock method calculateEntityDateIndices.
/**
* For every included entity, calculate min and max and store them as statistics in the CBlock.
*
* @implNote This is an unrolled implementation of {@link CDateRange#spanClosed(CDateRange)}.
*/
private static CDateRange[] calculateEntityDateIndices(Bucket bucket, int bucketSize) {
CDateRange[] spans = new CDateRange[bucketSize];
Arrays.fill(spans, CDateRange.all());
// First initialize to an illegal state that's easy on our comparisons
Table table = bucket.getTable();
for (Column column : table.getColumns()) {
if (!column.getType().isDateCompatible()) {
continue;
}
for (int entity : bucket.getEntities()) {
final int index = bucket.getEntityIndex(entity);
final int end = bucket.getEntityEnd(entity);
// We unroll spanClosed for the whole bucket/entity, this avoids costly
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
for (int event = bucket.getEntityStart(entity); event < end; event++) {
if (!bucket.has(event, column)) {
continue;
}
CDateRange range = bucket.getAsDateRange(event, column);
if (range.hasLowerBound()) {
final int minValue = range.getMinValue();
max = Math.max(max, minValue);
min = Math.min(min, minValue);
}
if (range.hasUpperBound()) {
final int maxValue = range.getMaxValue();
max = Math.max(max, maxValue);
min = Math.min(min, maxValue);
}
}
spans[index] = createClosed(max, min, spans[index]);
}
}
return spans;
}
use of com.bakdata.conquery.models.datasets.Table in project conquery by bakdata.
the class LoadingUtil method importTables.
public static void importTables(StandaloneSupport support, List<RequiredTable> tables) throws JSONException {
for (RequiredTable rTable : tables) {
final Table table = rTable.toTable(support.getDataset(), support.getNamespace().getStorage().getCentralRegistry());
support.getDatasetsProcessor().addTable(table, support.getNamespace());
}
}
use of com.bakdata.conquery.models.datasets.Table 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.datasets.Table in project conquery by bakdata.
the class UIProcessor method getTableStatistics.
public TableStatistics getTableStatistics(Table table) {
final NamespaceStorage storage = getDatasetRegistry().get(table.getDataset().getId()).getStorage();
List<Import> imports = table.findImports(storage).collect(Collectors.toList());
final long entries = imports.stream().mapToLong(Import::getNumberOfEntries).sum();
return new TableStatistics(table, entries, // total size of dictionaries
imports.stream().flatMap(imp -> imp.getDictionaries().stream()).filter(Objects::nonNull).map(storage::getDictionary).mapToLong(Dictionary::estimateMemoryConsumption).sum(), // total size of entries
imports.stream().mapToLong(Import::estimateMemoryConsumption).sum(), // Total size of CBlocks
imports.stream().mapToLong(imp -> calculateCBlocksSizeBytes(imp, storage.getAllConcepts())).sum(), imports);
}
use of com.bakdata.conquery.models.datasets.Table in project conquery by bakdata.
the class SerializationTests method treeConcept.
@Test
public void treeConcept() throws IOException, JSONException {
Dataset dataset = new Dataset();
dataset.setName("datasetName");
TreeConcept concept = new TreeConcept();
concept.setDataset(dataset);
concept.setLabel("conceptLabel");
concept.setName("conceptName");
Table table = new Table();
Column column = new Column();
column.setLabel("colLabel");
column.setName("colName");
column.setType(MajorTypeId.STRING);
column.setTable(table);
Column dateColumn = new Column();
dateColumn.setLabel("colLabel2");
dateColumn.setName("colName2");
dateColumn.setType(MajorTypeId.DATE);
dateColumn.setTable(table);
table.setColumns(new Column[] { column, dateColumn });
table.setDataset(dataset);
table.setLabel("tableLabel");
table.setName("tableName");
column.setTable(table);
ConceptTreeConnector connector = new ConceptTreeConnector();
connector.setConcept(concept);
connector.setLabel("connLabel");
connector.setName("connName");
connector.setColumn(column);
concept.setConnectors(List.of(connector));
ValidityDate valDate = new ValidityDate();
valDate.setColumn(dateColumn);
valDate.setConnector(connector);
valDate.setLabel("valLabel");
valDate.setName("valName");
connector.setValidityDates(List.of(valDate));
CentralRegistry registry = new CentralRegistry();
registry.register(dataset);
registry.register(concept);
registry.register(column);
registry.register(dateColumn);
registry.register(table);
registry.register(connector);
registry.register(valDate);
final Validator validator = Validators.newValidator();
concept.setValidator(validator);
SerializationTestUtil.forType(TreeConcept.class).registry(registry).injectables(new Injectable() {
@Override
public MutableInjectableValues inject(MutableInjectableValues values) {
return values.add(Validator.class, validator);
}
}).test(concept);
}
Aggregations