@@ -134,13 +134,18 @@ pub trait GroupValues: Send {
134134pub fn new_group_values (
135135 schema : SchemaRef ,
136136 group_ordering : & GroupOrdering ,
137+ capacity_hint : Option < usize > ,
137138) -> Result < Box < dyn GroupValues > > {
139+ let capacity = capacity_hint. unwrap_or ( 0 ) ;
138140 if schema. fields . len ( ) == 1 {
139141 let d = schema. fields [ 0 ] . data_type ( ) ;
140142
141143 macro_rules! downcast_helper {
142144 ( $t: ty, $d: ident) => {
143- return Ok ( Box :: new( GroupValuesPrimitive :: <$t>:: new( $d. clone( ) ) ) )
145+ return Ok ( Box :: new( GroupValuesPrimitive :: <$t>:: new(
146+ $d. clone( ) ,
147+ capacity,
148+ ) ) )
144149 } ;
145150 }
146151
@@ -176,22 +181,40 @@ pub fn new_group_values(
176181 downcast_helper ! ( Decimal128Type , d) ;
177182 }
178183 DataType :: Utf8 => {
179- return Ok ( Box :: new ( GroupValuesBytes :: < i32 > :: new ( OutputType :: Utf8 ) ) ) ;
184+ return Ok ( Box :: new ( GroupValuesBytes :: < i32 > :: new (
185+ OutputType :: Utf8 ,
186+ capacity,
187+ ) ) ) ;
180188 }
181189 DataType :: LargeUtf8 => {
182- return Ok ( Box :: new ( GroupValuesBytes :: < i64 > :: new ( OutputType :: Utf8 ) ) ) ;
190+ return Ok ( Box :: new ( GroupValuesBytes :: < i64 > :: new (
191+ OutputType :: Utf8 ,
192+ capacity,
193+ ) ) ) ;
183194 }
184195 DataType :: Utf8View => {
185- return Ok ( Box :: new ( GroupValuesBytesView :: new ( OutputType :: Utf8View ) ) ) ;
196+ return Ok ( Box :: new ( GroupValuesBytesView :: new (
197+ OutputType :: Utf8View ,
198+ capacity,
199+ ) ) ) ;
186200 }
187201 DataType :: Binary => {
188- return Ok ( Box :: new ( GroupValuesBytes :: < i32 > :: new ( OutputType :: Binary ) ) ) ;
202+ return Ok ( Box :: new ( GroupValuesBytes :: < i32 > :: new (
203+ OutputType :: Binary ,
204+ capacity,
205+ ) ) ) ;
189206 }
190207 DataType :: LargeBinary => {
191- return Ok ( Box :: new ( GroupValuesBytes :: < i64 > :: new ( OutputType :: Binary ) ) ) ;
208+ return Ok ( Box :: new ( GroupValuesBytes :: < i64 > :: new (
209+ OutputType :: Binary ,
210+ capacity,
211+ ) ) ) ;
192212 }
193213 DataType :: BinaryView => {
194- return Ok ( Box :: new ( GroupValuesBytesView :: new ( OutputType :: BinaryView ) ) ) ;
214+ return Ok ( Box :: new ( GroupValuesBytesView :: new (
215+ OutputType :: BinaryView ,
216+ capacity,
217+ ) ) ) ;
195218 }
196219 DataType :: Boolean => {
197220 return Ok ( Box :: new ( GroupValuesBoolean :: new ( ) ) ) ;
@@ -202,11 +225,15 @@ pub fn new_group_values(
202225
203226 if multi_group_by:: supported_schema ( schema. as_ref ( ) ) {
204227 if matches ! ( group_ordering, GroupOrdering :: None ) {
205- Ok ( Box :: new ( GroupValuesColumn :: < false > :: try_new ( schema) ?) )
228+ Ok ( Box :: new ( GroupValuesColumn :: < false > :: try_new (
229+ schema, capacity,
230+ ) ?) )
206231 } else {
207- Ok ( Box :: new ( GroupValuesColumn :: < true > :: try_new ( schema) ?) )
232+ Ok ( Box :: new ( GroupValuesColumn :: < true > :: try_new (
233+ schema, capacity,
234+ ) ?) )
208235 }
209236 } else {
210- Ok ( Box :: new ( GroupValuesRows :: try_new ( schema) ?) )
237+ Ok ( Box :: new ( GroupValuesRows :: try_new ( schema, capacity ) ?) )
211238 }
212239}
0 commit comments