aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Interpreters/getTableOverride.cpp
blob: 903d9e808366d4d2ba64fca8e819226be2e5165f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "getTableOverride.h"

#include <Interpreters/DatabaseCatalog.h>
#include <Parsers/ASTCreateQuery.h>
#include <Parsers/ASTTableOverrides.h>
#include <Databases/IDatabase.h>

namespace DB
{

ASTPtr tryGetTableOverride(const String & mapped_database, const String & table)
{
    if (auto database_ptr = DatabaseCatalog::instance().tryGetDatabase(mapped_database))
    {
        auto create_query = database_ptr->getCreateDatabaseQuery();
        if (auto * create_database_query = create_query->as<ASTCreateQuery>())
        {
            if (create_database_query->table_overrides)
            {
                return create_database_query->table_overrides->tryGetTableOverride(table);
            }
        }
    }
    return nullptr;
}

}