Search in sources :

Example 1 with Table

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;
}
Also used : Table(com.bakdata.conquery.models.datasets.Table) Column(com.bakdata.conquery.models.datasets.Column) CDateRange(com.bakdata.conquery.models.common.daterange.CDateRange)

Example 2 with Table

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());
    }
}
Also used : Table(com.bakdata.conquery.models.datasets.Table)

Example 3 with Table

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));
}
Also used : Bucket(com.bakdata.conquery.models.events.Bucket) Getter(lombok.Getter) Table(com.bakdata.conquery.models.datasets.Table) EntityResult(com.bakdata.conquery.models.query.results.EntityResult) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CDateRange(com.bakdata.conquery.models.common.daterange.CDateRange) MultilineEntityResult(com.bakdata.conquery.models.query.results.MultilineEntityResult) ArrayList(java.util.ArrayList) Entity(com.bakdata.conquery.models.query.entity.Entity) List(java.util.List) QueryExecutionContext(com.bakdata.conquery.models.query.QueryExecutionContext) Map(java.util.Map) Aggregator(com.bakdata.conquery.models.query.queryplan.aggregators.Aggregator) Optional(java.util.Optional) Nullable(javax.annotation.Nullable) CDateSet(com.bakdata.conquery.models.common.CDateSet) Column(com.bakdata.conquery.models.datasets.Column) Bucket(com.bakdata.conquery.models.events.Bucket) Column(com.bakdata.conquery.models.datasets.Column) ArrayList(java.util.ArrayList) MultilineEntityResult(com.bakdata.conquery.models.query.results.MultilineEntityResult)

Example 4 with Table

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);
}
Also used : Role(com.bakdata.conquery.models.auth.entities.Role) Dictionary(com.bakdata.conquery.models.dictionary.Dictionary) java.util(java.util) Getter(lombok.Getter) UserId(com.bakdata.conquery.models.identifiable.ids.specific.UserId) RequiredArgsConstructor(lombok.RequiredArgsConstructor) ConceptTreeNode(com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeNode) Import(com.bakdata.conquery.models.datasets.Import) NamespaceStorage(com.bakdata.conquery.io.storage.NamespaceStorage) Pair(org.apache.commons.lang3.tuple.Pair) com.bakdata.conquery.resources.admin.ui.model(com.bakdata.conquery.resources.admin.ui.model) TreeConcept(com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept) Group(com.bakdata.conquery.models.auth.entities.Group) ConqueryPermission(com.bakdata.conquery.models.auth.permissions.ConqueryPermission) Table(com.bakdata.conquery.models.datasets.Table) StringPermissionBuilder(com.bakdata.conquery.models.auth.permissions.StringPermissionBuilder) Concept(com.bakdata.conquery.models.datasets.concepts.Concept) CPSTypeIdResolver(com.bakdata.conquery.io.cps.CPSTypeIdResolver) User(com.bakdata.conquery.models.auth.entities.User) Collectors(java.util.stream.Collectors) AuthorizationHelper(com.bakdata.conquery.models.auth.AuthorizationHelper) Slf4j(lombok.extern.slf4j.Slf4j) Ability(com.bakdata.conquery.models.auth.permissions.Ability) CBlock(com.bakdata.conquery.models.events.CBlock) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) Dictionary(com.bakdata.conquery.models.dictionary.Dictionary) Import(com.bakdata.conquery.models.datasets.Import) NamespaceStorage(com.bakdata.conquery.io.storage.NamespaceStorage)

Example 5 with Table

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);
}
Also used : Injectable(com.bakdata.conquery.io.jackson.Injectable) ValidityDate(com.bakdata.conquery.models.datasets.concepts.ValidityDate) CQTable(com.bakdata.conquery.apiv1.query.concept.filter.CQTable) Table(com.bakdata.conquery.models.datasets.Table) Column(com.bakdata.conquery.models.datasets.Column) Dataset(com.bakdata.conquery.models.datasets.Dataset) TreeConcept(com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept) MutableInjectableValues(com.bakdata.conquery.io.jackson.MutableInjectableValues) ConceptTreeConnector(com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeConnector) CentralRegistry(com.bakdata.conquery.models.identifiable.CentralRegistry) Validator(javax.validation.Validator) Test(org.junit.jupiter.api.Test) IdMapSerialisationTest(com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)

Aggregations

Table (com.bakdata.conquery.models.datasets.Table)22 Column (com.bakdata.conquery.models.datasets.Column)12 Dataset (com.bakdata.conquery.models.datasets.Dataset)11 CentralRegistry (com.bakdata.conquery.models.identifiable.CentralRegistry)8 Test (org.junit.jupiter.api.Test)8 Validator (javax.validation.Validator)7 Import (com.bakdata.conquery.models.datasets.Import)6 TreeConcept (com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept)6 CQTable (com.bakdata.conquery.apiv1.query.concept.filter.CQTable)5 ConceptTreeConnector (com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeConnector)5 Getter (lombok.Getter)5 Injectable (com.bakdata.conquery.io.jackson.Injectable)4 MutableInjectableValues (com.bakdata.conquery.io.jackson.MutableInjectableValues)4 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)4 Concept (com.bakdata.conquery.models.datasets.concepts.Concept)4 Connector (com.bakdata.conquery.models.datasets.concepts.Connector)4 Bucket (com.bakdata.conquery.models.events.Bucket)4 SneakyThrows (lombok.SneakyThrows)4 NamespaceStorage (com.bakdata.conquery.io.storage.NamespaceStorage)3 SecondaryIdDescription (com.bakdata.conquery.models.datasets.SecondaryIdDescription)3