Search in sources :

Example 21 with QueryImpl

use of datawave.webservice.query.QueryImpl in project datawave by NationalSecurityAgency.

the class CompositeQueryLogicTest method testInitializeWithDifferentResponseTypes.

@Test
public void testInitializeWithDifferentResponseTypes() throws Exception {
    List<BaseQueryLogic<?>> logics = new ArrayList<>();
    logics.add(new TestQueryLogic());
    logics.add(new DifferentTestQueryLogic());
    QueryImpl settings = new QueryImpl();
    settings.setPagesize(100);
    settings.setQueryAuthorizations(auths.toString());
    settings.setQuery("FOO == 'BAR'");
    settings.setParameters(new HashSet<>());
    settings.setId(UUID.randomUUID());
    CompositeQueryLogic c = new CompositeQueryLogic();
    c.setQueryLogics(logics);
    c.initialize((Connector) null, (Query) settings, Collections.singleton(auths));
}
Also used : QueryImpl(datawave.webservice.query.QueryImpl) ArrayList(java.util.ArrayList) BaseQueryLogic(datawave.webservice.query.logic.BaseQueryLogic) Test(org.junit.Test)

Example 22 with QueryImpl

use of datawave.webservice.query.QueryImpl in project datawave by NationalSecurityAgency.

the class CompositeQueryLogicTest method testInitialize.

@Test
public void testInitialize() throws Exception {
    List<BaseQueryLogic<?>> logics = new ArrayList<>();
    logics.add(new TestQueryLogic());
    logics.add(new TestQueryLogic2());
    QueryImpl settings = new QueryImpl();
    settings.setPagesize(100);
    settings.setQueryAuthorizations(auths.toString());
    settings.setQuery("FOO == 'BAR'");
    settings.setParameters(new HashSet<>());
    settings.setId(UUID.randomUUID());
    CompositeQueryLogic c = new CompositeQueryLogic();
    c.setQueryLogics(logics);
    c.initialize((Connector) null, (Query) settings, Collections.singleton(auths));
}
Also used : QueryImpl(datawave.webservice.query.QueryImpl) ArrayList(java.util.ArrayList) BaseQueryLogic(datawave.webservice.query.logic.BaseQueryLogic) Test(org.junit.Test)

Example 23 with QueryImpl

use of datawave.webservice.query.QueryImpl in project datawave by NationalSecurityAgency.

the class CompositeQueryLogicTest method testQueryLogicWithMaxResultsOverride.

@Test
public // testQueryLogic with max.results.override is set
void testQueryLogicWithMaxResultsOverride() throws Exception {
    Logger.getLogger(CompositeQueryLogic.class).setLevel(Level.TRACE);
    Logger.getLogger(CompositeQueryLogicResults.class).setLevel(Level.TRACE);
    Logger.getLogger(CompositeQueryLogicTransformer.class).setLevel(Level.TRACE);
    List<BaseQueryLogic<?>> logics = new ArrayList<>();
    TestQueryLogic logic1 = new TestQueryLogic();
    TestQueryLogic2 logic2 = new TestQueryLogic2();
    logics.add(logic1);
    logics.add(logic2);
    logic1.getData().put(key1, value1);
    logic1.getData().put(key2, value2);
    logic2.getData().put(key3, value3);
    logic2.getData().put(key4, value4);
    logic1.getData().put(key5, value5);
    logic1.getData().put(key6, value6);
    logic2.getData().put(key7, value7);
    logic2.getData().put(key8, value8);
    QueryImpl settings = new QueryImpl();
    settings.setPagesize(100);
    settings.setQueryAuthorizations(auths.toString());
    settings.setQuery("FOO == 'BAR'");
    settings.setParameters(new HashSet<>());
    settings.setId(UUID.randomUUID());
    CompositeQueryLogic c = new CompositeQueryLogic();
    // max.results.override is set to -1 when it is not passed in as it is an optional parameter
    logic1.setMaxResults(0);
    logic2.setMaxResults(4);
    /**
     * RunningQuery.setupConnection()
     */
    c.setQueryLogics(logics);
    c.initialize((Connector) null, (Query) settings, Collections.singleton(auths));
    c.setupQuery(null);
    TransformIterator iter = c.getTransformIterator((Query) settings);
    /**
     * RunningQuery.next() - iterate over results coming from tablet server through the TransformIterator to turn them into the objects.
     */
    List<Object> results = new ArrayList<>();
    while (iter.hasNext()) {
        Object o = iter.next();
        if (null == o)
            break;
        Assert.assertTrue(o instanceof TestQueryResponse);
        results.add((TestQueryResponse) o);
    }
    Assert.assertEquals(4, results.size());
    ResultsPage page = new ResultsPage(results, Status.COMPLETE);
    /**
     * QueryExecutorBean.next() - transform list of objects into JAXB response
     */
    TestQueryResponseList response = (TestQueryResponseList) c.getTransformer((Query) settings).createResponse(page);
    Assert.assertEquals(4, response.getResponses().size());
    for (TestQueryResponse r : response.getResponses()) {
        Assert.assertNotNull(r);
    }
    c.close();
}
Also used : TransformIterator(org.apache.commons.collections4.iterators.TransformIterator) ArrayList(java.util.ArrayList) ResultsPage(datawave.webservice.query.cache.ResultsPage) QueryImpl(datawave.webservice.query.QueryImpl) BaseQueryLogic(datawave.webservice.query.logic.BaseQueryLogic) Test(org.junit.Test)

Example 24 with QueryImpl

use of datawave.webservice.query.QueryImpl in project datawave by NationalSecurityAgency.

the class CompositeQueryLogicTest method testQueryLogicNoDataLogic1.

@Test
public void testQueryLogicNoDataLogic1() throws Exception {
    List<BaseQueryLogic<?>> logics = new ArrayList<>();
    TestQueryLogic logic1 = new TestQueryLogic();
    TestQueryLogic2 logic2 = new TestQueryLogic2();
    logics.add(logic1);
    logics.add(logic2);
    logic2.getData().put(key1, value1);
    logic2.getData().put(key2, value2);
    logic2.getData().put(key3, value3);
    logic2.getData().put(key4, value4);
    logic2.getData().put(key5, value5);
    logic2.getData().put(key6, value6);
    logic2.getData().put(key7, value7);
    logic2.getData().put(key8, value8);
    QueryImpl settings = new QueryImpl();
    settings.setPagesize(100);
    settings.setQueryAuthorizations(auths.serialize());
    settings.setQuery("FOO == 'BAR'");
    settings.setParameters(new HashSet<>());
    settings.setId(UUID.randomUUID());
    CompositeQueryLogic c = new CompositeQueryLogic();
    // max.results.override is set to -1 when it is not passed in as it is an optional paramter
    logic2.setMaxResults(-1);
    logic1.setMaxResults(-1);
    /**
     * RunningQuery.setupConnection()
     */
    c.setQueryLogics(logics);
    c.initialize((Connector) null, (Query) settings, Collections.singleton(auths));
    c.setupQuery(null);
    TransformIterator iter = c.getTransformIterator((Query) settings);
    /**
     * RunningQuery.next() - iterate over results coming from tablet server through the TransformIterator to turn them into the objects.
     */
    List<Object> results = new ArrayList<>();
    while (iter.hasNext()) {
        Object o = iter.next();
        if (null == o)
            break;
        Assert.assertTrue(o instanceof TestQueryResponse);
        results.add((TestQueryResponse) o);
    }
    Assert.assertEquals(8, results.size());
    ResultsPage page = new ResultsPage(results, Status.COMPLETE);
    /**
     * QueryExecutorBean.next() - transform list of objects into JAXB response
     */
    TestQueryResponseList response = (TestQueryResponseList) c.getTransformer((Query) settings).createResponse(page);
    Assert.assertEquals(8, response.getResponses().size());
    for (TestQueryResponse r : response.getResponses()) {
        Assert.assertNotNull(r);
    }
    c.close();
}
Also used : TransformIterator(org.apache.commons.collections4.iterators.TransformIterator) ArrayList(java.util.ArrayList) ResultsPage(datawave.webservice.query.cache.ResultsPage) QueryImpl(datawave.webservice.query.QueryImpl) BaseQueryLogic(datawave.webservice.query.logic.BaseQueryLogic) Test(org.junit.Test)

