Search in sources :

Example 1 with QueryData

use of datawave.webservice.query.configuration.QueryData in project datawave by NationalSecurityAgency.

the class DefaultExtendedEdgeQueryLogic method setupQuery.

@Override
public void setupQuery(GenericQueryConfiguration configuration) throws Exception {
    EdgeExtendedSummaryConfiguration localConf = (EdgeExtendedSummaryConfiguration) configuration;
    config = (EdgeExtendedSummaryConfiguration) configuration;
    prefilterValues = null;
    EdgeExtendedSummaryConfiguration.dateType dateFilterType = localConf.getDateRangeType();
    if (log.isTraceEnabled()) {
        log.trace("Performing edge table query: " + config.getQueryString());
    }
    // TODO check to see if overriding I/O necessary
    if (allowOverrideIO && localConf.isOverRideInput()) {
        this.summaryInputType = localConf.isSummaryInputType();
    }
    if (allowOverrideIO && localConf.isOverRideOutput()) {
        this.summaryOutputType = localConf.isAggregateResults();
    }
    boolean includeStats = localConf.includeStats();
    String queryString = config.getQueryString();
    MetadataHelper metadataHelper = super.prepareMetadataHelper(config.getConnector(), config.getModelTableName(), config.getAuthorizations());
    loadQueryModel(metadataHelper, config);
    // list of source values...no field names to translate
    if (this.summaryInputType == false) {
        queryString = applyQueryModel(queryString);
    }
    // set the modified queryString back into the config, for easy access
    config.setQueryString(queryString);
    String normalizedQuery = "";
    String statsNormalizedQuery = "";
    QueryData qData = configureRanges(queryString);
    setRanges(qData.getRanges());
    VisitationContext context = null;
    if (this.summaryInputType == false) {
        try {
            context = normalizeJexlQuery(queryString, false);
            normalizedQuery = context.getNormalizedQuery().toString();
            statsNormalizedQuery = context.getNormalizedStatsQuery().toString();
            if (log.isTraceEnabled()) {
                log.trace("Jexl after normalizing both vertices: " + normalizedQuery);
            }
        } catch (JexlException ex) {
            try {
                log.error("Error parsing user query.", ex);
            } catch (Exception ex2) {
                log.error("Exception thrown by logger (???)");
            }
        }
    }
    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("")) {
        if (log.isTraceEnabled()) {
            log.trace("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);
    }
    if (log.isTraceEnabled()) {
        log.trace("Configuring connection: tableName: " + config.getTableName() + ", auths: " + config.getAuthorizations());
    }
    BatchScanner scanner = createBatchScanner(config);
    if (log.isTraceEnabled()) {
        log.trace("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 : EdgeExtendedSummaryConfiguration(datawave.query.config.EdgeExtendedSummaryConfiguration) 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) ParseException(org.apache.commons.jexl2.parser.ParseException) JexlException(org.apache.commons.jexl2.JexlException) EdgeFilterIterator(datawave.query.iterator.filter.EdgeFilterIterator) MetadataHelper(datawave.query.util.MetadataHelper) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) VisitationContext(datawave.query.tables.edge.contexts.VisitationContext)

Example 2 with QueryData

use of datawave.webservice.query.configuration.QueryData in project datawave by NationalSecurityAgency.

the class DefaultQueryPlanner method process.

protected CloseableIterable<QueryData> process(ScannerFactory scannerFactory, MetadataHelper metadataHelper, DateIndexHelper dateIndexHelper, ShardQueryConfiguration config, String query, Query settings) throws DatawaveQueryException {
    final QueryData queryData = new QueryData();
    settingFuture = null;
    IteratorSetting cfg = null;
    if (preloadOptions) {
        cfg = getQueryIterator(metadataHelper, config, settings, "", false);
    }
    try {
        config.setQueryTree(updateQueryTree(scannerFactory, metadataHelper, dateIndexHelper, config, query, queryData, settings));
    } catch (StackOverflowError e) {
        if (log.isTraceEnabled()) {
            log.trace("Stack trace for overflow " + e);
        }
        PreConditionFailedQueryException qe = new PreConditionFailedQueryException(DatawaveErrorCode.QUERY_DEPTH_OR_TERM_THRESHOLD_EXCEEDED, e);
        log.warn(qe);
        throw new DatawaveFatalQueryException(qe);
    } catch (NoResultsException e) {
        if (log.isTraceEnabled()) {
            log.trace("Definitively determined that no results exist from the indexes");
        }
        return DefaultQueryPlanner.emptyCloseableIterator();
    }
    boolean isFullTable = false;
    Tuple2<CloseableIterable<QueryPlan>, Boolean> queryRanges = null;
    if (!config.isGeneratePlanOnly()) {
        queryRanges = getQueryRanges(scannerFactory, metadataHelper, config, config.getQueryTree());
        // a full table scan is required if
        isFullTable = queryRanges.second();
        // abort if we cannot handle full table scans
        if (isFullTable && !config.getFullTableScanEnabled()) {
            PreConditionFailedQueryException qe = new PreConditionFailedQueryException(DatawaveErrorCode.FULL_TABLE_SCAN_REQUIRED_BUT_DISABLED);
            throw new FullTableScansDisallowedException(qe);
        }
    }
    final QueryStopwatch timers = config.getTimers();
    TraceStopwatch stopwatch = timers.newStartedStopwatch("DefaultQueryPlanner - Rebuild JEXL String from AST");
    // Set the final query after we're done mucking with it
    String newQueryString = JexlStringBuildingVisitor.buildQuery(config.getQueryTree());
    if (log.isTraceEnabled())
        log.trace("newQueryString is " + newQueryString);
    if (StringUtils.isBlank(newQueryString)) {
        stopwatch.stop();
        QueryException qe = new QueryException(DatawaveErrorCode.EMPTY_QUERY_STRING_AFTER_MODIFICATION);
        throw new DatawaveFatalQueryException(qe);
    }
    stopwatch.stop();
    stopwatch = timers.newStartedStopwatch("DefaultQueryPlanner - Construct IteratorSettings");
    queryData.setQuery(newQueryString);
    if (!config.isGeneratePlanOnly()) {
        while (null == cfg) {
            cfg = getQueryIterator(metadataHelper, config, settings, "", false);
        }
        configureIterator(config, cfg, newQueryString, isFullTable);
    }
    // Load the IteratorSettings into the QueryData instance
    queryData.setSettings(Lists.newArrayList(cfg));
    stopwatch.stop();
    this.plannedScript = newQueryString;
    config.setQueryString(this.plannedScript);
    // docsToCombineForEvaluation is only enabled when threading is used
    if (config.getMaxEvaluationPipelines() == 1)
        docsToCombineForEvaluation = -1;
    if (!config.isGeneratePlanOnly()) {
        // add the geo query comparator to sort by geo range granularity if this is a geo query
        List<Comparator<QueryPlan>> queryPlanComparators = null;
        if (config.isSortGeoWaveQueryRanges()) {
            List<String> geoFields = new ArrayList<>();
            for (String fieldName : config.getIndexedFields()) {
                for (Type type : config.getQueryFieldsDatatypes().get(fieldName)) {
                    if (type instanceof AbstractGeometryType) {
                        geoFields.add(fieldName);
                        break;
                    }
                }
            }
            if (!geoFields.isEmpty()) {
                queryPlanComparators = new ArrayList<>();
                queryPlanComparators.add(new GeoWaveQueryPlanComparator(geoFields));
                queryPlanComparators.add(new DefaultQueryPlanComparator());
            }
        }
        // @formatter:off
        return new ThreadedRangeBundler.Builder().setOriginal(queryData).setQueryTree(config.getQueryTree()).setRanges(queryRanges.first()).setMaxRanges(maxRangesPerQueryPiece()).setDocsToCombine(docsToCombineForEvaluation).setSettings(settings).setDocSpecificLimitOverride(docSpecificOverride).setMaxRangeWaitMillis(maxRangeWaitMillis).setQueryPlanComparators(queryPlanComparators).setNumRangesToBuffer(config.getNumRangesToBuffer()).setRangeBufferTimeoutMillis(config.getRangeBufferTimeoutMillis()).setRangeBufferPollMillis(config.getRangeBufferPollMillis()).build();
    // @formatter:on
    } else {
        return null;
    }
}
Also used : NoResultsException(datawave.query.exceptions.NoResultsException) QueryData(datawave.webservice.query.configuration.QueryData) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) ArrayList(java.util.ArrayList) GeoWaveQueryPlanComparator(datawave.query.planner.comparator.GeoWaveQueryPlanComparator) DefaultQueryPlanComparator(datawave.query.planner.comparator.DefaultQueryPlanComparator) Comparator(java.util.Comparator) TraceStopwatch(datawave.util.time.TraceStopwatch) GeoWaveQueryPlanComparator(datawave.query.planner.comparator.GeoWaveQueryPlanComparator) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) QueryStopwatch(datawave.query.util.QueryStopwatch) AbstractGeometryType(datawave.data.type.AbstractGeometryType) CloseableIterable(datawave.query.CloseableIterable) DatawaveQueryException(datawave.query.exceptions.DatawaveQueryException) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) DoNotPerformOptimizedQueryException(datawave.query.exceptions.DoNotPerformOptimizedQueryException) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) QueryException(datawave.webservice.query.exception.QueryException) InvalidQueryException(datawave.query.exceptions.InvalidQueryException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) AbstractGeometryType(datawave.data.type.AbstractGeometryType) Type(datawave.data.type.Type) DefaultQueryPlanComparator(datawave.query.planner.comparator.DefaultQueryPlanComparator) FullTableScansDisallowedException(datawave.query.exceptions.FullTableScansDisallowedException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting)

Example 3 with QueryData

use of datawave.webservice.query.configuration.QueryData in project datawave by NationalSecurityAgency.

the class CompositeIndexTest method getQueryRanges.

private List<QueryData> getQueryRanges(String queryString, boolean useIvarator) throws Exception {
    ShardQueryLogic logic = getShardQueryLogic(useIvarator);
    Iterator iter = getQueryRangesIterator(queryString, logic);
    List<QueryData> queryData = new ArrayList<>();
    while (iter.hasNext()) queryData.add((QueryData) iter.next());
    return queryData;
}
Also used : QueryData(datawave.webservice.query.configuration.QueryData) ShardQueryLogic(datawave.query.tables.ShardQueryLogic) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList)

Example 4 with QueryData

use of datawave.webservice.query.configuration.QueryData in project datawave by NationalSecurityAgency.

the class MultiValueCompositeIndexTest method getQueryRanges.

private List<QueryData> getQueryRanges(String queryString, boolean useIvarator) throws Exception {
    ShardQueryLogic logic = getShardQueryLogic(useIvarator);
    Iterator iter = getQueryRangesIterator(queryString, logic);
    List<QueryData> queryData = new ArrayList<>();
    while (iter.hasNext()) queryData.add((QueryData) iter.next());
    return queryData;
}
Also used : QueryData(datawave.webservice.query.configuration.QueryData) ShardQueryLogic(datawave.query.tables.ShardQueryLogic) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList)

