Search in sources :

Example 1 with IteratingEvaluator

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

the class ExpressionCompiler method verifyMappingEvaluatorReduced.

private void verifyMappingEvaluatorReduced(final Evaluator<?> evaluator) {
    final Evaluator<?> rightMostEvaluator;
    if (evaluator instanceof IteratingEvaluator) {
        rightMostEvaluator = ((IteratingEvaluator<?>) evaluator).getLogicEvaluator();
    } else {
        rightMostEvaluator = evaluator;
    }
    Evaluator<?> eval = rightMostEvaluator.getSubjectEvaluator();
    Evaluator<?> lastEval = rightMostEvaluator;
    while (eval != null) {
        if (eval instanceof ReduceEvaluator) {
            throw new AttributeExpressionLanguageParsingException("Expression attempts to call function '" + lastEval.getToken() + "' on the result of '" + eval.getToken() + "'. This is not allowed. Instead, use \"${literal( ${<embedded expression>} ):" + lastEval.getToken() + "(...)}\"");
        }
        lastEval = eval;
        eval = eval.getSubjectEvaluator();
    }
    // if the result type of the evaluator is BOOLEAN, then it will always
    // be reduced when evaluator.
    final ResultType resultType = evaluator.getResultType();
    if (resultType == ResultType.BOOLEAN) {
        return;
    }
    final Evaluator<?> rootEvaluator = getRootSubjectEvaluator(evaluator);
    if (rootEvaluator != null && rootEvaluator instanceof MultiAttributeEvaluator) {
        final MultiAttributeEvaluator multiAttrEval = (MultiAttributeEvaluator) rootEvaluator;
        switch(multiAttrEval.getEvaluationType()) {
            case ALL_ATTRIBUTES:
            case ALL_MATCHING_ATTRIBUTES:
            case ALL_DELINEATED_VALUES:
                {
                    if (!(evaluator instanceof ReduceEvaluator)) {
                        throw new AttributeExpressionLanguageParsingException("Cannot evaluate expression because it attempts to reference multiple attributes but does not use a reducing function");
                    }
                    break;
                }
            default:
                throw new AttributeExpressionLanguageParsingException("Cannot evaluate expression because it attempts to reference multiple attributes but does not use a reducing function");
        }
    }
}
Also used : IteratingEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.IteratingEvaluator) ResultType(org.apache.nifi.expression.AttributeExpression.ResultType) MultiAttributeEvaluator(org.apache.nifi.attribute.expression.language.evaluation.selection.MultiAttributeEvaluator) ReduceEvaluator(org.apache.nifi.attribute.expression.language.evaluation.reduce.ReduceEvaluator) AttributeExpressionLanguageParsingException(org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageParsingException)

Aggregations

ReduceEvaluator (org.apache.nifi.attribute.expression.language.evaluation.reduce.ReduceEvaluator)1 IteratingEvaluator (org.apache.nifi.attribute.expression.language.evaluation.selection.IteratingEvaluator)1 MultiAttributeEvaluator (org.apache.nifi.attribute.expression.language.evaluation.selection.MultiAttributeEvaluator)1 AttributeExpressionLanguageParsingException (org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageParsingException)1 ResultType (org.apache.nifi.expression.AttributeExpression.ResultType)1