Skip to content

Commit

Permalink
fix cmake error in pr #5846 (#5955)
Browse files Browse the repository at this point in the history
* feat(function): support md5

(cherry picked from commit 84bb690)

* format code

Signed-off-by: alexsehep <[email protected]>
(cherry picked from commit d2b17d4)

* clean cmake option

Signed-off-by: alexsehep <[email protected]>
(cherry picked from commit 993bea6)

* fix cmake

Signed-off-by: alexsehep <[email protected]>
(cherry picked from commit e607095)

* fix cmake error in #5846

---------

Co-authored-by: alexsehep <[email protected]>
  • Loading branch information
E2ern1ty and fansehep authored Oct 9, 2024
1 parent 41b095e commit 831c174
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/common/base/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ nebula_add_executable(
LIBRARIES
follybenchmark
${THRIFT_LIBRARIES}
${PROXYGEN_LIBRARIES}
)

nebula_add_test(
Expand Down
3 changes: 3 additions & 0 deletions src/common/datatypes/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ nebula_add_test(
LIBRARIES
gtest
${THRIFT_LIBRARIES}
${PROXYGEN_LIBRARIES}
)


Expand All @@ -73,6 +74,7 @@ nebula_add_test(
LIBRARIES
gtest
${THRIFT_LIBRARIES}
${PROXYGEN_LIBRARIES}
)

nebula_add_test(
Expand Down Expand Up @@ -122,6 +124,7 @@ nebula_add_test(
LIBRARIES
gtest
${THRIFT_LIBRARIES}
${PROXYGEN_LIBRARIES}
)

nebula_add_executable(
Expand Down
2 changes: 2 additions & 0 deletions src/common/expression/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ nebula_add_executable(
follybenchmark
boost_regex
${THRIFT_LIBRARIES}
${PROXYGEN_LIBRARIES}
)

nebula_add_executable(
Expand All @@ -163,4 +164,5 @@ nebula_add_executable(
follybenchmark
boost_regex
${THRIFT_LIBRARIES}
${PROXYGEN_LIBRARIES}
)
23 changes: 22 additions & 1 deletion src/common/function/FunctionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <float.h>
#include <folly/json.h>
#include <proxygen/lib/utils/CryptUtil.h>

#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/replace.hpp>
Expand Down Expand Up @@ -442,9 +443,9 @@ std::unordered_map<std::string, std::vector<TypeSignature>> 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<Value::Type> FunctionManager::getReturnType(const std::string &funcName,
const std::vector<Value::Type> &argsType) {
auto func = funcName;
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/common/function/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ nebula_add_test(
LIBRARIES
gtest
gtest_main
${PROXYGEN_LIBRARIES}
)

nebula_add_test(
Expand All @@ -37,6 +38,7 @@ nebula_add_test(
$<TARGET_OBJECTS:fs_obj>
LIBRARIES
gtest
${PROXYGEN_LIBRARIES}
)

nebula_add_test(
Expand All @@ -52,5 +54,6 @@ nebula_add_test(
LIBRARIES
gtest
gtest_main
${PROXYGEN_LIBRARIES}
)

6 changes: 4 additions & 2 deletions src/common/function/test/FunctionManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ std::unordered_map<std::string, std::vector<Value>> 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__)); \
Expand Down Expand Up @@ -248,6 +248,7 @@ TEST_F(FunctionManagerTest, testNull) {
TEST_FUNCTION(concat, args_["nullvalue"], Value::kNullValue);
TEST_FUNCTION(concat_ws, std::vector<Value>({Value::kNullValue, 1, 2}), Value::kNullValue);
TEST_FUNCTION(concat_ws, std::vector<Value>({1, 1, 2}), Value::kNullValue);
TEST_FUNCTION(md5, args_["nullvalue"], Value::kNullValue);
}

TEST_F(FunctionManagerTest, functionCall) {
Expand Down Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions src/common/geo/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ nebula_add_test(
LIBRARIES
gtest
gtest_main
${PROXYGEN_LIBRARIES}
)

nebula_add_test(
Expand Down
3 changes: 3 additions & 0 deletions src/common/utils/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ nebula_add_test(
LIBRARIES
gtest
${THRIFT_LIBRARIES}
${PROXYGEN_LIBRARIES}
)

nebula_add_test(
Expand Down Expand Up @@ -80,6 +81,7 @@ nebula_add_test(
LIBRARIES
gtest
${THRIFT_LIBRARIES}
${PROXYGEN_LIBRARIES}
)

nebula_add_test(
Expand Down Expand Up @@ -123,6 +125,7 @@ nebula_add_test(
LIBRARIES
gtest
${THRIFT_LIBRARIES}
${PROXYGEN_LIBRARIES}
)

nebula_add_test(
Expand Down

0 comments on commit 831c174

Please sign in to comment.