udf_validate.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "udf_validate.h"
  2. #include <util/string/join.h>
  3. #include <util/generic/yexception.h>
  4. namespace NYql {
  5. namespace NUdf {
  6. #define SWITCH_ENUM_TYPE_TO_STR(name, val) \
  7. case val: return TStringBuf(#name);
  8. TString ValidateModeAvailables() {
  9. return Join(", ",
  10. ValidateModeAsStr(EValidateMode::None),
  11. ValidateModeAsStr(EValidateMode::Lazy),
  12. ValidateModeAsStr(EValidateMode::Greedy)
  13. );
  14. }
  15. TStringBuf ValidateModeAsStr(EValidateMode validateMode) {
  16. switch (static_cast<int>(validateMode)) {
  17. UDF_VALIDATE_MODE(SWITCH_ENUM_TYPE_TO_STR)
  18. }
  19. return TStringBuf("unknown");
  20. }
  21. EValidateMode ValidateModeByStr(const TString& validateModeStr) {
  22. const TString lowerValidateModeStr = to_lower(validateModeStr);
  23. for (auto val = EValidateMode::None; val < EValidateMode::Max; val = static_cast<EValidateMode>(static_cast<ui8>(val) + 1)) {
  24. if (lowerValidateModeStr == to_lower(TString(ValidateModeAsStr(val)))) {
  25. return val;
  26. }
  27. }
  28. ythrow yexception() << "Unknown udf validate mode: " << validateModeStr;
  29. }
  30. TStringBuf ValidatePolicyAsStr(EValidatePolicy validatePolicy) {
  31. switch (static_cast<int>(validatePolicy)) {
  32. UDF_VALIDATE_POLICY(SWITCH_ENUM_TYPE_TO_STR)
  33. }
  34. return TStringBuf("unknown");
  35. }
  36. EValidatePolicy ValidatePolicyByStr(const TString& validatePolicyStr) {
  37. const TString lowerValidatePolicyStr = to_lower(validatePolicyStr);
  38. for (auto val = EValidatePolicy::Fail; val < EValidatePolicy::Max; val = static_cast<EValidatePolicy>(static_cast<ui8>(val) + 1)) {
  39. if (lowerValidatePolicyStr == to_lower(TString(ValidatePolicyAsStr(val)))) {
  40. return val;
  41. }
  42. }
  43. ythrow yexception() << "Unknown udf validate policy: " << validatePolicyStr;
  44. }
  45. } // namspace NUdf
  46. } // namspace NYql