Search in sources :

Example 36 with ShardQueryConfiguration

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

the class ExecutableExpansionVisitorTest method testSingleOr.

@Test
public void testSingleOr() throws Exception {
    ASTJexlScript queryTree = JexlASTHelper.parseJexlQuery("UUID == 'capone' && (QUOTE =='kind' || BIRTH_DATE == '123')");
    // grab the reference to the QUOTE=='kind' eqnode
    JexlNode quoteNode = queryTree.jjtGetChild(0).jjtGetChild(1).jjtGetChild(0).jjtGetChild(0).jjtGetChild(0);
    ASTOrNode newOr = new ASTOrNode(ParserTreeConstants.JJTORNODE);
    newOr.jjtAddChild(quoteNode, 0);
    quoteNode.jjtSetParent(newOr);
    // attach the new or node
    queryTree.jjtGetChild(0).jjtGetChild(1).jjtGetChild(0).jjtAddChild(newOr, 0);
    newOr.jjtSetParent(queryTree.jjtGetChild(0).jjtGetChild(1).jjtGetChild(0));
    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);
    // starts 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 : ASTOrNode(org.apache.commons.jexl2.parser.ASTOrNode) 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 37 with ShardQueryConfiguration

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

the class FunctionIndexQueryExpansionVisitorTest method setUp.

@Before
public void setUp() throws Exception {
    config = new ShardQueryConfiguration();
    metadataHelper = new MockMetadataHelper();
    dateIndexHelper = new MockDateIndexHelper();
}
Also used : MockMetadataHelper(datawave.query.util.MockMetadataHelper) MockDateIndexHelper(datawave.query.util.MockDateIndexHelper) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) Before(org.junit.Before)

Example 38 with ShardQueryConfiguration

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

the class ExpandCompositeTermsTest method test27.

@Test
public void test27() throws Exception {
    ShardQueryConfiguration conf = new ShardQueryConfiguration();
    Multimap<String, String> compositeToFieldMap = LinkedListMultimap.create();
    compositeToFieldMap.put("GEO", "GEO");
    compositeToFieldMap.put("GEO", "WKT");
    conf.setCompositeToFieldMap(compositeToFieldMap);
    Map<String, String> compositeToSeparatorMap = new HashMap<>();
    compositeToSeparatorMap.put("GEO", ",");
    conf.setCompositeFieldSeparators(compositeToSeparatorMap);
    Set<String> indexedFields = new HashSet<>();
    indexedFields.add("GEO");
    conf.getFieldToDiscreteIndexTypes().put("GEO", new GeometryType());
    String normNum = Normalizer.NUMBER_NORMALIZER.normalize("55");
    String query = "(GEO == '0202' || (((_Bounded_ = true) && (GEO >= '030a' && GEO <= '0335')))) && WKT == '" + normNum + "'";
    String expected = "(GEO == '0202,+bE5.5' || ((((_Bounded_ = true) && (GEO >= '030a,+bE5.5' && GEO <= '0335,+bE5.5')) && ((_Eval_ = true) && (((_Bounded_ = true) && (GEO >= '030a' && GEO <= '0335')) && WKT == '+bE5.5')))))";
    runTestQuery(query, expected, indexedFields, conf);
}
Also used : GeometryType(datawave.data.type.GeometryType) HashMap(java.util.HashMap) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 39 with ShardQueryConfiguration

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

the class ExpandCompositeTermsTest method test14.

@Test
public void test14() throws Exception {
    ShardQueryConfiguration conf = new ShardQueryConfiguration();
    Multimap<String, String> compositeToFieldMap = LinkedListMultimap.create();
    compositeToFieldMap.put("GEO", "GEO");
    compositeToFieldMap.put("GEO", "WKT_BYTE_LENGTH");
    conf.setCompositeToFieldMap(compositeToFieldMap);
    Map<String, String> compositeToSeparatorMap = new HashMap<>();
    compositeToSeparatorMap.put("GEO", ",");
    conf.setCompositeFieldSeparators(compositeToSeparatorMap);
    Set<String> indexedFields = new HashSet<>();
    indexedFields.add("GEO");
    conf.getFieldToDiscreteIndexTypes().put("GEO", new GeometryType());
    String query = "((_Bounded_ = true) && (GEO >= '0100' && GEO <= '0103')) && WKT_BYTE_LENGTH <= '" + Normalizer.NUMBER_NORMALIZER.normalize("12345") + "'";
    String expected = "((_Bounded_ = true) && (GEO >= '0100' && GEO <= '0103,+eE1.2345')) && ((_Eval_ = true) && (((_Bounded_ = true) && (GEO >= '0100' && GEO <= '0103')) && WKT_BYTE_LENGTH <= '+eE1.2345'))";
    runTestQuery(query, expected, indexedFields, conf);
}
Also used : GeometryType(datawave.data.type.GeometryType) HashMap(java.util.HashMap) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 40 with ShardQueryConfiguration

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

the class ExpandCompositeTermsTest method test29.

@Test
public void test29() throws Exception {
    ShardQueryConfiguration conf = new ShardQueryConfiguration();
    Multimap<String, String> compositeToFieldMap = LinkedListMultimap.create();
    compositeToFieldMap.put("GEO", "GEO");
    compositeToFieldMap.put("GEO", "WKT");
    conf.setCompositeToFieldMap(compositeToFieldMap);
    Map<String, String> compositeToSeparatorMap = new HashMap<>();
    compositeToSeparatorMap.put("GEO", ",");
    conf.setCompositeFieldSeparators(compositeToSeparatorMap);
    Set<String> indexedFields = new HashSet<>();
    indexedFields.add("GEO");
    conf.getFieldToDiscreteIndexTypes().put("GEO", new GeometryType());
    String query = "(GEO == '0202' || GEO >= '030a') && WKT == '+bE5.5'";
    String expected = "((WKT == '+bE5.5' && GEO >= '030a') || GEO == '0202,+bE5.5')";
    runTestQuery(query, expected, indexedFields, conf);
}
Also used : GeometryType(datawave.data.type.GeometryType) HashMap(java.util.HashMap) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) HashSet(java.util.HashSet) Test(org.junit.Test)

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