File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -190,14 +190,25 @@ impl<W: Write + Send> SerializedFileWriter<W> {
190
190
/// Creates new row group from this file writer.
191
191
/// In case of IO error or Thrift error, returns `Err`.
192
192
///
193
- /// There is no limit on a number of row groups in a file; however, row groups have
193
+ /// There can be at most 2^15 row groups in a file; and row groups have
194
194
/// to be written sequentially. Every time the next row group is requested, the
195
195
/// previous row group must be finalised and closed using `RowGroupWriter::close` method.
196
196
pub fn next_row_group ( & mut self ) -> Result < SerializedRowGroupWriter < ' _ , W > > {
197
197
self . assert_previous_writer_closed ( ) ?;
198
198
let ordinal = self . row_group_index ;
199
199
200
- self . row_group_index += 1 ;
200
+ let ordinal: i16 = ordinal. try_into ( ) . map_err ( |_| {
201
+ ParquetError :: General ( format ! (
202
+ "Parquet does not support more than {} row groups per file (currently: {})" ,
203
+ i16 :: MAX ,
204
+ ordinal
205
+ ) )
206
+ } ) ?;
207
+
208
+ self . row_group_index = self
209
+ . row_group_index
210
+ . checked_add ( 1 )
211
+ . expect ( "SerializedFileWriter::row_group_index overflowed" ) ;
201
212
202
213
let bloom_filter_position = self . properties ( ) . bloom_filter_position ( ) ;
203
214
let row_groups = & mut self . row_groups ;
@@ -227,7 +238,7 @@ impl<W: Write + Send> SerializedFileWriter<W> {
227
238
self . descr . clone ( ) ,
228
239
self . props . clone ( ) ,
229
240
& mut self . buf ,
230
- ordinal as i16 ,
241
+ ordinal,
231
242
Some ( Box :: new ( on_close) ) ,
232
243
) ;
233
244
Ok ( row_group_writer)
You can’t perform that action at this time.
0 commit comments