Search in sources :

Example 1 with EdgeQueryConfiguration

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

the class EdgeQueryLogic method initialize.

@Override
public GenericQueryConfiguration initialize(Connector connection, Query settings, Set<Authorizations> auths) throws Exception {
    currentIteratorPriority = super.getBaseIteratorPriority() + 30;
    EdgeQueryConfiguration cfg = setUpConfig(settings);
    cfg.setConnector(connection);
    cfg.setAuthorizations(auths);
    String queryString = settings.getQuery();
    if (null == queryString) {
        throw new IllegalArgumentException("Query cannot be null");
    } else {
        cfg.setQueryString(queryString);
    }
    cfg.setBeginDate(settings.getBeginDate());
    cfg.setEndDate(settings.getEndDate());
    scannerFactory = new ScannerFactory(connection);
    return cfg;
}
Also used : ScannerFactory(datawave.query.tables.ScannerFactory) EdgeQueryConfiguration(datawave.query.config.EdgeQueryConfiguration)

Example 2 with EdgeQueryConfiguration

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

the class EdgeQueryLogic method setupQuery.

@Override
public void setupQuery(GenericQueryConfiguration configuration) throws Exception {
    config = (EdgeQueryConfiguration) configuration;
    prefilterValues = null;
    EdgeQueryConfiguration.dateType dateFilterType = ((EdgeQueryConfiguration) configuration).getDateRangeType();
    log.debug("Performing edge table query: " + config.getQueryString());
    boolean includeStats = ((EdgeQueryConfiguration) configuration).includeStats();
    String queryString = config.getQueryString();
    String normalizedQuery = null;
    String statsNormalizedQuery = null;
    queryString = fixQueryString(queryString);
    QueryData qData = configureRanges(queryString);
    setRanges(qData.getRanges());
    VisitationContext context = null;
    try {
        context = normalizeJexlQuery(queryString, false);
        normalizedQuery = context.getNormalizedQuery().toString();
        statsNormalizedQuery = context.getNormalizedStatsQuery().toString();
        log.debug("Jexl after normalizing SOURCE and SINK: " + normalizedQuery);
    } catch (JexlException ex) {
        log.error("Error parsing user query.", ex);
    }
    if ((null == normalizedQuery || normalizedQuery.equals("")) && qData.getRanges().size() < 1) {
        throw new IllegalStateException("Query string is empty after initial processing, no ranges or filters can be generated to execute.");
    }
    addIterators(qData, getDateBasedIterators(config.getBeginDate(), config.getEndDate(), currentIteratorPriority, dateFilterSkipLimit, dateFilterScanLimit, dateFilterType));
    if (!normalizedQuery.equals("")) {
        log.debug("Query being sent to the filter iterator: " + normalizedQuery);
        IteratorSetting edgeIteratorSetting = new IteratorSetting(currentIteratorPriority, EdgeFilterIterator.class.getSimpleName() + "_" + currentIteratorPriority, EdgeFilterIterator.class);
        edgeIteratorSetting.addOption(EdgeFilterIterator.JEXL_OPTION, normalizedQuery);
        edgeIteratorSetting.addOption(EdgeFilterIterator.PROTOBUF_OPTION, "TRUE");
        if (!statsNormalizedQuery.equals("")) {
            edgeIteratorSetting.addOption(EdgeFilterIterator.JEXL_STATS_OPTION, statsNormalizedQuery);
        }
        if (prefilterValues != null) {
            String value = serializePrefilter();
            edgeIteratorSetting.addOption(EdgeFilterIterator.PREFILTER_WHITELIST, value);
        }
        if (includeStats) {
            edgeIteratorSetting.addOption(EdgeFilterIterator.INCLUDE_STATS_OPTION, "TRUE");
        } else {
            edgeIteratorSetting.addOption(EdgeFilterIterator.INCLUDE_STATS_OPTION, "FALSE");
        }
        addIterator(qData, edgeIteratorSetting);
    }
    log.debug("Configuring connection: tableName: " + config.getTableName() + ", auths: " + config.getAuthorizations());
    BatchScanner scanner = createBatchScanner(config);
    log.debug("Using the following ranges: " + qData.getRanges());
    if (context != null && context.isHasAllCompleteColumnFamilies()) {
        for (Text columnFamily : context.getColumnFamilies()) {
            scanner.fetchColumnFamily(columnFamily);
        }
    }
    scanner.setRanges(qData.getRanges());
    addCustomFilters(qData, currentIteratorPriority);
    for (IteratorSetting setting : qData.getSettings()) {
        scanner.addScanIterator(setting);
    }
    this.scanner = scanner;
    iterator = scanner.iterator();
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) QueryData(datawave.webservice.query.configuration.QueryData) JexlException(org.apache.commons.jexl2.JexlException) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Text(org.apache.hadoop.io.Text) VisitationContext(datawave.query.tables.edge.contexts.VisitationContext) EdgeQueryConfiguration(datawave.query.config.EdgeQueryConfiguration) EdgeFilterIterator(datawave.query.iterator.filter.EdgeFilterIterator)

Aggregations

EdgeQueryConfiguration (datawave.query.config.EdgeQueryConfiguration)2 EdgeFilterIterator (datawave.query.iterator.filter.EdgeFilterIterator)1 ScannerFactory (datawave.query.tables.ScannerFactory)1 VisitationContext (datawave.query.tables.edge.contexts.VisitationContext)1 QueryData (datawave.webservice.query.configuration.QueryData)1 BatchScanner (org.apache.accumulo.core.client.BatchScanner)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 JexlException (org.apache.commons.jexl2.JexlException)1 Text (org.apache.hadoop.io.Text)1