MCPcopy Create free account
hub / github.com/ByConity/ByConity / selectGroup

Method selectGroup

src/ResourceGroup/ResourceGroupSelectStrategy.cpp:23–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21}
22
23IResourceGroup* UserTableSelectStrategy::selectGroup(const Context & query_context, const IAST *ast)
24{
25 auto & select_cases = resource_group_manager->getSelectCases();
26 const ClientInfo & client_info = query_context.getClientInfo();
27
28 const auto get_user_group = [&select_cases, &client_info]() -> IResourceGroup * {
29 for (const auto & [_, select_case] : select_cases)
30 {
31 if ((select_case.user == nullptr || std::regex_match(client_info.initial_user, *(select_case.user))))
32 return select_case.group;
33 }
34 return nullptr;
35 };
36
37 IResourceGroup * user_group = get_user_group();
38 LOG_DEBUG(logger, "user {} user_group {} children_size {}",
39 client_info.initial_user, user_group ? user_group->getName() : "not found",
40 user_group ? user_group->getChildren().size() : 0);
41 if (user_group && !user_group->getChildren().empty())
42 {
43 size_t group_idx = 0;
44
45 std::vector<IResourceGroup *> groups;
46 const auto & children = user_group->getChildren();
47 for (const auto & item: children)
48 {
49 groups.emplace_back(item.second);
50 }
51
52 const ASTSelectQuery * select_query = nullptr;
53 if (ast->as<ASTSelectQuery>())
54 {
55 select_query = ast->as<ASTSelectQuery>();
56 }
57 else if (ast->as<ASTSelectWithUnionQuery>())
58 {
59 const ASTSelectWithUnionQuery * union_ast = ast->as<ASTSelectWithUnionQuery>();
60 if (union_ast->list_of_selects->children.size() == 1)
61 {
62 const ASTPtr first_select_ast = union_ast->list_of_selects->children.at(0);
63 select_query = dynamic_cast<ASTSelectQuery *>(first_select_ast.get());
64 }
65 }
66
67 std::optional<DatabaseAndTableWithAlias> database_and_table;
68 if (select_query)
69 {
70 database_and_table = getDatabaseAndTable(*select_query, 0);
71 }
72
73 LOG_DEBUG(logger, "user_query {} user_group {} table {}",
74 select_query ? "select" : "not_select",
75 user_group->getName(),
76 database_and_table ? database_and_table->table : "empty");
77
78 if (select_query && database_and_table.has_value())
79 {
80 auto table = database_and_table->table;

Callers

nothing calls this directly

Calls 15

getDatabaseAndTableFunction · 0.85
CityHash64Function · 0.85
getChildrenMethod · 0.80
has_valueMethod · 0.80
getServerTypeMethod · 0.80
lengthMethod · 0.80
tryGetCurrentVWMethod · 0.80
setInUseMethod · 0.80
ExceptionClass · 0.50
getNameMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected