summaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/complete/core/name.cpp
blob: 80a13ca773a4f00affb19a629f9c57e748fe081d (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
35
36
37
38
39
40
41
42
43
#include "name.h"

#include <yql/essentials/core/sql_types/normalize_name.h>

#include <util/stream/output.h>
#include <util/charset/utf8.h>

namespace NSQLComplete {

    bool operator<(const TTableId& lhs, const TTableId& rhs) {
        return std::tie(lhs.Cluster, lhs.Path) < std::tie(rhs.Cluster, rhs.Path);
    }

    TString LowerizeName(TStringBuf name) {
        return ToLowerUTF8(name);
    }

    TString NormalizeName(TStringBuf name) {
        TString normalized(name);
        TMaybe<NYql::TIssue> error = NYql::NormalizeName(NYql::TPosition(), normalized);
        if (!error.Empty()) {
            return LowerizeName(name);
        }
        return normalized;
    }

} // namespace NSQLComplete

template <>
void Out<NSQLComplete::TTableId>(IOutputStream& out, const NSQLComplete::TTableId& value) {
    out << value.Cluster << ".`" << value.Path << "`";
}

template <>
void Out<NSQLComplete::TAliased<NSQLComplete::TTableId>>(IOutputStream& out, const NSQLComplete::TAliased<NSQLComplete::TTableId>& value) {
    Out<NSQLComplete::TTableId>(out, value);
    out << " AS " << value.Alias;
}

template <>
void Out<NSQLComplete::TColumnId>(IOutputStream& out, const NSQLComplete::TColumnId& value) {
    out << value.TableAlias << "." << value.Name;
}