| 127 | } |
| 128 | |
| 129 | std::optional<MutationCommand> MutationCommand::parse( |
| 130 | const ASTAlterCommand & command, |
| 131 | bool parse_alter_commands, |
| 132 | bool with_pure_metadata_commands, |
| 133 | UInt64 max_parser_depth, |
| 134 | UInt64 max_parser_backtracks) |
| 135 | { |
| 136 | MutationCommand res; |
| 137 | res.ast_text = command.formatWithSecretsOneLine(); |
| 138 | res.max_parser_depth = max_parser_depth; |
| 139 | res.max_parser_backtracks = max_parser_backtracks; |
| 140 | if (with_pure_metadata_commands) |
| 141 | { |
| 142 | res.type = ALTER_WITHOUT_MUTATION; |
| 143 | return res; |
| 144 | } |
| 145 | |
| 146 | if (command.type == ASTAlterCommand::DELETE) |
| 147 | { |
| 148 | res.type = DELETE; |
| 149 | return res; |
| 150 | } |
| 151 | if (command.type == ASTAlterCommand::UPDATE) |
| 152 | { |
| 153 | res.type = UPDATE; |
| 154 | NameSet seen_columns; |
| 155 | for (const ASTPtr & assignment_ast : command.update_assignments->children) |
| 156 | { |
| 157 | const auto & assignment = assignment_ast->as<ASTAssignment &>(); |
| 158 | if (!seen_columns.insert(assignment.column_name).second) |
| 159 | throw Exception( |
| 160 | ErrorCodes::MULTIPLE_ASSIGNMENTS_TO_COLUMN, |
| 161 | "Multiple assignments in the single statement to column {}", |
| 162 | backQuote(assignment.column_name)); |
| 163 | } |
| 164 | return res; |
| 165 | } |
| 166 | if (command.type == ASTAlterCommand::APPLY_DELETED_MASK) |
| 167 | { |
| 168 | res.type = APPLY_DELETED_MASK; |
| 169 | return res; |
| 170 | } |
| 171 | else if (command.type == ASTAlterCommand::APPLY_PATCHES) |
| 172 | { |
| 173 | res.type = APPLY_PATCHES; |
| 174 | return res; |
| 175 | } |
| 176 | if (command.type == ASTAlterCommand::MATERIALIZE_INDEX) |
| 177 | { |
| 178 | res.type = MATERIALIZE_INDEX; |
| 179 | res.index_name = command.index->as<ASTIdentifier &>().name(); |
| 180 | return res; |
| 181 | } |
| 182 | if (command.type == ASTAlterCommand::MATERIALIZE_STATISTICS) |
| 183 | { |
| 184 | res.type = MATERIALIZE_STATISTICS; |
| 185 | if (command.statistics_decl) |
| 186 | { |
nothing calls this directly
no test coverage detected