Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/124451.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 124451
summary: Improve downsample dimension processing
area: Downsampling
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,29 @@ void reset() {
isEmpty = true;
}

void collect(final Object value) {
void collectOnce(final Object value) {
assert isEmpty;
Objects.requireNonNull(value);
if (isEmpty) {
this.value = value;
this.isEmpty = false;
return;
}
if (value.equals(this.value) == false) {
throw new IllegalArgumentException("Dimension value changed without tsid change [" + value + "] != [" + this.value + "]");
this.value = value;
this.isEmpty = false;
}

/**
* This is an expensive check, that slows down downsampling significantly.
* Given that index is sorted by tsid as primary key, this shouldn't really happen.
*/
boolean validate(FormattedDocValues docValues, int docId) throws IOException {
if (docValues.advanceExact(docId)) {
int docValueCount = docValues.docValueCount();
for (int i = 0; i < docValueCount; i++) {
var value = docValues.nextValue();
if (value.equals(this.value) == false) {
assert false : "Dimension value changed without tsid change [" + value + "] != [" + this.value + "]";
}
}
}

return true;
}
}

Expand All @@ -69,12 +82,17 @@ public boolean isEmpty() {

@Override
public void collect(FormattedDocValues docValues, int docId) throws IOException {
if (dimension.isEmpty == false) {
assert dimension.validate(docValues, docId);
return;
}

if (docValues.advanceExact(docId) == false) {
return;
}
int docValueCount = docValues.docValueCount();
for (int i = 0; i < docValueCount; i++) {
this.dimension.collect(docValues.nextValue());
this.dimension.collectOnce(docValues.nextValue());
}
}

Expand Down