From 831c17487a874acdfa29a2f162f5c9ef5fcaad80 Mon Sep 17 00:00:00 2001 From: E2ern1ty Date: Wed, 9 Oct 2024 17:15:15 +0800 Subject: [PATCH] fix cmake error in pr #5846 (#5955) * feat(function): support md5 (cherry picked from commit 84bb690fc4cd472cb6e0a19eddf2b009a699547c) * format code Signed-off-by: alexsehep (cherry picked from commit d2b17d4bae8bf5c0ac4454520df49cb14905308a) * clean cmake option Signed-off-by: alexsehep (cherry picked from commit 993bea68399f2edf5a191c4952143b41e15b4d28) * fix cmake Signed-off-by: alexsehep (cherry picked from commit e607095df4fa4d07db33ceabf903517f2c83ca97) * fix cmake error in #5846 --------- Co-authored-by: alexsehep --- src/common/base/test/CMakeLists.txt | 1 + src/common/datatypes/test/CMakeLists.txt | 3 +++ src/common/expression/test/CMakeLists.txt | 2 ++ src/common/function/FunctionManager.cpp | 23 ++++++++++++++++++- src/common/function/test/CMakeLists.txt | 3 +++ .../function/test/FunctionManagerTest.cpp | 6 +++-- src/common/geo/test/CMakeLists.txt | 1 + src/common/utils/test/CMakeLists.txt | 3 +++ 8 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/common/base/test/CMakeLists.txt b/src/common/base/test/CMakeLists.txt index e644906d920..cf46e0c8763 100644 --- a/src/common/base/test/CMakeLists.txt +++ b/src/common/base/test/CMakeLists.txt @@ -120,6 +120,7 @@ nebula_add_executable( LIBRARIES follybenchmark ${THRIFT_LIBRARIES} + ${PROXYGEN_LIBRARIES} ) nebula_add_test( diff --git a/src/common/datatypes/test/CMakeLists.txt b/src/common/datatypes/test/CMakeLists.txt index f31731cf58b..557f51edf56 100644 --- a/src/common/datatypes/test/CMakeLists.txt +++ b/src/common/datatypes/test/CMakeLists.txt @@ -52,6 +52,7 @@ nebula_add_test( LIBRARIES gtest ${THRIFT_LIBRARIES} + ${PROXYGEN_LIBRARIES} ) @@ -73,6 +74,7 @@ nebula_add_test( LIBRARIES gtest ${THRIFT_LIBRARIES} + ${PROXYGEN_LIBRARIES} ) nebula_add_test( @@ -122,6 +124,7 @@ nebula_add_test( LIBRARIES gtest ${THRIFT_LIBRARIES} + ${PROXYGEN_LIBRARIES} ) nebula_add_executable( diff --git a/src/common/expression/test/CMakeLists.txt b/src/common/expression/test/CMakeLists.txt index d2c8b304859..b40218c53a3 100644 --- a/src/common/expression/test/CMakeLists.txt +++ b/src/common/expression/test/CMakeLists.txt @@ -138,6 +138,7 @@ nebula_add_executable( follybenchmark boost_regex ${THRIFT_LIBRARIES} + ${PROXYGEN_LIBRARIES} ) nebula_add_executable( @@ -163,4 +164,5 @@ nebula_add_executable( follybenchmark boost_regex ${THRIFT_LIBRARIES} + ${PROXYGEN_LIBRARIES} ) diff --git a/src/common/function/FunctionManager.cpp b/src/common/function/FunctionManager.cpp index cc2393a775d..f654ba64dd0 100644 --- a/src/common/function/FunctionManager.cpp +++ b/src/common/function/FunctionManager.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -442,9 +443,9 @@ std::unordered_map> FunctionManager::typ {TypeSignature({Value::Type::STRING}, Value::Type::MAP), TypeSignature({Value::Type::STRING}, Value::Type::NULLVALUE)}}, {"score", {TypeSignature({}, Value::Type::__EMPTY__)}}, + {"md5", {TypeSignature({Value::Type::STRING}, Value::Type::STRING)}}, }; -// static StatusOr FunctionManager::getReturnType(const std::string &funcName, const std::vector &argsType) { auto func = funcName; @@ -3000,6 +3001,26 @@ FunctionManager::FunctionManager() { return Value::kNullValue; }; } + { + auto &attr = functions_["md5"]; + attr.minArity_ = 1; + attr.maxArity_ = 1; + attr.isAlwaysPure_ = true; + attr.body_ = [](const auto &args) -> Value { + switch (args[0].get().type()) { + case Value::Type::NULLVALUE: { + return Value::kNullValue; + } + case Value::Type::STRING: { + std::string value(args[0].get().getStr()); + return proxygen::md5Encode(folly::StringPiece(value)); + } + default: { + return Value::kNullBadType; + } + } + }; + } } // NOLINT // static diff --git a/src/common/function/test/CMakeLists.txt b/src/common/function/test/CMakeLists.txt index ab547cf44a6..c0410a30c22 100644 --- a/src/common/function/test/CMakeLists.txt +++ b/src/common/function/test/CMakeLists.txt @@ -19,6 +19,7 @@ nebula_add_test( LIBRARIES gtest gtest_main + ${PROXYGEN_LIBRARIES} ) nebula_add_test( @@ -37,6 +38,7 @@ nebula_add_test( $ LIBRARIES gtest + ${PROXYGEN_LIBRARIES} ) nebula_add_test( @@ -52,5 +54,6 @@ nebula_add_test( LIBRARIES gtest gtest_main + ${PROXYGEN_LIBRARIES} ) diff --git a/src/common/function/test/FunctionManagerTest.cpp b/src/common/function/test/FunctionManagerTest.cpp index 88ff49888df..babb1ef8b4a 100644 --- a/src/common/function/test/FunctionManagerTest.cpp +++ b/src/common/function/test/FunctionManagerTest.cpp @@ -170,8 +170,8 @@ std::unordered_map> FunctionManagerTest::args_ = {"json_extract1", {"{\"a\": 1, \"b\": 0.2, \"c\": {\"d\": true}}"}}, {"json_extract2", {"_"}}, {"json_extract3", {"{a: 1, \"b\": 0.2}"}}, - {"json_extract4", {"{\"a\": \"foo\", \"b\": 0.2, \"c\": {\"d\": {\"e\": 0.1}}}"}}}; - + {"json_extract4", {"{\"a\": \"foo\", \"b\": 0.2, \"c\": {\"d\": {\"e\": 0.1}}}"}}, + {"md5", {"abcdefghijkl"}}}; #define TEST_FUNCTION(expr, ...) \ do { \ EXPECT_TRUE(testFunction(#expr, __VA_ARGS__)); \ @@ -248,6 +248,7 @@ TEST_F(FunctionManagerTest, testNull) { TEST_FUNCTION(concat, args_["nullvalue"], Value::kNullValue); TEST_FUNCTION(concat_ws, std::vector({Value::kNullValue, 1, 2}), Value::kNullValue); TEST_FUNCTION(concat_ws, std::vector({1, 1, 2}), Value::kNullValue); + TEST_FUNCTION(md5, args_["nullvalue"], Value::kNullValue); } TEST_F(FunctionManagerTest, functionCall) { @@ -474,6 +475,7 @@ TEST_F(FunctionManagerTest, functionCall) { args_["json_extract4"], Value(Map({{"a", Value("foo")}, {"b", Value(0.2)}, {"c", Value(Map())}}))); } + { TEST_FUNCTION(md5, args_["md5"], "9fc9d606912030dca86582ed62595cf7"); } { auto result = FunctionManager::get("hash", 1); ASSERT_TRUE(result.ok()); diff --git a/src/common/geo/test/CMakeLists.txt b/src/common/geo/test/CMakeLists.txt index 5b37c79ffb9..5bd9b5527e4 100644 --- a/src/common/geo/test/CMakeLists.txt +++ b/src/common/geo/test/CMakeLists.txt @@ -18,6 +18,7 @@ nebula_add_test( LIBRARIES gtest gtest_main + ${PROXYGEN_LIBRARIES} ) nebula_add_test( diff --git a/src/common/utils/test/CMakeLists.txt b/src/common/utils/test/CMakeLists.txt index 41729c853d7..4481bec8f13 100644 --- a/src/common/utils/test/CMakeLists.txt +++ b/src/common/utils/test/CMakeLists.txt @@ -40,6 +40,7 @@ nebula_add_test( LIBRARIES gtest ${THRIFT_LIBRARIES} + ${PROXYGEN_LIBRARIES} ) nebula_add_test( @@ -80,6 +81,7 @@ nebula_add_test( LIBRARIES gtest ${THRIFT_LIBRARIES} + ${PROXYGEN_LIBRARIES} ) nebula_add_test( @@ -123,6 +125,7 @@ nebula_add_test( LIBRARIES gtest ${THRIFT_LIBRARIES} + ${PROXYGEN_LIBRARIES} ) nebula_add_test(