@@ -318,6 +318,7 @@ ParquetRecordReader::ParquetRecordReader(
318318 std::shared_ptr<::arrow::io::RandomAccessFile> arrow_file,
319319 const FormatSettings & format_settings,
320320 std::vector<int > row_groups_indices_,
321+ const std::optional<std::vector<Int32>> & column_indices_,
321322 std::shared_ptr<parquet::FileMetaData> metadata)
322323 : file_reader(createFileReader(std::move(arrow_file), reader_properties_, std::move(metadata)))
323324 , arrow_properties(arrow_properties_)
@@ -338,20 +339,26 @@ ParquetRecordReader::ParquetRecordReader(
338339
339340 parquet_col_indice.reserve (header.columns ());
340341 column_readers.reserve (header.columns ());
341- for ( const auto & col_with_name : header )
342+ if (!column_indices_ )
342343 {
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 );
346349
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" );
350353
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+ }
354358 }
359+ else
360+ parquet_col_indice = *column_indices_;
361+
355362 if (arrow_properties.pre_buffer ())
356363 {
357364 THROW_PARQUET_EXCEPTION (file_reader->PreBuffer (
0 commit comments