-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Make a builder for _tsid #83799
Make a builder for _tsid #83799
Conversation
Pinging @elastic/es-analytics-geo (Team:Analytics) |
? TimeSeriesIdFieldMapper.encodeTsidValue(NetworkAddress.format(address)) | ||
: null; | ||
context.doc().addDimensionBytes(fieldType().name(), bytes); | ||
context.doc().getDimensions().addIp(fieldType().name(), address); |
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 gets decided when the LuceneDocument
is built - no need to check.
return decodeTsid(input); | ||
} catch (IOException ex) { | ||
throw new IllegalArgumentException("Dimension field cannot be deserialized.", ex); | ||
public static class TimeSeriesIdBuilder implements DocumentDimensions { |
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 stuffed this as an inner class because I have more follow up plans that I've half written that'd move it and this seemed like the most convenient temporary spot.
`_tsid` is built by getting a sorted list of encoded dimensions. This creates a `TimeSeriesIdBuilder` that abstracts that behind sensibly named methods.
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.
These changes exceeded my expectations of potential benefits from this refactoring. I really like how it consolidates the tsid-related logic together and where it is going. I added a couple of small suggestions, but otherwise it looks awesome!
|
||
@Override | ||
public DocumentDimensions buildDimensionConsumer() { | ||
return new DocumentDimensions.OnlySingleValueAllowed(); |
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 really like this, but is this a breaking change?
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.
That's how it always worked.
server/src/main/java/org/elasticsearch/search/DocValueFormat.java
Outdated
Show resolved
Hide resolved
|
||
LuceneDocument(String path, LuceneDocument parent) { | ||
LuceneDocument(String path, LuceneDocument parent, DocumentDimensions dimensions) { |
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.
Does it need to be a part of lucene document?
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.
Hmmmmmm........ It needs to be part of the DocumentParserContext
. I suppose it makes more sense for it to live there!
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's a shame that we don't pass DocumentParserContext
in the LuceneDocument
. Injecting the DocumentDimensions
object feels a bit weird 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.
I broke it out of LuceneDocument
and it is much nicer now.
@@ -269,7 +269,7 @@ public final DocumentParserContext createNestedContext(String fullPath) { | |||
// nested context will already have been set up for copy_to fields | |||
return this; | |||
} | |||
final LuceneDocument doc = new LuceneDocument(fullPath, doc()); | |||
final LuceneDocument doc = new LuceneDocument(fullPath, doc(), doc().getDimensions()); |
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.
Does it mean that nested documents can contribute dimensions into the root document? I don't think we should allow it.
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 couple of things:
- Nested fields aren't allowed at all in time series mode. I've opened up TSDB: improve error message for nested fields #83837 to add a test for this.
- Nested fields are allowed to have dimensions currently. And it'd be breaking to change that. I think these are documented as experimental so maybe we can? But I don't want to change it in a refactoring PR. TSDB: improve error message for nested fields #83837 adds a test for the behavior we have.
return timeSeriesId; | ||
} | ||
TimeSeriesIdBuilder timeSeriesIdBuilder = (TimeSeriesIdBuilder) context.doc().getDimensions(); | ||
context.doc().add(new SortedDocValuesField(fieldType().name(), timeSeriesIdBuilder.build().toBytesRef())); |
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 I would either 1) move this logic to LuceneDocument and teach it how to create tsid or 2) move the builder to context and keep LuceneDocument blissfully unaware of time series world otherwise this "Please hold this for me" type of interaction with LuceneDocument is a bit weird. I think I would prefer 2). The first solution would make more sense if we wanted to do keep different dimensions for nested documents, but at the moment they share the same set of dimensions anyway (which is probably a topic for another discussion).
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'll move it.
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's so much cleaner!
run elasticsearch-ci/part-2 |
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
|
||
LuceneDocument(String path, LuceneDocument parent) { | ||
LuceneDocument(String path, LuceneDocument parent, DocumentDimensions dimensions) { |
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's a shame that we don't pass DocumentParserContext
in the LuceneDocument
. Injecting the DocumentDimensions
object feels a bit weird here.
? TimeSeriesIdFieldMapper.encodeTsidValue(NetworkAddress.format(address)) | ||
: null; | ||
context.doc().addDimensionBytes(fieldType().name(), bytes); | ||
context.getDimensions().addIp(fieldType().name(), address); |
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 lot cleaner this way. Happy to see the conditional leave 👍
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 really like where it is going. Thanks for iterating on this.
_tsid
is built by getting a sorted list of encoded dimensions. Thiscreates a
TimeSeriesIdBuilder
that abstracts that behind sensiblynamed methods.