-
Notifications
You must be signed in to change notification settings - Fork 242
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
Open
lbschanno
wants to merge
14
commits into
integration
Choose a base branch
from
task/queryValidationEndpointImpl
base: integration
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
ivakegg
reviewed
Nov 29, 2024
warehouse/query-core/src/main/java/datawave/query/language/parser/QueryParser.java
Outdated
Show resolved
Hide resolved
ivakegg
reviewed
Nov 29, 2024
.../query-core/src/main/java/datawave/query/language/parser/jexl/JexlControlledQueryParser.java
Outdated
Show resolved
Hide resolved
ivakegg
reviewed
Nov 29, 2024
core/query/src/main/java/datawave/core/query/logic/QueryLogic.java
Outdated
Show resolved
Hide resolved
ivakegg
reviewed
Nov 29, 2024
warehouse/query-core/src/main/java/datawave/query/tables/ShardQueryLogic.java
Outdated
Show resolved
Hide resolved
ivakegg
reviewed
Nov 29, 2024
web-services/query/src/main/java/datawave/webservice/query/runner/QueryExecutorBean.java
Outdated
Show resolved
Hide resolved
ivakegg
reviewed
Nov 29, 2024
web-services/query/src/main/java/datawave/webservice/query/runner/QueryExecutorBean.java
Outdated
Show resolved
Hide resolved
ivakegg
reviewed
Nov 29, 2024
web-services/query/src/main/java/datawave/webservice/query/runner/QueryExecutorBean.java
Outdated
Show resolved
Hide resolved
ivakegg
reviewed
Nov 29, 2024
warehouse/query-core/src/main/java/datawave/query/tables/ShardQueryLogic.java
Outdated
Show resolved
Hide resolved
ivakegg
reviewed
Nov 29, 2024
...se/query-core/src/main/java/datawave/query/jexl/visitors/FieldsWithNumericValuesVisitor.java
Show resolved
Hide resolved
ivakegg
reviewed
Nov 29, 2024
.../query-core/src/main/java/datawave/query/lucene/visitors/AmbiguousUnfieldedTermsVisitor.java
Show resolved
Hide resolved
ivakegg
reviewed
Nov 29, 2024
warehouse/query-core/src/main/java/datawave/query/lucene/visitors/BaseVisitor.java
Show resolved
Hide resolved
ivakegg
reviewed
Nov 29, 2024
warehouse/query-core/src/main/java/datawave/query/lucene/visitors/PrintingVisitor.java
Show resolved
Hide resolved
ivakegg
requested changes
Nov 29, 2024
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
ivakegg
previously approved these changes
Jan 8, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: