@@ -52,72 +52,75 @@ public class StatsAggregator extends MetricsAggregator {
5252
5353 protected ObjectArray <StatsSampling <?>> samplings ;
5454
55- public StatsAggregator (String name , List <NamedValuesSourceSpec <Numeric >> valuesSources ,
56- SearchContext context ,
57- Aggregator parent , MultiValueMode multiValueMode ,
58- List <PipelineAggregator > pipelineAggregators ,
59- Map <String , Object > metaData ) throws IOException {
55+ public StatsAggregator (final String name ,
56+ final List <NamedValuesSourceSpec <Numeric >> valuesSources ,
57+ final SearchContext context ,
58+ final Aggregator parent , final MultiValueMode multiValueMode ,
59+ final List <PipelineAggregator > pipelineAggregators ,
60+ final Map <String , Object > metaData ) throws IOException {
6061 super (name , context , parent , pipelineAggregators , metaData );
6162 if (valuesSources != null && !valuesSources .isEmpty ()) {
6263 this .valuesSources = new NumericMultiValuesSource (valuesSources , multiValueMode );
63- samplings = context .bigArrays ().newObjectArray (1 );
64+ this . samplings = context .bigArrays ().newObjectArray (1 );
6465 } else {
6566 this .valuesSources = null ;
6667 }
6768 }
6869
6970 @ Override
7071 public boolean needsScores () {
71- return ( valuesSources == null ) ? false : valuesSources .needsScores ();
72+ return this . valuesSources == null || this . valuesSources .needsScores ();
7273 }
7374
7475 @ Override
75- public LeafBucketCollector getLeafCollector (LeafReaderContext ctx ,
76+ public LeafBucketCollector getLeafCollector (final LeafReaderContext ctx ,
7677 final LeafBucketCollector sub ) throws IOException {
77- if (valuesSources == null ) {
78+ if (this . valuesSources == null ) {
7879 return LeafBucketCollector .NO_OP_COLLECTOR ;
7980 }
80- final BigArrays bigArrays = context .bigArrays ();
81- final NumericDoubleValues [] values = new NumericDoubleValues [valuesSources .fieldNames ().length ];
81+ final BigArrays bigArrays = this .context .bigArrays ();
82+ final NumericDoubleValues [] values = new NumericDoubleValues [this .valuesSources
83+ .fieldNames ().length ];
8284 for (int i = 0 ; i < values .length ; ++i ) {
83- values [i ] = valuesSources .getField (i , ctx );
85+ values [i ] = this . valuesSources .getField (i , ctx );
8486 }
8587
8688 return new LeafBucketCollectorBase (sub , values ) {
87- final String [] fieldNames = valuesSources .fieldNames ();
88- final double [] fieldVals = new double [fieldNames .length ];
89+ final String [] fieldNames = StatsAggregator . this . valuesSources .fieldNames ();
90+ final double [] fieldVals = new double [this . fieldNames .length ];
8991
9092 @ Override
91- public void collect (int doc , long bucket ) throws IOException {
93+ public void collect (final int doc , final long bucket ) throws IOException {
9294 // get fields
9395 if (includeDocument (doc ) == true ) {
94- samplings = bigArrays .grow (samplings , bucket + 1 );
95- StatsSampling <?> sampling = samplings .get (bucket );
96+ StatsAggregator .this .samplings = bigArrays
97+ .grow (StatsAggregator .this .samplings , bucket + 1 );
98+ StatsSampling <?> sampling = StatsAggregator .this .samplings .get (bucket );
9699 // add document fields to correlation stats
97100 if (sampling == null ) {
98- sampling = StatsAggregationBuilder .buildSampling (fieldNames .length - 1 );
99- samplings .set (bucket , sampling );
101+ sampling = StatsAggregationBuilder .buildSampling (this . fieldNames .length - 1 );
102+ StatsAggregator . this . samplings .set (bucket , sampling );
100103 }
101- LOGGER .info ("Sampling for bucket={}, fields={}" , bucket , fieldVals );
102- sampling .sample (fieldVals , fieldVals [fieldVals .length - 1 ]);
104+ LOGGER .info ("Sampling for bucket={}, fields={}" , bucket , this . fieldVals );
105+ sampling .sample (this . fieldVals , this . fieldVals [this . fieldVals .length - 1 ]);
103106 } else {
104- LOGGER .warn ("Skipped bucket={}, fields={}" , bucket , fieldVals );
107+ LOGGER .warn ("Skipped bucket={}, fields={}" , bucket , this . fieldVals );
105108 }
106109 }
107110
108111 /**
109112 * return a map of field names and data
110113 */
111- private boolean includeDocument (int doc ) {
114+ private boolean includeDocument (final int doc ) {
112115 // loop over fields
113- for (int i = 0 ; i < fieldVals .length ; ++i ) {
116+ for (int i = 0 ; i < this . fieldVals .length ; ++i ) {
114117 final NumericDoubleValues doubleValues = values [i ];
115118 final double value = doubleValues .get (doc );
116119 // skip if value is missing
117120 if (value == Double .NEGATIVE_INFINITY ) {
118121 return false ;
119122 }
120- fieldVals [i ] = value ;
123+ this . fieldVals [i ] = value ;
121124 }
122125 return true ;
123126 }
@@ -126,18 +129,18 @@ private boolean includeDocument(int doc) {
126129
127130
128131 @ Override
129- public InternalAggregation buildAggregation (long bucket ) {
130- if (valuesSources == null || bucket >= samplings .size ()) {
132+ public InternalAggregation buildAggregation (final long bucket ) {
133+ if (this . valuesSources == null || bucket >= this . samplings .size ()) {
131134 return buildEmptyAggregation ();
132135 }
133- return new InternalStats (name , valuesSources .fieldNames ().length - 1 ,
134- samplings .get (bucket ), null ,
136+ return new InternalStats (this . name , this . valuesSources .fieldNames ().length - 1 ,
137+ this . samplings .get (bucket ), null ,
135138 pipelineAggregators (), metaData ());
136139 }
137140
138141 @ Override
139142 public InternalAggregation buildEmptyAggregation () {
140- return new InternalStats (name , 0 , null , null , pipelineAggregators (), metaData ());
143+ return new InternalStats (this . name , 0 , null , null , pipelineAggregators (), metaData ());
141144 }
142145
143146 @ Override
0 commit comments