Search in sources :

Example 1 with MockDateIndexHelper

use of datawave.query.util.MockDateIndexHelper in project datawave by NationalSecurityAgency.

the class FunctionIndexQueryExpansionVisitorTest method setUp.

@Before
public void setUp() throws Exception {
    config = new ShardQueryConfiguration();
    metadataHelper = new MockMetadataHelper();
    dateIndexHelper = new MockDateIndexHelper();
}
Also used : MockMetadataHelper(datawave.query.util.MockMetadataHelper) MockDateIndexHelper(datawave.query.util.MockDateIndexHelper) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) Before(org.junit.Before)

Example 2 with MockDateIndexHelper

use of datawave.query.util.MockDateIndexHelper in project datawave by NationalSecurityAgency.

the class ContentFunctionsTest method testJexlFunctionArgumentDescriptors.

private void testJexlFunctionArgumentDescriptors(String query, String expected, Set<String> contentFields) throws ParseException {
    MockMetadataHelper metadataHelper = new MockMetadataHelper();
    metadataHelper.addTermFrequencyFields(Arrays.asList("BODY", "META"));
    metadataHelper.setIndexedFields(Sets.newHashSet("BODY", "META"));
    if (contentFields != null) {
        metadataHelper.addContentFields(contentFields);
    }
    MockDateIndexHelper dateIndexHelper = new MockDateIndexHelper();
    ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
    JexlNode ref = script.jjtGetChild(0);
    Assert.assertEquals("First child of ASTJexlScript is not an ASTReference", ASTReference.class, ref.getClass());
    JexlNode child = ref.jjtGetChild(0);
    Assert.assertEquals("First child of ASTJexlScript is not an AStFunctionNode", ASTFunctionNode.class, child.getClass());
    ASTFunctionNode function = (ASTFunctionNode) child;
    JexlArgumentDescriptor desc = new ContentFunctionsDescriptor().getArgumentDescriptor(function);
    JexlNode indexQuery = desc.getIndexQuery(null, metadataHelper, dateIndexHelper, null);
    ASTJexlScript expectedScript = JexlASTHelper.parseJexlQuery(expected);
    JexlNode scriptChild = expectedScript.jjtGetChild(0);
    Assert.assertTrue("Expected " + JexlStringBuildingVisitor.buildQuery(scriptChild) + " but was " + JexlStringBuildingVisitor.buildQuery(indexQuery), JexlASTHelper.equals(scriptChild, indexQuery));
}
Also used : MockMetadataHelper(datawave.query.util.MockMetadataHelper) ASTFunctionNode(org.apache.commons.jexl2.parser.ASTFunctionNode) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) JexlNode(org.apache.commons.jexl2.parser.JexlNode) JexlArgumentDescriptor(datawave.query.jexl.functions.arguments.JexlArgumentDescriptor) MockDateIndexHelper(datawave.query.util.MockDateIndexHelper)

Aggregations

MockDateIndexHelper (datawave.query.util.MockDateIndexHelper)2 MockMetadataHelper (datawave.query.util.MockMetadataHelper)2 ShardQueryConfiguration (datawave.query.config.ShardQueryConfiguration)1 JexlArgumentDescriptor (datawave.query.jexl.functions.arguments.JexlArgumentDescriptor)1 ASTFunctionNode (org.apache.commons.jexl2.parser.ASTFunctionNode)1 ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)1 JexlNode (org.apache.commons.jexl2.parser.JexlNode)1 Before (org.junit.Before)1