Search in sources :

Example 1 with ASTStringLiteral

use of org.apache.commons.jexl3.parser.ASTStringLiteral 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 2 with ASTStringLiteral

use of org.apache.commons.jexl3.parser.ASTStringLiteral in project datawave by NationalSecurityAgency.

the class DatawaveInterpreterTest method invocationFails_alwaysThrowsException.

@Test
public void invocationFails_alwaysThrowsException() {
    JexlEngine engine = mock(JexlEngine.class);
    JexlContext context = mock(JexlContext.class);
    DatawaveInterpreter interpreter = new DatawaveInterpreter(engine, context, false, false);
    JexlException exception = new JexlException(new ASTStringLiteral(1), "Function failure");
    // Make mocks available.
    EasyMock.replay(engine, context);
    // Capture the expected exception.
    Exception thrown = null;
    try {
        interpreter.invocationFailed(exception);
    } catch (Exception e) {
        thrown = e;
    }
    // Verify that an exception is thrown even when strict == false.
    Assert.assertEquals(thrown, exception);
}
Also used : ASTStringLiteral(org.apache.commons.jexl2.parser.ASTStringLiteral) JexlEngine(org.apache.commons.jexl2.JexlEngine) JexlException(org.apache.commons.jexl2.JexlException) JexlContext(org.apache.commons.jexl2.JexlContext) JexlException(org.apache.commons.jexl2.JexlException) Test(org.junit.Test)

Example 3 with ASTStringLiteral

use of org.apache.commons.jexl3.parser.ASTStringLiteral in project datawave by NationalSecurityAgency.

the class AncestorUidIntersectorTest method setup.

@Before
public void setup() {
    intersector = new AncestorUidIntersector();
    uids1 = new TreeSet<>();
    uids2 = new TreeSet<>();
    node1 = new ASTEQNode(1);
    JexlNode reference1 = new ASTReference(2);
    node1.jjtAddChild(reference1, 0);
    JexlNode name = new ASTIdentifier(3);
    name.image = "fieldName1";
    reference1.jjtAddChild(name, 0);
    JexlNode reference2 = new ASTReference(4);
    node1.jjtAddChild(reference2, 1);
    JexlNode value = new ASTStringLiteral(5);
    value.image = "fieldValue1";
    reference2.jjtAddChild(value, 0);
    node2 = new ASTEQNode(6);
    reference1 = new ASTReference(7);
    node2.jjtAddChild(reference1, 0);
    name = new ASTIdentifier(8);
    name.image = "fieldName2";
    reference1.jjtAddChild(name, 0);
    reference2 = new ASTReference(9);
    node2.jjtAddChild(reference2, 1);
    value = new ASTStringLiteral(10);
    value.image = "fieldValue2";
    reference2.jjtAddChild(value, 0);
}
Also used : ASTStringLiteral(org.apache.commons.jexl2.parser.ASTStringLiteral) ASTEQNode(org.apache.commons.jexl2.parser.ASTEQNode) JexlNode(org.apache.commons.jexl2.parser.JexlNode) ASTIdentifier(org.apache.commons.jexl2.parser.ASTIdentifier) ASTReference(org.apache.commons.jexl2.parser.ASTReference) Before(org.junit.Before)

Example 4 with ASTStringLiteral

use of org.apache.commons.jexl3.parser.ASTStringLiteral in project datawave by NationalSecurityAgency.

the class JexlASTHelper method normalizeLiteral.

public static ASTReference normalizeLiteral(JexlNode literal, Type<?> normalizer) throws NormalizationException {
    String normalizedImg = normalizer.normalize(literal.image);
    ASTStringLiteral normalizedLiteral = new ASTStringLiteral(ParserTreeConstants.JJTSTRINGLITERAL);
    normalizedLiteral.image = normalizedImg;
    return JexlNodes.makeRef(normalizedLiteral);
}
Also used : ASTStringLiteral(org.apache.commons.jexl2.parser.ASTStringLiteral)

Example 5 with ASTStringLiteral

use of org.apache.commons.jexl3.parser.ASTStringLiteral in project datawave by NationalSecurityAgency.

the class JexlNodeFactory method shallowCopy.

/**
 * A shallow copy of the given JexlNode, creates a new node of the same type with the same parent and image. Children are not copied
 *
 * @param original
 * @return
 */
