Search in sources :

Example 1 with BadRequestQueryException

use of datawave.webservice.query.exception.BadRequestQueryException in project datawave by NationalSecurityAgency.

the class DocumentSerialization method consumeHeader.

public static InputStream consumeHeader(byte[] data) throws InvalidDocumentHeader {
    if (null == data || 3 > data.length) {
        QueryException qe = new QueryException(DatawaveErrorCode.DATA_INVALID_ERROR, MessageFormat.format("Length: {0}", (null != data ? data.length : null)));
        throw new InvalidDocumentHeader(qe);
    }
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    int magic = readUShort(bais);
    if (DOC_MAGIC != magic) {
        NotFoundQueryException qe = new NotFoundQueryException(DatawaveErrorCode.EXPECTED_HEADER_NOT_FOUND);
        throw new InvalidDocumentHeader(qe);
    }
    int compression = readUByte(bais);
    if (NONE == compression) {
        return new ByteArrayInputStream(data, 3, data.length - 3);
    } else if (GZIP == compression) {
        ByteArrayInputStream bytes = new ByteArrayInputStream(data, 3, data.length - 3);
        return new InflaterInputStream(bytes, new Inflater(), 1024);
    } else {
        BadRequestQueryException qe = new BadRequestQueryException(DatawaveErrorCode.UNKNOWN_COMPRESSION_SCHEME, MessageFormat.format("{0}", compression));
        throw new InvalidDocumentHeader(qe);
    }
}
Also used : InvalidDocumentHeader(datawave.query.exceptions.InvalidDocumentHeader) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException) QueryException(datawave.webservice.query.exception.QueryException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) ByteArrayInputStream(java.io.ByteArrayInputStream) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) InflaterInputStream(java.util.zip.InflaterInputStream) Inflater(java.util.zip.Inflater) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException)

Example 2 with BadRequestQueryException

use of datawave.webservice.query.exception.BadRequestQueryException in project datawave by NationalSecurityAgency.

the class AbstractEvaluationPhaseFunction method initialize.

@Override
public void initialize(List<String> parameterList, int depth, QueryNode parent) throws IllegalArgumentException {
    // super initialize will call validate
    super.initialize(parameterList, depth, parent);
    type = WildcardFieldedFilter.BooleanType.AND;
    int x = 0;
    if (this.parameterList.size() != 1 && this.parameterList.size() % 2 == 1) {
        try {
            String firstArg = this.parameterList.get(0);
            type = WildcardFieldedFilter.BooleanType.valueOf(firstArg.toUpperCase());
        } catch (Exception e) {
            BadRequestQueryException qe = new BadRequestQueryException(DatawaveErrorCode.INVALID_FUNCTION_ARGUMENTS, MessageFormat.format("{0}", this.name));
            throw new IllegalArgumentException(qe);
        }
        x = 1;
        this.parameterList.remove(0);
    }
}
Also used : BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException)

Example 3 with BadRequestQueryException

use of datawave.webservice.query.exception.BadRequestQueryException in project datawave by NationalSecurityAgency.

the class GetAllMatches method initialize.

@Override
public void initialize(List<String> parameterList, int depth, QueryNode parent) throws IllegalArgumentException {
    super.initialize(parameterList, depth, parent);
    type = WildcardFieldedFilter.BooleanType.AND;
    int x = 0;
    if (this.parameterList.size() % 2 == 1) {
        try {
            String firstArg = this.parameterList.get(0);
            type = WildcardFieldedFilter.BooleanType.valueOf(firstArg.toUpperCase());
        } catch (Exception e) {
            BadRequestQueryException qe = new BadRequestQueryException(DatawaveErrorCode.INVALID_FUNCTION_ARGUMENTS, MessageFormat.format("{0}", e, this.name));
            throw new IllegalArgumentException(qe);
        }
        x = 1;
        this.parameterList.remove(0);
    }
}
Also used : BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException)

Example 4 with BadRequestQueryException

use of datawave.webservice.query.exception.BadRequestQueryException in project datawave by NationalSecurityAgency.

the class EvaluationOnly method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("((_Eval_ = true) && (");
    List<String> params = getParameterList();
    if (params.size() != 1) {
        BadRequestQueryException qe = new BadRequestQueryException(DatawaveErrorCode.INVALID_FUNCTION_ARGUMENTS, MessageFormat.format("{0}", this.name));
        throw new IllegalArgumentException(qe);
    } else {
        try {
            sb.append(parser.parse(params.get(0)).getOriginalQuery());
        } catch (ParseException e) {
            BadRequestQueryException qe = new BadRequestQueryException(DatawaveErrorCode.INVALID_FUNCTION_ARGUMENTS, MessageFormat.format("{0}", this.name));
            throw new IllegalArgumentException(qe);
        }
    }
    sb.append("))");
    return sb.toString();
}
Also used : BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) ParseException(datawave.query.language.parser.ParseException)

Example 5 with BadRequestQueryException

use of datawave.webservice.query.exception.BadRequestQueryException in project datawave by NationalSecurityAgency.

the class VisitorFunction method apply.

@Override
@Nullable
public ScannerChunk apply(@Nullable ScannerChunk input) {
    SessionOptions options = input.getOptions();
    ScannerChunk newSettings = new ScannerChunk(null, input.getRanges(), input.getLastKnownLocation());
    SessionOptions newOptions = new SessionOptions(options);
    for (IteratorSetting setting : options.getIterators()) {
        final String query = setting.getOptions().get(QueryOptions.QUERY);
        if (null != query) {
            IteratorSetting newIteratorSetting = new IteratorSetting(setting.getPriority(), setting.getName(), setting.getIteratorClass());
            newIteratorSetting.addOptions(setting.getOptions());
            try {
                ASTJexlScript script = null;
                boolean evaluatedPreviously = previouslyExecutable(query);
                boolean madeChange = false;
                if (!evaluatedPreviously && config.isCleanupShardsAndDaysQueryHints()) {
                    script = JexlASTHelper.parseAndFlattenJexlQuery(query);
                    script = DateIndexCleanupVisitor.cleanup(script);
                    madeChange = true;
                }
                String newQuery = evaluatedPreviously ? previouslyExpanded.get(query) : query;
                List<String> debug = null;
                if (log.isTraceEnabled())
                    debug = Lists.newArrayList();
                if (!config.isDisableWhindexFieldMappings() && !evaluatedPreviously) {
                    if (null == script)
                        script = JexlASTHelper.parseAndFlattenJexlQuery(query);
                    // apply the whindex using the shard date
                    ASTJexlScript rebuiltScript = WhindexVisitor.apply(script, config, getEarliestBeginDate(newSettings.getRanges()), metadataHelper);
                    // if the query changed, save it, and mark it as such
                    if (!TreeEqualityVisitor.isEqual(script, rebuiltScript)) {
                        log.debug("[" + config.getQuery().getId() + "] The WhindexVisitor updated the query: " + JexlStringBuildingVisitor.buildQuery(script));
                        script = rebuiltScript;
                        madeChange = true;
                    }
                }
                if (!config.isBypassExecutabilityCheck() || !evaluatedPreviously) {
                    if (null == script)
                        script = JexlASTHelper.parseAndFlattenJexlQuery(query);
                    if (!ExecutableDeterminationVisitor.isExecutable(script, config, indexedFields, indexOnlyFields, nonEventFields, true, debug, this.metadataHelper)) {
                        if (log.isTraceEnabled()) {
                            log.trace("Need to pull up non-executable query: " + JexlStringBuildingVisitor.buildQuery(script));
                            for (String debugStatement : debug) {
                                log.trace(debugStatement);
                            }
                            DefaultQueryPlanner.logQuery(script, "Failing query:");
                        }
                        script = (ASTJexlScript) PullupUnexecutableNodesVisitor.pullupDelayedPredicates(script, true, config, indexedFields, indexOnlyFields, nonEventFields, metadataHelper);
                        madeChange = true;
                        STATE state = ExecutableDeterminationVisitor.getState(script, config, indexedFields, indexOnlyFields, nonEventFields, true, debug, metadataHelper);
                        /**
                         * We could achieve better performance if we live with the small number of queries that error due to the full table scan exception.
                         *
                         * Either look at improving PushdownUnexecutableNodesVisitor or avoid the process altogether.
                         */
                        if (state != STATE.EXECUTABLE) {
                            if (log.isTraceEnabled()) {
                                log.trace("Need to push down non-executable query: " + JexlStringBuildingVisitor.buildQuery(script));
                                for (String debugStatement : debug) {
                                    log.trace(debugStatement);
                                }
                            }
                            script = (ASTJexlScript) PushdownUnexecutableNodesVisitor.pushdownPredicates(script, true, config, indexedFields, indexOnlyFields, nonEventFields, metadataHelper);
                        }
                        state = ExecutableDeterminationVisitor.getState(script, config, indexedFields, indexOnlyFields, nonEventFields, true, debug, metadataHelper);
                        if (state != STATE.EXECUTABLE) {
                            if (state == STATE.ERROR) {
                                log.warn("After expanding the query, it is determined that the query cannot be executed due to index-only fields mixed with expressions that cannot be run against the index.");
                                BadRequestQueryException qe = new BadRequestQueryException(DatawaveErrorCode.INDEX_ONLY_FIELDS_MIXED_INVALID_EXPRESSIONS);
                                throw new InvalidQueryException(qe);
                            }
                            log.warn("After expanding the query, it is determined that the query cannot be executed against the field index and a full table scan is required");
                            if (!config.getFullTableScanEnabled()) {
                                if (log.isTraceEnabled()) {
                                    log.trace("Full Table fail of " + JexlStringBuildingVisitor.buildQuery(script));
                                    for (String debugStatement : debug) {
                                        log.trace(debugStatement);
                                    }
                                    DefaultQueryPlanner.logQuery(script, "Failing query:");
                                }
                                PreConditionFailedQueryException qe = new PreConditionFailedQueryException(DatawaveErrorCode.FULL_TABLE_SCAN_REQUIRED_BUT_DISABLED);
                                throw new DatawaveFatalQueryException(qe);
                            }
                        }
                        if (log.isTraceEnabled()) {
                            for (String debugStatement : debug) {
                                log.trace(debugStatement);
                            }
                            DefaultQueryPlanner.logQuery(script, "Query pushing down large fielded lists:");
                        }
                    }
                }
                if (config.getSerializeQueryIterator()) {
                    serializeQuery(newIteratorSetting);
                } else {
                    if (!evaluatedPreviously) {
                        // if we have an hdfs configuration, then we can pushdown large fielded lists to an ivarator
                        if (config.getHdfsSiteConfigURLs() != null && setting.getOptions().get(QueryOptions.BATCHED_QUERY) == null) {
                            if (null == script)
                                script = JexlASTHelper.parseAndFlattenJexlQuery(query);
                            try {
                                script = pushdownLargeFieldedLists(config, script);
                                madeChange = true;
                            } catch (IOException ioe) {
                                log.error("Unable to pushdown large fielded lists....leaving in expanded form", ioe);
                            }
                        }
                    }
                }
                // only recompile the script if changes were made to the query
                if (madeChange)
                    newQuery = JexlStringBuildingVisitor.buildQuery(script);
                try {
                    previouslyExpanded.put(query, newQuery);
                } catch (NullPointerException npe) {
                    throw new DatawaveFatalQueryException(String.format("New query is null! madeChange: %b, qid: %s", madeChange, setting.getOptions().get(QueryOptions.QUERY_ID)), npe);
                }
                // test the final script for thresholds
                DefaultQueryPlanner.validateQuerySize("VisitorFunction", script, config, false);
                newIteratorSetting.addOption(QueryOptions.QUERY, newQuery);
                newOptions.removeScanIterator(setting.getName());
                newOptions.addScanIterator(newIteratorSetting);
                if (log.isDebugEnabled()) {
                    log.debug("VisitorFunction result: " + newSettings.getRanges());
                }
                if (log.isTraceEnabled()) {
                    DefaultQueryPlanner.logTrace(PrintingVisitor.formattedQueryStringList(script), "VistorFunction::apply method");
                } else if (log.isDebugEnabled()) {
                    DefaultQueryPlanner.logDebug(PrintingVisitor.formattedQueryStringList(script, DefaultQueryPlanner.maxChildNodesToPrint), "VistorFunction::apply method");
                }
            } catch (ParseException e) {
                throw new DatawaveFatalQueryException(e);
            }
        }
    }
    newSettings.setOptions(newOptions);
    return newSettings;
}
Also used : BadRequestQueryException(datawave.webservice.query.exception.BadRequestQueryException) PreConditionFailedQueryException(datawave.webservice.query.exception.PreConditionFailedQueryException) SessionOptions(datawave.query.tables.SessionOptions) ASTJexlScript(org.apache.commons.jexl2.parser.ASTJexlScript) STATE(datawave.query.jexl.visitors.ExecutableDeterminationVisitor.STATE) ScannerChunk(datawave.query.tables.async.ScannerChunk) IOException(java.io.IOException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) DatawaveFatalQueryException(datawave.query.exceptions.DatawaveFatalQueryException) ParseException(org.apache.commons.jexl2.parser.ParseException) InvalidQueryException(datawave.query.exceptions.InvalidQueryException) Nullable(javax.annotation.Nullable)

Aggregations

BadRequestQueryException (datawave.webservice.query.exception.BadRequestQueryException)30 BadRequestException (datawave.webservice.common.exception.BadRequestException)12 QueryException (datawave.webservice.query.exception.QueryException)12 NotFoundQueryException (datawave.webservice.query.exception.NotFoundQueryException)11 DatawaveWebApplicationException (datawave.webservice.common.exception.DatawaveWebApplicationException)10 UnauthorizedException (datawave.webservice.common.exception.UnauthorizedException)10 PreConditionFailedQueryException (datawave.webservice.query.exception.PreConditionFailedQueryException)10 UnauthorizedQueryException (datawave.webservice.query.exception.UnauthorizedQueryException)10 IOException (java.io.IOException)10 Produces (javax.ws.rs.Produces)10 WebApplicationException (javax.ws.rs.WebApplicationException)8 NoResultsException (datawave.webservice.common.exception.NoResultsException)7 NoResultsQueryException (datawave.webservice.query.exception.NoResultsQueryException)7 Path (javax.ws.rs.Path)7 GZIP (org.jboss.resteasy.annotations.GZIP)7 DatawavePrincipal (datawave.security.authorization.DatawavePrincipal)6 GenericResponse (datawave.webservice.result.GenericResponse)6 CancellationException (java.util.concurrent.CancellationException)6 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)6 Interceptors (javax.interceptor.Interceptors)6