Edge construction method and device of graph database

By generating numerical long integer identifiers of edges in the graph database and writing them to the database, the problem of low update and rewrite performance caused by unknown edge identifiers in the graph database is solved, and a more efficient edge update and rewrite process is achieved.

CN119691234AActive Publication Date: 2025-03-25ZHEJIANG DAHUA TECH CO LTD

Patent Information

Application Number
CN202510204576.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-24
Publication Date
2025-03-25
Estimated Expiration
2045-02-24

AI Technical Summary

Technical Problem

In the graph database, when there is a secondary update or rewrite of an edge, since the edge identification is unknown, the edge needs to be queried and updated or rewrite, which greatly affects the performance of update or rewrite.

Method used

By generating a string based on the attribute value of edges in the graph database, converting characters at the preset position in the string into long integers, obtaining the numerical long integer identifier of the edge, and writing it to the graph database, thereby changing the unknown edge identifier into known.

Benefits of technology

Avoid the action of querying edges before updating or rewriting edges, which significantly improves the performance of updating or rewriting edges.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119691234A_ABST
    Figure CN119691234A_ABST
Patent Text Reader

Abstract

The invention discloses an edge construction method and device of a graph database. The edge construction method of the graph database comprises the steps of generating character strings based on attribute values of edges in the graph database; converting a character at a preset position in the character string into a long integer to obtain a numeric long integer identifier of the edge; and writing the numeric long integer identifier into the graph database as an identifier of the edge. According to the method, the unknown edge identifier can be changed into the known edge identifier through the edge construction method, so that the action of querying the edge before the edge is updated or rewritten can be avoided, and the performance of updating or rewriting the edge is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of graph databases, and in particular to a method and device for constructing edges of a graph database. Background Art

[0002] A graph database is a database system used to store and process graph data. It is mainly used to store and query data with relational properties, such as social networks, logistics networks, knowledge graphs, etc. Compared with traditional relational databases, graph databases have better ability to process graph data, so they are widely used in big data analysis, artificial intelligence, machine learning and other fields.

[0003] During the long-term research and development process, the inventors of the present application discovered that when an existing edge in a graph database is updated or rewritten for a second time, since the identifier of the edge is unknown, it is necessary to query the edge before updating or rewriting it, which will greatly affect the performance of the update or rewrite. Summary of the invention

[0004] The present application provides an edge construction method and device for a graph database. The edge construction method of the present application can be used to convert unknown edge identifiers into known ones, thereby avoiding the action of querying edges before updating or rewriting edges, thereby improving the performance of updating or rewriting edges.

[0005] To achieve the above object, the present application provides a method for constructing edges in a graph database, the method comprising: Generate a string based on the attribute value of the edge in the graph database; Convert the characters at the preset positions in the string into long integers to obtain the numerical long integer identifier of the edge; The numerical long integer identifier is written into the graph database as the identifier of the edge.

[0006] To achieve the above objectives, the present application also provides an electronic device, which includes a processor; the processor is used to execute instructions to implement the steps of the above method.

[0007] To achieve the above objectives, the present application also provides a computer-readable storage medium, which is used to store instructions / program data, and the instructions / program data can be executed to implement the above method.

[0008] The edge construction method of the graph database of the present application generates a character string from the attribute value of the edge in the graph database; converts the characters at a preset position in the character string into a long integer to obtain a numerical long integer identifier of the edge; and writes the numerical long integer identifier into the graph database as the identifier of the edge. In this way, the edge construction method of the present application can be used to convert unknown edge identifiers into known ones, and the action of querying the edge before updating or rewriting the edge can be avoided, thereby improving the performance of updating or rewriting the edge. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings: Figure 1 It is a flowchart of an implementation method of an edge construction method of a graph database of the present application; Figure 2 It is a flowchart of an embodiment of an edge construction method of a graph database of the present application; Figure 3 It is a structural schematic diagram of an embodiment of the electronic device of the present application; Figure 4 It is a structural schematic diagram of an implementation method of a computer-readable storage medium of the present application. DETAILED DESCRIPTION

[0010] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without making creative work are within the scope of protection of the present application. In addition, unless otherwise specified (for example, "or in addition" or "or in an alternative"), the term "or" as used herein refers to a non-exclusive "or" (that is, "and / or"). Moreover, the various embodiments described herein are not necessarily mutually exclusive, because some embodiments can be combined with one or more other embodiments to form new embodiments.

[0011] As one of the representatives of open source graph databases, Janusgraph uses a technology called point partitioning to implement graph data storage and query. Point partitioning is a commonly used graph database partitioning method. In short, it is to store the relationship data at the two ends of the points. For example, when hbase is used as the storage engine of janusgraph, the "communication connection relationship between device A and device B" will generate a "device A" point and a "device B" point when storing, and the "communication connection" relationship edge will be stored in the cells of the "device A" and "device B" points respectively. Point partitioning can greatly improve the concurrent read and write performance and query efficiency of JanusGraph, because it distributes data on multiple nodes, and only needs to query or modify operations on the target node, without operating on the entire graph data.

[0012] For the edge data of the graph database, a common edge is uniquely identified by four elements: left point identifier (ID), right point ID, edge label name, and edge ID. When updating or rewriting an edge, these four elements need to be known in order to update or rewrite the edge. In actual usage scenarios, the edge ID of the open source janusgraph is automatically generated as a long type when writing the edge. When the existing edge in the graph database is updated or rewritten for the second time, since the edge ID is unknown, the edge needs to be queried before updating or rewriting, which will greatly affect the performance of the update or rewrite.

[0013] Based on this, the present application proposes a graph database edge construction method, which generates a string based on the attribute value of the edge in the graph database; converts the characters at a preset position in the string into a long integer to obtain a numerical long integer identifier of the edge; and writes the numerical long integer identifier into the graph database as the identifier of the edge. In this way, the edge construction method of the present application can be used to make unknown edge identifiers known, which can avoid the action of querying the edge before updating or rewriting the edge, thereby improving the performance of updating or rewriting the edge.

[0014] Specifically, Figure 1 As shown, the edge construction method of a graph database proposed in this application specifically includes the following steps. It should be noted that the following step numbers are only used to simplify the description and are not intended to limit the execution order of the steps. The steps of this implementation can be changed in any order without violating the technical idea of ​​this application.

[0015] S101: Generate a character string based on the attribute value of the edge in the graph database.

[0016] Optionally, a string may be first generated based on the attribute value of the edge in the graph database, so that an edge identifier may be subsequently generated based on the string and written into the graph database.

[0017] Optionally, the string calculation may be performed based on at least one attribute value that can uniquely determine the relationship between two nodes connected by the edge, that is, at least one attribute value (which can be one or more feature combinations) that can uniquely determine the relationship between two nodes connected by the edge may be used as an input parameter for the string calculation. For example, for the identification of the edge between the object node and the location node to be confirmed in the object left behind event, the attribute values ​​of the time when the object was left behind and the location where it was left behind may be used as input parameters for the string calculation.

[0018] Of course, in other embodiments, the string calculation may also be performed based on the common attribute value of the edge, for example, the string calculation may be performed according to the type of the edge, that is, the common attribute value of the edge may be used as an input parameter for the string calculation.

[0019] In other implementations, a string may be generated based on the attribute value of the edge and the attribute values ​​of the two nodes connected by the edge, that is, the attribute value of the edge and the attribute values ​​of the two nodes connected by the edge may be used as input parameters for string calculation. For example, a string may be calculated based on the identifiers of the two nodes connected by the edge and the general attribute value of the edge. Alternatively, a string may be calculated based on the identifiers of the two nodes connected by the edge and the characteristic attribute value of the edge.

[0020] The generated string can be considered as stringEdgeId of string type. The calculation method of the string is not restricted.

[0021] For example, the input parameter of the string calculation can be subjected to md5 calculation to obtain the string. For example, for the communication relationship between device nodes, the attribute values ​​of the communication mode and the communication time can be used as the input parameters of the md5 calculation to obtain a randomly hashed 32-character string.