public static JexlNode shallowCopy(JexlNode original) {
    if (null == original) {
        throw new IllegalArgumentException();
    }
    JexlNode copy;
    Class<?> clz = original.getClass();
    if (ASTAndNode.class.isAssignableFrom(clz)) {
        copy = new ASTAndNode(ParserTreeConstants.JJTANDNODE);
    } else if (ASTBitwiseAndNode.class.isAssignableFrom(clz)) {
        copy = new ASTBitwiseAndNode(ParserTreeConstants.JJTBITWISEANDNODE);
    } else if (ASTBitwiseComplNode.class.isAssignableFrom(clz)) {
        copy = new ASTBitwiseComplNode(ParserTreeConstants.JJTBITWISECOMPLNODE);
    } else if (ASTBitwiseOrNode.class.isAssignableFrom(clz)) {
        copy = new ASTBitwiseOrNode(ParserTreeConstants.JJTBITWISEORNODE);
    } else if (ASTBitwiseXorNode.class.isAssignableFrom(clz)) {
        copy = new ASTBitwiseXorNode(ParserTreeConstants.JJTBITWISEXORNODE);
    } else if (ASTEmptyFunction.class.isAssignableFrom(clz)) {
        copy = new ASTEmptyFunction(ParserTreeConstants.JJTEMPTYFUNCTION);
    } else if (ASTEQNode.class.isAssignableFrom(clz)) {
        copy = new ASTEQNode(ParserTreeConstants.JJTEQNODE);
    } else if (ASTERNode.class.isAssignableFrom(clz)) {
        copy = new ASTERNode(ParserTreeConstants.JJTERNODE);
    } else if (ASTFalseNode.class.isAssignableFrom(clz)) {
        copy = new ASTFalseNode(ParserTreeConstants.JJTFALSENODE);
    } else if (ASTGENode.class.isAssignableFrom(clz)) {
        copy = new ASTGENode(ParserTreeConstants.JJTGENODE);
    } else if (ASTGTNode.class.isAssignableFrom(clz)) {
        copy = new ASTGTNode(ParserTreeConstants.JJTGTNODE);
    } else if (ASTIdentifier.class.isAssignableFrom(clz)) {
        copy = new ASTIdentifier(ParserTreeConstants.JJTIDENTIFIER);
    } else if (ASTLENode.class.isAssignableFrom(clz)) {
        copy = new ASTLENode(ParserTreeConstants.JJTLENODE);
    } else if (ASTLTNode.class.isAssignableFrom(clz)) {
        copy = new ASTLTNode(ParserTreeConstants.JJTLTNODE);
    } else if (ASTNENode.class.isAssignableFrom(clz)) {
        copy = new ASTNENode(ParserTreeConstants.JJTNENODE);
    } else if (ASTNRNode.class.isAssignableFrom(clz)) {
        copy = new ASTNRNode(ParserTreeConstants.JJTNRNODE);
    } else if (ASTNotNode.class.isAssignableFrom(clz)) {
        copy = new ASTNotNode(ParserTreeConstants.JJTNOTNODE);
    } else if (ASTNullLiteral.class.isAssignableFrom(clz)) {
        copy = new ASTNullLiteral(ParserTreeConstants.JJTNULLLITERAL);
    } else if (ASTNumberLiteral.class.isAssignableFrom(clz)) {
        copy = new ASTNumberLiteral(ParserTreeConstants.JJTNUMBERLITERAL);
        JexlNodes.setLiteral((ASTNumberLiteral) copy, ((ASTNumberLiteral) original).getLiteral());
    } else if (ASTOrNode.class.isAssignableFrom(clz)) {
        copy = new ASTOrNode(ParserTreeConstants.JJTORNODE);
    } else if (ASTStringLiteral.class.isAssignableFrom(clz)) {
        copy = new ASTStringLiteral(ParserTreeConstants.JJTSTRINGLITERAL);
        JexlNodes.setLiteral((ASTStringLiteral) copy, ((ASTStringLiteral) original).getLiteral());
    } else if (ASTTrueNode.class.isAssignableFrom(clz)) {
        copy = new ASTTrueNode(ParserTreeConstants.JJTTRUENODE);
    } else if (ASTReferenceExpression.class.isAssignableFrom(clz)) {
        copy = new ASTReferenceExpression(ParserTreeConstants.JJTREFERENCEEXPRESSION);
    } else if (ASTReference.class.isAssignableFrom(clz)) {
        copy = new ASTReference(ParserTreeConstants.JJTREFERENCE);
    } else if (ASTAdditiveNode.class.isAssignableFrom(clz)) {
        copy = new ASTAdditiveNode(ParserTreeConstants.JJTADDITIVENODE);
    } else if (ASTMethodNode.class.isAssignableFrom(clz)) {
        copy = new ASTMethodNode(ParserTreeConstants.JJTMETHODNODE);
    } else if (ASTFunctionNode.class.isAssignableFrom(clz)) {
        copy = new ASTFunctionNode(ParserTreeConstants.JJTFUNCTIONNODE);
    } else if (ASTMulNode.class.isAssignableFrom(clz)) {
        copy = new ASTMulNode(ParserTreeConstants.JJTMULNODE);
    } else if (ASTAssignment.class.isAssignableFrom(clz)) {
        copy = new ASTAssignment(ParserTreeConstants.JJTASSIGNMENT);
    } else {
        throw new UnsupportedOperationException();
    }
    copy.jjtSetParent(original.jjtGetParent());
    copy.image = original.image;
    return copy;
}
Also used : ASTReferenceExpression(org.apache.commons.jexl2.parser.ASTReferenceExpression) ASTNENode(org.apache.commons.jexl2.parser.ASTNENode) ASTNumberLiteral(org.apache.commons.jexl2.parser.ASTNumberLiteral) ASTMulNode(org.apache.commons.jexl2.parser.ASTMulNode) ASTBitwiseComplNode(org.apache.commons.jexl2.parser.ASTBitwiseComplNode) ASTMethodNode(org.apache.commons.jexl2.parser.ASTMethodNode) ASTBitwiseXorNode(org.apache.commons.jexl2.parser.ASTBitwiseXorNode) ASTOrNode(org.apache.commons.jexl2.parser.ASTOrNode) ASTStringLiteral(org.apache.commons.jexl2.parser.ASTStringLiteral) ASTBitwiseAndNode(org.apache.commons.jexl2.parser.ASTBitwiseAndNode) ASTNotNode(org.apache.commons.jexl2.parser.ASTNotNode) ASTGENode(org.apache.commons.jexl2.parser.ASTGENode) ASTERNode(org.apache.commons.jexl2.parser.ASTERNode) ASTAdditiveNode(org.apache.commons.jexl2.parser.ASTAdditiveNode) ASTNRNode(org.apache.commons.jexl2.parser.ASTNRNode) ASTTrueNode(org.apache.commons.jexl2.parser.ASTTrueNode) ASTIdentifier(org.apache.commons.jexl2.parser.ASTIdentifier) ASTAssignment(org.apache.commons.jexl2.parser.ASTAssignment) ASTGTNode(org.apache.commons.jexl2.parser.ASTGTNode) ASTNullLiteral(org.apache.commons.jexl2.parser.ASTNullLiteral) ASTLTNode(org.apache.commons.jexl2.parser.ASTLTNode) ASTReference(org.apache.commons.jexl2.parser.ASTReference) ASTBitwiseOrNode(org.apache.commons.jexl2.parser.ASTBitwiseOrNode) ASTFunctionNode(org.apache.commons.jexl2.parser.ASTFunctionNode) ASTLENode(org.apache.commons.jexl2.parser.ASTLENode) ASTEQNode(org.apache.commons.jexl2.parser.ASTEQNode) ASTFalseNode(org.apache.commons.jexl2.parser.ASTFalseNode) ExceededValueThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode) JexlNode(org.apache.commons.jexl2.parser.JexlNode) ExceededTermThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode) ASTEmptyFunction(org.apache.commons.jexl2.parser.ASTEmptyFunction) ASTAndNode(org.apache.commons.jexl2.parser.ASTAndNode)

Aggregations

ASTStringLiteral (org.apache.commons.jexl2.parser.ASTStringLiteral)13 ASTStringLiteral (org.apache.commons.jexl3.parser.ASTStringLiteral)7 JexlNode (org.apache.commons.jexl3.parser.JexlNode)7 ASTIdentifier (org.apache.commons.jexl2.parser.ASTIdentifier)6 ASTReference (org.apache.commons.jexl2.parser.ASTReference)6 JexlNode (org.apache.commons.jexl2.parser.JexlNode)5 ASTFunctionNode (org.apache.commons.jexl2.parser.ASTFunctionNode)3 ASTNumberLiteral (org.apache.commons.jexl2.parser.ASTNumberLiteral)3 JexlException (org.apache.commons.jexl3.JexlException)3 ASTAssignment (org.apache.commons.jexl2.parser.ASTAssignment)2 ASTEQNode (org.apache.commons.jexl2.parser.ASTEQNode)2 ASTReferenceExpression (org.apache.commons.jexl2.parser.ASTReferenceExpression)2 DatawaveFatalQueryException (datawave.query.exceptions.DatawaveFatalQueryException)1 FunctionJexlNodeVisitor (datawave.query.jexl.functions.FunctionJexlNodeVisitor)1 JexlArgumentDescriptor (datawave.query.jexl.functions.arguments.JexlArgumentDescriptor)1 ExceededTermThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededTermThresholdMarkerJexlNode)1 ExceededValueThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode)1 QueryException (datawave.webservice.query.exception.QueryException)1 JexlContext (org.apache.commons.jexl2.JexlContext)1 JexlEngine (org.apache.commons.jexl2.JexlEngine)1