summaryrefslogtreecommitdiffstats
path: root/yql/essentials/minikql/jsonpath/jsonpath.cpp
blob: bb4bd27d30b0cd0667071e5d035eaa3934b7a188 (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
#include "jsonpath.h"

#include <yql/essentials/minikql/jsonpath/parser/binary.h>
#include "executor.h"

using namespace NYql;
using namespace NYql::NUdf;
using namespace NJson;

namespace NYql::NJsonPath {

TResult ExecuteJsonPath(
    const TJsonPathPtr jsonPath,
    const TValue& json,
    const TVariablesMap& variables,
    const NUdf::IValueBuilder* valueBuilder) {
    TExecutor executor(jsonPath, {json}, variables, valueBuilder);
    return executor.Execute();
}

TVariablesMap DictToVariables(const NUdf::TUnboxedValue& dict) {
    TVariablesMap variables;
    TUnboxedValue key;
    TUnboxedValue payload;
    auto it = dict.GetDictIterator();
    while (it.NextPair(key, payload)) {
        variables[key.AsStringRef()] = TValue(payload);
    }
    return variables;
}

}