Search in sources :

Example 1 with ContainsRegex

use of org.apache.nifi.record.path.filter.ContainsRegex in project nifi by apache.

the class RecordPathCompiler method createFunctionFilter.

private static RecordPathFilter createFunctionFilter(final Tree functionTree, final boolean absolute) {
    final String functionName = functionTree.getChild(0).getText();
    final Tree argumentListTree = functionTree.getChild(1);
    switch(functionName) {
        case "contains":
            {
                final RecordPathSegment[] args = getArgPaths(argumentListTree, 2, functionName, absolute);
                return new Contains(args[0], args[1]);
            }
        case "matchesRegex":
            {
                final RecordPathSegment[] args = getArgPaths(argumentListTree, 2, functionName, absolute);
                return new MatchesRegex(args[0], args[1]);
            }
        case "containsRegex":
            {
                final RecordPathSegment[] args = getArgPaths(argumentListTree, 2, functionName, absolute);
                return new ContainsRegex(args[0], args[1]);
            }
        case "startsWith":
            {
                final RecordPathSegment[] args = getArgPaths(argumentListTree, 2, functionName, absolute);
                return new StartsWith(args[0], args[1]);
            }
        case "endsWith":
            {
                final RecordPathSegment[] args = getArgPaths(argumentListTree, 2, functionName, absolute);
                return new EndsWith(args[0], args[1]);
            }
        case "isEmpty":
            {
                final RecordPathSegment[] args = getArgPaths(argumentListTree, 1, functionName, absolute);
                return new IsEmpty(args[0]);
            }
        case "isBlank":
            {
                final RecordPathSegment[] args = getArgPaths(argumentListTree, 1, functionName, absolute);
                return new IsBlank(args[0]);
            }
        case "not":
            {
                final int numArgs = argumentListTree.getChildCount();
                if (numArgs != 1) {
                    throw new RecordPathException("Invalid number of arguments: " + functionName + " function takes 1 argument but got " + numArgs);
                }
                final Tree childTree = argumentListTree.getChild(0);
                final RecordPathFilter childFilter = createFilter(childTree, null, absolute);
                return new NotFilter(childFilter);
            }
    }
    throw new RecordPathException("Invalid function name: " + functionName);
}
Also used : MatchesRegex(org.apache.nifi.record.path.filter.MatchesRegex) IsEmpty(org.apache.nifi.record.path.filter.IsEmpty) RecordPathFilter(org.apache.nifi.record.path.filter.RecordPathFilter) IsBlank(org.apache.nifi.record.path.filter.IsBlank) NotFilter(org.apache.nifi.record.path.filter.NotFilter) Contains(org.apache.nifi.record.path.filter.Contains) Tree(org.antlr.runtime.tree.Tree) ContainsRegex(org.apache.nifi.record.path.filter.ContainsRegex) StartsWith(org.apache.nifi.record.path.filter.StartsWith) RecordPathException(org.apache.nifi.record.path.exception.RecordPathException) EndsWith(org.apache.nifi.record.path.filter.EndsWith)

Aggregations

Tree (org.antlr.runtime.tree.Tree)1 RecordPathException (org.apache.nifi.record.path.exception.RecordPathException)1 Contains (org.apache.nifi.record.path.filter.Contains)1 ContainsRegex (org.apache.nifi.record.path.filter.ContainsRegex)1 EndsWith (org.apache.nifi.record.path.filter.EndsWith)1 IsBlank (org.apache.nifi.record.path.filter.IsBlank)1 IsEmpty (org.apache.nifi.record.path.filter.IsEmpty)1 MatchesRegex (org.apache.nifi.record.path.filter.MatchesRegex)1 NotFilter (org.apache.nifi.record.path.filter.NotFilter)1 RecordPathFilter (org.apache.nifi.record.path.filter.RecordPathFilter)1 StartsWith (org.apache.nifi.record.path.filter.StartsWith)1