Search in sources :

Example 1 with IllegalRangeArgumentException

use of datawave.query.exceptions.IllegalRangeArgumentException in project datawave by NationalSecurityAgency.

the class ShardIndexQueryTableStaticMethods method getBoundedRangeRange.

/**
 * Get the accumulo range for a literal query range. Note that it is assumed that the column family set will include the fieldname.
 *
 * @param literalRange
 * @return
 * @throws IllegalRangeArgumentException
 */
public static Range getBoundedRangeRange(LiteralRange<?> literalRange) throws IllegalRangeArgumentException {
    String lower = literalRange.getLower().toString(), upper = literalRange.getUpper().toString();
    Key startKey = new Key(new Text(lower));
    Key endKey = new Key(new Text(literalRange.isUpperInclusive() ? upper + Constants.MAX_UNICODE_STRING : upper));
    Range range = null;
    try {
        range = new Range(startKey, literalRange.isLowerInclusive(), endKey, literalRange.isUpperInclusive());
    } catch (IllegalArgumentException e) {
        QueryException qe = new QueryException(DatawaveErrorCode.RANGE_CREATE_ERROR, e, MessageFormat.format("{0}", literalRange));
        log.debug(qe);
        throw new IllegalRangeArgumentException(qe);
    }
    return range;
}
Also used : DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) DoNotPerformOptimizedQueryException(datawave.query.exceptions.DoNotPerformOptimizedQueryException) QueryException(datawave.webservice.query.exception.QueryException) Text(org.apache.hadoop.io.Text) LongRange(org.apache.commons.lang.math.LongRange) LiteralRange(datawave.query.jexl.LiteralRange) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey) IllegalRangeArgumentException(datawave.query.exceptions.IllegalRangeArgumentException)

Example 2 with IllegalRangeArgumentException

use of datawave.query.exceptions.IllegalRangeArgumentException in project datawave by NationalSecurityAgency.

the class DiscoveryLogic method makeRanges.

/**
 * Makes two collections of ranges: one for the forward index (value0) and one for the reverse index (value1).
 *
 * If a literal has a field name, then the Range for that term will include the column family. If there are multiple fields, then multiple ranges are
 * created.
 *
 * @param config
 * @return
 * @throws TableNotFoundException
 * @throws ExecutionException
 */
@SuppressWarnings("unchecked")
public static Pair<Set<Range>, Set<Range>> makeRanges(DiscoveryQueryConfiguration config, Set<Text> familiesToSeek, MetadataHelper metadataHelper) throws TableNotFoundException, ExecutionException {
    Set<Range> forwardRanges = new HashSet<>();
    for (Entry<String, String> literalAndField : config.getLiterals().entries()) {
        String literal = literalAndField.getKey(), field = literalAndField.getValue();
        // if we're _ANYFIELD_, then use null when making the literal range
        field = Constants.ANY_FIELD.equals(field) ? null : field;
        if (field != null) {
            familiesToSeek.add(new Text(field));
        }
        forwardRanges.add(ShardIndexQueryTableStaticMethods.getLiteralRange(field, literal));
    }
    for (Entry<String, LiteralRange<String>> rangeEntry : config.getRanges().entries()) {
        LiteralRange<String> range = rangeEntry.getValue();
        String field = rangeEntry.getKey();
        // if we're _ANYFIELD_, then use null when making the literal range
        field = Constants.ANY_FIELD.equals(field) ? null : field;
        if (field != null) {
            familiesToSeek.add(new Text(field));
        }
        try {
            forwardRanges.add(ShardIndexQueryTableStaticMethods.getBoundedRangeRange(range));
        } catch (IllegalRangeArgumentException e) {
            log.error("Error using range [" + range + "]", e);
            continue;
        }
    }
    Set<Range> reverseRanges = new HashSet<>();
    for (Entry<String, String> patternAndField : config.getPatterns().entries()) {
        String pattern = patternAndField.getKey(), field = patternAndField.getValue();
        // if we're _ANYFIELD_, then use null when making the literal range
        field = Constants.ANY_FIELD.equals(field) ? null : field;
        ShardIndexQueryTableStaticMethods.RefactoredRangeDescription description;
        try {
            if (field != null) {
                familiesToSeek.add(new Text(field));
            }
            description = ShardIndexQueryTableStaticMethods.getRegexRange(field, pattern, false, metadataHelper, config);
        } catch (JavaRegexParseException e) {
            log.error("Error parsing pattern [" + pattern + "]", e);
            continue;
        }
        if (description.isForReverseIndex) {
            reverseRanges.add(description.range);
        } else {
            forwardRanges.add(description.range);
        }
    }
    return Pair.with(forwardRanges, reverseRanges);
}
Also used : Text(org.apache.hadoop.io.Text) LongRange(org.apache.commons.lang.math.LongRange) LiteralRange(datawave.query.jexl.LiteralRange) Range(org.apache.accumulo.core.data.Range) ShardIndexQueryTableStaticMethods(datawave.query.jexl.lookups.ShardIndexQueryTableStaticMethods) JavaRegexParseException(datawave.query.parser.JavaRegexAnalyzer.JavaRegexParseException) LiteralRange(datawave.query.jexl.LiteralRange) HashSet(java.util.HashSet) IllegalRangeArgumentException(datawave.query.exceptions.IllegalRangeArgumentException)

