Search in sources :

Example 1 with LuceneToJexlQueryParser

use of datawave.query.language.parser.jexl.LuceneToJexlQueryParser in project datawave by NationalSecurityAgency.

the class GroupingTest method testGroupingUsingLuceneFunction.

@Test
public void testGroupingUsingLuceneFunction() throws Exception {
    Map<String, String> extraParameters = new HashMap<>();
    extraParameters.put("group.fields.batch.size", "6");
    Date startDate = format.parse("20091231");
    Date endDate = format.parse("20150101");
    String queryString = "(UUID:C* or UUID:S* ) and #GROUPBY('AGE','$GENDER')";
    // @formatter:off
    Map<String, Integer> expectedMap = ImmutableMap.<String, Integer>builder().put("FEMALE-18", 2).put("MALE-30", 1).put("MALE-34", 1).put("MALE-16", 1).put("MALE-40", 2).put("MALE-20", 2).put("MALE-24", 1).put("MALE-22", 2).build();
    // @formatter:on
    logic.setParser(new LuceneToJexlQueryParser());
    for (RebuildingScannerTestHelper.TEARDOWN teardown : TEARDOWNS) {
        for (RebuildingScannerTestHelper.INTERRUPT interrupt : INTERRUPTS) {
            runTestQueryWithGrouping(expectedMap, queryString, startDate, endDate, extraParameters, teardown, interrupt);
        }
    }
    logic.setParser(new JexlControlledQueryParser());
}
Also used : HashMap(java.util.HashMap) RebuildingScannerTestHelper(datawave.query.RebuildingScannerTestHelper) LuceneToJexlQueryParser(datawave.query.language.parser.jexl.LuceneToJexlQueryParser) Date(java.util.Date) JexlControlledQueryParser(datawave.query.language.parser.jexl.JexlControlledQueryParser) Test(org.junit.Test)

Example 2 with LuceneToJexlQueryParser

use of datawave.query.language.parser.jexl.LuceneToJexlQueryParser in project datawave by NationalSecurityAgency.

the class CompositeFunctionsTest method testWithLucene.

@Test
public void testWithLucene() throws Exception {
    eventQueryLogic.setParser(new LuceneToJexlQueryParser());
    Map<String, String> extraParameters = new HashMap<>();
    extraParameters.put("include.grouping.context", "true");
    if (log.isDebugEnabled()) {
        log.debug("testWithLucene");
    }
    // @formatter:off
    String[] queryStrings = { // family name starts with 'C'
    "UUID:C*", // family name is SOPRANO
    "UUID:SOPRANO", // family name starts with C or S
    "UUID:C* OR UUID:S* ", // family has child CONSTANZIA
    "(UUID:C* OR UUID:S*) AND #INCLUDE(NAM, 'CONSTANZIA') ", // family has child MICHAEL
    "(UUID:C* OR UUID:S*) AND #INCLUDE(NAM, 'MICHAEL') ", // test LUCENE function to deliver jexl
    "#JEXL(\"$UUID == 'CORLEONE' AND filter:getAllMatches(NAM,'SANTINO').size() == 1\")", "UUID:CORLEONE AND #JEXL(\"filter:getAllMatches(NAM,'SANTINO').size() == 1\")" };
    @SuppressWarnings("unchecked") List<String>[] expectedLists = new List[] { // family name starts with 'C'
    Arrays.asList("CAPONE", "CORLEONE"), // family name is SOPRANO
    Collections.singletonList("SOPRANO"), // family name starts with C or S
    Arrays.asList("SOPRANO", "CORLEONE", "CAPONE"), // family has child CONSTANZIA
    Collections.singletonList("CORLEONE"), // family has child MICHAEL
    Arrays.asList("CORLEONE", "CAPONE"), Collections.singletonList("CORLEONE"), Collections.singletonList("CORLEONE") };
    for (int i = 0; i < queryStrings.length; i++) {
        runTestQuery(expectedLists[i], queryStrings[i], format.parse("20091231"), format.parse("20150101"), extraParameters);
    }
}
Also used : HashMap(java.util.HashMap) List(java.util.List) LuceneToJexlQueryParser(datawave.query.language.parser.jexl.LuceneToJexlQueryParser) Test(org.junit.Test)

