| 748 | } |
| 749 | |
| 750 | void interpretSettings(ASTPtr query, ContextMutablePtr context) |
| 751 | { |
| 752 | auto & ast = query; |
| 753 | if (auto * explain_select_query = ast->as<ASTExplainQuery>()) |
| 754 | ast = explain_select_query->getExplainedQuery(); |
| 755 | |
| 756 | if (const auto * select_query = ast->as<ASTSelectQuery>()) |
| 757 | { |
| 758 | if (auto new_settings = select_query->settings()) |
| 759 | InterpreterSetQuery(new_settings, context).executeForCurrentContext(); |
| 760 | } |
| 761 | else if (const auto * select_with_union_query = ast->as<ASTSelectWithUnionQuery>()) |
| 762 | { |
| 763 | if (!select_with_union_query->list_of_selects->children.empty()) |
| 764 | { |
| 765 | // We might have an arbitrarily complex UNION tree, so just give |
| 766 | // up if the last first-order child is not a plain SELECT. |
| 767 | // It is flattened later, when we process UNION ALL/DISTINCT. |
| 768 | const auto * last_select = select_with_union_query->list_of_selects->children.back()->as<ASTSelectQuery>(); |
| 769 | if (last_select && last_select->settings()) |
| 770 | { |
| 771 | InterpreterSetQuery(last_select->settings(), context).executeForCurrentContext(); |
| 772 | } |
| 773 | } |
| 774 | } |
| 775 | else if (const auto * create_select_query = ast->as<ASTCreateQuery>(); create_select_query && create_select_query->select) |
| 776 | { |
| 777 | const auto * select_in_query = create_select_query->select->as<ASTSelectWithUnionQuery>(); |
| 778 | if (select_in_query && !select_in_query->list_of_selects->children.empty()) |
| 779 | { |
| 780 | const auto * last_select = select_in_query->list_of_selects->children.back()->as<ASTSelectQuery>(); |
| 781 | if (last_select && last_select->settings()) |
| 782 | InterpreterSetQuery(last_select->settings(), context).executeForCurrentContext(); |
| 783 | } |
| 784 | } |
| 785 | else if (const auto * query_with_output = dynamic_cast<const ASTQueryWithOutput *>(ast.get())) |
| 786 | { |
| 787 | if (query_with_output->settings_ast) |
| 788 | InterpreterSetQuery(query_with_output->settings_ast, context).executeForCurrentContext(); |
| 789 | } |
| 790 | else if (const auto * insert_query = ast->as<ASTInsertQuery>()) |
| 791 | { |
| 792 | if (insert_query->settings_ast) |
| 793 | InterpreterSetQuery(insert_query->settings_ast, context).executeForCurrentContext(); |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | static std::tuple<ASTPtr, BlockIO> executeQueryImpl( |
| 798 | const char * begin, |
no test coverage detected