Search in sources :

Example 1 with DefaultQueryPlanner

use of datawave.query.planner.DefaultQueryPlanner in project datawave by NationalSecurityAgency.

the class AnyFieldQueryTest method testRegexPushdownAnyfield.

@Test
public void testRegexPushdownAnyfield() throws Exception {
    String roPhrase = RE_OP + "'ro.*'";
    String anyRo = this.dataManager.convertAnyField(roPhrase);
    String oPhrase = RE_OP + "'.*a'";
    String anyO = this.dataManager.convertAnyField(oPhrase);
    String query = Constants.ANY_FIELD + roPhrase + AND_OP + Constants.ANY_FIELD + oPhrase;
    RegexPushdownTransformRule rule = new RegexPushdownTransformRule();
    rule.setRegexPatterns(Arrays.asList("\\.\\*[0-9a-zA-Z]", "[0-9a-zA-Z]\\.\\*"));
    ((DefaultQueryPlanner) (logic.getQueryPlanner())).setTransformRules(Collections.singletonList(rule));
    // Test the plan with all expansions
    try {
        String plan = getPlan(query, true, true);
        fail("Expected failure for regex pushdown on anyfield");
    } catch (Exception e) {
    // expected
    }
    try {
        String plan = getPlan(query, false, true);
        fail("Expected failure for regex pushdown on anyfield");
    } catch (Exception e) {
    // expected
    }
    try {
        String plan = getPlan(query, true, false);
        fail("Expected failure for regex pushdown on anyfield");
    } catch (Exception e) {
    // expected
    }
    // test running the query
    String expect = anyRo + AND_OP + anyO;
    try {
        runTest(query, expect);
        fail("Expected failure for regex pushdown on anyfield");
    } catch (Exception e) {
    // expected
    }
}
Also used : DefaultQueryPlanner(datawave.query.planner.DefaultQueryPlanner) RegexPushdownTransformRule(datawave.query.planner.rules.RegexPushdownTransformRule) FullTableScansDisallowedException(datawave.query.exceptions.FullTableScansDisallowedException) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) Test(org.junit.Test)

Example 2 with DefaultQueryPlanner

use of datawave.query.planner.DefaultQueryPlanner in project datawave by NationalSecurityAgency.

the class MixedGeoAndGeoWaveTest method getShardQueryLogic.

private ShardQueryLogic getShardQueryLogic() {
    ShardQueryLogic logic = new ShardQueryLogic(this.logic);
    // increase the depth threshold
    logic.setMaxDepthThreshold(20);
    // set the pushdown threshold really high to avoid collapsing uids into shards (overrides setCollapseUids if #terms is greater than this threshold)
    ((DefaultQueryPlanner) (logic.getQueryPlanner())).setPushdownThreshold(1000000);
    URL hdfsSiteConfig = this.getClass().getResource("/testhadoop.config");
    logic.setHdfsSiteConfigURLs(hdfsSiteConfig.toExternalForm());
    setupIvarator(logic);
    return logic;
}
Also used : ShardQueryLogic(datawave.query.tables.ShardQueryLogic) DefaultQueryPlanner(datawave.query.planner.DefaultQueryPlanner) URL(java.net.URL)

Example 3 with DefaultQueryPlanner

use of datawave.query.planner.DefaultQueryPlanner in project datawave by NationalSecurityAgency.

the class ShardQueryLogic method initialize.

