Search in sources :

Example 1 with StringLiteralEvaluator

use of org.apache.nifi.attribute.expression.language.evaluation.literals.StringLiteralEvaluator in project nifi by apache.

the class ExpressionCompiler method newStringLiteralEvaluator.

private Evaluator<String> newStringLiteralEvaluator(final String literalValue) {
    if (literalValue == null || literalValue.length() < 2) {
        return addToken(new StringLiteralEvaluator(literalValue), literalValue);
    }
    final List<Range> ranges = Query.extractExpressionRanges(literalValue);
    if (ranges.isEmpty()) {
        return addToken(new StringLiteralEvaluator(literalValue), literalValue);
    }
    final List<Evaluator<?>> evaluators = new ArrayList<>();
    int lastIndex = 0;
    for (final Range range : ranges) {
        if (range.getStart() > lastIndex) {
            evaluators.add(newStringLiteralEvaluator(literalValue.substring(lastIndex, range.getStart())));
        }
        final String treeText = literalValue.substring(range.getStart(), range.getEnd() + 1);
        evaluators.add(buildEvaluator(compileTree(treeText)));
        lastIndex = range.getEnd() + 1;
    }
    final Range lastRange = ranges.get(ranges.size() - 1);
    if (lastRange.getEnd() + 1 < literalValue.length()) {
        final String treeText = literalValue.substring(lastRange.getEnd() + 1);
        evaluators.add(newStringLiteralEvaluator(treeText));
    }
    if (evaluators.size() == 1) {
        return toStringEvaluator(evaluators.get(0));
    }
    Evaluator<String> lastEvaluator = toStringEvaluator(evaluators.get(0));
    for (int i = 1; i < evaluators.size(); i++) {
        lastEvaluator = new AppendEvaluator(lastEvaluator, toStringEvaluator(evaluators.get(i)));
    }
    this.evaluators.addAll(evaluators);
    return lastEvaluator;
}
Also used : StringLiteralEvaluator(org.apache.nifi.attribute.expression.language.evaluation.literals.StringLiteralEvaluator) ArrayList(java.util.ArrayList) AppendEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.AppendEvaluator) Range(org.apache.nifi.attribute.expression.language.Query.Range) IfElseEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.IfElseEvaluator) OrEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.OrEvaluator) GreaterThanEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.GreaterThanEvaluator) LastIndexOfEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.LastIndexOfEvaluator) UrlEncodeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.UrlEncodeEvaluator) IteratingEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.IteratingEvaluator) SubstringAfterLastEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.SubstringAfterLastEvaluator) ReplaceNullEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.ReplaceNullEvaluator) ToLiteralEvaluator(org.apache.nifi.attribute.expression.language.evaluation.literals.ToLiteralEvaluator) AppendEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.AppendEvaluator) GetStateVariableEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.GetStateVariableEvaluator) MinusEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.MinusEvaluator) ReplaceAllEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.ReplaceAllEvaluator) Base64DecodeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.Base64DecodeEvaluator) ToStringEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.ToStringEvaluator) MultiAttributeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.MultiAttributeEvaluator) AttributeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.AttributeEvaluator) GreaterThanOrEqualEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.GreaterThanOrEqualEvaluator) AnyAttributeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.AnyAttributeEvaluator) MappingEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.MappingEvaluator) AndEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.AndEvaluator) NumberToDateEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.NumberToDateEvaluator) OneUpSequenceEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.OneUpSequenceEvaluator) StringLiteralEvaluator(org.apache.nifi.attribute.expression.language.evaluation.literals.StringLiteralEvaluator) WholeNumberCastEvaluator(org.apache.nifi.attribute.expression.language.evaluation.cast.WholeNumberCastEvaluator) IsEmptyEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.IsEmptyEvaluator) InEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.InEvaluator) LessThanOrEqualEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.LessThanOrEqualEvaluator) UuidEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.UuidEvaluator) IPEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.IPEvaluator) EqualsEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.EqualsEvaluator) CharSequenceTranslatorEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.CharSequenceTranslatorEvaluator) IsNullEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.IsNullEvaluator) NowEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.NowEvaluator) IndexOfEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.IndexOfEvaluator) CountEvaluator(org.apache.nifi.attribute.expression.language.evaluation.reduce.CountEvaluator) ToRadixEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.ToRadixEvaluator) ReplaceFirstEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.ReplaceFirstEvaluator) ToUpperEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.ToUpperEvaluator) ReplaceEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.ReplaceEvaluator) EqualsIgnoreCaseEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.EqualsIgnoreCaseEvaluator) ContainsEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.ContainsEvaluator) PlusEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.PlusEvaluator) FindEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.FindEvaluator) MatchesEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.MatchesEvaluator) Evaluator(org.apache.nifi.attribute.expression.language.evaluation.Evaluator) ModEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.ModEvaluator) Base64EncodeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.Base64EncodeEvaluator) GetDelimitedFieldEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.GetDelimitedFieldEvaluator) DateEvaluator(org.apache.nifi.attribute.expression.language.evaluation.DateEvaluator) TrimEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.TrimEvaluator) FromRadixEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.FromRadixEvaluator) JsonPathEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.JsonPathEvaluator) BooleanLiteralEvaluator(org.apache.nifi.attribute.expression.language.evaluation.literals.BooleanLiteralEvaluator) DecimalLiteralEvaluator(org.apache.nifi.attribute.expression.language.evaluation.literals.DecimalLiteralEvaluator) LessThanEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.LessThanEvaluator) WholeNumberLiteralEvaluator(org.apache.nifi.attribute.expression.language.evaluation.literals.WholeNumberLiteralEvaluator) StringEvaluator(org.apache.nifi.attribute.expression.language.evaluation.StringEvaluator) LengthEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.LengthEvaluator) ReduceEvaluator(org.apache.nifi.attribute.expression.language.evaluation.reduce.ReduceEvaluator) SubstringAfterEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.SubstringAfterEvaluator) MathEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.MathEvaluator) MultiplyEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.MultiplyEvaluator) AllAttributesEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.AllAttributesEvaluator) SubstringEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.SubstringEvaluator) MultiNamedAttributeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.MultiNamedAttributeEvaluator) NotEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.NotEvaluator) SubstringBeforeLastEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.SubstringBeforeLastEvaluator) FormatEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.FormatEvaluator) StartsWithEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.StartsWithEvaluator) PrependEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.PrependEvaluator) EndsWithEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.EndsWithEvaluator) ToLowerEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.ToLowerEvaluator) MultiMatchAttributeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.MultiMatchAttributeEvaluator) BooleanEvaluator(org.apache.nifi.attribute.expression.language.evaluation.BooleanEvaluator) ReplaceEmptyEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.ReplaceEmptyEvaluator) DelineatedAttributeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.DelineatedAttributeEvaluator) NumberCastEvaluator(org.apache.nifi.attribute.expression.language.evaluation.cast.NumberCastEvaluator) HostnameEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.HostnameEvaluator) StringCastEvaluator(org.apache.nifi.attribute.expression.language.evaluation.cast.StringCastEvaluator) BooleanCastEvaluator(org.apache.nifi.attribute.expression.language.evaluation.cast.BooleanCastEvaluator) UrlDecodeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.UrlDecodeEvaluator) RandomNumberGeneratorEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.RandomNumberGeneratorEvaluator) NotNullEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.NotNullEvaluator) DecimalCastEvaluator(org.apache.nifi.attribute.expression.language.evaluation.cast.DecimalCastEvaluator) JoinEvaluator(org.apache.nifi.attribute.expression.language.evaluation.reduce.JoinEvaluator) SubstringBeforeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.SubstringBeforeEvaluator) StringToDateEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.StringToDateEvaluator) DateCastEvaluator(org.apache.nifi.attribute.expression.language.evaluation.cast.DateCastEvaluator) DivideEvaluator(org.apache.nifi.attribute.expression.language.evaluation.functions.DivideEvaluator)

Example 2 with StringLiteralEvaluator

use of org.apache.nifi.attribute.expression.language.evaluation.literals.StringLiteralEvaluator 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

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Range (org.apache.nifi.attribute.expression.language.Query.Range)1 BooleanEvaluator (org.apache.nifi.attribute.expression.language.evaluation.BooleanEvaluator)1 DateEvaluator (org.apache.nifi.attribute.expression.language.evaluation.DateEvaluator)1 Evaluator (org.apache.nifi.attribute.expression.language.evaluation.Evaluator)1 StringEvaluator (org.apache.nifi.attribute.expression.language.evaluation.StringEvaluator)1 BooleanCastEvaluator (org.apache.nifi.attribute.expression.language.evaluation.cast.BooleanCastEvaluator)1 DateCastEvaluator (org.apache.nifi.attribute.expression.language.evaluation.cast.DateCastEvaluator)1 DecimalCastEvaluator (org.apache.nifi.attribute.expression.language.evaluation.cast.DecimalCastEvaluator)1 NumberCastEvaluator (org.apache.nifi.attribute.expression.language.evaluation.cast.NumberCastEvaluator)1 StringCastEvaluator (org.apache.nifi.attribute.expression.language.evaluation.cast.StringCastEvaluator)1 WholeNumberCastEvaluator (org.apache.nifi.attribute.expression.language.evaluation.cast.WholeNumberCastEvaluator)1 AndEvaluator (org.apache.nifi.attribute.expression.language.evaluation.functions.AndEvaluator)1 AppendEvaluator (org.apache.nifi.attribute.expression.language.evaluation.functions.AppendEvaluator)1 Base64DecodeEvaluator (org.apache.nifi.attribute.expression.language.evaluation.functions.Base64DecodeEvaluator)1 Base64EncodeEvaluator (org.apache.nifi.attribute.expression.language.evaluation.functions.Base64EncodeEvaluator)1 CharSequenceTranslatorEvaluator (org.apache.nifi.attribute.expression.language.evaluation.functions.CharSequenceTranslatorEvaluator)1 ContainsEvaluator (org.apache.nifi.attribute.expression.language.evaluation.functions.ContainsEvaluator)1 DivideEvaluator (org.apache.nifi.attribute.expression.language.evaluation.functions.DivideEvaluator)1