Search in sources :

Example 1 with MultiNamedAttributeEvaluator

use of org.apache.nifi.attribute.expression.language.evaluation.selection.MultiNamedAttributeEvaluator in project nifi by apache.

the class StandardPreparedQuery method getVariableImpact.

@Override
public VariableImpact getVariableImpact() {
    final VariableImpact existing = this.variableImpact;
    if (existing != null) {
        return existing;
    }
    final Set<String> variables = new HashSet<>();
    for (final Expression expression : expressions) {
        if (!(expression instanceof CompiledExpression)) {
            continue;
        }
        final CompiledExpression compiled = (CompiledExpression) expression;
        for (final Evaluator<?> evaluator : compiled.getAllEvaluators()) {
            if (evaluator instanceof AttributeEvaluator) {
                final AttributeEvaluator attributeEval = (AttributeEvaluator) evaluator;
                final Evaluator<String> nameEval = attributeEval.getNameEvaluator();
                if (nameEval instanceof StringLiteralEvaluator) {
                    final String referencedVar = nameEval.evaluate(Collections.emptyMap()).getValue();
                    variables.add(referencedVar);
                }
            } else if (evaluator instanceof AllAttributesEvaluator) {
                final AllAttributesEvaluator allAttrsEval = (AllAttributesEvaluator) evaluator;
                final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator();
                if (iteratingEval instanceof MultiNamedAttributeEvaluator) {
                    variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames());
                } else if (iteratingEval instanceof MultiMatchAttributeEvaluator) {
                    return VariableImpact.ALWAYS_IMPACTED;
                }
            } else if (evaluator instanceof AnyAttributeEvaluator) {
                final AnyAttributeEvaluator allAttrsEval = (AnyAttributeEvaluator) evaluator;
                final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator();
                if (iteratingEval instanceof MultiNamedAttributeEvaluator) {
                    variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames());
                } else if (iteratingEval instanceof MultiMatchAttributeEvaluator) {
                    return VariableImpact.ALWAYS_IMPACTED;
                }
            } else if (evaluator instanceof MappingEvaluator) {
                final MappingEvaluator<?> allAttrsEval = (MappingEvaluator<?>) evaluator;
                final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator();
                if (iteratingEval instanceof MultiNamedAttributeEvaluator) {
                    variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames());
                }
            }
        }
    }
    final VariableImpact impact = new NamedVariableImpact(variables);
    this.variableImpact = impact;
    return impact;
}
Also used : MultiNamedAttributeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.MultiNamedAttributeEvaluator) MultiAttributeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.MultiAttributeEvaluator) MultiMatchAttributeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.MultiMatchAttributeEvaluator) AnyAttributeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.AnyAttributeEvaluator) MultiMatchAttributeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.MultiMatchAttributeEvaluator) MultiNamedAttributeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.MultiNamedAttributeEvaluator) MultiAttributeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.MultiAttributeEvaluator) AttributeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.AttributeEvaluator) MappingEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.MappingEvaluator) StringLiteralEvaluator(org.apache.nifi.attribute.expression.language.evaluation.literals.StringLiteralEvaluator) AllAttributesEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.AllAttributesEvaluator) AnyAttributeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.AnyAttributeEvaluator) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 StringLiteralEvaluator (org.apache.nifi.attribute.expression.language.evaluation.literals.StringLiteralEvaluator)1 AllAttributesEvaluator (org.apache.nifi.attribute.expression.language.evaluation.selection.AllAttributesEvaluator)1 AnyAttributeEvaluator (org.apache.nifi.attribute.expression.language.evaluation.selection.AnyAttributeEvaluator)1 AttributeEvaluator (org.apache.nifi.attribute.expression.language.evaluation.selection.AttributeEvaluator)1 MappingEvaluator (org.apache.nifi.attribute.expression.language.evaluation.selection.MappingEvaluator)1 MultiAttributeEvaluator (org.apache.nifi.attribute.expression.language.evaluation.selection.MultiAttributeEvaluator)1 MultiMatchAttributeEvaluator (org.apache.nifi.attribute.expression.language.evaluation.selection.MultiMatchAttributeEvaluator)1 MultiNamedAttributeEvaluator (org.apache.nifi.attribute.expression.language.evaluation.selection.MultiNamedAttributeEvaluator)1