@@ -318,6 +318,7 @@ ParquetRecordReader::ParquetRecordReader(
318
318
std::shared_ptr<::arrow::io::RandomAccessFile> arrow_file,
319
319
const FormatSettings & format_settings,
320
320
std::vector<int > row_groups_indices_,
321
+ const std::optional<std::vector<Int32>> & column_indices_,
321
322
std::shared_ptr<parquet::FileMetaData> metadata)
322
323
: file_reader(createFileReader(std::move(arrow_file), reader_properties_, std::move(metadata)))
323
324
, arrow_properties(arrow_properties_)
@@ -338,20 +339,26 @@ ParquetRecordReader::ParquetRecordReader(
338
339
339
340
parquet_col_indice.reserve (header.columns ());
340
341
column_readers.reserve (header.columns ());
341
- for ( const auto & col_with_name : header )
342
+ if (!column_indices_ )
342
343
{
343
- auto it = parquet_columns.find (col_with_name.name );
344
- if (it == parquet_columns.end ())
345
- throw Exception (ErrorCodes::PARQUET_EXCEPTION, " no column with '{}' in parquet file" , col_with_name.name );
344
+ for (const auto & col_with_name : header)
345
+ {
346
+ auto it = parquet_columns.find (col_with_name.name );
347
+ if (it == parquet_columns.end ())
348
+ throw Exception (ErrorCodes::PARQUET_EXCEPTION, " no column with '{}' in parquet file" , col_with_name.name );
346
349
347
- const auto & node = it->second ;
348
- if (!node->is_primitive ())
349
- throw Exception (ErrorCodes::NOT_IMPLEMENTED, " arrays and maps are not implemented in native parquet reader" );
350
+ const auto & node = it->second ;
351
+ if (!node->is_primitive ())
352
+ throw Exception (ErrorCodes::NOT_IMPLEMENTED, " arrays and maps are not implemented in native parquet reader" );
350
353
351
- auto idx = file_reader->metadata ()->schema ()->ColumnIndex (*node);
352
- chassert (idx >= 0 );
353
- parquet_col_indice.push_back (idx);
354
+ auto idx = file_reader->metadata ()->schema ()->ColumnIndex (*node);
355
+ chassert (idx >= 0 );
356
+ parquet_col_indice.push_back (idx);
357
+ }
354
358
}
359
+ else
360
+ parquet_col_indice = *column_indices_;
361
+
355
362
if (arrow_properties.pre_buffer ())
356
363
{
357
364
THROW_PARQUET_EXCEPTION (file_reader->PreBuffer (
0 commit comments