Example 3 with LuceneToJexlQueryParser

use of datawave.query.language.parser.jexl.LuceneToJexlQueryParser in project datawave by NationalSecurityAgency.

the class CompositeFunctionsTest method testMatchesAtLeastCountOfWithLucene.

@Test
public void testMatchesAtLeastCountOfWithLucene() throws Exception {
    eventQueryLogic.setParser(new LuceneToJexlQueryParser());
    Map<String, String> extraParameters = new HashMap<>();
    extraParameters.put("include.grouping.context", "true");
    if (log.isDebugEnabled()) {
        log.debug("testMatchesAtLeastCountOfWithLucene");
    }
    String[] queryStrings = { "(UUID:C* OR UUID:S*) AND #MATCHES_AT_LEAST_COUNT_OF('3',NAM,'MICHAEL','VINCENT','FREDO','TONY')" };
    @SuppressWarnings("unchecked") List<String>[] expectedLists = new List[] { Collections.singletonList("CORLEONE") };
    for (int i = 0; i < queryStrings.length; i++) {
        runTestQuery(expectedLists[i], queryStrings[i], format.parse("20091231"), format.parse("20150101"), extraParameters);
    }
}
Also used : HashMap(java.util.HashMap) List(java.util.List) LuceneToJexlQueryParser(datawave.query.language.parser.jexl.LuceneToJexlQueryParser) Test(org.junit.Test)

Example 4 with LuceneToJexlQueryParser

use of datawave.query.language.parser.jexl.LuceneToJexlQueryParser in project datawave by NationalSecurityAgency.

the class CompositeFunctionsTest method testWithLuceneAndOptionsFunction.

@Test
public void testWithLuceneAndOptionsFunction() throws Exception {
    eventQueryLogic.setParser(new LuceneToJexlQueryParser());
    Map<String, String> extraParameters = new HashMap<>();
    if (log.isDebugEnabled()) {
        log.debug("testWithLucene");
    }
    // @formatter:off
    String[] queryStrings = { // family name starts with 'C'
    "UUID:C* AND #OPTIONS('include.grouping.context', 'true')", // family name is SOPRANO
    "UUID:SOPRANO AND #OPTIONS('include.grouping.context', 'true')", // family name starts with C or S
    "UUID:C* OR UUID:S*  AND #OPTIONS('include.grouping.context', 'true')", // family has child CONSTANZIA
    "(UUID:C* OR UUID:S*) AND #INCLUDE(NAM, 'CONSTANZIA')  AND #OPTIONS('include.grouping.context', 'true')", // family has child MICHAEL
    "(UUID:C* OR UUID:S*) AND #INCLUDE(NAM, 'MICHAEL')  AND #OPTIONS('include.grouping.context', 'true')", // test LUCENE function to deliver jexl
    "#JEXL(\"$UUID == 'CORLEONE' AND filter:getAllMatches(NAM,'SANTINO').size() == 1\") AND #OPTIONS('include.grouping.context', 'true')", "UUID:CORLEONE AND #JEXL(\"filter:getAllMatches(NAM,'SANTINO').size() == 1\") AND #OPTIONS('include.grouping.context', 'true')" };
    @SuppressWarnings("unchecked") List<String>[] expectedLists = new List[] { // family name starts with 'C'
    Arrays.asList("CAPONE", "CORLEONE"), // family name is SOPRANO
    Collections.singletonList("SOPRANO"), // family name starts with C or S
    Arrays.asList("SOPRANO", "CORLEONE", "CAPONE"), // family has child CONSTANZIA
    Collections.singletonList("CORLEONE"), // family has child MICHAEL
    Arrays.asList("CORLEONE", "CAPONE"), Collections.singletonList("CORLEONE"), Collections.singletonList("CORLEONE") };
    // @formatter:on
    for (int i = 0; i < queryStrings.length; i++) {
        runTestQuery(expectedLists[i], queryStrings[i], format.parse("20091231"), format.parse("20150101"), extraParameters);
    }
}
Also used : HashMap(java.util.HashMap) List(java.util.List) LuceneToJexlQueryParser(datawave.query.language.parser.jexl.LuceneToJexlQueryParser) Test(org.junit.Test)

