aboutsummaryrefslogtreecommitdiffstats
path: root/yql/tools/yqlrun/http/yql_functions_servlet.cpp
blob: 9cf5ef54f325ac290f0b11a07792c82454ad9756 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "yql_functions_servlet.h"

#include <yt/yql/providers/yt/provider/yql_yt_provider.h>
#include <yql/essentials/providers/config/yql_config_provider.h>
#include <yql/essentials/providers/result/provider/yql_result_provider.h>
#include <yql/essentials/core/type_ann/type_ann_core.h>


namespace {

void OutputKnownFunctions(TStringStream& out)
{
    using namespace NYql;

    out <<
            "window.yql = {};\n"
            "window.yql.builtinFunctions = [";

    const auto& builtinFuncs = GetBuiltinFunctions();
    for (const auto& func: builtinFuncs) {
        out << '"' << func << "\",";
    }
    out << "];\n";

    out << "window.yql.supportedFunctions = [";

    const THashSet<TStringBuf>* functionsSet[] = {
        &YtDataSourceFunctions(),
        &YtDataSinkFunctions(),
        &ResultProviderFunctions(),
        &ConfigProviderFunctions()
    };

    for (const auto& funcs: functionsSet) {
        for (const auto& func: *funcs) {
            out << '"' << func << "\",";
        }
    }

    out << "];";
}

} // namspace

namespace NYql {
namespace NHttp {

void TYqlFunctoinsServlet::DoGet(const TRequest& req, TResponse& resp) const
{
    Y_UNUSED(req);

    TStringStream out;
    OutputKnownFunctions(out);
    resp.Body = TBlob::FromString(out.Str());
    resp.Headers.AddHeader(THttpInputHeader("Content-Type: text/javascript"));
}

} // namspace NNttp
} // namspace NYql