-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Add support for script to boolean field mapper #71454
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
Add support for script to boolean field mapper #71454
Conversation
@@ -293,7 +293,7 @@ public void newDynamicDoubleField(ParseContext context, String name) throws IOEx | |||
|
|||
@Override | |||
public void newDynamicBooleanField(ParseContext context, String name) throws IOException { | |||
createDynamicField(new BooleanFieldMapper.Builder(name), context); | |||
createDynamicField(new BooleanFieldMapper.Builder(name, null), 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.
I wonder if instead of null we should have some impl of ScriptCompiler that throws UnsupportedOperationException when used.
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.
++, either here or in a follow up - it will be useful on the other field mappers as well
MultiFields multiFields, CopyTo copyTo, | ||
boolean hasScript, String onScriptError) { | ||
this(simpleName, mappedFieldType, Collections.emptyMap(), multiFields, copyTo, hasScript, onScriptError); | ||
} |
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.
if we agree on the new constructors, I think we should try to move all the callers of the ones without the additional parameters to these, otherwise we end up with too many constructors
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 like pulling out the common behaviour, but maybe we should try and localise this more? Have an intermediate class called ScriptableFieldMapper
or something like that?
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 sure it's worth the complexity of one additional intermediate base class, especially as more types will support a script.
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.
Fair enough - we can probably merge the single analyzer and multiple analyzer constructors at least without causing too much noise.
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.
agreed, let's do it as a followup?
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 couple of suggestions, I'm guessing tests will come in soon now that #71322 has been merged?
MultiFields multiFields, CopyTo copyTo, | ||
boolean hasScript, String onScriptError) { | ||
this(simpleName, mappedFieldType, Collections.emptyMap(), multiFields, copyTo, hasScript, onScriptError); | ||
} |
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 like pulling out the common behaviour, but maybe we should try and localise this more? Have an intermediate class called ScriptableFieldMapper
or something like that?
runForDoc(docId); | ||
int count = trues + falses; | ||
for (int i = 0; i < count; i++) { | ||
consumer.accept(i >= falses); |
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 think we need to emit true
trues
times and then false
falses
times here? Otherwise we're collapsing things down to a single value where there may be multiple values in the source.
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 think that is what I am doing: count is trues + falses. I emit false until there are falses left, and then trues. I may be missing something though as I don't follow the collapsing concern you mentioned :)
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.
duh yes, I am clearly not reading properly today. Maybe add a comment?
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.
Maybe it's because the code is cryptic. this is some simplification that IntelliJ suggested, I should go back to something more readable although longer.
Pinging @elastic/es-search (Team:Search) |
I pushed an update including docs and yaml tests |
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.
LGTM!
the document will be rejected with an error. | ||
Scripts are in the same format as their | ||
<<runtime-mapping-fields,runtime equivalent>>. Scripts can only be | ||
configured on `long` and `double` field types. |
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.
Don't need this last sentence for booleans :)
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.
ops
@@ -208,14 +242,21 @@ public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower | |||
private final boolean indexed; | |||
private final boolean hasDocValues; | |||
private final boolean stored; | |||
private final Script script; | |||
private final FieldValues<Boolean> scriptValues; | |||
private final ScriptCompiler scriptCompiler; |
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.
One feature freeze is gone I want to look seriously at moving merge
to Builder objects, having to carry this stuff around is a real pain.
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.
agreed! I am happy to help with that
@@ -293,7 +293,7 @@ public void newDynamicDoubleField(ParseContext context, String name) throws IOEx | |||
|
|||
@Override | |||
public void newDynamicBooleanField(ParseContext context, String name) throws IOException { | |||
createDynamicField(new BooleanFieldMapper.Builder(name), context); | |||
createDynamicField(new BooleanFieldMapper.Builder(name, null), 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.
++, either here or in a follow up - it will be useful on the other field mappers as well
MultiFields multiFields, CopyTo copyTo, | ||
boolean hasScript, String onScriptError) { | ||
this(simpleName, mappedFieldType, Collections.emptyMap(), multiFields, copyTo, hasScript, onScriptError); | ||
} |
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.
Fair enough - we can probably merge the single analyzer and multiple analyzer constructors at least without causing too much noise.
if (script.getIdOrCode().equals("serializer_test")) { | ||
return (T) serializableScript(); | ||
return (T)serializableScript(); |
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.
nit: I definitely prefer a space here...
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 not meant to happen :)
Relates to #68984