forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Star Tree Request/Response structure #227
Closed
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,12 +32,14 @@ | |
package org.opensearch.search.aggregations.metrics; | ||
|
||
import org.apache.lucene.index.LeafReaderContext; | ||
import org.apache.lucene.index.SortedNumericDocValues; | ||
import org.apache.lucene.search.ScoreMode; | ||
import org.opensearch.common.lease.Releasables; | ||
import org.opensearch.common.util.BigArrays; | ||
import org.opensearch.common.util.DoubleArray; | ||
import org.opensearch.index.codec.composite.CompositeIndexFieldInfo; | ||
import org.opensearch.index.codec.composite.datacube.startree.StarTreeValues; | ||
import org.opensearch.index.compositeindex.datacube.startree.utils.StarTreeHelper; | ||
import org.opensearch.index.fielddata.SortedNumericDoubleValues; | ||
import org.opensearch.search.DocValueFormat; | ||
import org.opensearch.search.aggregations.Aggregator; | ||
|
@@ -137,8 +139,9 @@ private LeafBucketCollector getStarTreeLeafCollector(LeafReaderContext ctx, Leaf | |
|
||
StarTreeValues starTreeValues = getStarTreeValues(ctx, starTree); | ||
|
||
// | ||
String fieldName = ((ValuesSource.Numeric.FieldData) valuesSource).getIndexFieldName(); | ||
String metricName = StarTreeHelper.fullFieldNameForStarTreeMetricsDocValues(starTree.getField(), fieldName, "sum"); | ||
|
||
|
||
return new LeafBucketCollectorBase(sub, starTreeValues) { | ||
@Override | ||
|
@@ -147,7 +150,23 @@ public void collect(int doc, long bucket) throws IOException { | |
sums = bigArrays.grow(sums, bucket + 1); | ||
compensations = bigArrays.grow(compensations, bucket + 1); | ||
compensations.set(bucket, kahanSummation.delta()); | ||
sums.set(bucket, kahanSummation.value()); | ||
|
||
SortedNumericDocValues dv = (SortedNumericDocValues) starTreeValues.getMetricDocValuesIteratorMap().get(metricName); | ||
|
||
if (dv.advanceExact(doc)) { | ||
final int valuesCount = dv.docValueCount(); | ||
double sum = sums.get(bucket); | ||
double compensation = compensations.get(bucket); | ||
kahanSummation.reset(sum, compensation); | ||
|
||
for (int i = 0; i < valuesCount; i++) { | ||
double value = Double.longBitsToDouble(dv.nextValue()); | ||
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. shouldn't we do this ?
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. Also lets see if we can get double sorted numeric dv ahead
|
||
kahanSummation.add(value); | ||
} | ||
|
||
compensations.set(bucket, kahanSummation.delta()); | ||
sums.set(bucket, kahanSummation.value()); | ||
} | ||
} | ||
}; | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we extract out the default implementation
getDefaultLeafCollector
and reuse the same logic.I really like the approach of reusing the existing aggregators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll try and do that, I am inclined to on refactoring & re-using same implementations wherever possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final SortedNumericDoubleValues values = valuesSource.doubleValues(ctx);
we can check if we are able to get sortedNumericDoubleValues , otherwise we need to convert to double for each doc