#pragma once #include #include #include #include #include #include namespace DB { struct Settings; class SettingsChanges; class SettingsConstraints; class ASTSettingsProfileElement; class ASTSettingsProfileElements; class AccessControl; struct SettingsProfileElement { std::optional parent_profile; String setting_name; std::optional value; std::optional min_value; std::optional max_value; std::optional writability; auto toTuple() const { return std::tie(parent_profile, setting_name, value, min_value, max_value, writability); } friend bool operator==(const SettingsProfileElement & lhs, const SettingsProfileElement & rhs) { return lhs.toTuple() == rhs.toTuple(); } friend bool operator!=(const SettingsProfileElement & lhs, const SettingsProfileElement & rhs) { return !(lhs == rhs); } friend bool operator <(const SettingsProfileElement & lhs, const SettingsProfileElement & rhs) { return lhs.toTuple() < rhs.toTuple(); } friend bool operator >(const SettingsProfileElement & lhs, const SettingsProfileElement & rhs) { return rhs < lhs; } friend bool operator <=(const SettingsProfileElement & lhs, const SettingsProfileElement & rhs) { return !(rhs < lhs); } friend bool operator >=(const SettingsProfileElement & lhs, const SettingsProfileElement & rhs) { return !(lhs < rhs); } SettingsProfileElement() = default; /// The constructor from AST requires the AccessControl if `ast.id_mode == false`. SettingsProfileElement(const ASTSettingsProfileElement & ast); /// NOLINT SettingsProfileElement(const ASTSettingsProfileElement & ast, const AccessControl & access_control); std::shared_ptr toAST() const; std::shared_ptr toASTWithNames(const AccessControl & access_control) const; bool isConstraint() const; private: void init(const ASTSettingsProfileElement & ast, const AccessControl * access_control); }; class SettingsProfileElements : public std::vector { public: SettingsProfileElements() = default; /// The constructor from AST requires the AccessControl if `ast.id_mode == false`. SettingsProfileElements(const ASTSettingsProfileElements & ast); /// NOLINT SettingsProfileElements(const ASTSettingsProfileElements & ast, const AccessControl & access_control); std::shared_ptr toAST() const; std::shared_ptr toASTWithNames(const AccessControl & access_control) const; std::vector findDependencies() const; bool hasDependencies(const std::unordered_set & ids) const; void replaceDependencies(const std::unordered_map & old_to_new_ids); void copyDependenciesFrom(const SettingsProfileElements & src, const std::unordered_set & ids); void removeDependencies(const std::unordered_set & ids); void removeSettingsKeepProfiles(); void merge(const SettingsProfileElements & other); Settings toSettings() const; SettingsChanges toSettingsChanges() const; SettingsConstraints toSettingsConstraints(const AccessControl & access_control) const; std::vector toProfileIDs() const; bool isBackupAllowed() const; static bool isAllowBackupSetting(const String & setting_name); }; }