Search in sources :

Example 31 with MockMetadataHelper

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

the class FunctionIndexQueryExpansionVisitorTest method expandContentPhraseFunctionIntoSingleFieldWithNoExpansion.

@Test
public void expandContentPhraseFunctionIntoSingleFieldWithNoExpansion() throws ParseException {
    Set<String> fields = Sets.newHashSet("FOO", "BAR");
    Set<String> tfFields = Sets.newHashSet("FOO");
    // Configure the mock metadata helper.
    MockMetadataHelper mockMetadataHelper = new MockMetadataHelper();
    mockMetadataHelper.setIndexedFields(fields);
    mockMetadataHelper.addTermFrequencyFields(tfFields);
    ShardQueryConfiguration config = new ShardQueryConfiguration();
    config.setNoExpansionFields(Sets.newHashSet("FOO"));
    // Execute the test.
    String original = "content:phrase(termOffsetMap, 'abc', 'def')";
    runTest(original, original, config, mockMetadataHelper);
}
Also used : MockMetadataHelper(datawave.query.util.MockMetadataHelper) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) Test(org.junit.Test)

Example 32 with MockMetadataHelper

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

the class FunctionIndexQueryExpansionVisitorTest method expandContentPhraseFunctionIntoMultipleFields.

@Test
public void expandContentPhraseFunctionIntoMultipleFields() throws ParseException {
    Set<String> fields = Sets.newHashSet("FOO", "BAR");
    // Configure the mock metadata helper.
    MockMetadataHelper mockMetadataHelper = new MockMetadataHelper();
    mockMetadataHelper.setIndexedFields(fields);
    mockMetadataHelper.addTermFrequencyFields(fields);
    this.metadataHelper = mockMetadataHelper;
    // Execute the test.
    String original = "content:phrase(termOffsetMap, 'abc', 'def')";
    String expected = "((content:phrase(FOO, termOffsetMap, 'abc', 'def') && FOO == 'def' && FOO == 'abc') || (content:phrase(BAR, termOffsetMap, 'abc', 'def') && BAR == 'def' && BAR == 'abc'))";
    runTest(original, expected);
    original = "content:phrase((FOO || BAR), termOffsetMap, 'abc', 'def')";
    expected = "((content:phrase(FOO, termOffsetMap, 'abc', 'def') && FOO == 'def' && FOO == 'abc') || (content:phrase(BAR, termOffsetMap, 'abc', 'def') && BAR == 'def' && BAR == 'abc'))";
    runTest(original, expected, mockMetadataHelper);
}
Also used : MockMetadataHelper(datawave.query.util.MockMetadataHelper) Test(org.junit.Test)

Example 33 with MockMetadataHelper

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

the class FunctionIndexQueryExpansionVisitorTest method expandContentScoredPhraseFunctionIntoMultipleFields.

@Test
public void expandContentScoredPhraseFunctionIntoMultipleFields() throws ParseException {
    Set<String> fields = Sets.newHashSet("FOO", "BAR");
    Set<String> tfFields = Sets.newHashSet("FOO", "BAR");
    // Configure the mock metadata helper.
    MockMetadataHelper mockMetadataHelper = new MockMetadataHelper();
    mockMetadataHelper.setIndexedFields(fields);
    mockMetadataHelper.addTermFrequencyFields(tfFields);
    this.metadataHelper = mockMetadataHelper;
    // Execute the test.
    String original = "content:scoredPhrase(-1.5, termOffsetMap, 'abc', 'def')";
    String expected = "(content:scoredPhrase(FOO, -1.5, termOffsetMap, 'abc', 'def') && FOO == 'def' && FOO == 'abc') || (content:scoredPhrase(BAR, -1.5, termOffsetMap, 'abc', 'def') && BAR == 'def' && BAR == 'abc')";
    runTest(original, expected);
}
Also used : MockMetadataHelper(datawave.query.util.MockMetadataHelper) Test(org.junit.Test)

Example 34 with MockMetadataHelper

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

the class FunctionIndexQueryExpansionVisitorTest method expandContentAdjacentFunctionIntoMultipleFields.

@Test
public void expandContentAdjacentFunctionIntoMultipleFields() throws ParseException {
    Set<String> fields = Sets.newHashSet("FOO", "BAR");
    Set<String> tfFields = Sets.newHashSet("FOO", "BAR");
    // Configure the mock metadata helper.
    MockMetadataHelper mockMetadataHelper = new MockMetadataHelper();
    mockMetadataHelper.setIndexedFields(fields);
    mockMetadataHelper.addTermFrequencyFields(tfFields);
    this.metadataHelper = mockMetadataHelper;
    // Execute the test.
    String original = "content:adjacent(termOffsetMap, 'abc', 'def')";
    String expected = "((content:adjacent(FOO, termOffsetMap, 'abc', 'def') && FOO == 'def' && FOO == 'abc') || (content:adjacent(BAR, termOffsetMap, 'abc', 'def') && BAR == 'def' && BAR == 'abc'))";
    runTest(original, expected);
    original = "content:adjacent((FOO || BAR), termOffsetMap, 'abc', 'def')";
    expected = "((content:adjacent(FOO, termOffsetMap, 'abc', 'def') && FOO == 'def' && FOO == 'abc') || (content:adjacent(BAR, termOffsetMap, 'abc', 'def') && BAR == 'def' && BAR == 'abc'))";
    runTest(original, expected);
}
Also used : MockMetadataHelper(datawave.query.util.MockMetadataHelper) Test(org.junit.Test)

Example 35 with MockMetadataHelper

use of datawave.query.util.MockMetadataHelper 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

MockMetadataHelper (datawave.query.util.MockMetadataHelper)55 Test (org.junit.Test)45 ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)40 LcNoDiacriticsType (datawave.data.type.LcNoDiacriticsType)35 Type (datawave.data.type.Type)35 NoOpType (datawave.data.type.NoOpType)34 ScannerFactory (datawave.query.tables.ScannerFactory)34 NumberType (datawave.data.type.NumberType)33 RangeFactoryForTests.makeTestRange (datawave.common.test.utils.query.RangeFactoryForTests.makeTestRange)25 QueryPlan (datawave.query.planner.QueryPlan)25 Range (org.apache.accumulo.core.data.Range)25 SimpleDateFormat (java.text.SimpleDateFormat)9 ShardQueryConfiguration (datawave.query.config.ShardQueryConfiguration)7 Before (org.junit.Before)4 JexlNode (org.apache.commons.jexl2.parser.JexlNode)3 JexlArgumentDescriptor (datawave.query.jexl.functions.arguments.JexlArgumentDescriptor)2 MockDateIndexHelper (datawave.query.util.MockDateIndexHelper)2 ASTFunctionNode (org.apache.commons.jexl2.parser.ASTFunctionNode)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 Multimap (com.google.common.collect.Multimap)1