Search in sources :

Example 21 with MockMetadataHelper

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

the class FunctionIndexQueryExpansionVisitorTest method expandContentAdjacentFunctionIntoSingleField.

@Test
public void expandContentAdjacentFunctionIntoSingleField() 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);
    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')";
    runTest(original, expected);
    original = "content:adjacent(FOO, termOffsetMap, 'abc', 'def')";
    expected = "(content:adjacent(FOO, termOffsetMap, 'abc', 'def') && FOO == 'def' && FOO == 'abc')";
    runTest(original, expected);
}
Also used : MockMetadataHelper(datawave.query.util.MockMetadataHelper) Test(org.junit.Test)

Example 22 with MockMetadataHelper

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

the class FunctionIndexQueryExpansionVisitorTest method expandContentPhraseFunctionIntoSingleField.

@Test
public void expandContentPhraseFunctionIntoSingleField() throws ParseException {
    Set<String> fields = Sets.newHashSet("FOO");
    // 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')";
    runTest(original, expected);
    original = "content:phrase(FOO, termOffsetMap, 'abc', 'def')";
    expected = "(content:phrase(FOO, termOffsetMap, 'abc', 'def') && FOO == 'def' && FOO == 'abc')";
    runTest(original, expected);
}
Also used : MockMetadataHelper(datawave.query.util.MockMetadataHelper) Test(org.junit.Test)

Example 23 with MockMetadataHelper

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

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

the class ExecutableExpansionVisitorTest2 method beforeEach.

@Before
public void beforeEach() {
    config = new ShardQueryConfiguration();
    config.setIndexedFields(indexedFields);
    metadataHelper = new MockMetadataHelper();
    metadataHelper.setIndexedFields(indexedFields);
}
Also used : MockMetadataHelper(datawave.query.util.MockMetadataHelper) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) Before(org.junit.Before)

Example 25 with MockMetadataHelper

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

the class ExpandCompositeTermsTest method runTestQuery.

void runTestQuery(String query, String expected, Set<String> indexedFields, ShardQueryConfiguration conf) throws ParseException {
    ASTJexlScript original = JexlASTHelper.parseJexlQuery(query);
    MockMetadataHelper helper = new MockMetadataHelper();
    helper.setIndexedFields(indexedFields);
    ASTJexlScript expand = FunctionIndexQueryExpansionVisitor.expandFunctions(conf, helper, DateIndexHelper.getInstance(), original);
    expand = ExpandCompositeTerms.expandTerms(conf, expand);
    // Verify the script is as expected, and has a valid lineage.
    JexlNodeAssert.assertThat(expand).isEqualTo(expected).hasValidLineage();
    // Verify the original script was not modified, and still has a valid lineage.
    JexlNodeAssert.assertThat(original).isEqualTo(query).hasValidLineage();
}
Also used : MockMetadataHelper(datawave.query.util.MockMetadataHelper) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript)

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