[0022] For another example, a hash calculation may be performed on an input parameter of a string calculation to obtain a string. For example, the identifiers of two nodes connected by an edge and the attribute value of the edge may be used as input parameters of the hash calculation to obtain a string.

[0023] Optionally, step S101 may be generated by an upper service layer.

[0024] S102: Convert the characters at the preset positions in the character string into long integers to obtain the numerical long integer identifier of the edge.

[0025] After the character string is calculated based on step S101, the characters at the preset positions in the character string may be converted into long integers to obtain the numerical long integer identifier of the edge.

[0026] The preset position may refer to all positions in the string, that is, the entire string may be converted into a long integer to obtain a numerical long integer identifier of the edge.

[0027] A preset position can also refer to a partial position in a string.

[0028] For example, the preset position may refer to the first number of characters in the string, so the first number of characters in the string may be converted into long integers to obtain the numerical long integer identifier of the edge.

[0029] Among them, the first number is set according to the actual situation, and there is no restriction here, for example, it can be 12 or 24. In a specific example, the first 12 characters in the string can be converted into a long integer to obtain the numerical long integer identifier of the edge. Preferably, the first number is less than or equal to 12, because 36^13>2^63+1, that is, when it is 12 characters, it is less than the maximum value of the long type, and when it is 13 characters, it will exceed the long type storage and overflow. More preferably, the first number is equal to 12, because the custom identifier of the edge is calculated by the business layer according to the attribute value on the edge, and the result is a randomly hashed string. Only the first 12 bits are taken. In terms of probability statistics, the possibility of conflict is not great; on the other hand, even if the stringId of two different types of edges conflict, it does not matter, because the ordinary edge is uniquely determined by the left point id + right point id + edge label + edge id, so there will be no duplication for the edge.

[0030] In this step, if Figure 2 As shown, you can first determine whether the length of the string is greater than the first number. If the length is greater than the first number, you can directly truncate the string to truncate the excess character part and obtain the first first number of characters in the string, and then convert the first first number of characters in the string into long integers; if the length is less than or equal to 12, the string can be directly converted into a long integer.

[0031] For another example, the preset position may refer to the second number of characters in the middle of the string, so the second number of characters in the middle of the string may be converted into a long integer to obtain a numerical long integer identifier of the edge.

[0032] For another example, the preset position may refer to the third number of characters in the string, so the third number of characters in the string may be converted into a long integer to obtain a numerical long integer identifier of the edge.

[0033] For another example, the preset number may refer to all even-numbered characters in the string, so all even-numbered characters in the string may be converted into long integers to obtain the numerical long integer identifier of the edge.

[0034] Before step S102, it can be determined whether the string meets the specification; if it meets the specification, step S102 is executed; if it does not meet the specification, step S102 may not be executed, that is, the edge identifier update fails. Exemplarily, it can be determined whether the string is a character in the basic string. The basic string can be set according to actual conditions and is not limited here. For example, it can be "0123456789abcdefghijklmnopqrstuvwxyz".

[0035] Optionally, the edge online access interface of the graph database may be called to concurrently write or update edge data, wherein the edge data may include the above-mentioned string; then the graph database edge online access interface receives the data and starts processing the data, and then executes step S102 for each edge data. Figure 2 As shown, the rule engine calls the edge online access interface of the graph database to concurrently write edge data to improve the processing efficiency of edge data.

[0036] There are many methods for converting characters at preset positions in a character string into long integers, which are not limited here.

[0037] For example, a character-to-long integer (long) codec may be used to decode a character at a preset position.

[0038] Among them, each character at the preset position can be traversed to find out the position order of the currently traversed character in the basic string, wherein the characters at different positions in the basic string are different; a first value is calculated based on the position order, the total number of characters in the basic string, and the order of the currently traversed character in all the characters at the preset position; the first value and the current numerical long integer identifier are added to obtain an updated current numerical long integer identifier, wherein the current numerical long integer identifier starts with a preset value; if the currently traversed character is not the last one of the characters at the preset position, continue to use the next character as the currently traversed character, and return to execute the step of finding out the position order of the currently traversed character in the basic string and subsequent steps; if the currently traversed character is the last one of the characters at the preset position, use the current numerical long integer identifier as the final numerical long integer identifier.

