| 44 | } |
| 45 | |
| 46 | void StorageWithCommonVirtualColumns::read( |
| 47 | QueryPlan & query_plan, |
| 48 | const Names & column_names, |
| 49 | const StorageSnapshotPtr & storage_snapshot, |
| 50 | SelectQueryInfo & query_info, |
| 51 | ContextPtr context, |
| 52 | QueryProcessingStage::Enum processed_stage, |
| 53 | size_t max_block_size, |
| 54 | size_t num_streams) |
| 55 | { |
| 56 | if (processed_stage > QueryProcessingStage::FetchColumns) |
| 57 | { |
| 58 | readImpl(query_plan, column_names, storage_snapshot, query_info, context, processed_stage, max_block_size, num_streams); |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | /// Proxy to underlying storage. |
| 63 | auto filtered_columns = VirtualColumnUtils::filterVirtualColumns(column_names, storage_snapshot->metadata, VirtualsKind::Ephemeral, VirtualsMaterializationPlace::Plan); |
| 64 | readImpl(query_plan, filtered_columns, storage_snapshot, query_info, context, processed_stage, max_block_size, num_streams); |
| 65 | |
| 66 | /// Materialize constant virtuals. |
| 67 | if (query_plan.isInitialized()) |
| 68 | { |
| 69 | if (std::ranges::contains(column_names, "_database") && !query_plan.getCurrentHeader()->has("_database")) |
| 70 | materializeConstantColumn(query_plan, "_database", std::make_shared<DataTypeLowCardinality>(std::make_shared<DataTypeString>()), getStorageID().getDatabaseName()); |
| 71 | |
| 72 | if (std::ranges::contains(column_names, "_table") && !query_plan.getCurrentHeader()->has("_table")) |
| 73 | { |
| 74 | std::string table_name = getStorageID().getTableName(); |
| 75 | if (query_info.table_expression) |
| 76 | if (auto * table_node = query_info.table_expression->as<TableNode>()) |
| 77 | if (table_node->isTemporaryTable()) |
| 78 | table_name = table_node->getTemporaryTableName(); |
| 79 | |
| 80 | materializeConstantColumn(query_plan, "_table", std::make_shared<DataTypeLowCardinality>(std::make_shared<DataTypeString>()), table_name); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /// Match column_names sequence |
| 85 | if (query_plan.isInitialized()) |
| 86 | if (filtered_columns != column_names) |
| 87 | convertToHeader(query_plan, storage_snapshot->getSampleBlockForColumns(column_names), context); |
| 88 | } |
| 89 | |
| 90 | void StorageWithCommonVirtualColumns::readImpl( |
| 91 | QueryPlan & query_plan, |
nothing calls this directly
no test coverage detected