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));
}
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
}
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);
}
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);
}
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);
}
Aggregations