Example 25 with QueryImpl

use of datawave.webservice.query.QueryImpl in project datawave by NationalSecurityAgency.

the class ShardQueryConfigurationTest method testDeepCopyConstructor.

/**
 * Test that for a given set of collections, stored in a ShardQueryConfiguration, will in fact be deep-copied into a new ShardQueryConfiguration object.
 */
@Test
public void testDeepCopyConstructor() {
    // Instantiate a 'other' ShardQueryConfiguration
    ShardQueryConfiguration other = ShardQueryConfiguration.create();
    // Setup collections for deep copy
    List<String> realmSuffixExclusionPatterns = Lists.newArrayList("somePattern");
    SimpleDateFormat shardDateFormatter = new SimpleDateFormat("yyyyMMdd");
    List<String> enricherClassNames = Lists.newArrayList("enricherClassNameA");
    List<String> filterClassNames = Lists.newArrayList("filterClassNameA");
    List<String> indexFilteringClassNames = Lists.newArrayList("indexFilteringClassNameA");
    Set<String> nonEventKeyPrefixes = Sets.newHashSet("nonEventKeyPrefixA");
    Set<String> unevaluatedFields = Sets.newHashSet("unevaluatedFieldA");
    Set<String> dataTypeFilter = Sets.newHashSet("dataTypeFilterA");
    IndexHole indexHole = new IndexHole(new String[] { "0", "1" }, new String[] { "2", "3" });
    List<IndexHole> indexHoles = Lists.newArrayList(indexHole);
    Set<String> projectFields = Sets.newHashSet("projectFieldA");
    Set<String> blacklistedFields = Sets.newHashSet("blacklistedFieldA");
    Set<String> indexedFields = Sets.newHashSet("indexedFieldA");
    Set<String> normalizedFields = Sets.newHashSet("normalizedFieldA");
    Multimap<String, Type<?>> dataTypes = HashMultimap.create();
    dataTypes.put("K001", new NoOpType("V"));
    Multimap<String, Type<?>> queryFieldsDatatypes = HashMultimap.create();
    queryFieldsDatatypes.put("K002", new NoOpType("V"));
    Multimap<String, Type<?>> normalizedFieldsDatatypes = HashMultimap.create();
    normalizedFieldsDatatypes.put("K003", new NoOpType("V"));
    Multimap<String, String> compositeToFieldMap = HashMultimap.create();
    compositeToFieldMap.put("K004", "V");
    Map<String, DiscreteIndexType<?>> fieldToDiscreteIndexType = Maps.newHashMap();
    fieldToDiscreteIndexType.put("GEO", new GeometryType());
    Map<String, Date> compositeTransitionDates = Maps.newHashMap();
    Date transitionDate = new Date();
    compositeTransitionDates.put("K005", transitionDate);
    Map<String, String> compositeFieldSeparators = Maps.newHashMap();
    compositeFieldSeparators.put("GEO", " ");
    Set<String> queryTermFrequencyFields = Sets.newHashSet("fieldA");
    Set<String> limitFields = Sets.newHashSet("limitFieldA");
    Map<String, String> hierarchyFieldOptions = Maps.newHashMap();
    hierarchyFieldOptions.put("K006", "V");
    List<String> documentPermutations = Lists.newArrayList(DocumentPermutation.class.getName());
    QueryModel queryModel = new QueryModel();
    QueryImpl query = new QueryImpl();
    Set<String> groupFields = Sets.newHashSet("groupFieldA");
    UniqueFields uniqueFields = new UniqueFields();
    uniqueFields.put("uniqueFieldA", UniqueGranularity.ALL);
    List<String> contentFieldNames = Lists.newArrayList("fieldA");
    Set<String> noExpansionFields = Sets.newHashSet("NoExpansionFieldA");
    Set<String> disallowedRegexPatterns = Sets.newHashSet(".*", ".*?");
    // Set collections on 'other' ShardQueryConfiguration
    other.setRealmSuffixExclusionPatterns(realmSuffixExclusionPatterns);
    other.setShardDateFormatter(shardDateFormatter);
    other.setEnricherClassNames(enricherClassNames);
    other.setFilterClassNames(filterClassNames);
    other.setIndexFilteringClassNames(indexFilteringClassNames);
    other.setNonEventKeyPrefixes(nonEventKeyPrefixes);
    other.setUnevaluatedFields(unevaluatedFields);
    other.setDatatypeFilter(dataTypeFilter);
    other.setIndexHoles(indexHoles);
    other.setProjectFields(projectFields);
    other.setBlacklistedFields(blacklistedFields);
    other.setIndexedFields(indexedFields);
    other.setNormalizedFields(normalizedFields);
    other.setDataTypes(dataTypes);
    other.setQueryFieldsDatatypes(queryFieldsDatatypes);
    other.setNormalizedFieldsDatatypes(normalizedFieldsDatatypes);
    other.setCompositeToFieldMap(compositeToFieldMap);
    other.setFieldToDiscreteIndexTypes(fieldToDiscreteIndexType);
    other.setCompositeTransitionDates(compositeTransitionDates);
    other.setCompositeFieldSeparators(compositeFieldSeparators);
    other.setQueryTermFrequencyFields(queryTermFrequencyFields);
    other.setLimitFields(limitFields);
    other.setHierarchyFieldOptions(hierarchyFieldOptions);
    other.setDocumentPermutations(documentPermutations);
    other.setQueryModel(queryModel);
    other.setQuery(query);
    other.setGroupFields(groupFields);
    other.setUniqueFields(uniqueFields);
    other.setContentFieldNames(contentFieldNames);
    other.setNoExpansionFields(noExpansionFields);
    other.setDisallowedRegexPatterns(disallowedRegexPatterns);
    // Copy 'other' ShardQueryConfiguration into a new config
    ShardQueryConfiguration config = ShardQueryConfiguration.create(other);
    // Modify original collections
    realmSuffixExclusionPatterns.add("anotherPattern");
    shardDateFormatter = new SimpleDateFormat("yyyyMMdd-mm:SS");
    enricherClassNames.add("enricherClassNameB");
    filterClassNames.add("filterClassNameB");
    indexFilteringClassNames.add("indexFilteringClassNameB");
    nonEventKeyPrefixes.add("nonEventKeyPrefixB");
    unevaluatedFields.add("unevaluatedFieldB");
    dataTypeFilter.add("dataTypeFilterB");
    IndexHole otherIndexHole = new IndexHole(new String[] { "4", "5" }, new String[] { "6", "7" });
    indexHoles.add(otherIndexHole);
    projectFields.add("projectFieldB");
    blacklistedFields.add("blacklistedFieldB");
    indexedFields.add("indexedFieldB");
    normalizedFields.add("normalizedFieldB");
    dataTypes.put("K2", new NoOpType("V2"));
    queryFieldsDatatypes.put("K", new NoOpType("V2"));
    normalizedFieldsDatatypes.put("K2", new NoOpType("V2"));
    compositeToFieldMap.put("K2", "V2");
    queryTermFrequencyFields.add("fieldB");
    limitFields.add("limitFieldB");
    hierarchyFieldOptions.put("K2", "V2");
    documentPermutations.add(DocumentProjection.class.getName());
    queryModel.addTermToModel("aliasA", "diskNameA");
    query.setId(UUID.randomUUID());
    groupFields.add("groupFieldB");
    uniqueFields.put("uniqueFieldB", UniqueGranularity.ALL);
    contentFieldNames.add("fieldB");
    disallowedRegexPatterns.add("blah");
    // Assert that copied collections were deep copied and remain unchanged
    Assert.assertEquals(Lists.newArrayList("somePattern"), config.getRealmSuffixExclusionPatterns());
    Assert.assertEquals(new SimpleDateFormat("yyyyMMdd"), config.getShardDateFormatter());
    Assert.assertEquals(Lists.newArrayList("enricherClassNameA"), config.getEnricherClassNames());
    Assert.assertEquals(Lists.newArrayList("filterClassNameA"), config.getFilterClassNames());
    Assert.assertEquals(Lists.newArrayList("indexFilteringClassNameA"), config.getIndexFilteringClassNames());
    Assert.assertEquals(Sets.newHashSet("nonEventKeyPrefixA"), config.getNonEventKeyPrefixes());
    Assert.assertEquals(Sets.newHashSet("unevaluatedFieldA"), config.getUnevaluatedFields());
    Assert.assertEquals(Sets.newHashSet("dataTypeFilterA"), config.getDatatypeFilter());
    IndexHole expectedIndexHole = new IndexHole(new String[] { "0", "1" }, new String[] { "2", "3" });
    Assert.assertEquals(Lists.newArrayList(expectedIndexHole), config.getIndexHoles());
    Assert.assertEquals(Sets.newHashSet("projectFieldA"), config.getProjectFields());
    Assert.assertEquals(Sets.newHashSet("blacklistedFieldA"), config.getBlacklistedFields());
    Assert.assertEquals(Sets.newHashSet("indexedFieldA"), config.getIndexedFields());
    // This assert is different from the setter as setNormalizedFieldsAsDatatypes will overwrite the normalizedFields with
    // a new keyset.
    Assert.assertEquals(Sets.newHashSet("K003"), config.getNormalizedFields());
    Multimap<String, Type<?>> expectedDataTypes = HashMultimap.create();
    expectedDataTypes.put("K001", new NoOpType("V"));
    Assert.assertEquals(expectedDataTypes, config.getDataTypes());
    Multimap<String, Type<?>> expectedQueryFieldsDatatypes = HashMultimap.create();
    expectedQueryFieldsDatatypes.put("K002", new NoOpType("V"));
    Assert.assertEquals(expectedQueryFieldsDatatypes, config.getQueryFieldsDatatypes());
    Multimap<String, Type<?>> expectedNormalizedFieldsDatatypes = HashMultimap.create();
    expectedNormalizedFieldsDatatypes.put("K003", new NoOpType("V"));
    Assert.assertEquals(expectedNormalizedFieldsDatatypes, config.getNormalizedFieldsDatatypes());
    Multimap<String, String> expectedCompositeToFieldMap = ArrayListMultimap.create();
    expectedCompositeToFieldMap.put("K004", "V");
    Assert.assertEquals(expectedCompositeToFieldMap, config.getCompositeToFieldMap());
    Map<String, DiscreteIndexType<?>> expectedFieldToDiscreteIndexType = Maps.newHashMap();
    expectedFieldToDiscreteIndexType.put("GEO", new GeometryType());
    Assert.assertEquals(expectedFieldToDiscreteIndexType, config.getFieldToDiscreteIndexTypes());
    Map<String, Date> expectedCompositeTransitionDates = Maps.newHashMap();
    expectedCompositeTransitionDates.put("K005", transitionDate);
    Assert.assertEquals(expectedCompositeTransitionDates, config.getCompositeTransitionDates());
    Map<String, String> expectedCompositeFieldSeparators = Maps.newHashMap();
    expectedCompositeFieldSeparators.put("GEO", " ");
    Assert.assertEquals(expectedCompositeFieldSeparators, config.getCompositeFieldSeparators());
    Assert.assertEquals(Sets.newHashSet("fieldA"), config.getQueryTermFrequencyFields());
    Assert.assertEquals(Sets.newHashSet("limitFieldA"), config.getLimitFields());
    Map<String, String> expectedHierarchyFieldOptions = Maps.newHashMap();
    expectedHierarchyFieldOptions.put("K006", "V");
    Assert.assertEquals(expectedHierarchyFieldOptions, config.getHierarchyFieldOptions());
    Assert.assertEquals(Lists.newArrayList(DocumentPermutation.class.getName()), config.getDocumentPermutations());
    QueryModel expectedQueryModel = new QueryModel();
    Assert.assertEquals(expectedQueryModel.getForwardQueryMapping(), config.getQueryModel().getForwardQueryMapping());
    Assert.assertEquals(expectedQueryModel.getReverseQueryMapping(), config.getQueryModel().getReverseQueryMapping());
    Assert.assertEquals(expectedQueryModel.getUnevaluatedFields(), config.getQueryModel().getUnevaluatedFields());
    Assert.assertEquals(Sets.newHashSet(".*", ".*?"), config.getDisallowedRegexPatterns());
    // Account for QueryImpl.duplicate() generating a random UUID on the duplicate
    QueryImpl expectedQuery = new QueryImpl();
    expectedQuery.setId(config.getQuery().getId());
    Assert.assertEquals(expectedQuery, config.getQuery());
    Assert.assertEquals(Sets.newHashSet("groupFieldA"), config.getGroupFields());
    UniqueFields expectedUniqueFields = new UniqueFields();
    expectedUniqueFields.put("uniqueFieldA", UniqueGranularity.ALL);
    Assert.assertEquals(expectedUniqueFields, config.getUniqueFields());
    Assert.assertEquals(Lists.newArrayList("fieldA"), config.getContentFieldNames());
    Assert.assertEquals(Sets.newHashSet("NoExpansionFieldA"), config.getNoExpansionFields());
}
Also used : NoOpType(datawave.data.type.NoOpType) QueryModel(datawave.query.model.QueryModel) Date(java.util.Date) DiscreteIndexType(datawave.data.type.DiscreteIndexType) GeometryType(datawave.data.type.GeometryType) DocumentPermutation(datawave.query.function.DocumentPermutation) NoOpType(datawave.data.type.NoOpType) StringType(datawave.data.type.StringType) GeometryType(datawave.data.type.GeometryType) DiscreteIndexType(datawave.data.type.DiscreteIndexType) Type(datawave.data.type.Type) DateType(datawave.data.type.DateType) QueryImpl(datawave.webservice.query.QueryImpl) UniqueFields(datawave.query.attributes.UniqueFields) SimpleDateFormat(java.text.SimpleDateFormat) DocumentProjection(datawave.query.function.DocumentProjection) Test(org.junit.Test)

