Search in sources :

Example 1 with ConceptConfigurationException

use of com.bakdata.conquery.models.exceptions.ConceptConfigurationException in project conquery by bakdata.

the class GroovyCondition method compile.

private void compile() throws ConceptConfigurationException {
    if (compiled == null) {
        try {
            CompilerConfiguration config = new CompilerConfiguration();
            config.addCompilationCustomizers(new ImportCustomizer().addImports(AUTO_IMPORTS));
            config.setScriptBaseClass(ConditionScript.class.getName());
            GroovyShell groovy = new GroovyShell(config);
            compiled = (ConditionScript) groovy.parse(script);
            compiled.setNode(node);
        } catch (Exception | Error e) {
            throw new ConceptConfigurationException(node, "Failed to compile condition '" + script + "'", e);
        }
    }
}
Also used : CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) ImportCustomizer(org.codehaus.groovy.control.customizers.ImportCustomizer) GroovyShell(groovy.lang.GroovyShell) ConceptConfigurationException(com.bakdata.conquery.models.exceptions.ConceptConfigurationException) ConceptConfigurationException(com.bakdata.conquery.models.exceptions.ConceptConfigurationException)

Example 2 with ConceptConfigurationException

use of com.bakdata.conquery.models.exceptions.ConceptConfigurationException in project conquery by bakdata.

the class ConceptsProcessor method resolveConceptElements.

public ResolvedConceptsResult resolveConceptElements(TreeConcept concept, List<String> conceptCodes) {
    List<ConceptElementId<?>> resolvedCodes = new ArrayList<>();
    List<String> unknownCodes = new ArrayList<>();
    if (concept == null) {
        return new ResolvedConceptsResult(null, null, conceptCodes);
    }
    for (String conceptCode : conceptCodes) {
        ConceptTreeChild child;
        try {
            child = concept.findMostSpecificChild(conceptCode, new CalculatedValue<>(Collections::emptyMap));
            if (child != null) {
                resolvedCodes.add(child.getId());
            } else {
                unknownCodes.add(conceptCode);
            }
        } catch (ConceptConfigurationException e) {
            log.error("Error while trying to resolve " + conceptCode, e);
        }
    }
    return new ResolvedConceptsResult(resolvedCodes, null, unknownCodes);
}
Also used : ConceptElementId(com.bakdata.conquery.models.identifiable.ids.specific.ConceptElementId) ArrayList(java.util.ArrayList) ConceptTreeChild(com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeChild) CalculatedValue(com.bakdata.conquery.util.CalculatedValue) ToString(lombok.ToString) Collections(java.util.Collections) ConceptConfigurationException(com.bakdata.conquery.models.exceptions.ConceptConfigurationException)

Example 3 with ConceptConfigurationException

use of com.bakdata.conquery.models.exceptions.ConceptConfigurationException 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)

Aggregations

ConceptConfigurationException (com.bakdata.conquery.models.exceptions.ConceptConfigurationException)3 ConceptTreeChild (com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeChild)2 CalculatedValue (com.bakdata.conquery.util.CalculatedValue)2 Column (com.bakdata.conquery.models.datasets.Column)1 ConceptTreeCache (com.bakdata.conquery.models.datasets.concepts.tree.ConceptTreeCache)1 TreeConcept (com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept)1 StringStore (com.bakdata.conquery.models.events.stores.root.StringStore)1 ConceptElementId (com.bakdata.conquery.models.identifiable.ids.specific.ConceptElementId)1 GroovyShell (groovy.lang.GroovyShell)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Map (java.util.Map)1 ToString (lombok.ToString)1 CompilerConfiguration (org.codehaus.groovy.control.CompilerConfiguration)1 ImportCustomizer (org.codehaus.groovy.control.customizers.ImportCustomizer)1