Search in sources :

Example 16 with Column

use of com.bakdata.conquery.models.datasets.Column in project conquery by bakdata.

the class Filter method isForConnectorsTable.

@JsonIgnore
@ValidationMethod(message = "Not all Filters are for Connector's table.")
public boolean isForConnectorsTable() {
    boolean valid = true;
    for (Column column : getRequiredColumns()) {
        if (column == null || column.getTable() == connector.getTable()) {
            continue;
        }
        log.error("Filter[{}] of Table[{}] is not of Connector[{}]#Table[{}]", getId(), column.getTable().getId(), connector.getId(), connector.getTable().getId());
        valid = false;
    }
    return valid;
}
Also used : Column(com.bakdata.conquery.models.datasets.Column) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) ValidationMethod(io.dropwizard.validation.ValidationMethod)

Example 17 with Column

use of com.bakdata.conquery.models.datasets.Column in project conquery by bakdata.

the class CBlock method calculateSpecificChildrenPaths.

/**
 * Calculates the path for each event from the root of the {@link TreeConcept} to the most specific {@link ConceptTreeChild}
 * denoted by the individual {@link ConceptTreeChild#getPrefix()}.
 */
private static int[][] calculateSpecificChildrenPaths(Bucket bucket, ConceptTreeConnector connector) {
    final Column column = connector.getColumn();
    final TreeConcept treeConcept = connector.getConcept();
    final StringStore stringStore;
    // If we have a column and it is of string-type, we create indices and caches.
    if (column != null && bucket.getStores()[column.getPosition()] instanceof StringStore) {
        stringStore = (StringStore) bucket.getStores()[column.getPosition()];
        // Create index and insert into Tree.
        TreeChildPrefixIndex.putIndexInto(treeConcept);
        treeConcept.initializeIdCache(stringStore, bucket.getImp());
    } else // No column only possible if we have just one tree element!
    if (treeConcept.countElements() == 1) {
        stringStore = null;
    } else {
        throw new IllegalStateException(String.format("Cannot build tree over Connector[%s] without Column", connector.getId()));
    }
    final int[][] mostSpecificChildren = new int[bucket.getNumberOfEvents()][];
    Arrays.fill(mostSpecificChildren, ConceptTreeConnector.NOT_CONTAINED);
    final ConceptTreeCache cache = treeConcept.getCache(bucket.getImp());
    final int[] root = treeConcept.getPrefix();
    for (int event = 0; event < bucket.getNumberOfEvents(); event++) {
        try {
            // Events can also be filtered, allowing a single table to be used by multiple connectors.
            if (column != null && !bucket.has(event, column)) {
                mostSpecificChildren[event] = Connector.NOT_CONTAINED;
                continue;
            }
            String stringValue = "";
            int valueIndex = -1;
            if (stringStore != null) {
                valueIndex = bucket.getString(event, column);
                stringValue = stringStore.getElement(valueIndex);
            }
            // Lazy evaluation of map to avoid allocations if possible.
            // Copy event for closure.
            final int _event = event;
            final CalculatedValue<Map<String, Object>> rowMap = new CalculatedValue<>(() -> bucket.calculateMap(_event));
            if ((connector.getCondition() != null && !connector.getCondition().matches(stringValue, rowMap))) {
                mostSpecificChildren[event] = Connector.NOT_CONTAINED;
                continue;
            }
            ConceptTreeChild child = cache == null ? treeConcept.findMostSpecificChild(stringValue, rowMap) : cache.findMostSpecificChild(valueIndex, stringValue, rowMap);
            // All unresolved elements resolve to the root.
            if (child == null) {
                mostSpecificChildren[event] = root;
                continue;
            }
            // put path into event
            mostSpecificChildren[event] = child.getPrefix();
        } catch (ConceptConfigurationException ex) {
            log.error("Failed to resolve event {}-{} against concept {}", bucket, event, treeConcept, ex);
        }
    }
    if (cache != null) {
        log.trace("Hits: {}, Misses: {}, Hits/Misses: {}, %Hits: {} (Up to now)", cache.getHits(), cache.getMisses(), (double) cache.getHits() / cache.getMisses(), (double) cache.getHits() / (cache.getHits() + cache.getMisses()));
    }
    return mostSpecificChildren;
}
Also used : ConceptTreeCache(com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeCache) ConceptTreeChild(com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeChild) StringStore(com.bakdata.conquery.models.events.stores.root.StringStore) ConceptConfigurationException(com.bakdata.conquery.models.exceptions.ConceptConfigurationException) Column(com.bakdata.conquery.models.datasets.Column) TreeConcept(com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept) CalculatedValue(com.bakdata.conquery.util.CalculatedValue) Map(java.util.Map)

Example 18 with Column

use of com.bakdata.conquery.models.datasets.Column in project conquery by bakdata.

the class RequiredTable method toTable.

public Table toTable(Dataset dataset, CentralRegistry centralRegistry) {
    Table table = new Table();
    table.setDataset(dataset);
    table.setName(name);
    table.setColumns(Arrays.stream(columns).map(col -> col.toColumn(table, centralRegistry)).toArray(Column[]::new));
    return table;
}
Also used : Table(com.bakdata.conquery.models.datasets.Table) Column(com.bakdata.conquery.models.datasets.Column)

Aggregations

Column (com.bakdata.conquery.models.datasets.Column)18 Table (com.bakdata.conquery.models.datasets.Table)10 Dataset (com.bakdata.conquery.models.datasets.Dataset)6 CQTable (com.bakdata.conquery.apiv1.query.concept.filter.CQTable)5 Validator (javax.validation.Validator)5 Injectable (com.bakdata.conquery.io.jackson.Injectable)4 MutableInjectableValues (com.bakdata.conquery.io.jackson.MutableInjectableValues)4 SecondaryIdDescription (com.bakdata.conquery.models.datasets.SecondaryIdDescription)4 CentralRegistry (com.bakdata.conquery.models.identifiable.CentralRegistry)4 Test (org.junit.jupiter.api.Test)4 Connector (com.bakdata.conquery.models.datasets.concepts.Connector)3 TreeConcept (com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept)3 IdMapSerialisationTest (com.bakdata.conquery.models.identifiable.IdMapSerialisationTest)3 CQUnfilteredTable (com.bakdata.conquery.apiv1.query.concept.filter.CQUnfilteredTable)2 InternalOnly (com.bakdata.conquery.io.jackson.InternalOnly)2 CDateSet (com.bakdata.conquery.models.common.CDateSet)2 CDateRange (com.bakdata.conquery.models.common.daterange.CDateRange)2 Import (com.bakdata.conquery.models.datasets.Import)2 Concept (com.bakdata.conquery.models.datasets.concepts.Concept)2 ValidityDate (com.bakdata.conquery.models.datasets.concepts.ValidityDate)2