[0039] The calculation formula of the first value is: ; Wherein, s is the first value, m is determined based on the total number of characters, for example, m can be equal to the total number of characters, or m can be equal to the sum of the total number of characters and the specified value, n is the order of the currently traversed character from right to left among all the characters at the preset position, and k is the position order. The above-mentioned specified value and preset value can also be set according to actual conditions, and are not limited here, for example, they can be 0 or 1.

[0040] In an example, the total number of characters in the above basic string is 36, so the string is regarded as a hexadecimal number (BASE_SYMBOLS length), and then converted to decimal to obtain the decimal value, thereby obtaining a numeric long integer identifier. Figure 2As shown, each character at the preset position can be traversed from left to right, regarded as high to low in hexadecimal; the position of the character is found in the basic string BASE_SYMBOLS, recorded as pos; the decoded edge value id num=num*36+pos; if the currently traversed character is not the last one at the preset position, continue to traverse the next character; if the currently traversed character is the last one at the preset position, use id num as a numerical long integer identifier.

[0041] In a specific example, the basic string BASE_SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyz" is 36 characters. The input string is regarded as a high-order hexadecimal number from left to right to complete the conversion between the string and the long type. The calculation method is as follows: if the input string is abc, the numeric long integer identifier is 10*36^2+11*36^1+12*36^0= 13368.

[0042] For another example, the characters at the preset positions can be weighted based on their positions. For example, the characters are weighted according to their positions in the character string, and then they are combined into a long integer to obtain a numerical long integer identifier.

[0043] For another example, the character at the preset position may be converted according to certain attributes of the character (such as position in the alphabet, uppercase and lowercase letters, etc.) to obtain a numerical long integer identifier.

[0044] S103: Write the numerical long integer identifier as the edge identifier into the graph database.

[0045] After the numerical long integer identifier is calculated based on step S101, the numerical long integer identifier can be written into the graph database as an edge identifier.

[0046] Optionally, a write request can be constructed based on the edge identifier, edge label name, and identifiers of the two nodes connected by the edge to write the edge data to the graph database, so as to load the edge identifier onto the edge and make the constructed edge an edge with a custom representation, thereby realizing the update or rewriting of the edge data.

[0047] In this implementation, a character string is generated based on the attribute value of the edge in the graph database; the characters at a preset position in the character string are converted into long integers to obtain a numerical long integer identifier of the edge; and the numerical long integer identifier is written into the graph database as the identifier of the edge. In this way, the unknown edge identifier can be made known through the edge construction method of the present application, and the action of querying the edge before updating or rewriting the edge can be avoided, thereby improving the performance of updating or rewriting the edge.

[0048] See also Figure 3 , Figure 3 2 is a schematic diagram of the structure of an embodiment of an electronic device of the present application. The electronic device 20 includes a processor 22, and the processor 22 is used to execute instructions to implement the above method. The specific implementation process can be found in the description of the above embodiment, which will not be repeated here.

[0049] The processor 22 may also be referred to as a CPU (Central Processing Unit). The processor 22 may be an integrated circuit chip having signal processing capabilities. The processor 22 may also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. A general-purpose processor may be a microprocessor or the processor 22 may also be any conventional processor, etc.

[0050] The electronic device 20 may further include a memory 21 for storing instructions and data required for the processor 22 to run.

[0051] The processor 22 is used to execute instructions to implement the method provided by any embodiment of the method of the present application and any non-conflicting combination.

[0052] Among them, the electronic device of the present application can be a confusion control system.

