@@ -171,23 +171,40 @@ mod tests {
171
171
use crate :: writer:: tests:: check_parquet_data_file;
172
172
use crate :: writer:: { IcebergWriter , IcebergWriterBuilder , RecordBatch } ;
173
173
174
+ fn make_test_schema ( ) -> Result < Schema > {
175
+ Schema :: builder ( )
176
+ . with_schema_id ( 1 )
177
+ . with_fields ( vec ! [
178
+ NestedField :: required( 1 , "id" , Type :: Primitive ( PrimitiveType :: Int ) ) . into( ) ,
179
+ NestedField :: required( 2 , "name" , Type :: Primitive ( PrimitiveType :: String ) ) . into( ) ,
180
+ ] )
181
+ . build ( )
182
+ }
183
+
184
+ fn make_test_arrow_schema ( ) -> ArrowSchema {
185
+ ArrowSchema :: new ( vec ! [
186
+ Field :: new( "id" , DataType :: Int32 , false ) . with_metadata( HashMap :: from( [ (
187
+ PARQUET_FIELD_ID_META_KEY . to_string( ) ,
188
+ 1 . to_string( ) ,
189
+ ) ] ) ) ,
190
+ Field :: new( "name" , DataType :: Utf8 , false ) . with_metadata( HashMap :: from( [ (
191
+ PARQUET_FIELD_ID_META_KEY . to_string( ) ,
192
+ 2 . to_string( ) ,
193
+ ) ] ) ) ,
194
+ ] )
195
+ }
196
+
174
197
#[ tokio:: test]
175
198
async fn test_rolling_writer_basic ( ) -> Result < ( ) > {
176
- let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
177
- let file_io = FileIOBuilder :: new_fs_io ( ) . build ( ) . unwrap ( ) ;
199
+ let temp_dir = TempDir :: new ( ) ? ;
200
+ let file_io = FileIOBuilder :: new_fs_io ( ) . build ( ) ? ;
178
201
let location_gen =
179
202
MockLocationGenerator :: new ( temp_dir. path ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ) ;
180
203
let file_name_gen =
181
204
DefaultFileNameGenerator :: new ( "test" . to_string ( ) , None , DataFileFormat :: Parquet ) ;
182
205
183
206
// Create schema
184
- let schema = Schema :: builder ( )
185
- . with_schema_id ( 1 )
186
- . with_fields ( vec ! [
187
- NestedField :: required( 1 , "id" , Type :: Primitive ( PrimitiveType :: Int ) ) . into( ) ,
188
- NestedField :: required( 2 , "name" , Type :: Primitive ( PrimitiveType :: String ) ) . into( ) ,
189
- ] )
190
- . build ( ) ?;
207
+ let schema = make_test_schema ( ) ?;
191
208
192
209
// Create writer builders
193
210
let parquet_writer_builder = ParquetWriterBuilder :: new (
@@ -209,16 +226,7 @@ mod tests {
209
226
let mut writer = rolling_writer_builder. build ( ) . await ?;
210
227
211
228
// Create test data
212
- let arrow_schema = ArrowSchema :: new ( vec ! [
213
- Field :: new( "id" , DataType :: Int32 , false ) . with_metadata( HashMap :: from( [ (
214
- PARQUET_FIELD_ID_META_KEY . to_string( ) ,
215
- 1 . to_string( ) ,
216
- ) ] ) ) ,
217
- Field :: new( "name" , DataType :: Utf8 , false ) . with_metadata( HashMap :: from( [ (
218
- PARQUET_FIELD_ID_META_KEY . to_string( ) ,
219
- 2 . to_string( ) ,
220
- ) ] ) ) ,
221
- ] ) ;
229
+ let arrow_schema = make_test_arrow_schema ( ) ;
222
230
223
231
let batch = RecordBatch :: try_new ( Arc :: new ( arrow_schema) , vec ! [
224
232
Arc :: new( Int32Array :: from( vec![ 1 , 2 , 3 ] ) ) ,
@@ -246,21 +254,15 @@ mod tests {
246
254
247
255
#[ tokio:: test]
248
256
async fn test_rolling_writer_with_rolling ( ) -> Result < ( ) > {
249
- let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
250
- let file_io = FileIOBuilder :: new_fs_io ( ) . build ( ) . unwrap ( ) ;
257
+ let temp_dir = TempDir :: new ( ) ? ;
258
+ let file_io = FileIOBuilder :: new_fs_io ( ) . build ( ) ? ;
251
259
let location_gen =
252
260
MockLocationGenerator :: new ( temp_dir. path ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ) ;
253
261
let file_name_gen =
254
262
DefaultFileNameGenerator :: new ( "test" . to_string ( ) , None , DataFileFormat :: Parquet ) ;
255
263
256
264
// Create schema
257
- let schema = Schema :: builder ( )
258
- . with_schema_id ( 1 )
259
- . with_fields ( vec ! [
260
- NestedField :: required( 1 , "id" , Type :: Primitive ( PrimitiveType :: Int ) ) . into( ) ,
261
- NestedField :: required( 2 , "name" , Type :: Primitive ( PrimitiveType :: String ) ) . into( ) ,
262
- ] )
263
- . build ( ) ?;
265
+ let schema = make_test_schema ( ) ?;
264
266
265
267
// Create writer builders
266
268
let parquet_writer_builder = ParquetWriterBuilder :: new (
@@ -282,16 +284,7 @@ mod tests {
282
284
let mut writer = rolling_writer_builder. build ( ) . await ?;
283
285
284
286
// Create test data
285
- let arrow_schema = ArrowSchema :: new ( vec ! [
286
- Field :: new( "id" , DataType :: Int32 , false ) . with_metadata( HashMap :: from( [ (
287
- PARQUET_FIELD_ID_META_KEY . to_string( ) ,
288
- 1 . to_string( ) ,
289
- ) ] ) ) ,
290
- Field :: new( "name" , DataType :: Utf8 , false ) . with_metadata( HashMap :: from( [ (
291
- PARQUET_FIELD_ID_META_KEY . to_string( ) ,
292
- 2 . to_string( ) ,
293
- ) ] ) ) ,
294
- ] ) ;
287
+ let arrow_schema = make_test_arrow_schema ( ) ;
295
288
296
289
// Create multiple batches to trigger rolling
297
290
let batch1 = RecordBatch :: try_new ( Arc :: new ( arrow_schema. clone ( ) ) , vec ! [
0 commit comments