MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / getRowPolicyFilter

Method getRowPolicyFilter

src/Access/ContextAccess.cpp:532–576  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

530#endif
531
532RowPolicyFilterPtr ContextAccess::getRowPolicyFilter(const String & database, const String & table_name, RowPolicyFilterType filter_type) const
533{
534 RowPolicyFilterPtr filter;
535
536 {
537 std::lock_guard lock{mutex};
538
539 if (initialized && !user && !user_was_dropped)
540 throw Exception(ErrorCodes::LOGICAL_ERROR, "ContextAccess is inconsistent (bug 55041)");
541
542 if (enabled_row_policies)
543 filter = enabled_row_policies->getFilter(database, table_name, filter_type);
544
545 if (row_policies_of_initial_user)
546 {
547 /// Find and set extra row policies to be used based on `client_info.initial_user`, if the initial user exists.
548 /// TODO: we need a better solution here. It seems we should pass the initial row policy
549 /// because a shard is allowed to not have the initial user or it might be another user
550 /// with the same name.
551 filter = row_policies_of_initial_user->getFilter(database, table_name, filter_type, filter);
552 }
553 }
554
555 if (filter && filter->policies.empty())
556 {
557 if (access_control->shouldThrowOnUnmatchedRowPolicies())
558 {
559 throw Exception(ErrorCodes::ACCESS_DENIED,
560 "{}: Table {}.{} has row policies, but none of them are for the current user",
561 getUserName(), backQuoteIfNeed(database), backQuoteIfNeed(table_name));
562 }
563 else
564 {
565 chassert(filter->isAlwaysTrue() || filter->isAlwaysFalse());
566 std::string_view filter_info =
567 filter->isAlwaysTrue() ? ", no filters will be used" :
568 (filter->isAlwaysFalse() ? ", no rows will be shown" : "");
569
570 LOG_TRACE(trace_log, "{}: Table {}.{} has row policies, but none of them are for the current user{}",
571 getUserName(), backQuoteIfNeed(database), backQuoteIfNeed(table_name), filter_info);
572 }
573 }
574
575 return filter;
576}
577
578std::shared_ptr<const EnabledQuota> ContextAccess::getQuota() const
579{

Callers 5

readImplMethod · 0.45
createChildrenPlansMethod · 0.45
getRowPolicyFilterFunction · 0.45

Calls 8

getUserNameFunction · 0.85
backQuoteIfNeedFunction · 0.85
getFilterMethod · 0.80
isAlwaysTrueMethod · 0.80
isAlwaysFalseMethod · 0.80
ExceptionClass · 0.50
emptyMethod · 0.45

Tested by

no test coverage detected