@@ -273,8 +273,6 @@ Chunk StorageObjectStorageSource::generate()
273273{
274274 lazyInitialize ();
275275
276- bool use_iceberg_read_optimization = read_context->getSettingsRef ()[Setting::allow_experimental_iceberg_read_optimization];
277-
278276 while (true )
279277 {
280278 if (isCancelled () || !reader)
@@ -330,14 +328,14 @@ Chunk StorageObjectStorageSource::generate()
330328 .data_lake_snapshot_version = file_iterator->getSnapshotVersion ()},
331329 read_context);
332330
333- if (use_iceberg_read_optimization)
331+ // / Not empty when allow_experimental_iceberg_read_optimization=true
332+ // / and some columns were removed from read list as columns with constant values.
333+ // / Restore data for these columns.
334+ for (const auto & constant_column : reader.constant_columns_with_values )
334335 {
335- for (const auto & constant_column : reader.constant_columns_with_values )
336- {
337- chunk.addColumn (constant_column.first ,
338- constant_column.second .name_and_type .type ->createColumnConst (
339- chunk.getNumRows (), constant_column.second .value )->convertToFullColumnIfConst ());
340- }
336+ chunk.addColumn (constant_column.first ,
337+ constant_column.second .name_and_type .type ->createColumnConst (
338+ chunk.getNumRows (), constant_column.second .value ));
341339 }
342340
343341#if USE_PARQUET && USE_AWS_S3
@@ -555,18 +553,19 @@ StorageObjectStorageSource::ReaderHolder StorageObjectStorageSource::createReade
555553 else
556554 rows_count_from_metadata = column.second .rows_count ;
557555 }
556+
558557 if (column.second .hyperrectangle .has_value ())
559558 {
559+ auto column_name = column.first ;
560+
561+ auto i_column = requested_columns_list.find (column_name);
562+ if (i_column == requested_columns_list.end ())
563+ continue ;
564+
560565 if (column.second .hyperrectangle .value ().isPoint () &&
561566 (!column.second .nulls_count .has_value () || column.second .nulls_count .value () <= 0 ))
562567 {
563- auto column_name = column.first ;
564-
565- auto i_column = requested_columns_list.find (column_name);
566- if (i_column == requested_columns_list.end ())
567- continue ;
568-
569- // / isPoint() method checks that left==right
568+ // / isPoint() method checks before that left==right
570569 constant_columns_with_values[i_column->second .first ] =
571570 ConstColumnWithValue{
572571 i_column->second .second ,
@@ -581,17 +580,9 @@ StorageObjectStorageSource::ReaderHolder StorageObjectStorageSource::createReade
581580 column.second .hyperrectangle .value ().left .dump ());
582581 }
583582 else if (column.second .rows_count .has_value () && column.second .nulls_count .has_value ()
584- && column.second .rows_count .value () == column.second .nulls_count .value ())
583+ && column.second .rows_count .value () == column.second .nulls_count .value ()
584+ && i_column->second .second .type ->isNullable ())
585585 {
586- auto column_name = column.first ;
587-
588- auto i_column = requested_columns_list.find (column_name);
589- if (i_column == requested_columns_list.end ())
590- continue ;
591-
592- if (!i_column->second .second .type ->isNullable ())
593- continue ;
594-
595586 constant_columns_with_values[i_column->second .first ] =
596587 ConstColumnWithValue{
597588 i_column->second .second ,
@@ -660,6 +651,8 @@ StorageObjectStorageSource::ReaderHolder StorageObjectStorageSource::createReade
660651 columns.emplace_back (type->createColumn (), type, name);
661652 builder.init (Pipe (std::make_shared<ConstChunkGenerator>(
662653 std::make_shared<const Block>(columns), *num_rows_from_cache, max_block_size)));
654+ if (!constant_columns.empty ())
655+ configuration->addDeleteTransformers (object_info, builder, format_settings, context_);
663656 }
664657 else
665658 {
0 commit comments