@@ -51,6 +51,8 @@ public abstract class BaseSamplingAggregator<S extends BaseSampling<S>> extends
5151
5252 protected ObjectArray <S > samplings ;
5353
54+ private int fieldsCount ;
55+
5456 public BaseSamplingAggregator (final String name ,
5557 final List <NamedValuesSourceSpec <Numeric >> valuesSources ,
5658 final SearchContext context ,
@@ -61,6 +63,7 @@ public BaseSamplingAggregator(final String name,
6163 if (valuesSources != null && !valuesSources .isEmpty ()) {
6264 this .valuesSources = new NumericMultiValuesSource (valuesSources , multiValueMode );
6365 this .samplings = context .bigArrays ().newObjectArray (1 );
66+ this .fieldsCount = this .valuesSources .fieldNames ().length ;
6467 } else {
6568 this .valuesSources = null ;
6669 }
@@ -78,15 +81,13 @@ public LeafBucketCollector getLeafCollector(final LeafReaderContext ctx,
7881 return LeafBucketCollector .NO_OP_COLLECTOR ;
7982 }
8083 final BigArrays bigArrays = this .context .bigArrays ();
81- final NumericDoubleValues [] values = new NumericDoubleValues [this .valuesSources
82- .fieldNames ().length ];
83- for (int i = 0 ; i < values .length ; ++i ) {
84+ final NumericDoubleValues [] values = new NumericDoubleValues [this .fieldsCount ];
85+ for (int i = 0 ; i < this .fieldsCount ; ++i ) {
8486 values [i ] = this .valuesSources .getField (i , ctx );
8587 }
8688
8789 return new LeafBucketCollectorBase (sub , values ) {
88- final String [] fieldNames = BaseSamplingAggregator .this .valuesSources .fieldNames ();
89- final double [] fieldVals = new double [this .fieldNames .length ];
90+ final double [] fieldVals = new double [BaseSamplingAggregator .this .fieldsCount ];
9091
9192 @ Override
9293 public void collect (final int doc , final long bucket ) throws IOException {
@@ -97,13 +98,14 @@ public void collect(final int doc, final long bucket) throws IOException {
9798 S sampling = BaseSamplingAggregator .this .samplings .get (bucket );
9899 // add document fields to correlation stats
99100 if (sampling == null ) {
100- sampling = buildSampling (this .fieldNames . length - 1 );
101+ sampling = buildSampling (BaseSamplingAggregator . this .fieldsCount - 1 );
101102 BaseSamplingAggregator .this .samplings .set (bucket , sampling );
102103 }
103- LOGGER .info ("Sampling for bucket={}, fields={}" , bucket , this .fieldVals );
104- sampling .sample (this .fieldVals , this .fieldVals [this .fieldVals .length - 1 ]);
104+ // LOGGER.info("Sampling for bucket={}, fields={}", bucket, this.fieldVals);
105+ sampling
106+ .sample (this .fieldVals , this .fieldVals [BaseSamplingAggregator .this .fieldsCount - 1 ]);
105107 } else {
106- LOGGER .warn ("Skipped bucket={}, fields={}" , bucket , this .fieldVals );
108+ // LOGGER.warn("Skipped bucket={}, fields={}", bucket, this.fieldVals);
107109 }
108110 }
109111
@@ -112,7 +114,7 @@ public void collect(final int doc, final long bucket) throws IOException {
112114 */
113115 private boolean includeDocument (final int doc ) {
114116 // loop over fields
115- for (int i = 0 ; i < this .fieldVals . length ; ++i ) {
117+ for (int i = 0 ; i < BaseSamplingAggregator . this .fieldsCount ; ++i ) {
116118 final NumericDoubleValues doubleValues = values [i ];
117119 final double value = doubleValues .get (doc );
118120 // skip if value is missing
0 commit comments