Skip to content
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

Merged
merged 8 commits into from
Feb 14, 2022
Merged

Make a builder for _tsid #83799

merged 8 commits into from
Feb 14, 2022

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Feb 10, 2022

_tsid is built by getting a sorted list of encoded dimensions. This
creates a TimeSeriesIdBuilder that abstracts that behind sensibly
named methods.

@nik9000 nik9000 requested review from imotov and csoulios February 10, 2022 18:37
@elasticmachine elasticmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Feb 10, 2022
@elasticmachine
Copy link
Collaborator

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);
Copy link
Member Author

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 {
Copy link
Member Author

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.
Copy link
Contributor

@imotov imotov left a 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();
Copy link
Contributor

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?

Copy link
Member Author

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.


LuceneDocument(String path, LuceneDocument parent) {
LuceneDocument(String path, LuceneDocument parent, DocumentDimensions dimensions) {
Copy link
Contributor

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?

Copy link
Member Author

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!

Copy link
Contributor

@csoulios csoulios Feb 11, 2022

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.

Copy link
Member Author

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());
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of things:

  1. 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.
  2. 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()));
Copy link
Contributor

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).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll move it.

Copy link
Member Author

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!

@nik9000
Copy link
Member Author

nik9000 commented Feb 11, 2022

run elasticsearch-ci/part-2

Copy link
Contributor

@csoulios csoulios left a 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) {
Copy link
Contributor

@csoulios csoulios Feb 11, 2022

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);
Copy link
Contributor

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 👍

Copy link
Contributor

@imotov imotov left a 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.

@nik9000 nik9000 merged commit da6a1e4 into elastic:master Feb 14, 2022
@nik9000
Copy link
Member Author

nik9000 commented Feb 14, 2022

Thanks @imotov and @csoulios !

nik9000 added a commit that referenced this pull request Feb 14, 2022
Like ships passing in the night #83799 and #83837 missed eachother and
then crashed together in the master branch causing failures. Ooops.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>non-issue :StorageEngine/TSDB You know, for Metrics Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants