Search in sources :

Example 1 with FieldIndexCountingIterator

use of datawave.query.iterators.FieldIndexCountingIterator in project datawave by NationalSecurityAgency.

the class FieldIndexCountQueryLogic method setupQuery.

/**
 * Create the batch scanner and set the iterator options / stack.
 *
 * @param genericConfig
 *            configuration object
 * @throws Exception
 */
@Override
public void setupQuery(GenericQueryConfiguration genericConfig) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("setupQuery");
    }
    if (!ShardQueryConfiguration.class.isAssignableFrom(genericConfig.getClass())) {
        throw new QueryException("Did not receive a ShardQueryConfiguration instance!!");
    }
    ShardQueryConfiguration config = (ShardQueryConfiguration) genericConfig;
    // Ensure we have all of the information needed to run a query
    if (!config.canRunQuery()) {
        logger.warn("The given query '" + config.getQueryString() + "' could not be run, most likely due to not matching any records in the global index.");
        // Stub out an iterator to correctly present "no results"
        this.iterator = new Iterator<Map.Entry<Key, Value>>() {

            @Override
            public boolean hasNext() {
                return false;
            }

            @Override
            public Map.Entry<Key, Value> next() {
                return null;
            }

            @Override
            public void remove() {
            }
        };
        this.scanner = null;
        return;
    }
    try {
        if (logger.isTraceEnabled()) {
            logger.trace("configuring batch scanner and iterators.");
        }
        BatchScanner bs = getScannerFactory().newScanner(config.getShardTableName(), config.getAuthorizations(), config.getNumQueryThreads(), config.getQuery());
        bs.setRanges(this.ranges);
        // The stack we want to use
        // 21 FieldIndexCountingIterator
        // FieldIndexCountingIterator setup
        IteratorSetting cfg;
        cfg = new IteratorSetting(config.getBaseIteratorPriority() + 21, "countingIter", FieldIndexCountingIterator.class);
        cfg.addOption(FieldIndexCountingIterator.DATA_TYPES, config.getDatatypeFilterAsString());
        cfg.addOption(FieldIndexCountingIterator.FIELD_NAMES, join(this.fieldNames, FieldIndexCountingIterator.SEP));
        if (null != this.fieldValues && !this.fieldValues.isEmpty()) {
            cfg.addOption(FieldIndexCountingIterator.FIELD_VALUES, join(this.fieldValues, FieldIndexCountingIterator.SEP));
        }
        SimpleDateFormat sdf = new SimpleDateFormat(FieldIndexCountingIterator.DATE_FORMAT_STRING);
        cfg.addOption(FieldIndexCountingIterator.START_TIME, sdf.format(config.getBeginDate()));
        cfg.addOption(FieldIndexCountingIterator.STOP_TIME, sdf.format(config.getEndDate()));
        cfg.addOption(FieldIndexCountingIterator.UNIQ_BY_DATA_TYPE, Boolean.toString(this.uniqueByDataType));
        bs.addScanIterator(cfg);
        this.iterator = bs.iterator();
        this.scanner = bs;
    } catch (TableNotFoundException e) {
        logger.error("The table '" + config.getShardTableName() + "' does not exist", e);
    }
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) QueryException(datawave.webservice.query.exception.QueryException) Entry(java.util.Map.Entry) FieldIndexCountingIterator(datawave.query.iterators.FieldIndexCountingIterator) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) BatchScanner(org.apache.accumulo.core.client.BatchScanner) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ShardQueryConfiguration (datawave.query.config.ShardQueryConfiguration)1 FieldIndexCountingIterator (datawave.query.iterators.FieldIndexCountingIterator)1 QueryException (datawave.webservice.query.exception.QueryException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Entry (java.util.Map.Entry)1 BatchScanner (org.apache.accumulo.core.client.BatchScanner)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1