| 3075 | } |
| 3076 | |
| 3077 | ColumnPtr IMergeTreeDataPart::getColumnSample(const NameAndTypePair & column) const |
| 3078 | { |
| 3079 | const size_t total_mark = getMarksCount(); |
| 3080 | /// If column doesn't have dynamic subcolumns or part has no data, just create column using it's type. |
| 3081 | if (!column.type->hasDynamicSubcolumns() || !total_mark) |
| 3082 | return column.type->createColumn(); |
| 3083 | |
| 3084 | /// Otherwise, read sample column with 0 rows from the part, so it will load dynamic structure. |
| 3085 | NamesAndTypesList cols; |
| 3086 | cols.emplace_back(column); |
| 3087 | |
| 3088 | const auto metadata_ptr = storage.getInMemoryMetadataPtr(storage.getContext(), false); |
| 3089 | StorageSnapshotPtr storage_snapshot_ptr = std::make_shared<StorageSnapshot>(storage, metadata_ptr); |
| 3090 | |
| 3091 | /// We need to read only prefixes, so no data will be read. |
| 3092 | /// Use read settings without prefetches/filesystem cache/etc. |
| 3093 | MergeTreeReaderSettings settings = MergeTreeReaderSettings::createFromSettings(getReadSettingsForMetadata()); |
| 3094 | settings.can_read_part_without_marks = true; |
| 3095 | /// Use prefixes deserialization thread pool to read prefixes faster. |
| 3096 | /// In JSON type there might be hundreds of small files that needs to be read. |
| 3097 | /// Set this to value from storage settings rather than true by default as this could cause starvation on huge JSON. |
| 3098 | settings.use_prefixes_deserialization_thread_pool = storage.getContext()->getSettingsRef()[Setting::merge_tree_use_prefixes_deserialization_thread_pool]; |
| 3099 | settings.read_only_column_sample = true; |
| 3100 | |
| 3101 | auto alter_conversions = std::make_shared<AlterConversions>(); |
| 3102 | auto part_info = std::make_shared<LoadedMergeTreeDataPartInfoForReader>(shared_from_this(), alter_conversions); |
| 3103 | |
| 3104 | MergeTreeReaderPtr reader = createMergeTreeReader( |
| 3105 | part_info, |
| 3106 | cols, |
| 3107 | storage_snapshot_ptr, |
| 3108 | storage.getSettings(), |
| 3109 | MarkRanges{MarkRange(0, total_mark)}, |
| 3110 | /*virtual_fields=*/ {}, |
| 3111 | /*uncompressed_cache=*/{}, |
| 3112 | storage.getContext()->getMarkCache().get(), |
| 3113 | nullptr, |
| 3114 | settings, |
| 3115 | ValueSizeMap{}, |
| 3116 | ReadBufferFromFileBase::ProfileCallback{}); |
| 3117 | |
| 3118 | Columns result; |
| 3119 | result.resize(1); |
| 3120 | reader->readRows(0, total_mark, false, 0, 0, result); |
| 3121 | return result[0]; |
| 3122 | } |
| 3123 | |
| 3124 | bool isCompactPart(const MergeTreeDataPartPtr & data_part) |
| 3125 | { |
no test coverage detected