This is an automated email from the ASF dual-hosted git repository.

marong pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new 92a62488a  [GLUTEN-6195][VL]Add unit tests for udf (#6603)
92a62488a is described below

commit 92a62488a1c56db4ab64760becf89991a3032827
Author: Jaime Pan <[email protected]>
AuthorDate: Fri Jul 26 16:45:23 2024 +0800

     [GLUTEN-6195][VL]Add unit tests for udf (#6603)
---
 cpp/velox/tests/CMakeLists.txt |  3 +++
 cpp/velox/tests/MyUdfTest.cc   | 45 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/cpp/velox/tests/CMakeLists.txt b/cpp/velox/tests/CMakeLists.txt
index dac83cd87..f7bc1cb13 100644
--- a/cpp/velox/tests/CMakeLists.txt
+++ b/cpp/velox/tests/CMakeLists.txt
@@ -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()
diff --git a/cpp/velox/tests/MyUdfTest.cc b/cpp/velox/tests/MyUdfTest.cc
new file mode 100644
index 000000000..46898b38c
--- /dev/null
+++ b/cpp/velox/tests/MyUdfTest.cc
@@ -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
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to