Aggregations

QueryImpl (datawave.webservice.query.QueryImpl)131 Test (org.junit.Test)96 ArrayList (java.util.ArrayList)54 Query (datawave.webservice.query.Query)40 HashSet (java.util.HashSet)27 BaseQueryLogic (datawave.webservice.query.logic.BaseQueryLogic)18 GenericQueryConfiguration (datawave.webservice.query.configuration.GenericQueryConfiguration)16 Date (java.util.Date)16 QueryParametersImpl (datawave.webservice.query.QueryParametersImpl)14 MultivaluedMapImpl (org.jboss.resteasy.specimpl.MultivaluedMapImpl)13 QueryMetricFactoryImpl (datawave.microservice.querymetric.QueryMetricFactoryImpl)12 QueryParameters (datawave.webservice.query.QueryParameters)12 Value (org.apache.accumulo.core.data.Value)10 Document (datawave.query.attributes.Document)9 ShardQueryConfiguration (datawave.query.config.ShardQueryConfiguration)9 EdgeQueryFunctionalTest (datawave.query.tables.edge.EdgeQueryFunctionalTest)9 QueryLogic (datawave.webservice.query.logic.QueryLogic)9 HashMap (java.util.HashMap)9 Key (org.apache.accumulo.core.data.Key)9 Authorizations (org.apache.accumulo.core.security.Authorizations)9