Example 3 with IllegalRangeArgumentException

use of datawave.query.exceptions.IllegalRangeArgumentException in project datawave by NationalSecurityAgency.

the class BoundedRangeIndexLookup method submit.

@Override
public synchronized void submit() {
    if (indexLookupMap == null) {
        String startDay = DateHelper.format(config.getBeginDate());
        String endDay = DateHelper.format(config.getEndDate());
        // build the start and end range for the scanner
        // Key for global index is Row-> Normalized FieldValue, CF-> FieldName,
        // CQ->shard_id\x00datatype
        indexLookupMap = new IndexLookupMap(config.getMaxUnfieldedExpansionThreshold(), config.getMaxValueExpansionThreshold());
        IteratorSetting fairnessIterator = null;
        if (config.getMaxIndexScanTimeMillis() > 0) {
            // The fairness iterator solves the problem whereby we have runaway iterators as a result of an evaluation that never finds anything
            fairnessIterator = new IteratorSetting(1, TimeoutIterator.class);
            long maxTime = config.getMaxIndexScanTimeMillis();
            if (maxTime < Long.MAX_VALUE / 2)
                maxTime *= 2;
            fairnessIterator.addOption(TimeoutIterator.MAX_SESSION_TIME, Long.valueOf(maxTime).toString());
        }
        String lower = literalRange.getLower().toString(), upper = literalRange.getUpper().toString();
        Key startKey;
        if (literalRange.isLowerInclusive()) {
            // inclusive
            startKey = new Key(new Text(lower));
        } else {
            // non-inclusive
            startKey = new Key(new Text(lower + "\0"));
        }
        Key endKey;
        if (literalRange.isUpperInclusive()) {
            // we should have our end key be the end of the range if we are going to use the WRI
            endKey = new Key(new Text(upper), new Text(literalRange.getFieldName()), new Text(endDay + Constants.MAX_UNICODE_STRING));
        } else {
            endKey = new Key(new Text(upper));
        }
        Range range;
        try {
            range = new Range(startKey, true, endKey, literalRange.isUpperInclusive());
        } catch (IllegalArgumentException e) {
            QueryException qe = new QueryException(DatawaveErrorCode.RANGE_CREATE_ERROR, e, MessageFormat.format("{0}", this.literalRange));
            log.debug(qe);
            throw new IllegalRangeArgumentException(qe);
        }
        log.debug("Range: " + range);
        bs = null;
        try {
            bs = scannerFactory.newScanner(config.getIndexTableName(), config.getAuthorizations(), config.getNumQueryThreads(), config.getQuery());
            bs.setRanges(Collections.singleton(range));
            bs.fetchColumnFamily(new Text(literalRange.getFieldName()));
            // set up the GlobalIndexRangeSamplingIterator
            IteratorSetting cfg = new IteratorSetting(config.getBaseIteratorPriority() + 50, "WholeRowIterator", WholeRowIterator.class);
            bs.addScanIterator(cfg);
            cfg = new IteratorSetting(config.getBaseIteratorPriority() + 48, "DateFilter", ColumnQualifierRangeIterator.class);
            // search from 20YYddMM to 20ZZddMM\uffff to ensure we encompass all of the current day
            String end = endDay + Constants.MAX_UNICODE_STRING;
            cfg.addOption(ColumnQualifierRangeIterator.RANGE_NAME, ColumnQualifierRangeIterator.encodeRange(new Range(startDay, end)));
            bs.addScanIterator(cfg);
            // If this is a composite field, with multiple terms, we need to setup our query to filter based on each component of the composite range
            if (config.getCompositeToFieldMap().get(literalRange.getFieldName()) != null) {
                String compositeSeparator = null;
                if (config.getCompositeFieldSeparators() != null)
                    compositeSeparator = config.getCompositeFieldSeparators().get(literalRange.getFieldName());
                if (compositeSeparator != null && (lower.contains(compositeSeparator) || upper.contains(compositeSeparator))) {
                    IteratorSetting compositeIterator = new IteratorSetting(config.getBaseIteratorPriority() + 51, CompositeSeekingIterator.class);
                    compositeIterator.addOption(CompositeSeekingIterator.COMPONENT_FIELDS, StringUtils.collectionToCommaDelimitedString(config.getCompositeToFieldMap().get(literalRange.getFieldName())));
                    for (String fieldName : config.getCompositeToFieldMap().get(literalRange.getFieldName())) {
                        DiscreteIndexType<?> type = config.getFieldToDiscreteIndexTypes().get(fieldName);
                        if (type != null)
                            compositeIterator.addOption(fieldName + CompositeSeekingIterator.DISCRETE_INDEX_TYPE, type.getClass().getName());
                    }
                    compositeIterator.addOption(CompositeSeekingIterator.SEPARATOR, compositeSeparator);
                    bs.addScanIterator(compositeIterator);
                }
            }
            if (null != fairnessIterator) {
                cfg = new IteratorSetting(config.getBaseIteratorPriority() + 100, TimeoutExceptionIterator.class);
                bs.addScanIterator(cfg);
            }
            timedScanFuture = execService.submit(createTimedCallable(bs.iterator()));
        } catch (TableNotFoundException e) {
            NotFoundQueryException qe = new NotFoundQueryException(DatawaveErrorCode.TABLE_NOT_FOUND, e, MessageFormat.format("Table: {0}", config.getIndexTableName()));
            log.error(qe);
            throw new DatawaveFatalQueryException(qe);
        } catch (IOException e) {
            QueryException qe = new QueryException(DatawaveErrorCode.RANGE_CREATE_ERROR, e, MessageFormat.format("{0}", this.literalRange));
            log.debug(qe);
            throw new IllegalRangeArgumentException(qe);
        }
    }
}
Also used : TimeoutIterator(datawave.core.iterators.TimeoutIterator) ColumnQualifierRangeIterator(datawave.core.iterators.ColumnQualifierRangeIterator) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) LiteralRange(datawave.query.jexl.LiteralRange) Range(org.apache.accumulo.core.data.Range) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) QueryException(datawave.webservice.query.exception.QueryException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) TimeoutExceptionIterator(datawave.core.iterators.TimeoutExceptionIterator) Key(org.apache.accumulo.core.data.Key) IllegalRangeArgumentException(datawave.query.exceptions.IllegalRangeArgumentException)