public void initialize(ShardQueryConfiguration config, Connector connection, Query settings, Set<Authorizations> auths) throws Exception {
    // Set the connector and the authorizations into the config object
    config.setConnector(connection);
    config.setAuthorizations(auths);
    config.setMaxScannerBatchSize(getMaxScannerBatchSize());
    config.setMaxIndexBatchSize(getMaxIndexBatchSize());
    setScannerFactory(new ScannerFactory(config));
    // load params before parsing jexl string so these can be injected
    loadQueryParameters(config, settings);
    String jexlQueryString = getJexlQueryString(settings);
    if (null == jexlQueryString) {
        throw new IllegalArgumentException("Query cannot be null");
    } else {
        config.setQueryString(jexlQueryString);
    }
    final Date beginDate = settings.getBeginDate();
    if (null == beginDate) {
        throw new IllegalArgumentException("Begin date cannot be null");
    } else {
        config.setBeginDate(beginDate);
    }
    final Date endDate = settings.getEndDate();
    if (null == endDate) {
        throw new IllegalArgumentException("End date cannot be null");
    } else {
        config.setEndDate(endDate);
    }
    MetadataHelper metadataHelper = prepareMetadataHelper(connection, this.getMetadataTableName(), auths, config.isRawTypes());
    DateIndexHelper dateIndexHelper = prepareDateIndexHelper(connection, this.getDateIndexTableName(), auths);
    if (config.isDateIndexTimeTravel()) {
        dateIndexHelper.setTimeTravel(config.isDateIndexTimeTravel());
    }
    QueryPlanner queryPlanner = getQueryPlanner();
    if (queryPlanner instanceof DefaultQueryPlanner) {
        DefaultQueryPlanner currentQueryPlanner = (DefaultQueryPlanner) queryPlanner;
        currentQueryPlanner.setMetadataHelper(metadataHelper);
        currentQueryPlanner.setDateIndexHelper(dateIndexHelper);
        QueryModelProvider queryModelProvider = currentQueryPlanner.getQueryModelProviderFactory().createQueryModelProvider();
        if (queryModelProvider instanceof MetadataHelperQueryModelProvider) {
            ((MetadataHelperQueryModelProvider) queryModelProvider).setMetadataHelper(metadataHelper);
            ((MetadataHelperQueryModelProvider) queryModelProvider).setConfig(config);
        }
        if (null != queryModelProvider.getQueryModel()) {
            queryModel = queryModelProvider.getQueryModel();
        }
    }
    if (this.queryModel == null)
        loadQueryModel(metadataHelper, config);
    getQueryPlanner().setCreateUidsIteratorClass(createUidsIteratorClass);
    getQueryPlanner().setUidIntersector(uidIntersector);
    validateConfiguration(config);
    if (getCardinalityConfiguration() != null && (!config.getBlacklistedFields().isEmpty() || !config.getProjectFields().isEmpty())) {
        // Ensure that fields used for resultCardinalities are returned. They will be removed in the DocumentTransformer.
        // Modify the projectFields and blacklistFields only for this stage, then return to the original values.
        // Not advisable to create a copy of the config object due to the embedded timers.
        Set<String> originalBlacklistedFields = new HashSet<>(config.getBlacklistedFields());
        Set<String> originalProjectFields = new HashSet<>(config.getProjectFields());
        // this will be caught when loadQueryParameters is called
        if (!config.getBlacklistedFields().isEmpty()) {
            config.setBlacklistedFields(getCardinalityConfiguration().getRevisedBlacklistFields(queryModel, originalBlacklistedFields));
        }
        if (!config.getProjectFields().isEmpty()) {
            config.setProjectFields(getCardinalityConfiguration().getRevisedProjectFields(queryModel, originalProjectFields));
        }
        this.queries = getQueryPlanner().process(config, jexlQueryString, settings, this.getScannerFactory());
        config.setBlacklistedFields(originalBlacklistedFields);
        config.setProjectFields(originalProjectFields);
    } else {
        this.queries = getQueryPlanner().process(config, jexlQueryString, settings, this.getScannerFactory());
    }
    TraceStopwatch stopwatch = config.getTimers().newStartedStopwatch("ShardQueryLogic - Get iterator of queries");
    if (this.queries != null) {
        config.setQueries(this.queries.iterator());
    }
    config.setQueryString(getQueryPlanner().getPlannedScript());
    stopwatch.stop();
}
Also used : DefaultQueryPlanner(datawave.query.planner.DefaultQueryPlanner) Date(java.util.Date) QueryPlanner(datawave.query.planner.QueryPlanner) DefaultQueryPlanner(datawave.query.planner.DefaultQueryPlanner) MetadataHelperQueryModelProvider(datawave.query.planner.MetadataHelperQueryModelProvider) QueryModelProvider(datawave.query.planner.QueryModelProvider) MetadataHelper(datawave.query.util.MetadataHelper) TraceStopwatch(datawave.util.time.TraceStopwatch) DateIndexHelper(datawave.query.util.DateIndexHelper) MetadataHelperQueryModelProvider(datawave.query.planner.MetadataHelperQueryModelProvider) HashSet(java.util.HashSet)

Example 4 with DefaultQueryPlanner

use of datawave.query.planner.DefaultQueryPlanner in project datawave by NationalSecurityAgency.

the class ContentFunctionQueryTest method getShardQueryLogic.

private ShardQueryLogic getShardQueryLogic(boolean useIvarator) {
    ShardQueryLogic logic = new ShardQueryLogic(this.logic);
    // increase the depth threshold
    logic.setMaxDepthThreshold(20);
    // set the pushdown threshold really high to avoid collapsing uids into shards (overrides setCollapseUids if #terms is greater than this threshold)
    ((DefaultQueryPlanner) (logic.getQueryPlanner())).setPushdownThreshold(1000000);
    URL hdfsSiteConfig = this.getClass().getResource("/testhadoop.config");
    logic.setHdfsSiteConfigURLs(hdfsSiteConfig.toExternalForm());
    logic.setIvaratorCacheDirConfigs(ivaratorCacheDirConfigs);
    if (useIvarator)
        setupIvarator(logic);
    return logic;
}
Also used : ShardQueryLogic(datawave.query.tables.ShardQueryLogic) DefaultQueryPlanner(datawave.query.planner.DefaultQueryPlanner) URL(java.net.URL)

Example 5 with DefaultQueryPlanner

use of datawave.query.planner.DefaultQueryPlanner in project datawave by NationalSecurityAgency.

the class UseOccurrenceToCountInJexlContextTest method setup.

@Before
public void setup() throws Exception {
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
    logic = new ShardQueryLogic();
    logic.setMetadataTableName(QueryTestTableHelper.METADATA_TABLE_NAME);
    logic.setTableName(TableName.SHARD);
    logic.setIndexTableName(TableName.SHARD_INDEX);
    logic.setReverseIndexTableName(TableName.SHARD_RINDEX);
    logic.setMaxResults(5000);
    logic.setMaxWork(25000);
    logic.setModelTableName(QueryTestTableHelper.METADATA_TABLE_NAME);
    logic.setQueryPlanner(new DefaultQueryPlanner());
    logic.setIncludeGroupingContext(true);
    logic.setMarkingFunctions(new MarkingFunctions.Default());
    logic.setMetadataHelperFactory(new MetadataHelperFactory());
    logic.setDateIndexHelperFactory(new DateIndexHelperFactory());
    logic.setMaxEvaluationPipelines(1);
    deserializer = new KryoDocumentDeserializer();
}
Also used : KryoDocumentDeserializer(datawave.query.function.deserializer.KryoDocumentDeserializer) ShardQueryLogic(datawave.query.tables.ShardQueryLogic) DefaultQueryPlanner(datawave.query.planner.DefaultQueryPlanner) MarkingFunctions(datawave.marking.MarkingFunctions) MetadataHelperFactory(datawave.query.util.MetadataHelperFactory) DateIndexHelperFactory(datawave.query.util.DateIndexHelperFactory) Before(org.junit.Before)

Aggregations

DefaultQueryPlanner (datawave.query.planner.DefaultQueryPlanner)12 ShardQueryLogic (datawave.query.tables.ShardQueryLogic)5 DateIndexHelperFactory (datawave.query.util.DateIndexHelperFactory)4 MetadataHelperFactory (datawave.query.util.MetadataHelperFactory)4 Before (org.junit.Before)4 MarkingFunctions (datawave.marking.MarkingFunctions)3 URL (java.net.URL)3 Test (org.junit.Test)3 KryoDocumentDeserializer (datawave.query.function.deserializer.KryoDocumentDeserializer)2 RegexPushdownTransformRule (datawave.query.planner.rules.RegexPushdownTransformRule)2 DatawavePrincipal (datawave.security.authorization.DatawavePrincipal)2 DatawaveUser (datawave.security.authorization.DatawaveUser)2 SubjectIssuerDNPair (datawave.security.authorization.SubjectIssuerDNPair)2 DefaultResponseObjectFactory (datawave.webservice.query.result.event.DefaultResponseObjectFactory)2 Default (datawave.marking.MarkingFunctions.Default)1 DatawaveFatalQueryException (datawave.query.exceptions.DatawaveFatalQueryException)1 FullTableScansDisallowedException (datawave.query.exceptions.FullTableScansDisallowedException)1 MetadataHelperQueryModelProvider (datawave.query.planner.MetadataHelperQueryModelProvider)1 QueryModelProvider (datawave.query.planner.QueryModelProvider)1 QueryPlanner (datawave.query.planner.QueryPlanner)1