| 155 | } |
| 156 | |
| 157 | StorageView::StorageView( |
| 158 | const StorageID & table_id_, |
| 159 | const ASTCreateQuery & query, |
| 160 | const ColumnsDescription & columns_, |
| 161 | const String & comment, |
| 162 | bool is_parameterized_view_) |
| 163 | : StorageWithCommonVirtualColumns(table_id_) |
| 164 | { |
| 165 | StorageInMemoryMetadata storage_metadata; |
| 166 | if (!is_parameterized_view_) |
| 167 | { |
| 168 | /// If CREATE query is to create parameterized view, then we dont want to set columns |
| 169 | if (!query.isParameterizedView()) |
| 170 | storage_metadata.setColumns(columns_); |
| 171 | } |
| 172 | else |
| 173 | storage_metadata.setColumns(columns_); |
| 174 | |
| 175 | storage_metadata.setComment(comment); |
| 176 | if (query.sql_security) |
| 177 | storage_metadata.setSQLSecurity(query.sql_security->as<ASTSQLSecurity &>()); |
| 178 | |
| 179 | if (storage_metadata.sql_security_type == SQLSecurityType::DEFINER) |
| 180 | ViewDefinerDependencies::instance().addViewDependency(*storage_metadata.definer, table_id_); |
| 181 | |
| 182 | if (!query.select) |
| 183 | throw Exception(ErrorCodes::INCORRECT_QUERY, "SELECT query is not specified for {}", getName()); |
| 184 | SelectQueryDescription description; |
| 185 | |
| 186 | description.inner_query = query.select->ptr(); |
| 187 | |
| 188 | NormalizeSelectWithUnionQueryVisitor::Data data{SetOperationMode::Unspecified}; |
| 189 | NormalizeSelectWithUnionQueryVisitor{data}.visit(description.inner_query); |
| 190 | |
| 191 | is_parameterized_view = is_parameterized_view_ || query.isParameterizedView(); |
| 192 | storage_metadata.setSelectQuery(description); |
| 193 | storage_metadata.setVirtuals(createVirtuals()); |
| 194 | setInMemoryMetadata(storage_metadata); |
| 195 | } |
| 196 | |
| 197 | /// Build and resolve the view's inner query tree |
| 198 | /// Then find the leftmost underlying MT storage eligible for parallel replicas. |
nothing calls this directly
no test coverage detected