use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.
the class ExecutableExpansionVisitorTest method testArbitraryNodeExpansionFlatten.
@Test
public void testArbitraryNodeExpansionFlatten() throws Exception {
ASTJexlScript queryTree = JexlASTHelper.parseJexlQuery("UUID == 'capone' && (filter:includeRegex(QUOTE,'.*kind.*') || QUOTE == 'kind' || BIRTH_DATE == '123')");
ShardQueryConfiguration config = EasyMock.createMock(ShardQueryConfiguration.class);
MetadataHelper helper = EasyMock.createMock(MetadataHelper.class);
HashSet<String> indexedFields = new HashSet<>();
indexedFields.add("UUID");
indexedFields.add("QUOTE");
EasyMock.expect(config.getIndexedFields()).andReturn(indexedFields).anyTimes();
EasyMock.replay(config, helper);
// find an orNode in the tree
ExecutableExpansionVisitor visitor = new ExecutableExpansionVisitor(config, helper);
ASTJexlScript rebuilt = TreeFlatteningRebuildingVisitor.flatten(queryTree);
visitor.visit(rebuilt.jjtGetChild(0), null);
EasyMock.verify(config, helper);
String expected = "(QUOTE == 'kind' && UUID == 'capone') || ((filter:includeRegex(QUOTE, '.*kind.*') || BIRTH_DATE == '123') && UUID == 'capone')";
Assert.assertEquals(expected, JexlStringBuildingVisitor.buildQuery(rebuilt));
}
use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.
the class ExecutableExpansionVisitorTest method testExceededOrThresholdCannotExpand.
@Test
public void testExceededOrThresholdCannotExpand() throws Exception {
ASTJexlScript queryTree = JexlASTHelper.parseJexlQuery("UUID == 'capone' && (((_List_ = true) && (((id = 'some-bogus-id') && (field = 'QUOTE') && (params = '{\"values\":[\"a\",\"b\",\"c\"]}')))))");
ShardQueryConfiguration config = EasyMock.createMock(ShardQueryConfiguration.class);
MetadataHelper helper = EasyMock.createMock(MetadataHelper.class);
HashSet<String> indexedFields = new HashSet<>();
indexedFields.add("UUID");
indexedFields.add("QUOTE");
EasyMock.expect(config.getIndexedFields()).andReturn(indexedFields).anyTimes();
EasyMock.replay(config, helper);
ASTJexlScript newTree = ExecutableExpansionVisitor.expand(queryTree, config, helper);
EasyMock.verify(config, helper);
// included ExceededValueThresholdMarker before
Assert.assertTrue(JexlStringBuildingVisitor.buildQuery(queryTree), JexlStringBuildingVisitor.buildQuery(queryTree).equals("UUID == 'capone' && (((_List_ = true) && (((id = 'some-bogus-id') && (field = 'QUOTE') && (params = '{\"values\":[\"a\",\"b\",\"c\"]}')))))"));
// starts off executable
Assert.assertTrue(ExecutableDeterminationVisitor.isExecutable(queryTree, config, helper));
// what came out is executable
Assert.assertTrue(ExecutableDeterminationVisitor.isExecutable(newTree, config, helper));
// the visitor changed nothing
Assert.assertTrue(JexlStringBuildingVisitor.buildQuery(newTree), JexlStringBuildingVisitor.buildQuery(newTree).equals(JexlStringBuildingVisitor.buildQuery(queryTree)));
}
use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.
the class ExecutableExpansionVisitorTest method testExceededThresholdExpansionInternal.
@Test
public void testExceededThresholdExpansionInternal() throws Exception {
ASTJexlScript queryTree = JexlASTHelper.parseJexlQuery("UUID == 'capone' && (filter:includeRegex(QUOTE,'.*kind.*') || QUOTE == 'kind' || BIRTH_DATE == '123')");
// update the generated queryTree to have an ExceededThreshold marker for BIRTH_DATE
JexlNode child = new ExceededValueThresholdMarkerJexlNode(queryTree.jjtGetChild(0).jjtGetChild(1).jjtGetChild(0).jjtGetChild(0).jjtGetChild(1));
// unlink the old node
queryTree.jjtGetChild(0).jjtGetChild(1).jjtGetChild(0).jjtGetChild(0).jjtGetChild(1).jjtSetParent(null);
// overwrite the old BIRTH_DATE==123 with the ExceededThreshold marker
queryTree.jjtGetChild(0).jjtGetChild(1).jjtGetChild(0).jjtGetChild(0).jjtAddChild(child, 1);
ShardQueryConfiguration config = EasyMock.createMock(ShardQueryConfiguration.class);
MetadataHelper helper = EasyMock.createMock(MetadataHelper.class);
HashSet<String> indexedFields = new HashSet<>();
indexedFields.add("UUID");
indexedFields.add("QUOTE");
EasyMock.expect(config.getIndexedFields()).andReturn(indexedFields).anyTimes();
EasyMock.replay(config, helper);
ASTJexlScript newTree = ExecutableExpansionVisitor.expand(queryTree, config, helper);
EasyMock.verify(config, helper);
// included ExceededValueThresholdMarker before
Assert.assertTrue(JexlStringBuildingVisitor.buildQuery(queryTree), JexlStringBuildingVisitor.buildQuery(queryTree).equals("UUID == 'capone' && (filter:includeRegex(QUOTE, '.*kind.*') || QUOTE == 'kind' || " + "((_Value_ = true) && (BIRTH_DATE == '123')))"));
// not executable
Assert.assertFalse(ExecutableDeterminationVisitor.isExecutable(queryTree, config, helper));
// what came out is executable
Assert.assertTrue(ExecutableDeterminationVisitor.isExecutable(newTree, config, helper));
// it looks like what we'd expect
String expected = "(QUOTE == 'kind' && UUID == 'capone') || " + "(((_Value_ = true) && (BIRTH_DATE == '123')) && UUID == 'capone') || " + "(filter:includeRegex(QUOTE, '.*kind.*') && UUID == 'capone')";
Assert.assertEquals(expected, JexlStringBuildingVisitor.buildQueryWithoutParse(newTree));
}
use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.
the class ExecutableExpansionVisitorTest method testDelayed.
@Test
public void testDelayed() throws Exception {
ASTJexlScript queryTree = JexlASTHelper.parseJexlQuery("UUID == 'capone' && (QUOTE == 'kind' || " + "((_Delayed_ = true) && BIRTH_DATE == '123'))");
ShardQueryConfiguration config = EasyMock.createMock(ShardQueryConfiguration.class);
MetadataHelper helper = EasyMock.createMock(MetadataHelper.class);
HashSet<String> indexedFields = new HashSet<>();
indexedFields.add("UUID");
indexedFields.add("QUOTE");
EasyMock.expect(config.getIndexedFields()).andReturn(indexedFields).anyTimes();
Set<String> dataTypes = new HashSet<>();
dataTypes.add("test");
Set<String> nonEventFields = new HashSet<>();
nonEventFields.add("QUOTE");
EasyMock.expect(config.getDatatypeFilter()).andReturn(dataTypes).anyTimes();
EasyMock.expect(helper.getNonEventFields(dataTypes)).andReturn(nonEventFields).anyTimes();
EasyMock.replay(config, helper);
ASTJexlScript newTree = ExecutableExpansionVisitor.expand(queryTree, config, helper);
EasyMock.verify(config, helper);
// included ExceededValueThresholdMarker before
Assert.assertTrue(JexlStringBuildingVisitor.buildQuery(queryTree), JexlStringBuildingVisitor.buildQuery(queryTree).equals("UUID == 'capone' && (QUOTE == 'kind' || " + "((_Delayed_ = true) && BIRTH_DATE == '123'))"));
// starts off executable
Assert.assertFalse(ExecutableDeterminationVisitor.isExecutable(queryTree, config, helper));
// what came out is executable
Assert.assertTrue(ExecutableDeterminationVisitor.isExecutable(newTree, config, helper));
// the visitor changed nothing
String expected = "(QUOTE == 'kind' && UUID == 'capone') || (((_Delayed_ = true) && BIRTH_DATE == '123') && UUID == 'capone')";
Assert.assertEquals(expected, JexlStringBuildingVisitor.buildQueryWithoutParse(newTree));
}
use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.
the class ExecutableExpansionVisitorTest method testNestedExpansionWithFailures.
@Test
public void testNestedExpansionWithFailures() throws Exception {
ASTJexlScript queryTree = JexlASTHelper.parseJexlQuery("UUID == 'A' && (QUOTE == 'kind' || BIRTH_DATE == '234'|| (BIRTH_DATE == '123' && QUOTE == 'kind' && !(filter:includeRegex(QUOTE, '.*unkind.*') || BIRTH_DATE =='555' )))");
ShardQueryConfiguration config = EasyMock.createMock(ShardQueryConfiguration.class);
MetadataHelper helper = EasyMock.createMock(MetadataHelper.class);
HashSet<String> indexedFields = new HashSet<>();
indexedFields.add("UUID");
indexedFields.add("QUOTE");
EasyMock.expect(config.getIndexedFields()).andReturn(indexedFields).anyTimes();
EasyMock.replay(config, helper);
// find an orNode in the tree
ExecutableExpansionVisitor visitor = new ExecutableExpansionVisitor(config, helper);
ASTJexlScript rebuilt = TreeFlatteningRebuildingVisitor.flatten(queryTree);
visitor.visit(rebuilt.jjtGetChild(0), null);
EasyMock.verify(config, helper);
Assert.assertTrue(ExecutableDeterminationVisitor.isExecutable(rebuilt, config, helper));
String expected = "(QUOTE == 'kind' && UUID == 'A') || (BIRTH_DATE == '123' && QUOTE == 'kind' && !(filter:includeRegex(QUOTE, '.*unkind.*') || BIRTH_DATE == '555') && UUID == 'A') || (BIRTH_DATE == '234' && UUID == 'A')";
Assert.assertEquals(expected, JexlStringBuildingVisitor.buildQueryWithoutParse(rebuilt));
}
Aggregations