Method and apparatus for inserting data into a graph database
By receiving the insertion statement to define the element identifier and object category of the graphical element, forming data rows and determining the primary key value, the problem of not being able to insert different types of elements and primary key conflicts in graph databases is solved, and efficient and reliable data insertion is achieved.
Patent Information
- Application Number
- CN202211355677.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-01
- Publication Date
- 2025-11-07
- Estimated Expiration
- 2042-11-01
AI Technical Summary
Existing methods for inserting data into graph databases cannot support the insertion of different types of graph elements, nor do they support the creation of primary key values or data updates when primary key conflicts occur.
A method and apparatus are provided that, by receiving an insert statement, define the element identifier and object category of a graphical element, form a data row, and determine the primary key value based on the element identifier and category, supports the insertion of nodes, edges, and paths, and has conflict detection and update functions.
It enables the simultaneous insertion of different types of graphical elements into a graph database, ensuring the correctness and efficiency of data insertion. It supports the creation of primary key values and conflict detection, thereby improving the reliability and efficiency of data insertion.
Smart Images

Figure CN115658711B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] One or more embodiments of the present specification relate to the field of databases, and in particular to a method and apparatus for inserting data into a graph database. BACKGROUND
[0002] Existing methods for inserting data into a graph database either do not support inserting nodes or edges, or can support inserting nodes or edges, but do not support creating primary keys for inserted data and data updates in the case of primary key conflicts. Therefore, it is necessary to provide a more reliable method for inserting data into a graph database. The data here can include private data. SUMMARY
[0003] One or more embodiments of the present specification describe a method for inserting data into a graph database, which can support inserting different types of graph elements into a graph database, and can support creating primary key values for inserted data.
[0004] In a first aspect, a method for inserting data into a graph database is provided, comprising:
[0005] receiving an insert statement for a target graph database; the insert statement at least including an insert keyword and a plurality of element definition lists corresponding to a plurality of graph elements; the graph elements including nodes and / or edges; the plurality of element definition lists being used to define element identifiers of the plurality of graph elements and object categories of objects represented by the graph elements, wherein each element definition list contains attribute values of a plurality of predefined attributes of a corresponding graph element;
[0006] executing the insert statement, wherein forming a plurality of data rows corresponding to the plurality of graph elements according to the attribute values in the element definition lists, and determining primary key values of the data rows according to the element identifiers of the graph elements and the object categories; and inserting the data rows into the target graph database according to the primary key values.
[0007] In a second aspect, an apparatus for inserting data into a graph database is provided, comprising:
[0008] a receiving unit configured to receive an insert statement for a target graph database; the insert statement at least including an insert keyword and a plurality of element definition lists corresponding to a plurality of graph elements; the graph elements including nodes and / or edges; the plurality of element definition lists being used to define element identifiers of the plurality of graph elements and object categories of objects represented by the graph elements, wherein each element definition list contains attribute values of a plurality of predefined attributes of a corresponding graph element;
[0009] The execution unit is configured to execute the insertion statement, including forming a data row corresponding to each graph element according to each attribute value in each element definition list, and determining a primary key value of the corresponding data row according to the element identifier and the object category of each graph element; and inserting each data row into the target graph database according to the primary key value.
[0010] In a third aspect, a computer storage medium is provided, which stores a computer program. When the computer program is executed in a computer, the computer program causes the computer to execute the method of the first aspect.
[0011] In a fourth aspect, a computing device is provided, which includes a memory and a processor. The memory stores executable code, and the processor executes the executable code to implement the method of the first aspect.
[0012] The method and device for inserting data into a graph database provided by one or more embodiments of the present specification can include a plurality of element definition lists corresponding to a plurality of graph elements, each of which is used to define the element identifier of the corresponding graph element and the object category of the object represented thereby. Then, the primary key value of the data row corresponding to the graph element can be determined according to the element identifier and the object category of the graph element, and the data row corresponding to the graph element can be inserted into the graph database according to the primary key value. That is, the present solution supports creating a primary key value for the inserted data row, so that conflict detection of the data row can be performed based on the primary key value, thereby ensuring the correctness of data insertion. In addition, the present solution supports simultaneous insertion of different types of graph elements. BRIEF DESCRIPTION OF DRAWINGS
[0013] In order to more clearly illustrate the technical solutions of the embodiments of the present specification, the drawings needed in the embodiment description will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present specification, and other drawings can be obtained by those skilled in the art without creative labor.
[0014] Figure 1 The schematic diagram of the implementation scenario of one embodiment disclosed in the present specification is shown.
[0015] Figure 2 The flowchart of the method for inserting data into a graph database according to one embodiment is shown.
[0016] Figure 3 The schematic diagram of the device for inserting data into a graph database according to one embodiment is shown. DETAILED DESCRIPTION
[0017] The solutions provided by the present specification will be described below with reference to the drawings.
[0018] As mentioned above, the existing method for inserting data into a graph database either does not support inserting nodes or edges, or can support inserting nodes or edges, but does not support creating primary keys for inserted data and updating data in case of primary key conflicts. The present solution optimizes the syntax of a graph query language, so that different types of graph elements can be inserted into a graph database, and primary key values can be created for inserted data.
[0019] Figure 1 An implementation scenario of an embodiment disclosed in the present specification is shown in the following figure. Figure 1 In the present solution, a data insertion device can receive an insertion statement sent by a client. The insertion statement at least includes an insertion keyword and a plurality of element definition lists corresponding to a plurality of graph elements. The plurality of element definition lists are used to define the element identifiers of the plurality of graph elements and the object categories of the objects represented by the graph elements, and each element definition list contains attribute values of each predefined attribute of the corresponding graph element. It should be understood that based on the attribute values of each predefined attribute of the graph element, the data row corresponding to the graph element can be obtained.
[0020] It should be noted that the plurality of graph elements can include nodes and / or edges, that is, the data insertion device can insert data rows corresponding to nodes (node category (node_type), node identifier (id), and other attribute values) and data rows corresponding to edges (edge category (edge_type), start identifier (src_id), end identifier (dst_id), timestamp, and other attribute values) into the graph database, and the data rows corresponding to the nodes and edges can be inserted at the same time.
[0021] Specifically, for the data row corresponding to a node or an edge, the primary key value of the corresponding data row can be determined according to the element identifier and the object category defined in the element definition list of the node or the edge. Then, the data row corresponding to the node or the edge is inserted into the graph database according to the primary key value.
[0022] It should be noted that since a path is composed of nodes and edges, the present solution can support the insertion of a path when nodes and edges are inserted at the same time.
[0023] In addition, in one example, the data row corresponding to a node or an edge can be stored in the form of a Key_Value pair in the graph database. The Key value can be the primary key value, and the Value value can be other attribute values other than the primary key value.
[0024] The syntax format of the insertion statement mentioned above is described as follows.
[0025] The insertion statement can be specifically represented as:
[0026] <insert statement> ::= INSERT <simple graph pattern> [ON DUPLICATE KEY UPDATE <update item list>]
[0027] INSERT <simple graph pattern> [ON DUPLICATE KEY UPDATE <update item list>]
[0028] Wherein, INSERT is an insert keyword, and <simple graph pattern> is a graph pattern list, which can include a list of several element definitions, and the graph pattern list is used to define nodes, edges or paths. The insert statement can include multiple graph pattern lists, which are separated by commas.
[0029] In addition, the ON DUPLICATE KEY UPDATE in the above syntax is a conflict detection clause, which is used to determine whether there is a target data row that conflicts with the primary key value of the already inserted data row in each data row to be inserted, and modify the target data row in the case where there is a target data row. The conflict detection clause can include the target attribute to be modified and the modified target attribute value or modification expression. Here, the target attribute to be modified and the modified target attribute value or modification expression can be defined by <update item list>.
[0030] Figure 2 A flowchart of a method for inserting data into a graph database according to an embodiment is shown. The method can be executed by any system, device, platform, apparatus, device cluster with computing and processing capabilities. As shown in Figure 2 The method can include the following steps.
[0031] Step 202, receiving an insert statement for a target graph database, the insert statement including at least an insert keyword and a list of several element definitions corresponding to several graph elements.
[0032] Any of the above several graph elements is a node or an edge, and the list of several element definitions is used to define the element identifier of each of the several graph elements and the object category of the object represented by the graph element. Each element definition list contains the attribute value of each predefined attribute of the corresponding graph element.
[0033] In one example, the list of several element definitions corresponding to the several graph elements includes a first node definition list corresponding to a first node, and the first node definition list contains a first node identifier of the first node and a first entity category of an entity represented by the first node.
[0034] For example, the insert statement can be as follows:
[0035] INSERT(:person{id:10,name:"shensi",age:27,company:"ant"});
[0036] In this example, the insert statement includes a first node definition list, and the first node definition list is represented by a preset pair of symbols "()", in which "person" is an entity category of an entity represented by a first node, and "id" is a node identifier of the first node. It should be noted that the "id", "name", "age", and "company" in the above-mentioned "{}" are collectively referred to as attributes, and the "10", "'shensi' ", "27", and " 'ant' " corresponding to the above-mentioned attributes are collectively referred to as attribute values. Of course, in actual applications, the above-mentioned entity category can also be referred to as an attribute of a graph element, and the present specification does not limit this.
[0037] It should be noted that for different entity categories, each attribute can be defined in advance, and for at least part of the attributes, a corresponding default attribute value can be set, so that when the corresponding attribute value is not included in the first node definition list, the default attribute value is directly used.
[0038] In actual applications, in addition to the above-mentioned first node definition list, the above-mentioned element definition list can also include a second node definition list corresponding to a second node, and the second node definition list includes a second node identifier of the second node and a second entity category of an entity represented by the second node.
[0039] In the first node definition list, the first node identifier and the second node identifier in the second node definition list are different; and / or, the first entity category in the first node definition list and the second entity category in the second node definition list are different.
[0040] In other words, at least one of the node identifiers and the entity categories included in the two node definition lists is different. The following examples are described in combination with examples:
[0041] Example 1:
[0042] INSERT(:student{id:10,name:"jason",age:30,class:"3-2"}),(:student{id:20,name:"joy",age:28,class:"6-1"});
[0043] In this example, the entity category included in each of the two node definition lists is "student", and the node identifier included in the former node definition list is "10", and the node identifier included in the latter node definition list is "20".
[0044] That is, in this example, the two node definition lists each contain the same entity class, but different node identifiers.
[0045] Example 2:
[0046] INSERT(:student{id:10,name:"jason",age:30,class:"3-2"}),(:book{id:10,name:"C++ Primer (5th Edition)",publication_time:"August 6, 2012",count:1714113});
[0047] In this example, the two node definition lists each contain the node identifier "10", and the preceding node definition list contains the entity class "student", and the following node definition list contains the entity class "book".
[0048] That is, in this example, the two node definition lists each contain the same node identifier, but different entity classes.
[0049] Example 3:
[0050] INSERT(:student{id:10,name:"jason",age:30,class:"3-2"}),(:book{id:9780,name:"Harry Potter and the Philosopher's Stone",publication_time:"June 26, 1997",count:589628513});
[0051] In this example, the preceding node definition list contains the entity class "student" and the node identifier "10", and the following node definition list contains the entity class "book" and the node identifier "9780".
[0052] That is, in this example, the two node definition lists each contain different node identifiers and different entity classes.
[0053] It should be noted that in the foregoing Examples 1-3, each node definition list alone constitutes a graph schema list, and the graph schema list is used to define a node.
[0054] In addition, the insert statement in the above example 1 to example 3, while including two graph pattern lists for defining nodes, can be understood as the solution provided by the embodiments of the present specification supporting the insertion of two nodes at the same time, of course, in actual application, more nodes can be inserted at the same time, which will not be repeated here.
[0055] It should be further noted that in actual application, the first node definition list can further include a first variable name, and the second node definition list can further include a second variable name, and the first and second variable names are different.
[0056] For example, the above example 1 can also be as follows:
[0057] INSERT (s1: student {id: 10, name: "jason", age: 30, class: "3-2"}), (s2: student {id: 20, name: "joy", age: 28, class: "6-1"});
[0058] In this example, s1 and s2 are two different variable names included in the two node definition lists respectively.
[0059] In another example, the plurality of element definition lists corresponding to the plurality of graph elements include a first edge definition list corresponding to a first edge, the first edge definition list including a first start identifier and a first end identifier of a start node and an end node of the first edge respectively, and a first relationship category of a relationship represented by the first edge. The first start identifier and the first end identifier form a first edge identifier of the first edge.
[0060] For example, the insert statement can be as follows:
[0061] INSERT()-[:friend {src_id: 10, dst_id: 20, timestamp: 0, intimacy: 100}]->();
[0062] In this example, the inserted statement includes a first edge definition list, and the first edge definition list is represented by a preset pair of symbols "[]", and "friend" is a relationship category of the relationship represented by the first edge, "src_id" is a start identifier of a start node of the first edge, "dst_id" is a termination identifier of a termination node of the first edge, and "timestamp" is a timestamp. It should be noted that the "src_id", "dst_id", "timestamp" and "intimacy" in the above "{}" are collectively referred to as attributes, and the "10", "20", "0" and "100" corresponding to the above attributes are collectively referred to as attribute values. Of course, in actual applications, the above relationship category can also be referred to as an attribute of a graph element, which is not limited in the present specification.
[0063] It should be noted that for different relationship categories, each attribute can be defined in advance, and for at least part of the attributes, a corresponding default attribute value can be set, so that when the corresponding attribute value is not included in the first edge definition list, the default attribute value is directly used.
[0064] In actual applications, in addition to the above first edge definition list, the above several element definition lists can also include a second edge definition list corresponding to a second edge, and the second edge definition list includes a second start identifier and a second termination identifier of a start node and a termination node of the second edge respectively, and a second relationship category of the relationship represented by the second edge.
[0065] Among them, the first start identifier in the first edge definition list and the second start identifier in the second edge definition list are different; and / or, the first termination identifier in the first edge definition list and the second termination identifier in the second edge definition list are different; and / or, the first relationship category in the first edge definition list and the second relationship category in the second edge definition list are different.
[0066] In other words, at least one of the start identifier, the termination identifier and the relationship category included in each of the two edge definition lists is different. The following is described in conjunction with examples:
[0067] Example 4:
[0068] INSERT()-[:friend{src_id:10,dst_id:20,timestamp:0,intimacy:100}]->(),()-[:friend{src_id:11,dst_id:20,timestamp:0,intimacy:39}]->();
[0069] In this example, the relationship class and the end identifier contained in each of the two edge definition lists are respectively "friend" and "20", and the start identifier contained in the former edge definition list is "10", and the start identifier contained in the latter edge definition list is "20".
[0070] That is, in this example, the relationship class and the end identifier contained in each of the two edge definition lists are the same, and the start identifier is different.
[0071] Example 5:
[0072] INSERT()-[:friend{src_id:10,dst_id:20,timestamp:0,intimacy:100}]->(),()-[:friend{src_id:10,dst_id:21,timestamp:0,intimacy:-5}]->();
[0073] In this example, the relationship class and the start identifier contained in each of the two edge definition lists are respectively "friend" and "10", and the end identifier contained in the former edge definition list is "20", and the end identifier contained in the latter edge definition list is "21".
[0074] That is, in this example, the relationship class and the start identifier contained in each of the two edge definition lists are the same, and the end identifier is different.
[0075] Example 6:
[0076] INSERT()-[:friend{src_id:10,dst_id:20,timestamp:0,intimacy:100}]->(),()-[:borrow{src_id:20,dst_id:9780,timestamp:0,gmt_create:"20201102"}]->();
[0077] In this example, the relationship class, the start identifier and the end identifier contained in the former edge definition list of the two edge definition lists are respectively "friend", "10" and "20", and the relationship class, the start identifier and the end identifier contained in the latter edge definition list are respectively "borrow", "20" and "9780".
[0078] That is, in this example, the relationship class, the start identifier and the end identifier contained in each of the two edge definition lists are different.
[0079] It should be noted that in the foregoing examples 4-6, each edge definition list is connected with the two empty node definition lists through the predetermined connectors “-” and “->”, to form a graph pattern list, which is used to define an edge (for example, a dangling edge).
[0080] In addition, the insertion statement in the foregoing examples 4-6 includes two graph pattern lists for defining edges, which can be understood as that the scheme provided by the embodiments of the present specification supports the insertion of two edges at the same time, and of course, more edges can be inserted at the same time in actual application, which will not be repeated here.
[0081] In addition, the scheme provided by the embodiments of the present specification also supports the insertion of nodes and edges at the same time, which is shown as follows:
[0082] Example 7:
[0083] INSERT(:person{id:10,name:"xiaoming",age:30}),()-[:relation{timestamp:1563248870,src_id:10,dst_id:20}]->();
[0084] In another example, the foregoing several element definition lists include two non-empty node definition lists and an edge definition list connected between the two non-empty node lists through a predetermined connector (for example, “-” and “->”), and the three together form a graph pattern list, which is used to define a path. That is, the path includes two nodes and an edge.
[0085] It should be noted that the edge definition list included in the graph pattern list for defining the path can not contain a start identifier and an end identifier, and the two identifiers can be determined based on the node identifiers contained in the two node definition lists respectively. The following is described in combination with examples:
[0086] Example 8:
[0087] INSERT(:student{id:10,name:"jason",age:30,class:"3-2"})-[:friend{timestamp:0,intimacy:100}]->(:student{id:20,name:"joy",age:28,class:"6-1"});
[0088] In this example, the insert statement only includes one graph pattern list, the path defined by the graph pattern list includes two nodes and one edge, and the start and end identifiers contained in the edge definition list used to define the one edge are the node identifiers contained in the two node definition lists respectively: 10 and 20.
[0089] Of course, the insert statement can include multiple graph pattern lists for defining paths, and each of the graph pattern lists includes several node definition lists and several edge definition lists. That is, the present solution supports inserting multiple paths at the same time, and each path can include several nodes and several edges. The following is described in conjunction with examples.
[0090] Example 9:
[0091] INSERT (:student {id: 10, name: "jason", age: 30, class: "3-2"} ) - [:friend {timestamp: 0, intimacy: 100} ] -> (:student {id: 20, name: "joy", age: 28, class: "6-1"} ), (:student {id: 11, name: "barm", age: 15, class: "1-1"} ) <- [:friend {timestamp: 0, intimacy: -5} ] - (:student {id: 21, name: "tom", age: 16, class: "1-2"} );
[0092] In this example, the insert statement includes two graph pattern lists for defining paths, and each of the graph pattern lists includes two node definition lists and one edge definition list. That is, two paths can be inserted into the graph database at the same time through the insert statement, and each path includes two nodes and one edge.
[0093] It should be understood that the present solution also supports simultaneous insertion of nodes, edges and paths.
[0094] Example 10:
[0095] INSERT(:student{id:10,name:"jason",age:30,class:"3-2"}),()-[:borrow{src_id:20,dst_id:9780,timestamp:0,gmt_create:"20201102"}]-();(:student{id:11,name:"barm",age:15,class:"1-1"})-[:friend{timestamp:0,intimacy:-5}]->(:student{id:21,name:"tom",age:16,class:"1-2"});
[0096] In step 204, the insertion statement is executed.
[0097] The execution of the insertion statement includes at least forming a data row corresponding to each graph element according to the attribute values in the element definition list of each element, and determining the primary key value of the corresponding data row according to the element identifier and object category of each graph element. According to the determined primary key value, each data row is inserted into the target graph database.
[0098] Taking the graph element as a node as an example, that is, the above-mentioned element definition list includes a node definition list, and the node definition list contains the node identifier of the node and the entity category of the entity represented by the node; the above-mentioned determination of the primary key value of the corresponding data row can include: determining the primary key value of the data row corresponding to the node according to the node identifier and the entity category.
[0099] Taking the graph element as an edge as an example, that is, the above-mentioned element definition list includes an edge definition list, and the edge definition list contains the start identifier and the end identifier of the start node and the end node of the edge respectively, and the relationship category of the relationship represented by the edge, and the start identifier and the end identifier form the edge identifier of the edge; the above-mentioned determination of the primary key value of the corresponding data row can include: determining the primary key value of the data row corresponding to the edge according to the edge identifier and the relationship category.
[0100] Of course, in actual application, when the edge definition list also contains a timestamp, the primary key value of the data row corresponding to the edge can be determined based on the combination of the edge identifier, the relationship category and the timestamp.
[0101] In addition, for an edge definition list that does not contain a start identifier and an end identifier (such as an edge definition list contained in a graph pattern list used to define a path), the edge identifier of the edge can be formed according to the node identifiers in the two node definition lists connected to the edge definition list through a predetermined connector. Then, the primary key value of the data row corresponding to the edge can be determined according to the edge identifier and the relationship category in the edge definition list.
[0102] Optionally, the insert statement described in the embodiments of the present specification can further include a conflict detection clause, which is used to determine whether there is a target data row that conflicts with the primary key value of the already inserted data row in each data row to be inserted, and modify the target data row in the case that the target data row exists.
[0103] In one example, the conflict detection clause includes a target attribute to be modified and a target attribute value or a modification expression after modification; and the modifying the target data row can include: modifying the attribute value (also referred to as the original attribute value) of the target attribute in the target data row to the target attribute value; or modifying the original attribute value of the target attribute in the target data row based on the modification expression.
[0104] For example, the insert statement can be as follows:
[0105] INSERT(:person{id:10,name:"shensi",age:27,company:"ant"}) ON DUPLICATE KEY UPDATE name="shensi",age=age+1,company="ant";
[0106] The meaning of the insert statement is that when there is a data row with the entity category of "person" and the node identifier of "10" in the graph database, the attribute value of the "name" attribute of the data row is modified to "shensi", the attribute value of the "age" attribute is increased by 1, and the attribute value of the "company" attribute is modified to "ant". It should be understood that "age=age+1" in the insert statement is a modification expression.
[0107] That is, based on the insert statement, the quick update of the data when the primary key values conflict can be realized. In the traditional technology, the update process of the data with conflicting primary key values needs to include the following three steps: first, find the conflicting data row from the graph database based on the primary key value. Second, read the conflicting data row. Third, update the conflicting data row.
[0108] Finally, in the case of batch inserting data into the graph database (such as simultaneously inserting multiple nodes, simultaneously inserting multiple edges, or simultaneously inserting multiple nodes and multiple edges, etc.), after executing the insert statement, an operation result notification can be returned, which at least includes the number of data rows successfully inserted in each data row to be inserted, and the number of data rows with conflicting primary key values or index values.
[0109] In summary, the method for inserting data into a graph database provided by the embodiments of the present specification supports the simultaneous insertion of multiple graph elements of different types, thereby greatly improving the user experience of users of the graph database. In addition, the present solution also supports the creation of primary key values for inserted data rows, and conflict detection based on the primary key values, as well as the rapid updating of conflicting data rows, thereby solving the problem of low data insertion efficiency caused by the failure of inserting data into the graph database due to the conflict between part of the data and the existing data.
[0110] Corresponding to the above method for inserting data into a graph database, one embodiment of the present specification also provides an apparatus for inserting data into a graph database, as shown in Figure 3 The apparatus can include:
[0111] The receiving unit 302 is configured to receive an insertion statement for a target graph database, the insertion statement including at least an insertion keyword and a plurality of element definition lists corresponding to a plurality of graph elements. The graph elements include nodes and / or edges. The plurality of element definition lists are used to define the element identifiers of the plurality of graph elements and the object categories of the objects represented by the plurality of graph elements, wherein each element definition list contains attribute values of each predefined attribute of the corresponding graph element.
[0112] The execution unit 304 is configured to execute the insertion statement, including forming a plurality of data rows corresponding to the plurality of graph elements according to the attribute values in the element definition lists, and determining the primary key values of the data rows according to the element identifiers and object categories of the plurality of graph elements. The plurality of data rows are inserted into the target graph database according to the determined primary key values.
[0113] Optionally, the insertion statement further includes a conflict detection clause, which is used to determine whether there is a target data row that conflicts with the primary key values of the inserted data rows in the plurality of data rows to be inserted, and modify the target data row in the case where the target data row exists.
[0114] The conflict detection clause includes a target attribute to be modified, and a target attribute value or a modification expression after modification.
[0115] The execution unit 304 is specifically configured to:
[0116] modify the attribute value of the target attribute in the target data row to the target attribute value; or
[0117] modify the attribute value of the target attribute in the target data row based on the modification expression.
[0118] Optionally, the apparatus further includes:
[0119] The sending unit 306 is configured to return an operation result notification, which at least includes the number of data rows successfully inserted in the data rows and the number of data rows with primary key value conflicts.
[0120] Optionally, the element definition list corresponding to each of the plurality of graphical elements includes a first node definition list corresponding to the first node. The first node definition list includes a first node identifier of the first node and a first entity category of an entity represented by the first node.
[0121] The execution unit 304 includes:
[0122] The first determination submodule 3042 is configured to determine the primary key value of the data row corresponding to the first node according to the first node identifier and the first entity category.
[0123] Optionally, the element definition list further includes a second node definition list corresponding to the second node. The second node definition list includes a second node identifier of the second node and a second entity category of an entity represented by the second node. At least one of the first node identifier and the second node identifier and the first entity category and the second entity category is different.
[0124] Optionally, the first node definition list further includes a first variable name, the second node definition list further includes a second variable name, and the first variable name and the second variable name are different.
[0125] Optionally, the element definition list further includes a third edge definition list connected between the first node definition list and the second node definition list by a predetermined connector. The third edge definition list includes a third relationship category of a relationship represented by a third edge formed by the first node, the third edge, and the second node.
[0126] The first determination submodule 3042 is further configured to form a third edge identifier of the third edge according to the first node identifier and the second node identifier. The primary key value of the data row corresponding to the third edge is determined according to the third edge identifier and the third relationship category.
[0127] Optionally, the element definition list corresponding to each of the plurality of graphical elements includes a first edge definition list corresponding to the first edge. The first edge definition list includes first start identifier and first end identifier of a start node and an end node of the first edge respectively, and a first relationship category of a relationship represented by the first edge. The first start identifier and the first end identifier form a first edge identifier of the first edge.
[0128] The execution unit 304 includes:
[0129] The second determination submodule 3044 is configured to determine the primary key value of the data row corresponding to the first edge according to the first edge identifier and the first relationship category.
[0130] Optionally, the first edge definition list further comprises a first timestamp; and the second determining sub-module 3044 is specifically configured for:
[0131] determining the primary key value of the data row corresponding to the first edge based on the combination of the first edge identifier, the first relationship category and the first timestamp.
[0132] Optionally, the element definition list further comprises a second edge definition list corresponding to a second edge. The second edge definition list comprises a second start identifier and a second end identifier of a start node and an end node of the second edge respectively, and a second relationship category of a relationship represented by the second edge. At least one of the first start identifier and the second start identifier, the first end identifier and the second end identifier, and the first relationship category and the second relationship category is different.
[0133] The functions of each functional module of the apparatuses described in the foregoing embodiments of the present specification can be realized by each step of the method embodiments, and thus the specific working process of the apparatuses provided by the embodiments of the present specification will not be repeated here.
[0134] The apparatus for inserting data into a graph database provided by the embodiments of the present specification can support inserting different types of graph elements into the graph database, and can support creating a primary key value for the inserted data.
[0135] According to another aspect, an embodiment also provides a computer-readable storage medium having stored thereon a computer program which, when executed in a computer, causes the computer to perform the method described in combination with the Figure 2 embodiments of the present specification.
[0136] According to another aspect, an embodiment also provides a computer-readable storage medium having stored thereon a computer program which, when executed in a computer, causes the computer to perform the method described in combination with the Figure 2 embodiments of the present specification.
[0137] Each of the embodiments of the present specification is described in a progressive manner, and the same or similar parts of each of the embodiments can be referred to each other. Each of the embodiments focuses on the difference from other embodiments. In particular, for the device embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the part of the method embodiments.
[0138] The steps of a method or algorithm described in connection with the present disclosure can be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module can reside in RAM memory, flash memory, ROM memory, EPROM memory, EEPROM memory, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor such that the processor can read information from, and write information to, the storage medium. In the alternative, the storage medium can be integral to the processor. The processor and the storage medium can reside in an ASIC. Alternatively, the processor and the storage medium can be located in a server that is in communication with, for example, the Internet. The processor and the storage medium can comprise one or more components of exemplary computing system 600.
[0139] Those skilled in the art will realize that the basic teachings of the present disclosure can be implemented without departing from the scope of the present disclosure. Such
[0140] The particular embodiments described above illustrate aspects of the present disclosure and do not limit the present disclosure. Other embodiments within the scope of the present disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the present disclosure. For instance, the methods described above can be performed in a different order than the order described above. Additionally, the processes depicted in the figures do not necessarily require the particular order shown, or sequential order to achieve desirable results. In certain instances, multitasking and parallel processing can be advantageous.
[0141] The specific embodiments described above are provided for purposes of illustration only and the present disclosure is not limited to the specific embodiments described above. Rather, the specific embodiments described above are provided to illustrate the present disclosure and to enable the best mode of practicing the present disclosure. The specific embodiments described above are not intended to limit the scope of the present disclosure, which is defined by the appended claims.
Claims
1. A method for inserting data into a graph database, comprising: receiving an insert statement for a target graph database; the insert statement comprising at least an insert keyword and a plurality of element definition lists corresponding to a plurality of graph elements; the graph elements comprising nodes and / or edges; each of the element definition lists containing attribute values of predefined attributes of the corresponding graph element and an object class of an object represented by the graph element; executing the insert statement, wherein forming a data row corresponding to each of the graph elements according to the attribute values in the element definition list, determining a primary key value of the data row according to the element identifier and the object class of the graph element, and inserting the data row into the target graph database according to the primary key value; 2. The method of claim 1, wherein, the insert statement further comprising a conflict detection clause for determining whether there is a target data row in the data rows that conflicts with the primary key value of a data row already inserted, and modifying the target data row in the case that the target data row exists; 3. The method of claim 2, wherein, the conflict detection clause comprising a target attribute to be modified and a target attribute value or a modification expression; the modifying the target data row comprising: modifying the attribute value of the target attribute in the target data row to the target attribute value; or, modifying the attribute value of the target attribute in the target data row based on the modification expression. 4.The method of claim 2, further comprising: returning an operation result notification comprising at least a number of data rows inserted successfully in the data rows and a number of data rows with conflicting primary key values. the plurality of element definition lists corresponding to the plurality of graph elements comprising a first node definition list corresponding to a first node; 5. The method of claim 1, wherein, the first node definition list containing a first node identifier of the first node and a first entity class of an entity represented by the first node; the determining the primary key value of the data row according to the element identifier and the object class of the graph element comprising: determining the primary key value of the data row corresponding to the first node according to the first node identifier and the first entity class. the plurality of element definition lists further comprising a second node definition list corresponding to a second node; 6. The method of claim 5, wherein, the second node definition list containing a second node identifier of the second node and a second entity class of an entity represented by the second node; wherein at least one of the first node identifier and the second node identifier and the first entity class and the second entity class is different; the first node definition list further containing a first variable name and the second node definition list further containing a second variable name; the first variable name and the second variable name being different.
7. The method of claim 6, wherein, the plurality of element definition lists corresponding to the plurality of graph elements comprising a first edge definition list corresponding to a first edge; the first edge definition list containing first start identifier and first end identifier of a start node and an end node of the first edge respectively and a first relationship class of a relationship represented by the first edge.
8. The method of claim 1, wherein, The first start identifier and the first end identifier form a first edge identifier of the first edge; The determining of the primary key value of the corresponding data row according to the element identifier and the object category of each graph element comprises: The determining of the primary key value of the corresponding data row according to the first edge identifier and the first relationship category.
9. The method of claim 8, wherein, The first edge definition list further comprises a first timestamp; the determining of the primary key value of the corresponding data row of the first edge comprises: The determining of the primary key value of the corresponding data row of the first edge based on the combination of the first edge identifier, the first relationship category and the first timestamp.
10. The method of claim 8, wherein, The plurality of element definition lists further comprise a second edge definition list corresponding to a second edge; the second edge definition list comprises a second start identifier and a second end identifier of the start node and the end node of the second edge respectively, and a second relationship category of the relationship represented by the second edge; wherein at least one of the first start identifier and the second start identifier, the first end identifier and the second end identifier, and the first relationship category and the second relationship category is different.
11. The method of claim 6, wherein, The plurality of element definition lists further comprise a third edge definition list connected between the first node definition list and the second node definition list by a predetermined connector, and the third edge definition list comprises a third relationship category of the relationship represented by the third edge; The first node, the third edge and the second node form a first path; The determining of the primary key value of the corresponding data row according to the element identifier and the object category of each graph element comprises: The first node identifier and the second node identifier form a third edge identifier of the third edge; The determining of the primary key value of the corresponding data row of the third edge according to the third edge identifier and the third relationship category.
12. An apparatus for inserting data into a graph database, comprising: a receiving unit configured to receive an insertion statement for a target graph database; the insertion statement at least comprising an insertion keyword and a plurality of element definition lists corresponding to a plurality of graph elements; the graph elements comprising nodes and / or edges; each of the plurality of element definition lists being used to define an element identifier of the corresponding graph element and an object category of an object represented by the corresponding graph element, wherein each element definition list comprises attribute values of a plurality of predefined attributes of the corresponding graph element; an executing unit configured to execute the insertion statement, wherein the executing comprises: forming a plurality of data rows corresponding to the plurality of graph elements according to the attribute values in each of the plurality of element definition lists, and determining primary key values of the corresponding data rows according to the element identifier and the object category of each graph element; and inserting the plurality of data rows into the target graph database according to the primary key values.
13. The apparatus of claim 12, wherein, The insertion statement further comprises a conflict detection clause, the conflict detection clause being used to determine whether there is a target data row conflicting with the primary key values of the already inserted data rows in the plurality of data rows, and modify the target data row in the case that the target data row exists.
14. The apparatus of claim 13, wherein, The conflict detection clause comprises a target attribute to be modified, and a target attribute value after modification or a modification expression; The executing unit is specifically configured to: modifying an attribute value of the target attribute in the target data row to the target attribute value; or modifying the attribute value of the target attribute in the target data row based on the modified expression.
15. The apparatus of claim 13, further comprising: a sending unit configured to return an operation result notification, wherein the operation result notification at least includes a number of data rows successfully inserted in the plurality of data rows and a number of data rows with primary key value conflicts.
16. The apparatus of claim 12, wherein, The plurality of element definition lists corresponding to the plurality of graph elements includes a first node definition list corresponding to a first node; The first node definition list includes a first node identifier of the first node and a first entity category of an entity represented by the first node; The execution unit includes: a first determining submodule configured to determine a primary key value of a data row corresponding to the first node according to the first node identifier and the first entity category.
17. The apparatus of claim 16, wherein, The plurality of element definition lists further includes a second node definition list corresponding to a second node; the second node definition list includes a second node identifier of the second node and a second entity category of an entity represented by the second node; and at least one of the first node identifier and the second node identifier and at least one of the first entity category and the second entity category are different.
18. The apparatus of claim 17, wherein, The first node definition list further includes a first variable name, and the second node definition list further includes a second variable name; the first variable name and the second variable name are different.
19. The apparatus of claim 12, wherein, The plurality of element definition lists corresponding to the plurality of graph elements includes a first edge definition list corresponding to a first edge; the first edge definition list includes a first start identifier and a first end identifier of a start node and an end node of the first edge respectively, and a first relationship category of a relationship represented by the first edge; The first start identifier and the first end identifier form a first edge identifier of the first edge; The execution unit includes: a second determining submodule configured to determine a primary key value of a data row corresponding to the first edge according to the first edge identifier and the first relationship category.
20. The apparatus of claim 19, wherein, The first edge definition list further includes a first timestamp; and the second determining submodule is specifically configured to: determine the primary key value of the data row corresponding to the first edge based on a combination of the first edge identifier, the first relationship category, and the first timestamp.
21. The apparatus of claim 19, wherein, The plurality of element definition lists further includes a second edge definition list corresponding to a second edge; the second edge definition list includes a second start identifier and a second end identifier of a start node and an end node of the second edge respectively, and a second relationship category of a relationship represented by the second edge; and at least one of the first start identifier and the second start identifier, at least one of the first end identifier and the second end identifier, and at least one of the first relationship category and the second relationship category are different.
22. The apparatus of claim 17, wherein, The plurality of element definition lists further includes a third edge definition list connected between the first node definition list and the second node definition list by a predetermined connector, and the third edge definition list includes a third relationship category of a relationship represented by the third edge; The first node, the third edge and the second node form a first path; The first determining sub-module is further configured to form a third edge identifier of the third edge according to the first node identifier and the second node identifier; and determine a primary key value of a data row corresponding to the third edge according to the third edge identifier and the third relationship category.
23. A computer readable storage medium having stored thereon a computer program, wherein, The computer program, when executed in the computer, causes the computer to perform the method of any one of claims 1-11.
24. A computing device comprising a memory and a processor, wherein, The memory stores executable code, and the processor executes the executable code to implement the method of any one of claims 1-11.
Citation Information
Patent Citations
Graph database-oriented automatic data storage method, device and equipment
CN113886482A
Data processing method and data processing device applied to database
CN114547020A