The columns list in the original INSERT query is incorrect because inserted blocks are transformed to the form of the sample block of the Distributed table. So we rewrite it and add all columns from the sample block instead.
| 195 | /// to the form of the sample block of the Distributed table. So we rewrite it and add all columns from |
| 196 | /// the sample block instead. |
| 197 | ASTPtr createInsertToRemoteTableQuery(const std::string & database, const std::string & table, const Block & sample_block) |
| 198 | { |
| 199 | auto query = std::make_shared<ASTInsertQuery>(); |
| 200 | query->table_id = StorageID(database, table); |
| 201 | |
| 202 | auto columns = std::make_shared<ASTExpressionList>(); |
| 203 | query->columns = columns; |
| 204 | query->children.push_back(columns); |
| 205 | for (const auto & col : sample_block) |
| 206 | columns->children.push_back(std::make_shared<ASTIdentifier>(col.name)); |
| 207 | |
| 208 | return query; |
| 209 | } |
| 210 | |
| 211 | /// Calculate maximum number in file names in directory and all subdirectories. |
| 212 | /// To ensure global order of data blocks yet to be sent across server restarts. |