Search in sources :

Example 1 with JexlQueryFunction

use of datawave.query.language.functions.jexl.JexlQueryFunction in project datawave by NationalSecurityAgency.

the class FunctionQueryNodeBuilder method build.

public JexlNode build(QueryNode queryNode) {
    JexlNode returnNode = null;
    int depth = 0;
    QueryNode parent = queryNode;
    while ((parent = parent.getParent()) != null) {
        depth++;
    }
    if (queryNode instanceof FunctionQueryNode) {
        FunctionQueryNode functionQueryNode = (FunctionQueryNode) queryNode;
        String functionName = functionQueryNode.getFunction();
        List<String> parameterList = functionQueryNode.getParameterList();
        JexlQueryFunction referenceFunction = allowedFunctionMap.get(functionName.toUpperCase());
        if (referenceFunction == null) {
            NotFoundQueryException qe = new NotFoundQueryException(DatawaveErrorCode.FUNCTION_NOT_FOUND, MessageFormat.format("{0}", functionName));
            throw new IllegalArgumentException(qe);
        }
        // if more than one term in quotes, use an AdjNode
        JexlQueryFunction function = (JexlQueryFunction) referenceFunction.duplicate();
        returnNode = new JexlFunctionNode(function, parameterList, depth, queryNode.getParent());
    }
    return returnNode;
}
Also used : JexlFunctionNode(datawave.query.language.parser.jexl.JexlFunctionNode) FieldQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode) FunctionQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.FunctionQueryNode) QueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QueryNode) FunctionQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.FunctionQueryNode) JexlNode(datawave.query.language.parser.jexl.JexlNode) JexlQueryFunction(datawave.query.language.functions.jexl.JexlQueryFunction) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException)

Example 2 with JexlQueryFunction

use of datawave.query.language.functions.jexl.JexlQueryFunction in project datawave by NationalSecurityAgency.

the class LuceneQueryTest method testInit.

// ============================================
// implemented abstract methods
protected void testInit() {
    this.auths = CitiesDataType.getTestAuths();
    this.documentKey = CityField.EVENT_ID.name();
    LuceneToJexlQueryParser parser = new LuceneToJexlQueryParser();
    for (JexlQueryFunction queryFunction : parser.getAllowedFunctions()) {
        if (queryFunction instanceof EvaluationOnly) {
            ((EvaluationOnly) queryFunction).setParser(parser);
            break;
        }
    }
    this.logic.setParser(parser);
}
Also used : EvaluationOnly(datawave.query.language.functions.jexl.EvaluationOnly) JexlQueryFunction(datawave.query.language.functions.jexl.JexlQueryFunction) LuceneToJexlQueryParser(datawave.query.language.parser.jexl.LuceneToJexlQueryParser)

Example 3 with JexlQueryFunction

use of datawave.query.language.functions.jexl.JexlQueryFunction in project datawave-query-metric-service by NationalSecurityAgency.

the class QueryMetricHandlerConfiguration method luceneToJexlQueryParser.

@Bean
@ConditionalOnMissingBean
public LuceneToJexlQueryParser luceneToJexlQueryParser() {
    LuceneToJexlQueryParser luceneToJexlQueryParser = new LuceneToJexlQueryParser();
    Set<String> skipTokenizedUnfieldedFields = new LinkedHashSet<>();
    skipTokenizedUnfieldedFields.add("DOMETA");
    luceneToJexlQueryParser.setSkipTokenizeUnfieldedFields(skipTokenizedUnfieldedFields);
    Map<String, JexlQueryFunction> allowedFunctions = new LinkedHashMap<>();
    for (JexlQueryFunction f : JexlTreeBuilder.DEFAULT_ALLOWED_FUNCTION_LIST) {
        allowedFunctions.put(f.getClass().getCanonicalName(), f);
    }
    // configure EvaluationOnly with this parser
    EvaluationOnly evaluationOnly = new EvaluationOnly();
    evaluationOnly.setParser(luceneToJexlQueryParser);
    allowedFunctions.put(EvaluationOnly.class.getCanonicalName(), evaluationOnly);
    luceneToJexlQueryParser.setAllowedFunctions(new ArrayList<>(allowedFunctions.values()));
    return luceneToJexlQueryParser;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) EvaluationOnly(datawave.query.language.functions.jexl.EvaluationOnly) JexlQueryFunction(datawave.query.language.functions.jexl.JexlQueryFunction) LuceneToJexlQueryParser(datawave.query.language.parser.jexl.LuceneToJexlQueryParser) LinkedHashMap(java.util.LinkedHashMap) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

JexlQueryFunction (datawave.query.language.functions.jexl.JexlQueryFunction)3 EvaluationOnly (datawave.query.language.functions.jexl.EvaluationOnly)2 LuceneToJexlQueryParser (datawave.query.language.parser.jexl.LuceneToJexlQueryParser)2 JexlFunctionNode (datawave.query.language.parser.jexl.JexlFunctionNode)1 JexlNode (datawave.query.language.parser.jexl.JexlNode)1 NotFoundQueryException (datawave.webservice.query.exception.NotFoundQueryException)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 FieldQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode)1 FunctionQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.FunctionQueryNode)1 QueryNode (org.apache.lucene.queryparser.flexible.core.nodes.QueryNode)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1