Example 5 with LuceneToJexlQueryParser

use of datawave.query.language.parser.jexl.LuceneToJexlQueryParser in project datawave by NationalSecurityAgency.

the class CompositeFunctionsTest method testDateDelta.

@Test
public void testDateDelta() throws Exception {
    Map<String, String> extraParameters = new HashMap<>();
    extraParameters.put("include.grouping.context", "true");
    extraParameters.put("hit.list", "true");
    if (log.isDebugEnabled()) {
        log.debug("testDateDelta");
    }
    // @formatter:off
    String[] queryStrings = { // 80+ years
    "UUID =~ '^[CS].*' AND filter:getMaxTime(DEATH_DATE) - filter:getMinTime(BIRTH_DATE) > 2522880000000L", // 60+ years
    "UUID =~ '^[CS].*' AND filter:getMaxTime(DEATH_DATE) - filter:getMinTime(BIRTH_DATE) > 1892160000000L", // 80+ years
    "UUID =~ '^[CS].*' AND filter:timeFunction(DEATH_DATE,BIRTH_DATE,'-','>',2522880000000L)", "(UUID:C* OR UUID:S*) AND #TIME_FUNCTION(DEATH_DATE,BIRTH_DATE,'-','>','2522880000000L')" };
    // timeFunction(Object time1, Object time2, String operatorString, String equalityString, long goal)
    @SuppressWarnings("unchecked") List<String>[] expectedLists = new List[] { Collections.singletonList("CAPONE"), Arrays.asList("CORLEONE", "CAPONE"), Collections.singletonList("CAPONE"), Collections.singletonList("CAPONE") };
    for (int i = 0; i < queryStrings.length; i++) {
        if (i == 3) {
            eventQueryLogic.setParser(new LuceneToJexlQueryParser());
        }
        runTestQuery(expectedLists[i], queryStrings[i], format.parse("20091231"), format.parse("20150101"), extraParameters);
    }
}
Also used : HashMap(java.util.HashMap) List(java.util.List) LuceneToJexlQueryParser(datawave.query.language.parser.jexl.LuceneToJexlQueryParser) Test(org.junit.Test)

Aggregations

LuceneToJexlQueryParser (datawave.query.language.parser.jexl.LuceneToJexlQueryParser)21 Test (org.junit.Test)17 HashMap (java.util.HashMap)11 List (java.util.List)7 Date (java.util.Date)5 RebuildingScannerTestHelper (datawave.query.RebuildingScannerTestHelper)3 JexlControlledQueryParser (datawave.query.language.parser.jexl.JexlControlledQueryParser)3 QueryNode (datawave.query.language.tree.QueryNode)3 Type (datawave.data.type.Type)2 ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)2 Stopwatch (com.google.common.base.Stopwatch)1 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 ShardIndexQueryConfiguration (datawave.query.config.ShardIndexQueryConfiguration)1 QueryValues (datawave.query.discovery.FindLiteralsAndPatternsVisitor.QueryValues)1 EmptyUnfieldedTermExpansionException (datawave.query.exceptions.EmptyUnfieldedTermExpansionException)1 ShardIndexQueryTableStaticMethods (datawave.query.jexl.lookups.ShardIndexQueryTableStaticMethods)1 EvaluationOnly (datawave.query.language.functions.jexl.EvaluationOnly)1 JexlQueryFunction (datawave.query.language.functions.jexl.JexlQueryFunction)1 QueryParser (datawave.query.language.parser.QueryParser)1