-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an MD5() function to NebulaGraph #5840
Comments
hi, @QingZ11 ,thinks for your good guide. I try to follow your guide. when i finish it, get compiler linking error.
|
Hi, @fansehep thank you for your practical contribution. I am pleasure to assist you. @Salieri-004 is nebula bravo core developer, and he will help you with this issue. |
@fansehep Hello, have you ever tried modifying cmake as described in the Implementation Approach? |
yep, i had modify it. but this change just about test binary. I think the error is due to a problem with the library not linking correctly to wangle. nebula/src/common/function/CMakeLists.txt Lines 5 to 18 in 594ed69
I think the error is about this? |
From the error messages in your image, we can see that some test compilations are failing because they can't find the implementation of
|
The idea was provided by @AntiTopQuark , thank you.
Requirement Description
MD5 (Message Digest Algorithm 5) is a widely used cryptographic hash function that produces a 128-bit hash value, commonly used to ensure the integrity and consistency of information transmission. In graph databases, MD5 can be used for rapidly comparing node or edge attribute values, generating unique identifiers, etc. Therefore, implementing the MD5 function will enhance NebulaGraph's data processing capabilities and provide more flexibility in data operations.
NebulaGraph already supports a variety of functions and expressions, such as
split
andconcat
. The implementations of these functions provide us with a reference framework for writing custom functions, which includes but is not limited to:Function registration: Understanding how to register new functions into NebulaGraph's function library.
Argument handling: Becoming familiar with how to process input arguments, including type checking and conversion.
Result returning: Mastering how to compute results and return them to the caller in the appropriate data type.
Implementation Approach
By consulting the official documentation, we can find that NebulaGraph has implemented a variety of functions and expressions, such as string functions. These existing implementations provide us with valuable references, allowing us to quickly locate the corresponding implementations and commit records in the codebase by searching for specific function names, like
json_extract
. For example, we can find commit records and merge request information related tojson_extract
.By analyzing these historical commits, we learn that implementing a new function involves the following steps:
Add the registration and computational logic of the function in the
src/common/function/FunctionManager.cpp
file.Add corresponding unit tests in the
src/common/function/test/FunctionManagerTest.cpp
file.For new features, add TCK integration tests.
(Optional) Update the documentation in the nebula-docs repository, providing explanations and examples for the new feature to help users better understand and use the new functionality.
Implementing the MD5 function may not require us to handle the details of the function from scratch; we can start by conducting a global search in the codebase to see if there are any existing implementations for reference. A simple search can easily locate some available function instances.
Drawing from the implementation of the
json_extract
function, we can write the relevant code for computing MD5 and compile and test it to verify its correctness.After starting the server, we need to verify that the implemented feature meets the expectations.
Referring to the test cases of the
json_extract
function, we added some unit tests for the MD5 function to ensure that it can correctly handle NULL values and regular values.In implementing the MD5 feature, we used the third-party
proxygen::md5Encode
function. Directly compiling the unit tests might encounter some linkage errors, such as undefined references. Therefore, we need to add some dependencies to the Makefile of the unit tests.Execute the unit tests to see if the results meet the expectations:
Great, the results are as expected.
Referring to the article on how to add a test case to NebulaGraph, we added TCK integration tests for the MD5 function and verified its correctness.
Execute the integration tests and verify the results to ensure everything works as expected.
Writing clear documentation is very valuable to help users better understand and use the newly added MD5 function. We encourage each contributor to write related documentation when implementing new features, which is beneficial not only to users but also enhances the contributor's sense of achievement.
中文版描述
为 Nebula Graph 新增一个 MD5() 函数
需求描述
MD5(Message Digest Algorithm 5)是一种广泛使用的哈希算法,生成 128 位的哈希值,通常用于确保信息传输的完整性和一致性。在图数据库中,MD5 可以用于快速比较节点或边的属性值、生成唯一标识符等。因此,实现 MD5 函数将增强 NebulaGraph 处理数据的能力,提供更多的数据操作灵活性。
NebulaGraph 现已支持多种函数和表达式,如
split
、concat
等。这些函数的实现为我们提供了编写自定义函数的参考框架,包括但不限于:函数注册:了解如何将新函数注册到 NebulaGraph 的函数库中。
参数处理:熟悉如何处理输入参数,包括参数类型检查和转换。
结果返回:掌握如何计算结果并以适当的数据类型返回给调用者。
实现思路
通过查阅官方文档,我们可以发现 NebulaGraph 已经实现了多种函数和表达式,例如:字符串函数。这些现有的实现为我们提供了宝贵的参考,使我们能够在代码库中通过搜索特定的函数名称,如
json_extract
,快速定位到相应的实现和提交记录。例如,我们可以查找到json_extract
相关的提交记录和合并请求信息。通过分析这些历史提交,我们得知实现一个新函数需要执行以下步骤:
在
src/common/function/FunctionManager.cpp
文件中添加函数的注册和计算逻辑。在
src/common/function/test/FunctionManagerTest.cpp
文件中添加相应的单元测试。对于新增加的功能,还需要添加TCK集成测试。
(可选)更新 nebula-docs 仓库中的文档,为新增功能提供说明和示例,以帮助用户更好地理解和使用新功能。
实现 MD5 函数可能不需要我们从头开始处理函数的细节,可以先在代码库中全局搜索看看是否有现成的实现可供参考。通过简单的搜索,我们可以轻松地找到一些可用的函数实例。
借鉴
json_extract
函数的实现,我们可以编写计算 MD5 的相关代码,并进行编译和测试以验证其正确性。启动服务器后,我们需要验证实现的功能是否符合预期。
参考
json_extract
函数的测试用例,我们为 MD5 函数添加了一些单元测试,确保它能够正确处理 NULL 值和正常值。在实现 MD5 功能时,我们采用了第三方的
proxygen::md5Encode
函数。直接编译单元测试可能会遇到一些链接错误,如undefined references
。因此,我们需要在单元测试的 Makefile 中添加一些依赖。执行单元测试,看看结果是否符合预期:
很棒,结果是符合我们预期的。
参考 如何向NebulaGraph添加一个测试用例的文章,我们为 MD5 函数添加了 TCK 集成测试,并验证了其正确性。
执行集成测试并验证结果,确保一切按预期工作。
为了帮助用户更好地理解和使用新增的 MD5 函数,编写清晰的文档是非常有价值的。我们鼓励每位贡献者在实现新功能时,能够撰写相关文档,这不仅有助于用户,也能提升自己的成就感。
The text was updated successfully, but these errors were encountered: