Implement query validation endpoint #2645
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implement the query/{logicName}/validate endpoint. This feature supports the ability to configure validation rules that will validate LUCENE and JEXL queries against a number of criteria and provide meaningful feedback to customers.
Closes #2585
Each validation criteria is implemented via a corresponding
datawave.query.rules.QueryRule implementation
.Rule implementations:
datawave.query.rules.AmbiguousNotRule
Checks LUCENE queries for usage of NOT without using parens (NOT takes precedence so the resulting plan could be quite incorrect):
FIELD1:abc OR FIELD2:def NOT FIELD3:123
-> should be(FIELD1:abc OR FIELD2:def) NOT FIELD3:123
Sample bean config:
Sample message for query
FIELD1:abc FIELD2:def NOT FIELD:ghi
:datawave.query.rules.AmbiguousOrPhrasesRule
Checks LUCENE queries for any parens before field or completely missing parens when using ORs:
FIELD:1234 OR 5678
-> should beFIELD:(1234 OR 5678)
(FIELD:1234 OR 5678)
-> should beFIELD:(1243 OR 5687)
Sample bean config:
Sample message for query
FOO:abc OR def OR efg
:datawave.query.rules.AmbiguousUnquotedPhrasesRule
Checks LUCENE queries for any phrases not quoted (where we would automatically AND) anywhere that the boolean operator is missing
FIELD:term1 term2
-> should beFIELD:"term1 term2"
Sample bean config:
Sample message for query
FOO:abc def ghi
:datawave.query.rules.FieldExistenceRule
Checks the query for any fields that do not exist in the data dictionary. Special fields may be specified that will not be flagged if they do not exist in the data dictionary.
Sample bean config:
Sample message for query
FOO:abc AND MISSING1:def AND MISSING2:efg
:datawave.query.rules.FieldPatternPresenceRule
Returns configured messages if we see field X or Y.
Sample bean config:
Sample messages for query
_ANYFIELD_:abc || FOO:.*
datawave.query.rules.IncludeExcludeArgsRule
Checks LUCENE queries for any
#INCLUDE
or#EXCLUDE
functions with an incorrect number of arguments, taking into account whether a boolean was given as the first argument.Sample bean config:
Sample message for query:
#INCLUDE(OR, 'value')
datawave.query.rules.IncludeExcludeIndexFieldsRule
Checks queries for any usage of
#INCLUDE
or#EXCLUDE
with index fields in them.Sample bean config:
Sample message for query:
FOO:abc AND #INCLUDE(INDEXED1, 'abc')
:datawave.query.rules.InvalidQuoteRule
Checks LUCENE queries for the usage of the quote ` instead of '.
Sample bean config:
Sample message for query
FOO:'abc' AND BAR:`def`
:datawave.query.rules.MinimumSlopProximityRule
Checks queries for any cases where the proximity is smaller than the number of terms.
FIELD:"term1 term2 term3"~1
-> the 1 should be 3 or greater.Sample bean config:
Sample message for query
FOO:"term1 term2 term3"~2
:datawave.query.rules.NumericValueRule
Checks queries for any cases where a numeric value is used against a non-numeric field.
Sample bean config:
Sample message for query
AGE:1 AND NON_NUMERIC_FIELD:4
datawave.query.rules.TimeFunctionRule
Checks queries for any usage of
#TIME_FUNCTION
with any non-date fields.Sample bean config:
Sample message for query
filter:timeFunction(DATE1,NON_DATE2,'-','>',2522880000000L)
:datawave.query.rules.UnescapedSpecialCharsRule
Checks queries for fields and patterns with unescaped special characters. Characters that should be considered exceptions to the rule may be configured for literals and patterns. The regex-reserved characters
. + * ? ^ $ ( ) [ ] { } | \
will always be treated as exceptions for patterns. Whether whitespace characters should be considered special characters is also configurable.Sample bean config:
Sample message for query
FOO == 'ab?c' || FOO =~ 'ab_cd'
:datawave.query.rules.UnescapedWildcardsInPhrasesRule
Checks LUCENE queries for any quoted phrases that have an unescaped wildcard in them.
Sample bean config:
Sample message for
FOO:"ab*"
:datawave.query.rules.UnfieldedTermsRule
Checks LUCENE queries for any unfielded terms.
Sample bean config:
Sample message for
FOO:abc def "efg"
Activating Rules
Rules must be configured in the QueryLogicFactory.xml and added to the list of rules configured for the
validationRules
property of a ShardQueryLogic.Sample bean config:
Some notes on rules:
validationRules
property.REST Response Schema
The REST response schema will be as follows: