Search in sources :

Example 1 with QueryModelProvider

use of datawave.query.planner.QueryModelProvider 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)

Aggregations

DefaultQueryPlanner (datawave.query.planner.DefaultQueryPlanner)1 MetadataHelperQueryModelProvider (datawave.query.planner.MetadataHelperQueryModelProvider)1 QueryModelProvider (datawave.query.planner.QueryModelProvider)1 QueryPlanner (datawave.query.planner.QueryPlanner)1 DateIndexHelper (datawave.query.util.DateIndexHelper)1 MetadataHelper (datawave.query.util.MetadataHelper)1 TraceStopwatch (datawave.util.time.TraceStopwatch)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1