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.
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.
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.
imotov
left a comment
There was a problem hiding this comment.
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.
I really like this, but is this a breaking change?
There was a problem hiding this comment.
That's how it always worked.
server/src/main/java/org/elasticsearch/search/DocValueFormat.java
Outdated
Show resolved
Hide resolved
| private SortedMap<BytesRef, BytesReference> dimensionBytes; | ||
|
|
||
| LuceneDocument(String path, LuceneDocument parent) { | ||
| LuceneDocument(String path, LuceneDocument parent, DocumentDimensions dimensions) { |
There was a problem hiding this comment.
Does it need to be a part of lucene document?
There was a problem hiding this comment.
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.
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.
I broke it out of LuceneDocument and it is much nicer now.
| 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.
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.
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.
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).
|
run elasticsearch-ci/part-2 |
| private SortedMap<BytesRef, BytesReference> dimensionBytes; | ||
|
|
||
| LuceneDocument(String path, LuceneDocument parent) { | ||
| LuceneDocument(String path, LuceneDocument parent, DocumentDimensions dimensions) { |
There was a problem hiding this comment.
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.
A lot cleaner this way. Happy to see the conditional leave 👍
imotov
left a comment
There was a problem hiding this comment.
I really like where it is going. Thanks for iterating on this.
_tsidis built by getting a sorted list of encoded dimensions. Thiscreates a
TimeSeriesIdBuilderthat abstracts that behind sensiblynamed methods.