Search in sources :

Example 46 with ShardQueryConfiguration

use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.

the class GeoWavePruningVisitorTest method testPrunedWrappedTermDoesNotLeaveEmptyWrappedTerm.

@Test
public void testPrunedWrappedTermDoesNotLeaveEmptyWrappedTerm() throws ParseException {
    String function = "geowave:intersects(GEO_FIELD, 'POLYGON((10 10, 20 10, 20 20, 10 20, 10 10))')";
    // Get the expanded geowave terms.
    String indexQuery = convertFunctionToIndexQuery(function, new ShardQueryConfiguration());
    // Add a wrapped term that should be pruned.
    String query = function + " && ((GEO_FIELD == '0100') || " + indexQuery + ")";
    String expected = function + " && (false || " + indexQuery + ")";
    Multimap<String, String> expectedPrunedTerms = HashMultimap.create();
    expectedPrunedTerms.put("GEO_FIELD", "0100");
    assertResult(query, expected, expectedPrunedTerms);
}
Also used : ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) Test(org.junit.Test)

Example 47 with ShardQueryConfiguration

use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.

the class ExecutableExpansionVisitorTest method testExceededOrThresholdExpansion.

@Test
public void testExceededOrThresholdExpansion() throws Exception {
    ASTJexlScript queryTree = JexlASTHelper.parseJexlQuery("UUID == 'capone' && (filter:includeRegex(QUOTE,'.*kind.*') || QUOTE == 'kind' || BIRTH_DATE == '123')");
    // update the generated queryTree to have an ExceededOrThreshold marker for BIRTH_DATE
    Set<String> birthdates = new HashSet<>();
    birthdates.add("123");
    birthdates.add("234");
    birthdates.add("345");
    JexlNode child = ExceededOrThresholdMarkerJexlNode.createFromValues("BIRTH_DATE", birthdates);
    // 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);
    String queryString = JexlStringBuildingVisitor.buildQuery(queryTree);
    String id = queryString.substring(queryString.indexOf("id = '") + 6, queryString.indexOf("') && (field"));
    // included ExceededValueThresholdMarker before
    Assert.assertTrue(queryString, queryString.equals("UUID == 'capone' && (filter:includeRegex(QUOTE, '.*kind.*') || QUOTE == 'kind' || " + "((_List_ = true) && ((id = '" + id + "') && (field = 'BIRTH_DATE') && (params = '{\"values\":[\"123\",\"234\",\"345\"]}'))))"));
    // not executable
    Assert.assertFalse(ExecutableDeterminationVisitor.isExecutable(queryTree, config, helper));
    // what came out is executable
    Assert.assertTrue(ExecutableDeterminationVisitor.isExecutable(newTree, config, helper));
    queryString = JexlStringBuildingVisitor.buildQuery(newTree);
    id = queryString.substring(queryString.indexOf("id = '") + 6, queryString.indexOf("') && (field"));
    // it looks like what we'd expect
    String expected = "(QUOTE == 'kind' && UUID == 'capone') || " + "(((_List_ = true) && ((id = '" + id + "') && (field = 'BIRTH_DATE') && (params = '{\"values\":[\"123\",\"234\",\"345\"]}'))) && UUID == 'capone') || " + "(filter:includeRegex(QUOTE, '.*kind.*') && UUID == 'capone')";
    Assert.assertEquals(expected, queryString);
}
Also used : MetadataHelper(datawave.query.util.MetadataHelper) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) ExceededValueThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode) ExceededOrThresholdMarkerJexlNode(datawave.query.jexl.nodes.ExceededOrThresholdMarkerJexlNode) JexlNode(org.apache.commons.jexl2.parser.JexlNode) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) HashSet(java.util.HashSet) CompositeFunctionsTest(datawave.query.CompositeFunctionsTest) Test(org.junit.Test)

Example 48 with ShardQueryConfiguration

use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.

the class ExecutableExpansionVisitorTest method testMinimumExpansionParse.

@Test
public void testMinimumExpansionParse() 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);
    ASTJexlScript newTree = ExecutableExpansionVisitor.expand(queryTree, config, helper);
    EasyMock.verify(config, helper);
    Assert.assertFalse(JexlStringBuildingVisitor.buildQuery(queryTree).equals(JexlStringBuildingVisitor.buildQuery(newTree)));
    String expected = "(QUOTE == 'kind' && UUID == 'capone') || ((filter:includeRegex(QUOTE, '.*kind.*') || BIRTH_DATE == '123') && UUID == 'capone')";
    Assert.assertEquals(expected, JexlStringBuildingVisitor.buildQuery(newTree));
}
Also used : MetadataHelper(datawave.query.util.MetadataHelper) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) HashSet(java.util.HashSet) CompositeFunctionsTest(datawave.query.CompositeFunctionsTest) Test(org.junit.Test)

Example 49 with ShardQueryConfiguration

use of datawave.query.config.ShardQueryConfiguration in project datawave by NationalSecurityAgency.

the class ExecutableExpansionVisitorTest method testDelayedDoubleExpansion.

@Test
public void testDelayedDoubleExpansion() throws Exception {
    ASTJexlScript queryTree = JexlASTHelper.parseJexlQuery("UUID == 'capone' && (((_Delayed_ = true) && 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");
    // QUOTE being delayed creates a query that is non-executable we cannot delay a field which is nonEvent
    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' && (((_Delayed_ = true) && QUOTE == 'kind') || " + "((_Delayed_ = true) && BIRTH_DATE == '123'))"));
    // 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)));
}
Also used : MetadataHelper(datawave.query.util.MetadataHelper) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) HashSet(java.util.HashSet) CompositeFunctionsTest(datawave.query.CompositeFunctionsTest) Test(org.junit.Test)

Example 50 with ShardQueryConfiguration

use of datawave.query.config.ShardQueryConfiguration 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)

Aggregations

ShardQueryConfiguration (datawave.query.config.ShardQueryConfiguration)108 Test (org.junit.Test)75 ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)48 HashSet (java.util.HashSet)42 Date (java.util.Date)38 GeometryType (datawave.data.type.GeometryType)17 MetadataHelper (datawave.query.util.MetadataHelper)17 HashMap (java.util.HashMap)16 CompositeFunctionsTest (datawave.query.CompositeFunctionsTest)13 Query (datawave.webservice.query.Query)10 Authorizations (org.apache.accumulo.core.security.Authorizations)10 Before (org.junit.Before)10 QueryImpl (datawave.webservice.query.QueryImpl)9 QueryParameters (datawave.webservice.query.QueryParameters)9 QueryParametersImpl (datawave.webservice.query.QueryParametersImpl)9 MultivaluedMapImpl (org.jboss.resteasy.specimpl.MultivaluedMapImpl)8 MockMetadataHelper (datawave.query.util.MockMetadataHelper)7 JexlNode (org.apache.commons.jexl2.parser.JexlNode)6 ExceededOrThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededOrThresholdMarkerJexlNode)5 ExceededValueThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode)5