Search in sources :

Example 71 with ShardQueryConfiguration

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

the class FunctionIndexQueryExpansionVisitorTest method expandContentPhraseFunctionIntoSingleFieldWithNoExpansion.

@Test
public void expandContentPhraseFunctionIntoSingleFieldWithNoExpansion() throws ParseException {
    Set<String> fields = Sets.newHashSet("FOO", "BAR");
    Set<String> tfFields = Sets.newHashSet("FOO");
    // Configure the mock metadata helper.
    MockMetadataHelper mockMetadataHelper = new MockMetadataHelper();
    mockMetadataHelper.setIndexedFields(fields);
    mockMetadataHelper.addTermFrequencyFields(tfFields);
    ShardQueryConfiguration config = new ShardQueryConfiguration();
    config.setNoExpansionFields(Sets.newHashSet("FOO"));
    // Execute the test.
    String original = "content:phrase(termOffsetMap, 'abc', 'def')";
    runTest(original, original, config, mockMetadataHelper);
}
Also used : MockMetadataHelper(datawave.query.util.MockMetadataHelper) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) Test(org.junit.Test)

Example 72 with ShardQueryConfiguration

use of datawave.query.config.ShardQueryConfiguration 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)

Example 73 with ShardQueryConfiguration

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

the class FieldIndexCountQueryLogic method initialize.

@Override
public GenericQueryConfiguration initialize(Connector connection, Query settings, Set<Authorizations> auths) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("initialize");
    }
    this.scannerFactory = new ScannerFactory(connection);
    MetadataHelper metadataHelper = prepareMetadataHelper(connection, this.getMetadataTableName(), auths);
    String modelName = this.getModelName();
    String modelTableName = this.getModelTableName();
    // Check if the default modelName and modelTableNames have been overriden by custom parameters.
    if (null != settings.findParameter(QueryParameters.PARAMETER_MODEL_NAME) && !settings.findParameter(QueryParameters.PARAMETER_MODEL_NAME).getParameterValue().trim().isEmpty()) {
        modelName = settings.findParameter(QueryParameters.PARAMETER_MODEL_NAME).getParameterValue().trim();
    }
    if (null != settings.findParameter(QueryParameters.PARAMETER_MODEL_TABLE_NAME) && !settings.findParameter(QueryParameters.PARAMETER_MODEL_TABLE_NAME).getParameterValue().trim().isEmpty()) {
        modelTableName = settings.findParameter(QueryParameters.PARAMETER_MODEL_TABLE_NAME).getParameterValue().trim();
    }
    if (null != modelName && null == modelTableName) {
        throw new IllegalArgumentException(QueryParameters.PARAMETER_MODEL_NAME + " has been specified but " + QueryParameters.PARAMETER_MODEL_TABLE_NAME + " is missing. Both are required to use a model");
    }
    if (null != modelName && null != modelTableName) {
        this.queryModel = metadataHelper.getQueryModel(modelTableName, modelName, this.getUnevaluatedFields());
    }
    // I'm using this config object in a pinch, we should probably create a custom one.
    ShardQueryConfiguration config = ShardQueryConfiguration.create(this, settings);
    config.setConnector(connection);
    config.setAuthorizations(auths);
    // the following throw IllegalArgumentExceptions if validation fails.
    parseQuery(config, settings);
    configDate(config, settings);
    configTypeFilter(config, settings);
    Set<String> normalizedFieldValues = null;
    Iterator<String> fieldNameIter = fieldNames.iterator();
    while (fieldNameIter.hasNext()) {
        String fieldName = fieldNameIter.next();
        // check that the field name is actually an indexed field
        Set<Type<?>> normalizerSet = metadataHelper.getDatatypesForField(fieldName, config.getDatatypeFilter());
        if (null != normalizerSet && !normalizerSet.isEmpty()) {
            if (null != this.fieldValues && !this.fieldValues.isEmpty()) {
                for (Type<?> norm : normalizerSet) {
                    if (null == normalizedFieldValues) {
                        normalizedFieldValues = new HashSet<>();
                    }
                    for (String val : this.fieldValues) {
                        try {
                            String normVal = norm.normalize(val);
                            if (null != normVal && !normVal.isEmpty()) {
                                normalizedFieldValues.add(normVal);
                            }
                        } catch (Exception e) {
                            logger.debug(norm + " failed to normalize value: " + val);
                        }
                    }
                }
            }
        } else {
            if (logger.isTraceEnabled()) {
                logger.trace("dropping fieldname " + fieldName + " because it's not indexed.");
            }
            // drop fieldName since it isn't indexed.
            fieldNameIter.remove();
        }
    }
    this.fieldValues = normalizedFieldValues;
    if (this.fieldNames.isEmpty()) {
        throw new IllegalArgumentException("Need at least 1 indexed field to query with.");
    }
    // Generate & set the query ranges
    this.ranges = generateRanges(config);
    // Find out if we need to list unique data types.
    if (null != settings.findParameter(Constants.UNIQ_DATATYPE)) {
        this.uniqueByDataType = Boolean.parseBoolean(settings.findParameter(Constants.UNIQ_DATATYPE).getParameterValue());
        if (logger.isTraceEnabled()) {
            logger.trace("uniqueByDataType: " + uniqueByDataType);
        }
    }
    // Find out if we need to list unique visibilities.
    if (null != settings.findParameter(Constants.UNIQ_VISIBILITY)) {
        this.uniqueByVisibility = Boolean.parseBoolean(settings.findParameter(Constants.UNIQ_VISIBILITY).getParameterValue());
        if (logger.isTraceEnabled()) {
            logger.trace("uniqueByVisibility: " + uniqueByVisibility);
        }
    }
    if (logger.isTraceEnabled()) {
        logger.trace("FieldNames: ");
        for (String f : this.fieldNames) {
            logger.trace("\t" + f);
        }
        logger.trace("FieldValues: ");
        if (null == this.fieldValues) {
            logger.trace("\tnone");
        } else {
            for (String f : this.fieldValues) {
                logger.trace("\t" + f);
            }
        }
        logger.trace("uniqueByDataType: " + uniqueByDataType);
        logger.trace("uniqueByVisibility: " + uniqueByVisibility);
    }
    return config;
}
Also used : MetadataHelper(datawave.query.util.MetadataHelper) Type(datawave.data.type.Type) ScannerFactory(datawave.query.tables.ScannerFactory) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) QueryException(datawave.webservice.query.exception.QueryException)

Example 74 with ShardQueryConfiguration

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

the class IndexStatsQueryLogic method setupQuery.

@Override
public void setupQuery(GenericQueryConfiguration config) throws Exception {
    ShardQueryConfiguration qConf = (ShardQueryConfiguration) config;
    HashSet<String> fields = new HashSet<>();
    Collections.addAll(fields, config.getQueryString().split(" "));
    StatsMonkey monkey = new StatsMonkey();
    monkey.con = connector;
    monkey.table = TableName.INDEX_STATS;
    List<FieldStat> stats = monkey.getStat(fields, qConf.getDatatypeFilter(), qConf.getBeginDate(), qConf.getEndDate());
    this.iterator = stats.iterator();
}
Also used : FieldStat(datawave.webservice.query.result.istat.FieldStat) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) HashSet(java.util.HashSet)

Example 75 with ShardQueryConfiguration

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

the class IndexStatsQueryLogic method initialize.

@Override
public GenericQueryConfiguration initialize(Connector connector, Query query, Set<Authorizations> auths) throws Exception {
    this.connector = connector;
    ShardQueryConfiguration config = new ShardQueryConfiguration();
    // Get the datatype set if specified
    String typeList = query.findParameter(QueryParameters.DATATYPE_FILTER_SET).getParameterValue();
    HashSet<String> typeFilter = null;
    if (null != typeList && !typeList.isEmpty()) {
        typeFilter = new HashSet<>();
        typeFilter.addAll(Arrays.asList(StringUtils.split(typeList, Constants.PARAM_VALUE_SEP)));
        if (!typeFilter.isEmpty()) {
            config.setDatatypeFilter(typeFilter);
            if (log.isDebugEnabled()) {
                log.debug("Type Filter: " + typeFilter);
            }
        }
    }
    config.setBeginDate(query.getBeginDate());
    config.setEndDate(query.getEndDate());
    config.setQueryString(query.getQuery());
    config.setAuthorizations(auths);
    return config;
}
Also used : ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration)

Aggregations

ShardQueryConfiguration (datawave.query.config.ShardQueryConfiguration)108 Test (org.junit.Test)75 ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)48 HashSet (java.util.HashSet)42 Date (java.util.Date)38 GeometryType (datawave.data.type.GeometryType)17 MetadataHelper (datawave.query.util.MetadataHelper)17 HashMap (java.util.HashMap)16 CompositeFunctionsTest (datawave.query.CompositeFunctionsTest)13 Query (datawave.webservice.query.Query)10 Authorizations (org.apache.accumulo.core.security.Authorizations)10 Before (org.junit.Before)10 QueryImpl (datawave.webservice.query.QueryImpl)9 QueryParameters (datawave.webservice.query.QueryParameters)9 QueryParametersImpl (datawave.webservice.query.QueryParametersImpl)9 MultivaluedMapImpl (org.jboss.resteasy.specimpl.MultivaluedMapImpl)8 MockMetadataHelper (datawave.query.util.MockMetadataHelper)7 JexlNode (org.apache.commons.jexl2.parser.JexlNode)6 ExceededOrThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededOrThresholdMarkerJexlNode)5 ExceededValueThresholdMarkerJexlNode (datawave.query.jexl.nodes.ExceededValueThresholdMarkerJexlNode)5