Skip to content

Commit

Permalink
Fix composite aggregation on unsigned long (#65715)
Browse files Browse the repository at this point in the history
This commit ensures that the after key is parsed with the doc value formatter.
This is needed for unsigned longs that uses shifted longs internally.

Closes #65685
  • Loading branch information
jimczi committed Dec 14, 2020
1 parent a783b16 commit 1f0b2ac
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,8 @@ private int compareValues(long v1, long v2) {
void setAfter(Comparable value) {
if (missingBucket && value == null) {
afterValue = null;
} else if (value instanceof Number) {
afterValue = ((Number) value).longValue();
} else {
// for date histogram source with "format", the after value is formatted
// as a string so we need to retrieve the original value in milliseconds.
// parse the value from a string in case it is a date or a formatted unsigned long.
afterValue = format.parseLong(value.toString(), false, () -> {
throw new IllegalArgumentException("now() is not supported in [after] key");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,80 @@ setup:
- match: { hits.hits.2.fields.ul.0 : "9223372036854775808" }
- match: { hits.hits.3.fields.ul.0 : "18446744073709551614" }
- match: { hits.hits.4.fields.ul.0 : "18446744073709551615" }

---
"Composite aggregations":
- skip:
version: " - 7.99.99"
reason: "TODO: unsigned_long support for composite aggs was fixed in 7.11"

- do:
search:
index: test1
body:
size: 0
aggs:
test:
composite:
size: 3
sources: [{
"ul": {
"terms": {
"field": "ul"
}
}
}]

- set: { aggregations.test.after_key: after_key }
- length: { aggregations.test.buckets: 3 }
- match: { aggregations.test.buckets.0.key.ul: 0 }
- match: { aggregations.test.buckets.0.doc_count: 1 }
- match: { aggregations.test.buckets.1.key.ul: 9223372036854775807 }
- match: { aggregations.test.buckets.1.doc_count: 1 }
- match: { aggregations.test.buckets.2.key.ul: 9223372036854775808 }
- match: { aggregations.test.buckets.2.doc_count: 1 }

- do:
search:
index: test1
body:
size: 0
aggs:
test:
composite:
size: 3
after: $after_key
sources: [{
"ul": {
"terms": {
"field": "ul"
}
}
}]

- set: { aggregations.test.after_key: after_key }
- length: { aggregations.test.buckets: 2 }
- match: { aggregations.test.buckets.0.key.ul: 18446744073709551614 }
- match: { aggregations.test.buckets.0.doc_count: 1 }
- match: { aggregations.test.buckets.1.key.ul: 18446744073709551615 }
- match: { aggregations.test.buckets.1.doc_count: 1 }

- do:
search:
index: test1
body:
size: 0
aggs:
test:
composite:
size: 3
after: $after_key
sources: [{
"ul": {
"terms": {
"field": "ul"
}
}
}]

- length: { aggregations.test.buckets: 0 }

0 comments on commit 1f0b2ac

Please sign in to comment.