Skip to content

Commit

Permalink
add unit test for udf
Browse files Browse the repository at this point in the history
  • Loading branch information
NEUpanning committed Jul 26, 2024
1 parent 264ff2e commit f343050
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cpp/velox/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ add_velox_test(spark_functions_test SOURCES SparkFunctionTest.cc
add_velox_test(execution_ctx_test SOURCES RuntimeTest.cc)
add_velox_test(velox_memory_test SOURCES MemoryManagerTest.cc)
add_velox_test(buffer_outputstream_test SOURCES BufferOutputStreamTest.cc)
if(BUILD_EXAMPLES)
add_velox_test(MyUdfTest SOURCES MyUdfTest.cc)
endif()
45 changes: 45 additions & 0 deletions cpp/velox/tests/MyUdfTest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <vector>
#include "udf/UdfLoader.h"
#include "velox/expression/VectorFunction.h"
#include "velox/functions/prestosql/tests/utils/FunctionBaseTest.h"
#include "velox/parse/TypeResolver.h"

using namespace facebook::velox::functions::test;
using namespace facebook::velox;
class MyUdfTest : public FunctionBaseTest {
protected:
static void SetUpTestCase() {
parse::registerTypeResolver();
auto udfLoader = gluten::UdfLoader::getInstance();
udfLoader->loadUdfLibraries("../udf/examples/libmyudf.so");
udfLoader->registerUdf();
memory::MemoryManager::testingSetInstance({});
}
};

TEST_F(MyUdfTest, myudf1) {
const auto myudf1 = [&](const int64_t& number) {
return evaluateOnce<int64_t>("myudf1(c0)", BIGINT(), std::make_optional(number));
};

EXPECT_EQ(5, myudf1(0));
EXPECT_EQ(105, myudf1(100));
EXPECT_EQ(3147483652, myudf1(3147483647)); // int64
}

0 comments on commit f343050

Please sign in to comment.