-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Add support for multi-value dimensions #112645
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
Changes from 11 commits
d9f5151
65ad357
86b49df
94f43b2
5db10ab
f57531e
fed89de
8ad80b3
2d4f48d
c75d9a1
237068d
699e97e
81227e4
106110c
2fcb198
0b100fb
30d334b
0ae986a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,7 +179,7 @@ public static class TimeSeriesIdBuilder implements DocumentDimensions { | |
private final Murmur3Hasher tsidHasher = new Murmur3Hasher(0); | ||
|
||
/** | ||
* A sorted set of the serialized values of dimension fields that will be used | ||
* A map of the serialized values of dimension fields that will be used | ||
* for generating the _tsid field. The map will be used by {@link TimeSeriesIdFieldMapper} | ||
* to build the _tsid field for the document. | ||
*/ | ||
|
@@ -205,6 +205,7 @@ public BytesReference buildLegacyTsid() throws IOException { | |
out.writeBytesRef(entry.getKey()); | ||
List<BytesReference> value = entry.getValue(); | ||
if (value.size() > 1) { | ||
// multi-value dimensions are only supported for newer indices that use buildTsidHash | ||
throw new IllegalArgumentException( | ||
felixbarny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"Dimension field [" + entry.getKey().utf8ToString() + "] cannot be a multi-valued field." | ||
); | ||
|
@@ -271,7 +272,9 @@ public BytesReference buildTsidHash() { | |
// NOTE: hash all dimension field allValues | ||
tsidHasher.reset(); | ||
for (final List<BytesReference> values : dimensions.values()) { | ||
values.forEach(v -> tsidHasher.update(v.toBytesRef().bytes)); | ||
for (BytesReference v : values) { | ||
tsidHasher.update(v.toBytesRef().bytes); | ||
} | ||
} | ||
tsidHashIndex = writeHash128(tsidHasher.digestHash(), tsidHash, tsidHashIndex); | ||
|
||
|
@@ -378,10 +381,15 @@ private void add(String fieldName, BytesReference encoded) throws IOException { | |
List<BytesReference> values = dimensions.get(name); | ||
if (values == null) { | ||
// optimize for the common case where dimensions are not multi-valued | ||
values = new ArrayList<>(1); | ||
values.add(encoded); | ||
dimensions.put(name, values); | ||
dimensions.put(name, List.of(encoded)); | ||
} else { | ||
if (values.size() == 1) { | ||
// converts the immutable list that's optimized for the common case of having only one value to a mutable list | ||
BytesReference previousValue = values.get(0); | ||
values = new ArrayList<>(4); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the multi valued case, do you often expect 4 ip values? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is assuming that when there are multiple values, we'll likely have less than 10 (the default size for ArrayLists), but probably more than 2. |
||
values.add(previousValue); | ||
dimensions.put(name, values); | ||
} | ||
values.add(encoded); | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.