Example 5 with QueryData

use of datawave.webservice.query.configuration.QueryData in project datawave by NationalSecurityAgency.

the class ThreadedRangeBundlerTest method whenInstantiatingViaModifiedBuilder_thenSpecifiedValuesAreSet.

@Test
public void whenInstantiatingViaModifiedBuilder_thenSpecifiedValuesAreSet() {
    QueryData original = mock(QueryData.class);
    CloseableIterable<QueryPlan> ranges = mock(CloseableIterable.class);
    Query settings = mock(Query.class);
    ASTJexlScript queryTree = mock(ASTJexlScript.class);
    Collection<Comparator<QueryPlan>> queryPlanComparators = mock(Collection.class);
    // @formatter:off
    ThreadedRangeBundler bundler = ThreadedRangeBundler.builder().setOriginal(original).setRanges(ranges).setMaxRanges(100).setSettings(settings).setQueryTree(queryTree).setDocSpecificLimitOverride(true).setDocsToCombine(10).setMaxRangeWaitMillis(1).setQueryPlanComparators(queryPlanComparators).setNumRangesToBuffer(1).setRangeBufferTimeoutMillis(10).setRangeBufferPollMillis(5).build();
    // @formatter:on
    assertEquals(original, bundler.getOriginal());
    assertEquals(ranges, bundler.getRanges());
    assertEquals(100L, bundler.getMaxRanges());
    assertEquals(settings, bundler.getSettings());
    assertEquals(queryTree, bundler.getQueryTree());
    assertTrue(bundler.isDocSpecificLimitOverride());
    assertEquals(10, bundler.getDocsToCombine());
    assertEquals(queryPlanComparators, bundler.getQueryPlanComparators());
    assertEquals(1, bundler.getNumRangesToBuffer());
    assertEquals(10L, bundler.getRangeBufferTimeoutMillis());
    assertEquals(5L, bundler.getRangeBufferPollMillis());
    assertEquals(1L, bundler.getMaxRangeWaitMillis());
}
Also used : Query(datawave.webservice.query.Query) QueryData(datawave.webservice.query.configuration.QueryData) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) Comparator(java.util.Comparator) Test(org.junit.Test)

Aggregations

QueryData (datawave.webservice.query.configuration.QueryData)20 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)7 DefaultEvent (datawave.webservice.query.result.event.DefaultEvent)4 DefaultField (datawave.webservice.query.result.event.DefaultField)4 Range (org.apache.accumulo.core.data.Range)4 ASTJexlScript (org.apache.commons.jexl2.parser.ASTJexlScript)4 DatawaveFatalQueryException (datawave.query.exceptions.DatawaveFatalQueryException)3 QueryIterator (datawave.query.iterator.QueryIterator)3 JexlException (org.apache.commons.jexl2.JexlException)3 NumberType (datawave.data.type.NumberType)2 CloseableIterable (datawave.query.CloseableIterable)2 ShardQueryConfiguration (datawave.query.config.ShardQueryConfiguration)2 EdgeFilterIterator (datawave.query.iterator.filter.EdgeFilterIterator)2 ShardQueryLogic (datawave.query.tables.ShardQueryLogic)2 VisitationContext (datawave.query.tables.edge.contexts.VisitationContext)2 QueryException (datawave.webservice.query.exception.QueryException)2 Comparator (java.util.Comparator)2 Iterator (java.util.Iterator)2