use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class QueryModelVisitorTest method testCastesianProduct.
@Test
public void testCastesianProduct() throws ParseException {
model.addTermToModel("FOO1", "1BAR");
model.addTermToModel("FOO1", "2BAR");
String original = "FOO == FOO1";
ASTJexlScript groomed = JexlASTHelper.InvertNodeVisitor.invertSwappedNodes(JexlASTHelper.parseJexlQuery(original));
String expected = "(BAR1 == $1BAR || BAR2 == $1BAR || BAR1 == $2BAR || BAR2 == $2BAR)";
assertResult(JexlStringBuildingVisitor.buildQuery(groomed), expected);
}
use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class QueryModelVisitorTest method assertResult.
private ASTJexlScript assertResult(String original, String expected) throws ParseException {
ASTJexlScript originalScript = JexlASTHelper.parseJexlQuery(original);
ASTJexlScript actualScript = QueryModelVisitor.applyModel(originalScript, model, allFields);
// Verify the resulting script is as expected with a valid lineage.
JexlNodeAssert.assertThat(actualScript).isEqualTo(expected).hasValidLineage();
// Verify the original script was not modified, and has a valid lineage.
JexlNodeAssert.assertThat(originalScript).isEqualTo(original).hasValidLineage();
return actualScript;
}
use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class QueryModelVisitorTest method testNoExpansion.
private void testNoExpansion(String query, String expected, QueryModel model, Set<String> expectedFields) {
try {
Set<String> allFields = new HashSet<>();
allFields.addAll(model.getForwardQueryMapping().keySet());
allFields.addAll(model.getForwardQueryMapping().values());
ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
NoExpansionFunctionVisitor.VisitResult result = NoExpansionFunctionVisitor.findNoExpansionFields(script);
JexlNodeAssert.assertThat(script).isNotEqualTo(result.script);
Assert.assertEquals(expectedFields, result.noExpansionFields);
ASTJexlScript applied;
if (result.noExpansionFields.size() > 0) {
applied = QueryModelVisitor.applyModel(result.script, model, allFields, result.noExpansionFields);
} else {
applied = QueryModelVisitor.applyModel(result.script, model, allFields);
}
if (log.isTraceEnabled()) {
log.trace("expected: " + expected);
log.trace("actual : " + JexlStringBuildingVisitor.buildQueryWithoutParse(applied));
}
ASTJexlScript expectedScript = JexlASTHelper.parseAndFlattenJexlQuery(expected);
assertTrue(TreeEqualityVisitor.checkEquality(expectedScript, applied).isEqual());
} catch (ParseException e) {
fail("Error testing query: " + query);
}
}
use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class QueryPropertyMarkerSourceConsolidatorTest method assertResult.
private void assertResult(String original, String expected) throws ParseException {
ASTJexlScript originalScript = JexlASTHelper.parseJexlQuery(original);
ASTJexlScript actual = QueryPropertyMarkerSourceConsolidator.consolidate(originalScript);
JexlNodeAssert.assertThat(actual).isEqualTo(expected).hasValidLineage();
JexlNodeAssert.assertThat(originalScript).hasExactQueryString(original).hasValidLineage();
}
use of org.apache.commons.jexl3.parser.ASTJexlScript in project datawave by NationalSecurityAgency.
the class QueryPruningVisitorTest method orFalseTest.
@Test
public void orFalseTest() throws ParseException {
String query = "false || _NOFIELD_ == 'z'";
ASTJexlScript script = JexlASTHelper.parseJexlQuery(query);
Assert.assertEquals(QueryPruningVisitor.TruthState.FALSE, QueryPruningVisitor.getState(script));
Assert.assertEquals(0, logAppender.getMessages().size(), logAppender.getMessages().size());
}
Aggregations