#include #include #include #include #include #include #include #include namespace DB { bool InsertQuerySettingsPushDownMatcher::needChildVisit(ASTPtr & node, const ASTPtr & child) { if (node->as()) return true; if (node->as()) return true; if (child->as()) return true; return false; } void InsertQuerySettingsPushDownMatcher::visit(ASTPtr & ast, Data & data) { if (auto * select_query = ast->as()) visit(*select_query, ast, data); } void InsertQuerySettingsPushDownMatcher::visit(ASTSelectQuery & select_query, ASTPtr &, Data & data) { ASTPtr select_settings_ast = select_query.settings(); if (!select_settings_ast) return; auto & insert_settings_ast = data.insert_settings_ast; if (!insert_settings_ast) { insert_settings_ast = select_settings_ast->clone(); return; } SettingsChanges & select_settings = select_settings_ast->as().changes; SettingsChanges & insert_settings = insert_settings_ast->as().changes; for (auto & setting : select_settings) { auto it = std::find_if(insert_settings.begin(), insert_settings.end(), [&](auto & select_setting) { return select_setting.name == setting.name; }); if (it == insert_settings.end()) insert_settings.push_back(setting); else { /// Do not overwrite setting that was passed for INSERT /// by settings that was passed for SELECT } } } }