aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/cluster_mapping.cpp
blob: 7a6ab64ecd06e95918442f2ae2763a9b140e7b52 (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
28
29
30
31
32
33
34
#include "cluster_mapping.h"
#include <yql/essentials/providers/common/provider/yql_provider_names.h>

using namespace NYql;

namespace NSQLTranslation {
TClusterMapping::TClusterMapping(const THashMap<TString, TString>& mapping) {
    for (const auto& p : mapping) {
        if (p.second == KikimrProviderName) {
            CaseSensitiveClusters.emplace(p);
            continue;
        }

        TString clusterLowerCase = to_lower(p.first);
        CaseInsensitiveClusters.emplace(clusterLowerCase, p.second);
    }
}

TMaybe<TString> TClusterMapping::GetClusterProvider(const TString& cluster, TString& normalizedClusterName) const {
    auto providerPtr1 = CaseSensitiveClusters.FindPtr(cluster);
    if (providerPtr1) {
        normalizedClusterName = cluster;
        return *providerPtr1;
    }

    TString clusterLowerCase = to_lower(cluster);
    auto providerPtr2 = CaseInsensitiveClusters.FindPtr(clusterLowerCase);
    if (providerPtr2) {
        normalizedClusterName = clusterLowerCase;
        return *providerPtr2;
    }
    return Nothing();
}
}