Search in sources :

Example 26 with MockMetadataHelper

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

the class QueryModelVisitorTest method testAppliedModelWithNullNoFail.

@Test
public void testAppliedModelWithNullNoFail() throws ParseException {
    model.addTermToModel("FOO1", "BAR1");
    model.addTermToModel("OTHER", "9_2");
    String original = "FOO1 == 'baz' and OTHER == null";
    ASTJexlScript groomed = JexlASTHelper.InvertNodeVisitor.invertSwappedNodes(JexlASTHelper.parseJexlQuery(original));
    String expected = "BAR1 == 'baz' and $9_2 == null";
    ASTJexlScript actualScript = assertResult(JexlStringBuildingVisitor.buildQuery(groomed), expected);
    MockMetadataHelper helper = new MockMetadataHelper();
    helper.addNormalizers("FOO1", Sets.newHashSet(new LcNoDiacriticsType()));
    Multimap<String, String> maps = ArrayListMultimap.create();
    maps.put("9_2", "datatype1");
    helper.addFieldsToDatatypes(maps);
    Multimap<String, Type<?>> types = FetchDataTypesVisitor.fetchDataTypes(helper, Collections.singleton("datatype1"), actualScript);
    assertEquals(types.size(), 4);
    assertTrue(types.values().stream().allMatch((o) -> o instanceof LcNoDiacriticsType || o instanceof NoOpType));
}
Also used : LcNoDiacriticsType(datawave.data.type.LcNoDiacriticsType) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ASTEQNode(org.apache.commons.jexl2.parser.ASTEQNode) JexlNodeAssert(datawave.test.JexlNodeAssert) JexlASTHelper(datawave.query.jexl.JexlASTHelper) MockMetadataHelper(datawave.query.util.MockMetadataHelper) QueryModel(datawave.query.model.QueryModel) ParseException(org.apache.commons.jexl2.parser.ParseException) Multimap(com.google.common.collect.Multimap) NoExpansion(datawave.query.language.functions.jexl.NoExpansion) NoOpType(datawave.data.type.NoOpType) HashSet(java.util.HashSet) Logger(org.apache.log4j.Logger) Assert.fail(org.junit.Assert.fail) Before(org.junit.Before) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Sets(com.google.common.collect.Sets) LcNoDiacriticsType(datawave.data.type.LcNoDiacriticsType) List(java.util.List) Type(datawave.data.type.Type) Assert(org.junit.Assert) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ASTReference(org.apache.commons.jexl2.parser.ASTReference) MockMetadataHelper(datawave.query.util.MockMetadataHelper) NoOpType(datawave.data.type.NoOpType) LcNoDiacriticsType(datawave.data.type.LcNoDiacriticsType) Type(datawave.data.type.Type) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) NoOpType(datawave.data.type.NoOpType) Test(org.junit.Test)

Example 27 with MockMetadataHelper

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

the class ExpandMultiNormalizedTermsTest method before.

@Before
public void before() {
    // Create fresh query config
    config = new ShardQueryConfiguration();
    config.setBeginDate(new Date(0));
    config.setEndDate(new Date(System.currentTimeMillis()));
    // Create fresh metadata helper.
    helper = new MockMetadataHelper();
// Each test configures fields as needed
}
Also used : MockMetadataHelper(datawave.query.util.MockMetadataHelper) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) Date(java.util.Date) Before(org.junit.Before)

Example 28 with MockMetadataHelper

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

the class FunctionIndexQueryExpansionVisitorTest method expandContentWithinFunctionIntoMultipleFields.

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

Example 29 with MockMetadataHelper

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

the class FunctionIndexQueryExpansionVisitorTest method expandContentScoredPhraseFunctionIntoSingleField.

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

Example 30 with MockMetadataHelper

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

the class FunctionIndexQueryExpansionVisitorTest method expandContentPhraseFunctionIntoMultipleFieldsWithNoExpansion.

// no expansion function also applies to index query expansion
@Test
public void expandContentPhraseFunctionIntoMultipleFieldsWithNoExpansion() 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);
    ShardQueryConfiguration config = new ShardQueryConfiguration();
    config.setNoExpansionFields(Sets.newHashSet("BAR"));
    // 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, config, mockMetadataHelper);
}
Also used : MockMetadataHelper(datawave.query.util.MockMetadataHelper) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) Test(org.junit.Test)

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