1 | #include <Access/RowPolicyContext.h> |
---|---|
2 | #include <boost/range/adaptor/map.hpp> |
3 | #include <boost/range/algorithm/copy.hpp> |
4 | |
5 | |
6 | namespace DB |
7 | { |
8 | size_t RowPolicyContext::Hash::operator()(const DatabaseAndTableNameRef & database_and_table_name) const |
9 | { |
10 | return std::hash<StringRef>{}(database_and_table_name.first) - std::hash<StringRef>{}(database_and_table_name.second); |
11 | } |
12 | |
13 | |
14 | RowPolicyContext::RowPolicyContext() |
15 | : atomic_map_of_mixed_conditions(std::make_shared<MapOfMixedConditions>()) |
16 | { |
17 | } |
18 | |
19 | |
20 | RowPolicyContext::~RowPolicyContext() = default; |
21 | |
22 | |
23 | RowPolicyContext::RowPolicyContext(const String & user_name_) |
24 | : user_name(user_name_) |
25 | {} |
26 | |
27 | |
28 | ASTPtr RowPolicyContext::getCondition(const String & database, const String & table_name, ConditionIndex index) const |
29 | { |
30 | /// We don't lock `mutex` here. |
31 | auto map_of_mixed_conditions = std::atomic_load(&atomic_map_of_mixed_conditions); |
32 | auto it = map_of_mixed_conditions->find({database, table_name}); |
33 | if (it == map_of_mixed_conditions->end()) |
34 | return {}; |
35 | return it->second.mixed_conditions[index]; |
36 | } |
37 | |
38 | |
39 | std::vector<UUID> RowPolicyContext::getCurrentPolicyIDs() const |
40 | { |
41 | /// We don't lock `mutex` here. |
42 | auto map_of_mixed_conditions = std::atomic_load(&atomic_map_of_mixed_conditions); |
43 | std::vector<UUID> policy_ids; |
44 | for (const auto & mixed_conditions : *map_of_mixed_conditions | boost::adaptors::map_values) |
45 | boost::range::copy(mixed_conditions.policy_ids, std::back_inserter(policy_ids)); |
46 | return policy_ids; |
47 | } |
48 | |
49 | |
50 | std::vector<UUID> RowPolicyContext::getCurrentPolicyIDs(const String & database, const String & table_name) const |
51 | { |
52 | /// We don't lock `mutex` here. |
53 | auto map_of_mixed_conditions = std::atomic_load(&atomic_map_of_mixed_conditions); |
54 | auto it = map_of_mixed_conditions->find({database, table_name}); |
55 | if (it == map_of_mixed_conditions->end()) |
56 | return {}; |
57 | return it->second.policy_ids; |
58 | } |
59 | } |
60 |