aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/public/udf/udf_validate.cpp
blob: be61b79cf29f5058aaa07b3fc24deed901aa6f47 (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
#include "udf_validate.h"
#include <util/string/join.h>
#include <util/generic/yexception.h>

namespace NYql {
namespace NUdf {

#define SWITCH_ENUM_TYPE_TO_STR(name, val) \
    case val: return TStringBuf(#name);

TString ValidateModeAvailables() {
    return Join(", ",
        ValidateModeAsStr(EValidateMode::None),
        ValidateModeAsStr(EValidateMode::Lazy),
        ValidateModeAsStr(EValidateMode::Greedy)
    );
}

TStringBuf ValidateModeAsStr(EValidateMode validateMode) {
    switch (static_cast<int>(validateMode)) {
        UDF_VALIDATE_MODE(SWITCH_ENUM_TYPE_TO_STR)
    }

    return TStringBuf("unknown");
}

EValidateMode ValidateModeByStr(const TString& validateModeStr) {
    const TString lowerValidateModeStr = to_lower(validateModeStr);
    for (auto val = EValidateMode::None; val < EValidateMode::Max; val = static_cast<EValidateMode>(static_cast<ui8>(val) + 1)) {
        if (lowerValidateModeStr == to_lower(TString(ValidateModeAsStr(val)))) {
            return val;
        }
    }
    ythrow yexception() << "Unknown udf validate mode: " << validateModeStr;
}

TStringBuf ValidatePolicyAsStr(EValidatePolicy validatePolicy) {
    switch (static_cast<int>(validatePolicy)) {
        UDF_VALIDATE_POLICY(SWITCH_ENUM_TYPE_TO_STR)
    }

    return TStringBuf("unknown");
}

EValidatePolicy ValidatePolicyByStr(const TString& validatePolicyStr) {
    const TString lowerValidatePolicyStr = to_lower(validatePolicyStr);
    for (auto val = EValidatePolicy::Fail; val < EValidatePolicy::Max; val = static_cast<EValidatePolicy>(static_cast<ui8>(val) + 1)) {
        if (lowerValidatePolicyStr == to_lower(TString(ValidatePolicyAsStr(val)))) {
            return val;
        }
    }
    ythrow yexception() << "Unknown udf validate policy: " << validatePolicyStr;
}

} // namspace NUdf
} // namspace NYql