@@ -114,6 +114,17 @@ fn build_decimal256_array(size: usize, precision: u8, scale: i8) -> ArrayRef {
114
114
)
115
115
}
116
116
117
+ fn build_dict_array ( size : usize ) -> ArrayRef {
118
+ let values = StringArray :: from_iter ( [
119
+ Some ( "small" ) ,
120
+ Some ( "larger string more than 12 bytes" ) ,
121
+ None ,
122
+ ] ) ;
123
+ let keys = UInt64Array :: from_iter ( ( 0 ..size as u64 ) . map ( |v| v % 3 ) ) ;
124
+
125
+ Arc :: new ( DictionaryArray :: new ( keys, Arc :: new ( values) ) )
126
+ }
127
+
117
128
// cast array from specified primitive array type to desired data type
118
129
fn cast_array ( array : & ArrayRef , to_type : DataType ) {
119
130
criterion:: black_box ( cast ( array, & to_type) . unwrap ( ) ) ;
@@ -138,6 +149,9 @@ fn add_benchmark(c: &mut Criterion) {
138
149
let decimal128_array = build_decimal128_array ( 512 , 10 , 3 ) ;
139
150
let decimal256_array = build_decimal256_array ( 512 , 50 , 3 ) ;
140
151
152
+ let dict_array = build_dict_array ( 10_000 ) ;
153
+ let string_view_array = cast ( & dict_array, & DataType :: Utf8View ) . unwrap ( ) ;
154
+
141
155
c. bench_function ( "cast int32 to int32 512" , |b| {
142
156
b. iter ( || cast_array ( & i32_array, DataType :: Int32 ) )
143
157
} ) ;
@@ -237,6 +251,17 @@ fn add_benchmark(c: &mut Criterion) {
237
251
c. bench_function ( "cast decimal256 to decimal256 512 with same scale" , |b| {
238
252
b. iter ( || cast_array ( & decimal256_array, DataType :: Decimal256 ( 60 , 3 ) ) )
239
253
} ) ;
254
+ c. bench_function ( "cast dict to string view" , |b| {
255
+ b. iter ( || cast_array ( & dict_array, DataType :: Utf8View ) )
256
+ } ) ;
257
+ c. bench_function ( "cast string view to dict" , |b| {
258
+ b. iter ( || {
259
+ cast_array (
260
+ & string_view_array,
261
+ DataType :: Dictionary ( Box :: new ( DataType :: UInt64 ) , Box :: new ( DataType :: Utf8 ) ) ,
262
+ )
263
+ } )
264
+ } ) ;
240
265
}
241
266
242
267
criterion_group ! ( benches, add_benchmark) ;
0 commit comments