#include "mkql_builtins.h" #include #include #include namespace NKikimr { namespace NMiniKQL { static TFunctionParamMetadata AddUi32Metadata[] = { { NUdf::TDataType::Id, 0 }, // result { NUdf::TDataType::Id, 0 }, // first arg { NUdf::TDataType::Id, 0 }, // second arg { 0, 0 } }; static NUdf::TUnboxedValuePod AddUi32(const NUdf::TUnboxedValuePod* args) { const ui32 first = args[0].Get(); const ui32 second = args[1].Get(); return NUdf::TUnboxedValuePod(first + second); } Y_UNIT_TEST_SUITE(TFunctionRegistryTest) { Y_UNIT_TEST(TestRegistration) { const auto functionRegistry = CreateBuiltinRegistry(); functionRegistry->Register("MyAdd", TFunctionDescriptor(AddUi32Metadata, &AddUi32)); const std::array argTypes ={{{ NUdf::TDataType::Id, false }, { NUdf::TDataType::Id, false }, { NUdf::TDataType::Id, false }}}; auto op = functionRegistry->GetBuiltin("MyAdd", argTypes.data(), argTypes.size()); UNIT_ASSERT_EQUAL(op.Function, &AddUi32); UNIT_ASSERT_EQUAL(op.ResultAndArgs[0].SchemeType, NUdf::TDataType::Id); UNIT_ASSERT_EQUAL(op.ResultAndArgs[0].Flags, 0); UNIT_ASSERT_EQUAL(op.ResultAndArgs[1].SchemeType, NUdf::TDataType::Id); UNIT_ASSERT_EQUAL(op.ResultAndArgs[1].Flags, 0); UNIT_ASSERT_EQUAL(op.ResultAndArgs[2].SchemeType, NUdf::TDataType::Id); UNIT_ASSERT_EQUAL(op.ResultAndArgs[2].Flags, 0); UNIT_ASSERT_EQUAL(op.ResultAndArgs[3].SchemeType, 0); const NUdf::TUnboxedValuePod args[2] = {NUdf::TUnboxedValuePod(ui32(2)), NUdf::TUnboxedValuePod(ui32(3))}; auto result = op.Function(&args[0]); UNIT_ASSERT_EQUAL(result.Get(), 5); } } } // namespace NMiniKQL } // namespace NKikimr