-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement query validation endpoint #2645
base: integration
Are you sure you want to change the base?
Conversation
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
warehouse/query-core/src/main/java/datawave/query/language/parser/QueryParser.java
Outdated
Show resolved
Hide resolved
.../query-core/src/main/java/datawave/query/language/parser/jexl/JexlControlledQueryParser.java
Outdated
Show resolved
Hide resolved
core/query/src/main/java/datawave/core/query/logic/QueryLogic.java
Outdated
Show resolved
Hide resolved
warehouse/query-core/src/main/java/datawave/query/tables/ShardQueryLogic.java
Outdated
Show resolved
Hide resolved
web-services/query/src/main/java/datawave/webservice/query/runner/QueryExecutorBean.java
Outdated
Show resolved
Hide resolved
web-services/query/src/main/java/datawave/webservice/query/runner/QueryExecutorBean.java
Outdated
Show resolved
Hide resolved
web-services/query/src/main/java/datawave/webservice/query/runner/QueryExecutorBean.java
Outdated
Show resolved
Hide resolved
warehouse/query-core/src/main/java/datawave/query/tables/ShardQueryLogic.java
Outdated
Show resolved
Hide resolved
...se/query-core/src/main/java/datawave/query/jexl/visitors/FieldsWithNumericValuesVisitor.java
Show resolved
Hide resolved
.../query-core/src/main/java/datawave/query/lucene/visitors/AmbiguousUnfieldedTermsVisitor.java
Show resolved
Hide resolved
warehouse/query-core/src/main/java/datawave/query/lucene/visitors/BaseVisitor.java
Show resolved
Hide resolved
|
||
import datawave.query.Constants; | ||
|
||
public class PrintingVisitor extends BaseVisitor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not seeing this class being used anywhere, what am I missing. Also what functionality does this provide that the LuceneQueryStringBuildingVisitor does not already supply?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class is analogous to the PrintingVisitor for JEXL queries. It prints the overall structure of LUCENE query trees so that we can the hierarchy of nodes and their details. We used it extensively when examining trees while writing tests. It is currently now used in at least one place to log the LUCENE query after the initial parse in ShardQueryLogic.validateQuery().
The LuceneQueryStringBuildingVisitor is analogous to JexlStringBuildingVisitor. It returns a LUCENE query tree as a query string, but does not show the actual structure of the tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments to handle, but all in all this looks pretty good! Created #2656 with some of the suggested changes.
* Suggested changes * Removed unused imports
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: