Search in sources :

Example 1 with JexlArgumentDescriptor

use of datawave.query.jexl.functions.arguments.JexlArgumentDescriptor in project datawave by NationalSecurityAgency.

the class EventDataQueryExpressionVisitor method visit.

@Override
public Object visit(ASTFunctionNode node, Object data) {
    JexlArgumentDescriptor desc = JexlFunctionArgumentDescriptorFactory.F.getArgumentDescriptor(node);
    desc.addFilters(attributeFactory, filterMap);
    return null;
}
Also used : JexlArgumentDescriptor(datawave.query.jexl.functions.arguments.JexlArgumentDescriptor)

Example 2 with JexlArgumentDescriptor

use of datawave.query.jexl.functions.arguments.JexlArgumentDescriptor in project datawave by NationalSecurityAgency.

the class ValidPatternVisitor method visit.

/**
 * Visit an ASTFunctionNode to catch cases like #INCLUDE or #EXCLUDE that accept a regex as an argument
 *
 * @param node
 *            - an ASTFunctionNode
 * @param data
 *            - the data
 * @return
 */
@Override
public Object visit(ASTFunctionNode node, Object data) {
    // Should pull back an EvaluationPhaseFilterFunctionsDescriptor
    JexlArgumentDescriptor descriptor = JexlFunctionArgumentDescriptorFactory.F.getArgumentDescriptor(node);
    if (descriptor == null) {
        throw new IllegalStateException("Could not get descriptor for ASTFunctionNode");
    }
    if (descriptor.regexArguments()) {
        // Extract the args for this function
        FunctionJexlNodeVisitor functionVisitor = new FunctionJexlNodeVisitor();
        functionVisitor.visit(node, null);
        List<JexlNode> args = functionVisitor.args();
        for (JexlNode arg : args) {
            // Only take the literals
            if (arg instanceof ASTStringLiteral) {
                parseAndPutPattern(arg);
            }
        }
    }
    // Do not descend to children, the ValidPatternVisitor views a function node as a leaf node.
    return data;
}
Also used : ASTStringLiteral(org.apache.commons.jexl2.parser.ASTStringLiteral) JexlArgumentDescriptor(datawave.query.jexl.functions.arguments.JexlArgumentDescriptor) JexlNode(org.apache.commons.jexl2.parser.JexlNode) FunctionJexlNodeVisitor(datawave.query.jexl.functions.FunctionJexlNodeVisitor)

Example 3 with JexlArgumentDescriptor

use of datawave.query.jexl.functions.arguments.JexlArgumentDescriptor in project datawave by NationalSecurityAgency.

the class SplitGeoWaveFunctionVisitor method visit.

@Override
public Object visit(ASTFunctionNode node, Object data) {
    JexlArgumentDescriptor descriptor = JexlFunctionArgumentDescriptorFactory.F.getArgumentDescriptor(node);
    if (descriptor instanceof GeoWaveFunctionsDescriptor.GeoWaveJexlArgumentDescriptor) {
        Set<String> fields = descriptor.fields(metadataHelper, Collections.emptySet());
        if (fields.size() > 1) {
            List<JexlNode> functionNodes = new ArrayList<>();
            FunctionJexlNodeVisitor functionVisitor = new FunctionJexlNodeVisitor();
            node.jjtAccept(functionVisitor, null);
            for (String field : fields) {
                List<JexlNode> newArgs = new ArrayList<>();
                for (int i = 0; i < functionVisitor.args().size(); i++) {
                    if (i == 0) {
                        newArgs.add(JexlNodeFactory.buildIdentifier(field));
                    } else {
                        newArgs.add(RebuildingVisitor.copy(functionVisitor.args().get(i)));
                    }
                }
                functionNodes.add(JexlNodes.makeRef(FunctionJexlNodeVisitor.makeFunctionFrom(functionVisitor.namespace(), functionVisitor.name(), newArgs.toArray(new JexlNode[0]))));
            }
            return JexlNodeFactory.createUnwrappedOrNode(functionNodes);
        }
    } else if (descriptor instanceof GeoFunctionsDescriptor.GeoJexlArgumentDescriptor) {
        Set<String> fields = descriptor.fields(metadataHelper, Collections.emptySet());
        if (fields.size() > 1) {
            List<JexlNode> functionNodes = new ArrayList<>();
            FunctionJexlNodeVisitor functionVisitor = new FunctionJexlNodeVisitor();
            node.jjtAccept(functionVisitor, null);
            // geo functions with > 3 args contain separate fields for lat/lon, and should not be considered
            if (functionVisitor.args().size() == 3) {
                for (String field : fields) {
                    List<JexlNode> newArgs = new ArrayList<>();
                    for (int i = 0; i < functionVisitor.args().size(); i++) {
                        if (i == 0) {
                            newArgs.add(JexlNodeFactory.buildIdentifier(field));
                        } else {
                            newArgs.add(RebuildingVisitor.copy(functionVisitor.args().get(i)));
                        }
                    }
                    functionNodes.add(JexlNodes.makeRef(FunctionJexlNodeVisitor.makeFunctionFrom(functionVisitor.namespace(), functionVisitor.name(), newArgs.toArray(new JexlNode[0]))));
                }
                return JexlNodeFactory.createUnwrappedOrNode(functionNodes);
            }
        }
    }
    return super.visit(node, data);
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) JexlArgumentDescriptor(datawave.query.jexl.functions.arguments.JexlArgumentDescriptor) FunctionJexlNodeVisitor(datawave.query.jexl.functions.FunctionJexlNodeVisitor) JexlNode(org.apache.commons.jexl2.parser.JexlNode) GeoFunctionsDescriptor(datawave.query.jexl.functions.GeoFunctionsDescriptor) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with JexlArgumentDescriptor

use of datawave.query.jexl.functions.arguments.JexlArgumentDescriptor in project datawave by NationalSecurityAgency.

the class GeoFunctionsDescriptorTest method antiMeridianTest1.

@Test
public void antiMeridianTest1() throws Exception {
    String query = "geo:within_bounding_box(GEO_FIELD, '40_170', '50_-170')";
    JexlNode node = JexlASTHelper.parseJexlQuery(query);
    JexlArgumentDescriptor argDesc = new GeoFunctionsDescriptor().getArgumentDescriptor((ASTFunctionNode) node.jjtGetChild(0).jjtGetChild(0));
    JexlNode queryNode = argDesc.getIndexQuery(null, null, null, null);
    Assert.assertEquals("(((_Bounded_ = true) && (GEO_FIELD >= '40.0_170.0' && GEO_FIELD <= '50.0_180')) && ((_Bounded_ = true) && (GEO_FIELD >= '40.0_-180' && GEO_FIELD <= '50.0_-170.0')))", JexlStringBuildingVisitor.buildQuery(queryNode));
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) JexlArgumentDescriptor(datawave.query.jexl.functions.arguments.JexlArgumentDescriptor) Test(org.junit.Test)

Example 5 with JexlArgumentDescriptor

use of datawave.query.jexl.functions.arguments.JexlArgumentDescriptor in project datawave by NationalSecurityAgency.

the class GeoFunctionsDescriptorTest method testMultiFieldGeoFunction.

@Test
public void testMultiFieldGeoFunction() throws Exception {
    String query = "geo:within_circle(FIELD_1 || FIELD_2, '0_0', '10')";
    JexlNode node = JexlASTHelper.parseJexlQuery(query);
    JexlArgumentDescriptor argDesc = new GeoFunctionsDescriptor().getArgumentDescriptor((ASTFunctionNode) node.jjtGetChild(0).jjtGetChild(0));
    JexlNode queryNode = argDesc.getIndexQuery(null, null, null, null);
    Assert.assertEquals("(((_Bounded_ = true) && (FIELD_1 >= '-10.0|-10.0' && FIELD_1 <= '10.0|10.0')) || ((_Bounded_ = true) && (FIELD_2 >= '-10.0|-10.0' && FIELD_2 <= '10.0|10.0')))", JexlStringBuildingVisitor.buildQuery(queryNode));
}
Also used : JexlNode(org.apache.commons.jexl2.parser.JexlNode) JexlArgumentDescriptor(datawave.query.jexl.functions.arguments.JexlArgumentDescriptor) Test(org.junit.Test)

Aggregations

JexlArgumentDescriptor (datawave.query.jexl.functions.arguments.JexlArgumentDescriptor)17 JexlNode (org.apache.commons.jexl2.parser.JexlNode)12 ASTFunctionNode (org.apache.commons.jexl2.parser.ASTFunctionNode)6 HashMultimap (com.google.common.collect.HashMultimap)3 Multimap (com.google.common.collect.Multimap)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Set (java.util.Set)3 Test (org.junit.Test)3 NoOpType (datawave.data.type.NoOpType)2 Type (datawave.data.type.Type)2 FunctionJexlNodeVisitor (datawave.query.jexl.functions.FunctionJexlNodeVisitor)2 GeoWaveFunctionsDescriptor (datawave.query.jexl.functions.GeoWaveFunctionsDescriptor)2 ExceededValueThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode)2 MockMetadataHelper (datawave.query.util.MockMetadataHelper)2 ASTAndNode (org.apache.commons.jexl2.parser.ASTAndNode)2 ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)2 JexlNodes.newInstanceOfType (org.apache.commons.jexl2.parser.JexlNodes.newInstanceOfType)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Sets (com.google.common.collect.Sets)1