[0053] See also Figure 4 , Figure 4 It is a schematic diagram of the structure of the computer-readable storage medium in the implementation mode of the present application. The computer-readable storage medium 30 of the embodiment of the present application stores instructions / program data 31, and when the instructions / program data 31 are executed, the method provided by any embodiment of the edge construction method of the graph database of the present application and any non-conflicting combination is implemented. In one embodiment, the instructions / program data 31 can form a program file and be stored in the above-mentioned storage medium 30 in the form of a software product, so that a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) executes all or part of the steps of the various implementation methods of the present application. The aforementioned storage medium 30 includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, RandomAccess Memory), a disk or an optical disk, or a terminal device such as a computer, a server, a mobile phone, and a tablet.

[0054] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0055] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0056] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0057] The above are only implementation methods of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A method for constructing edges in a graph database, characterized in that: The method comprises: Generate a string based on the attribute value of the edge in the graph database; Convert the characters at the preset positions in the string into long integers to obtain the numerical long integer identifier of the edge; The numerical long integer identifier is written into the graph database as the identifier of the edge.

2. The method according to claim 1, characterized in that The generating a string based on the attribute value of the edge in the graph database includes: The string calculation is performed based on at least one attribute value that can uniquely determine the relationship between two nodes connected by the edge.

3. The method according to claim 2, characterized in that The performing string calculation based on at least one attribute value that can uniquely determine the relationship between two nodes connected by an edge includes: performing md5 calculation on the at least one attribute value that can uniquely determine the relationship between two nodes connected by an edge to obtain the string.

4. The method according to claim 1, characterized in that: The characters at the preset positions are the first first number of characters in the character string.

5. The method according to claim 4, characterized in that The converting the characters at the preset positions in the character string into long integers to obtain the numerical long integer identifier of the edge includes: If the length of the string exceeds the first number, truncating the first number of characters in the string to obtain the character at the preset position; If the length of the character string is less than or equal to the first number, the character string is used as the character at the preset position.

6. The method according to claim 1, characterized in that The converting the characters at the preset positions in the character string into long integers to obtain the numerical long integer identifier of the edge includes: The character at the preset position is decoded using a character-to-long integer codec to obtain the numerical long integer identifier.

7. The method according to claim 6, characterized in that The character-to-long integer codec is used to decode the character at the preset position to obtain the numerical long integer identifier, including: Traversing each character at the preset position to find out the position sequence of the currently traversed character in the basic string, wherein the characters at different positions in the basic string are different; Calculate based on the position sequence, the total number of characters in the basic character string, and the order of the currently traversed character among all characters at the preset position to obtain a first value; Adding the first value and the current numeric long integer identifier to obtain an updated current numeric long integer identifier, wherein the current numeric long integer identifier starts with a preset value; If the currently traversed character is not the last one of the characters at the preset position, continue to use the next character as the currently traversed character, and return to the step of finding the position sequence of the currently traversed character in the basic string; If the currently traversed character is the last one of the characters at the preset position, the current numeric long integer identifier is used as the final numeric long integer identifier.

8. The method according to claim 7, characterized in that The calculation formula of the first value is: ; Among them, s is the first value, m is determined based on the total number of characters, n is the order of the currently traversed character from right to left among all the characters at the preset position, and k is the position order.

9. An electronic device, characterized in that: The electronic device comprises a processor; the processor is configured to execute instructions to implement the steps of the method according to any one of claims 1-8.

10. A computer-readable storage medium having a program and / or an instruction stored thereon, characterized in that: When the program and / or instruction is executed, the steps of the method according to any one of claims 1 to 8 are implemented.

Citation Information

Patent Citations

  • Character string value domain segmenting method and device

    CN106294371A

  • Data processing method and device for distributed graph database and electronic equipment

    CN112559631A

  • Method and a device for storing graph data

    CN113656411A

  • Graph database query method, index creation method and related equipment

    CN114741570A

  • Data duplicate checking method and device, equipment and storage medium

    CN117076509A

Cited By

  • Methods for cross-partition edge consistency verification in distributed graph databases

    CN122570608A

  • Consistency checking method for cross-partition edges in distributed graph database

    CN122570608B