Search in sources :

Example 6 with ParseException

use of datawave.query.language.parser.ParseException in project datawave by NationalSecurityAgency.

the class LuceneUUIDQueryParser method parse.

@Override
public datawave.query.language.tree.QueryNode parse(String query) throws ParseException {
    // replace open smart quote 147
    query = query.replaceAll("\\u0093", "\"");
    // replace close smart quote 148
    query = query.replaceAll("\\u0094", "\"");
    datawave.query.language.tree.QueryNode parsedQuery = null;
    parsedQuery = super.parse(query);
    if (!(parsedQuery instanceof SelectorNode)) {
        throw new ParseException("Query: " + query + " not supported with the LuceneQueryUUIDParser");
    }
    SelectorNode selectorNode = (SelectorNode) parsedQuery;
    FieldedTerm fieldedTerm = (FieldedTerm) selectorNode.getQuery();
    String field = fieldedTerm.getField();
    UUIDType uuidType = null;
    for (UUIDType u : uuidTypes) {
        if (u.getFieldName().equals(field)) {
            uuidType = u;
            break;
        }
    }
    if (uuidType == null) {
        throw new ParseException("Query: " + query + " not supported with the LuceneQueryUUIDParser");
    }
    if (fieldedTerm instanceof RangeFieldedTerm) {
        throw new ParseException("Query: " + query + " not supported with the LuceneQueryUUIDParser");
    }
    if (fieldedTerm instanceof WildcardFieldedTerm) {
        int firstWildcard = WildcardFieldedTerm.getFirstWildcardIndex(fieldedTerm.getSelector());
        Integer wildcardAllowedAfter = uuidType.getAllowWildcardAfter();
        if (wildcardAllowedAfter == null || firstWildcard < wildcardAllowedAfter) {
            throw new ParseException("Query: " + query + " not supported with the LuceneQueryUUIDParser");
        }
    }
    return parsedQuery;
}
Also used : WildcardFieldedTerm(datawave.query.search.WildcardFieldedTerm) RangeFieldedTerm(datawave.query.search.RangeFieldedTerm) UUIDType(datawave.query.data.UUIDType) SelectorNode(datawave.query.language.tree.SelectorNode) ParseException(datawave.query.language.parser.ParseException) RangeFieldedTerm(datawave.query.search.RangeFieldedTerm) FieldedTerm(datawave.query.search.FieldedTerm) WildcardFieldedTerm(datawave.query.search.WildcardFieldedTerm)

Example 7 with ParseException

use of datawave.query.language.parser.ParseException 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)

Aggregations

ParseException (datawave.query.language.parser.ParseException)7 FieldedTerm (datawave.query.search.FieldedTerm)2 RangeFieldedTerm (datawave.query.search.RangeFieldedTerm)2 BadRequestQueryException (datawave.webservice.query.exception.BadRequestQueryException)2 TreeSet (java.util.TreeSet)2 QueryBuilder (org.apache.lucene.queryparser.flexible.core.builders.QueryBuilder)2 QueryNodeProcessor (org.apache.lucene.queryparser.flexible.core.processors.QueryNodeProcessor)2 UUIDType (datawave.query.data.UUIDType)1 JexlTreeBuilder (datawave.query.language.builder.jexl.JexlTreeBuilder)1 AccumuloQueryTreeBuilder (datawave.query.language.builder.lucene.AccumuloQueryTreeBuilder)1 AccumuloSyntaxParser (datawave.query.language.parser.lucene.AccumuloSyntaxParser)1 CustomQueryNodeProcessorPipeline (datawave.query.language.processor.lucene.CustomQueryNodeProcessorPipeline)1 QueryNode (datawave.query.language.tree.QueryNode)1 SelectorNode (datawave.query.language.tree.SelectorNode)1 WildcardFieldedTerm (datawave.query.search.WildcardFieldedTerm)1 ASTIdentifier (org.apache.commons.jexl2.parser.ASTIdentifier)1 JexlNode (org.apache.commons.jexl2.parser.JexlNode)1 QueryNodeException (org.apache.lucene.queryparser.flexible.core.QueryNodeException)1 QueryNode (org.apache.lucene.queryparser.flexible.core.nodes.QueryNode)1