-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Separate AbstractScriptFieldType from RuntimeField implementations #74768
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
Separate AbstractScriptFieldType from RuntimeField implementations #74768
Conversation
Pinging @elastic/es-search (Team:Search) |
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 some initial comments, thanks for working on this
server/src/main/java/org/elasticsearch/index/mapper/BooleanScriptFieldType.java
Show resolved
Hide resolved
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
public abstract class ScriptRuntimeField implements RuntimeField { |
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 a bit on the fence on the naming, mostly because the object field is also going to hold a script but will not extend this class. Maybe this could be named LeafRuntimeField or something along those lines?
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.
++ to LeafRuntimeField, the main use of this base class is to simplify returning a single-valued collection from asMappedFieldTypes()
and 'Leaf' reinforces that.
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
public abstract class ScriptRuntimeField implements RuntimeField { |
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.
can you also add javadocs to explain what this class is intended for?
|
||
public abstract class ScriptRuntimeField implements RuntimeField { | ||
|
||
protected final String name; |
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 one corresponds to the simple field name in ObjectMapper right? It is only the name of the leaf field, although it can still contain dots? I wonder if we should clearly document this.
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.
We don't have object fields yet so there isn't a distinction here at the moment. Let's document it when we know precisely how the two different names will work?
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.
good point, thanks
@@ -288,6 +288,6 @@ public void execute() { | |||
} | |||
|
|||
private static IpScriptFieldType build(Script script) { | |||
return new IpScriptFieldType("test", factory(script), script, emptyMap(), (builder, params) -> builder); | |||
return new IpScriptFieldType("test", factory(script), script, emptyMap()); |
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 change feels good.
@@ -217,16 +217,14 @@ public void testRuntimeSectionMerge() throws IOException { | |||
merge(mapperService, mapping); | |||
DoubleScriptFieldType field = (DoubleScriptFieldType)mapperService.fieldType("field"); | |||
assertEquals(NumberFieldMapper.NumberType.DOUBLE.typeName(), field.typeName()); | |||
LongScriptFieldType field2Updated = (LongScriptFieldType)mapperService.fieldType("field2"); | |||
assertSame(field2, field2Updated); | |||
assertThat(mapperService.fieldType("field2"), instanceOf(LongScriptFieldType.class)); |
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.
so, now the runtime field is the same instance but not the mapped field type, or?
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.
yes, exactly.
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.
which makes me wonder: do we need to return a new instance each time asMappedFieldType is called? Probably not?
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.
We probably could create fixed MappedFieldTypes at construction time and always return the same object, but this is only called when Mappings are re-parsed so I'm not sure it really makes a lot of difference.
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.
it certainly complicates the test no? What do we do for field mappers? Don't we always expose the same field type, that is created at construction time?
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.
Have pushed a change to built the field types up front.
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 thanks!
💔 Backport failed
To backport manually run: |
…74768) AbstractScriptFieldType extends MappedFieldType and also implements RuntimeField. This means that the name() of a runtime field has to be the same as the name() of its corresponding mapped field type. However, for object fields we will want the nested child fields to have a specific short name, while their MappedFieldType will need to have a name that includes the parent. To make this distinction possible, this commit changes AbstractScriptFieldType subclasses to return their own implementations of RuntimeField from their type parsers instead of implementing the interface directly.
AbstractScriptFieldType extends MappedFieldType and also implements
RuntimeField. This means that the name() of a runtime field has to be the
same as the name() of its corresponding mapped field type. However, for
object fields we will want the nested child fields to have a specific short name,
while their MappedFieldType will need to have a name that includes the parent.
To make this distinction possible, this commit changes AbstractScriptFieldType
subclasses to return their own implementations of RuntimeField from their
type parsers instead of implementing the interface directly.