-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Check for runtime field loops in queries #61927
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
Conversation
We were checking for loops in queries before, but we had an "off by one" error where we wouldn't notice the "top level" runtime field when detecting a loop. So the error message would be wrong. I also caught a few bugs with query generation caused by missing `@Override` annotations and fixed a few of them. There is a bug with `regexp` queries with match options that I'm not fixing in this PR but will get to later. Relates to elastic#59332
Pinging @elastic/es-search (:Search/Search) |
@@ -61,6 +71,26 @@ public final boolean isAggregatable() { | |||
return true; | |||
} | |||
|
|||
/** |
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 pulled this function into the superclass because it the "for query" version of it is tricky. We could probably avoid the type parameter if we really wanted to by being a bit more tricky, but I'm not sure it is worth it.
public Query regexpQuery( | ||
String value, | ||
int flags, | ||
int syntaxFlags, | ||
int matchFlags, |
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.
Missing this was a bug that causes regexes not to work at all!
@@ -119,14 +109,18 @@ public Query rangeQuery( | |||
public Query termQuery(Object value, QueryShardContext context) { | |||
checkAllowExpensiveQueries(context); | |||
if (value instanceof InetAddress) { | |||
return InetAddressPoint.newExactQuery(name(), (InetAddress) value); | |||
return inetAddressQuery((InetAddress) value, context); |
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 was a bug!
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.
should we push this separately?
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'm ok pushing it as part of this because this is ready.
checkAllowExpensiveQueries(context); | ||
return new StringScriptFieldRegexpQuery(script, leafFactory(context.lookup()), name(), value, flags, maxDeterminizedStates); | ||
if (matchFlags != 0) { |
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'd like to leave this for later.
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 no longer sure what is left to do here. Do we need an issue for it? Didn't you push the regex changes separately?
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.
@markharwood is working on a change that'll take the matchFlags into account.
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'm not sure why this isn't a noop - I thought I pushed this exact change separately.
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.
Ah, not it is a noop.
public Query phrasePrefixQuery(TokenStream stream, int slop, int maxExpansions) throws IOException { | ||
throw new IllegalArgumentException(unsupported("phrase prefix", "text")); | ||
} | ||
|
||
@Override |
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've seen this popup in this and some other PR, can we merge this fix separately?
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've pushed a fix for this to master and 7.x. I'll merge that into this branch now.
@@ -183,6 +183,7 @@ setup: | |||
loop: | |||
terms: | |||
field: over_max_depth |
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.
do you mind adding one test here also for loops around queries? I know you wrote a lot of those above (thanks) but I would find this yaml suite more complete if we also covered loops for queries (I did not add specific tests in the first place because I knew they would fail)
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've added some in the last commit I pushed.
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.
thanks!
@@ -149,7 +179,7 @@ public SpanQuery spanPrefixQuery(String value, SpanMultiTermQueryWrapper.SpanRew | |||
} | |||
|
|||
private String unsupported(String query, String supported) { | |||
String thisField = "[" + name() + "] which is of type [script] with runtime_type [" + runtimeType() + "]"; | |||
String thisField = "[" + name() + "] which is of type [runtime] with runtime_type [" + runtimeType() + "]"; |
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 is something I bumped into while working on this. Just had the old name left over.
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.
use the constant, then renaming is much easier.
@@ -43,7 +43,7 @@ private void assertQueryOnlyOnTextAndKeyword(String queryName, ThrowingRunnable | |||
equalTo( | |||
"Can only use " | |||
+ queryName | |||
+ " queries on keyword and text fields - not on [test] which is of type [script] with runtime_type [" |
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 is the other half of the "old name" bug I fixed way above.
@@ -183,6 +183,7 @@ setup: | |||
loop: | |||
terms: | |||
field: over_max_depth |
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've added some in the last commit I pushed.
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 left a few nits, LGTM otherwise
We were checking for loops in queries before, but we had an "off by one" error where we wouldn't notice the "top level" runtime field when detecting a loop. So the error message would be wrong. I also caught a few bugs with query generation caused by missing `@Override` annotations and fixed a few of them. There is a bug with `regexp` queries with match options that I'm not fixing in this PR but will get to later. Relates to elastic#59332
We were checking for loops in queries before, but we had an "off by one" error where we wouldn't notice the "top level" runtime field when detecting a loop. So the error message would be wrong. I also caught a few bugs with query generation caused by missing `@Override` annotations and fixed a few of them. There is a bug with `regexp` queries with match options that I'm not fixing in this PR but will get to later. Relates to #59332
We were checking for loops in queries before, but we had an "off by one" error where we wouldn't notice the "top level" runtime field when detecting a loop. So the error message would be wrong. I also caught a few bugs with query generation caused by missing `@Override` annotations and fixed a few of them. There is a bug with `regexp` queries with match options that I'm not fixing in this PR but will get to later. Relates to #59332
We were checking for loops in queries before, but we had an "off by one"
error where we wouldn't notice the "top level" runtime field when
detecting a loop. So the error message would be wrong.
I also caught a few bugs with query generation caused by missing
@Override
annotations and fixed a few of them. There is a bug withregexp
queries with match options that I'm not fixing in this PR butwill get to later.
Relates to #59332