mkql_validate_impl.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #pragma once
  2. #include <util/string/cast.h>
  3. namespace NKikimr {
  4. namespace NMiniKQL {
  5. struct TValidateErrorPolicyNone {
  6. };
  7. struct TUdfValidateException: public yexception {
  8. };
  9. struct TValidateErrorPolicyThrow {
  10. static void Generate(const TString& message) {
  11. GenerateExc(TUdfValidateException() << message);
  12. }
  13. template<class TException>
  14. static void GenerateExc(const TException& exc) {
  15. static_assert(std::is_base_of<yexception, TException>::value, "Must be derived from yexception");
  16. ythrow TException() << exc.AsStrBuf();
  17. }
  18. };
  19. struct TValidateErrorPolicyFail {
  20. static void Generate(const TString& message) {
  21. Y_ABORT("value verify failed: %s", message.c_str());
  22. }
  23. template<class TException>
  24. static void GenerateExc(const TException& exc) {
  25. Generate(ToString(exc.AsStrBuf()));
  26. }
  27. };
  28. template<class TValidateMode>
  29. struct TValidate<TValidateErrorPolicyNone, TValidateMode> {
  30. static NUdf::TUnboxedValue Value(const NUdf::IValueBuilder* valueBuilder, const TType* type, NUdf::TUnboxedValue&& value, const TString& message, bool* wrapped) {
  31. Y_UNUSED(valueBuilder);
  32. Y_UNUSED(type);
  33. Y_UNUSED(message);
  34. Y_UNUSED(wrapped);
  35. return std::move(value);
  36. }
  37. static void WrapCallable(const TCallableType*, NUdf::TUnboxedValue&, const TString&) {}
  38. };
  39. } // namespace MiniKQL
  40. } // namespace NKikimr