Aggregations

IllegalRangeArgumentException (datawave.query.exceptions.IllegalRangeArgumentException)3 LiteralRange (datawave.query.jexl.LiteralRange)3 Range (org.apache.accumulo.core.data.Range)3 Text (org.apache.hadoop.io.Text)3 DatawaveFatalQueryException (datawave.query.exceptions.DatawaveFatalQueryException)2 QueryException (datawave.webservice.query.exception.QueryException)2 Key (org.apache.accumulo.core.data.Key)2 LongRange (org.apache.commons.lang.math.LongRange)2 ColumnQualifierRangeIterator (datawave.core.iterators.ColumnQualifierRangeIterator)1 TimeoutExceptionIterator (datawave.core.iterators.TimeoutExceptionIterator)1 TimeoutIterator (datawave.core.iterators.TimeoutIterator)1 DoNotPerformOptimizedQueryException (datawave.query.exceptions.DoNotPerformOptimizedQueryException)1 ShardIndexQueryTableStaticMethods (datawave.query.jexl.lookups.ShardIndexQueryTableStaticMethods)1 JavaRegexParseException (datawave.query.parser.JavaRegexAnalyzer.JavaRegexParseException)1 NotFoundQueryException (datawave.webservice.query.exception.NotFoundQueryException)1 PreConditionFailedQueryException (datawave.webservice.query.exception.PreConditionFailedQueryException)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1