@@ -68,17 +68,37 @@ public GroupByResultHolder createGroupByResultHolder(int initialCapacity, int ma
6868 public void aggregate (int length , AggregationResultHolder aggregationResultHolder ,
6969 Map <ExpressionContext , BlockValSet > blockValSetMap ) {
7070 BlockValSet blockValSet = blockValSetMap .get (_expression );
71- long [] values = blockValSet .getLongValuesSV ();
7271
73- Long min = foldNotNull (length , blockValSet , null , (acum , from , to ) -> {
74- long innerMin = values [from ];
75- for (int i = from ; i < to ; i ++) {
76- innerMin = Math .min (innerMin , values [i ]);
77- }
78- return acum == null ? innerMin : Math .min (acum , innerMin );
79- });
72+ if (blockValSet .isSingleValue ()) {
73+ long [] values = blockValSet .getLongValuesSV ();
74+
75+ Long min = foldNotNull (length , blockValSet , null , (acum , from , to ) -> {
76+ long innerMin = values [from ];
77+ for (int i = from ; i < to ; i ++) {
78+ innerMin = Math .min (innerMin , values [i ]);
79+ }
80+ return acum == null ? innerMin : Math .min (acum , innerMin );
81+ });
8082
81- updateAggregationResultHolder (aggregationResultHolder , min );
83+ updateAggregationResultHolder (aggregationResultHolder , min );
84+ } else {
85+ long [][] valuesArray = blockValSet .getLongValuesMV ();
86+
87+ Long min = foldNotNull (length , blockValSet , null , (acum , from , to ) -> {
88+ long innerMin = DEFAULT_VALUE ;
89+ for (int i = from ; i < to ; i ++) {
90+ long [] values = valuesArray [i ];
91+ for (long value : values ) {
92+ if (value < innerMin ) {
93+ innerMin = value ;
94+ }
95+ }
96+ }
97+ return acum == null ? innerMin : Math .min (acum , innerMin );
98+ });
99+
100+ updateAggregationResultHolder (aggregationResultHolder , min );
101+ }
82102 }
83103
84104 protected void updateAggregationResultHolder (AggregationResultHolder aggregationResultHolder , Long min ) {
@@ -97,8 +117,17 @@ protected void updateAggregationResultHolder(AggregationResultHolder aggregation
97117 public void aggregateGroupBySV (int length , int [] groupKeyArray , GroupByResultHolder groupByResultHolder ,
98118 Map <ExpressionContext , BlockValSet > blockValSetMap ) {
99119 BlockValSet blockValSet = blockValSetMap .get (_expression );
100- long [] valueArray = blockValSet .getLongValuesSV ();
101120
121+ if (blockValSet .isSingleValue ()) {
122+ aggregateSvGroupBySv (blockValSet , length , groupKeyArray , groupByResultHolder );
123+ } else {
124+ aggregateMvGroupBySv (blockValSet , length , groupKeyArray , groupByResultHolder );
125+ }
126+ }
127+
128+ private void aggregateSvGroupBySv (BlockValSet blockValSet , int length , int [] groupKeyArray ,
129+ GroupByResultHolder groupByResultHolder ) {
130+ long [] valueArray = blockValSet .getLongValuesSV ();
102131 if (_nullHandlingEnabled ) {
103132 forEachNotNull (length , blockValSet , (from , to ) -> {
104133 for (int i = from ; i < to ; i ++) {
@@ -121,10 +150,51 @@ public void aggregateGroupBySV(int length, int[] groupKeyArray, GroupByResultHol
121150 }
122151 }
123152
153+ private void aggregateMvGroupBySv (BlockValSet blockValSet , int length , int [] groupKeyArray ,
154+ GroupByResultHolder groupByResultHolder ) {
155+ long [][] valuesArray = blockValSet .getLongValuesMV ();
156+
157+ if (_nullHandlingEnabled ) {
158+ forEachNotNull (length , blockValSet , (from , to ) -> {
159+ for (int i = from ; i < to ; i ++) {
160+ int groupKey = groupKeyArray [i ];
161+ Long min = groupByResultHolder .getResult (groupKey );
162+ for (long value : valuesArray [i ]) {
163+ if (min == null || value < min ) {
164+ min = value ;
165+ }
166+ }
167+ groupByResultHolder .setValueForKey (groupKey , min );
168+ }
169+ });
170+ } else {
171+ for (int i = 0 ; i < length ; i ++) {
172+ int groupKey = groupKeyArray [i ];
173+ long min = groupByResultHolder .getLongResult (groupKey );
174+ for (long value : valuesArray [i ]) {
175+ if (value < min ) {
176+ min = value ;
177+ }
178+ }
179+ groupByResultHolder .setValueForKey (groupKey , min );
180+ }
181+ }
182+ }
183+
124184 @ Override
125185 public void aggregateGroupByMV (int length , int [][] groupKeysArray , GroupByResultHolder groupByResultHolder ,
126186 Map <ExpressionContext , BlockValSet > blockValSetMap ) {
127187 BlockValSet blockValSet = blockValSetMap .get (_expression );
188+
189+ if (blockValSet .isSingleValue ()) {
190+ aggregateSvGroupByMv (blockValSet , length , groupKeysArray , groupByResultHolder );
191+ } else {
192+ aggregateMvGroupByMv (blockValSet , length , groupKeysArray , groupByResultHolder );
193+ }
194+ }
195+
196+ private void aggregateSvGroupByMv (BlockValSet blockValSet , int length , int [][] groupKeysArray ,
197+ GroupByResultHolder groupByResultHolder ) {
128198 long [] valueArray = blockValSet .getLongValuesSV ();
129199
130200 if (_nullHandlingEnabled ) {
@@ -151,6 +221,44 @@ public void aggregateGroupByMV(int length, int[][] groupKeysArray, GroupByResult
151221 }
152222 }
153223
224+ private void aggregateMvGroupByMv (BlockValSet blockValSet , int length , int [][] groupKeysArray ,
225+ GroupByResultHolder groupByResultHolder ) {
226+ long [][] valuesArray = blockValSet .getLongValuesMV ();
227+
228+ if (_nullHandlingEnabled ) {
229+ forEachNotNull (length , blockValSet , (from , to ) -> {
230+ for (int i = from ; i < to ; i ++) {
231+ Long min = null ;
232+ for (long value : valuesArray [i ]) {
233+ if (min == null || value < min ) {
234+ min = value ;
235+ }
236+ }
237+
238+ for (int groupKey : groupKeysArray [i ]) {
239+ Long currentMin = groupByResultHolder .getResult (groupKey );
240+ if (currentMin == null || (min != null && min < currentMin )) {
241+ groupByResultHolder .setValueForKey (groupKey , min );
242+ }
243+ }
244+ }
245+ });
246+ } else {
247+ for (int i = 0 ; i < length ; i ++) {
248+ long [] values = valuesArray [i ];
249+ for (int groupKey : groupKeysArray [i ]) {
250+ long min = groupByResultHolder .getLongResult (groupKey );
251+ for (long value : values ) {
252+ if (value < min ) {
253+ min = value ;
254+ }
255+ }
256+ groupByResultHolder .setValueForKey (groupKey , min );
257+ }
258+ }
259+ }
260+ }
261+
154262 @ Override
155263 public Long extractAggregationResult (AggregationResultHolder aggregationResultHolder ) {
156264 if (_nullHandlingEnabled ) {
0 commit comments