mkql_builtins_ut.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "mkql_builtins.h"
  2. #include <yql/essentials/public/udf/udf_value.h>
  3. #include <library/cpp/testing/unittest/registar.h>
  4. #include <array>
  5. namespace NKikimr {
  6. namespace NMiniKQL {
  7. static TFunctionParamMetadata AddUi32Metadata[] = {
  8. { NUdf::TDataType<ui32>::Id, 0 }, // result
  9. { NUdf::TDataType<ui32>::Id, 0 }, // first arg
  10. { NUdf::TDataType<ui32>::Id, 0 }, // second arg
  11. { 0, 0 }
  12. };
  13. static NUdf::TUnboxedValuePod AddUi32(const NUdf::TUnboxedValuePod* args)
  14. {
  15. const ui32 first = args[0].Get<ui32>();
  16. const ui32 second = args[1].Get<ui32>();
  17. return NUdf::TUnboxedValuePod(first + second);
  18. }
  19. Y_UNIT_TEST_SUITE(TFunctionRegistryTest) {
  20. Y_UNIT_TEST(TestRegistration) {
  21. const auto functionRegistry = CreateBuiltinRegistry();
  22. functionRegistry->Register("MyAdd", TFunctionDescriptor(AddUi32Metadata, &AddUi32));
  23. const std::array<TArgType, 3U> argTypes ={{{ NUdf::TDataType<ui32>::Id, false }, { NUdf::TDataType<ui32>::Id, false }, { NUdf::TDataType<ui32>::Id, false }}};
  24. auto op = functionRegistry->GetBuiltin("MyAdd", argTypes.data(), argTypes.size());
  25. UNIT_ASSERT_EQUAL(op.Function, &AddUi32);
  26. UNIT_ASSERT_EQUAL(op.ResultAndArgs[0].SchemeType, NUdf::TDataType<ui32>::Id);
  27. UNIT_ASSERT_EQUAL(op.ResultAndArgs[0].Flags, 0);
  28. UNIT_ASSERT_EQUAL(op.ResultAndArgs[1].SchemeType, NUdf::TDataType<ui32>::Id);
  29. UNIT_ASSERT_EQUAL(op.ResultAndArgs[1].Flags, 0);
  30. UNIT_ASSERT_EQUAL(op.ResultAndArgs[2].SchemeType, NUdf::TDataType<ui32>::Id);
  31. UNIT_ASSERT_EQUAL(op.ResultAndArgs[2].Flags, 0);
  32. UNIT_ASSERT_EQUAL(op.ResultAndArgs[3].SchemeType, 0);
  33. const NUdf::TUnboxedValuePod args[2] = {NUdf::TUnboxedValuePod(ui32(2)), NUdf::TUnboxedValuePod(ui32(3))};
  34. auto result = op.Function(&args[0]);
  35. UNIT_ASSERT_EQUAL(result.Get<ui32>(), 5);
  36. }
  37. }
  38. } // namespace NMiniKQL
  39. } // namespace NKikimr