Key-value pair difference comparison method and device, equipment and medium

By constructing a data tree and merging tree structure, and using custom matching and similarity algorithms for key-value pair difference comparison, the problems of high time complexity and non-customizable rules in existing technologies are solved, achieving efficient and accurate key-value pair difference comparison.

CN115293279BActive Publication Date: 2026-08-25GUANGZHOU BAIGUOYUAN NETWORK TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210986864.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-17
Publication Date
2026-08-25
Estimated Expiration
2042-08-17

AI Technical Summary

Technical Problem

Existing key-value pair difference comparison methods have high time complexity and cannot customize difference comparison rules, resulting in low testing efficiency and inaccurate results.

Method used

By constructing a data tree and generating a merged tree structure, key-value pair differences are compared using custom matching and similarity algorithms. Custom comparison rules and similarity algorithms are used to meet business requirements, and recursive key-value pair differences are compared within the merged tree structure.

Benefits of technology

It reduces the time complexity of key-value pair difference comparison, improves comparison efficiency, and allows for customized difference comparison rules based on business scenarios, ensuring the accuracy and relevance of comparison results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115293279B_ABST
    Figure CN115293279B_ABST
Patent Text Reader

Abstract

The application relates to a key-value pair difference comparison method and device, equipment, medium and product in the technical field of data comparison, which comprises the following steps: merging the tree structures of a first data tree and a second data tree to generate a merged tree structure; based on the node path of the merged tree structure and comparison rules thereof, cross-comparing the key-value pairs of nodes at the same layer in the first data tree and the second data tree, matching the comparison groups and difference types of the two key-value pairs in the same layer according to a matching algorithm, and calculating the similarity of each comparison group according to a similarity algorithm; determining the comparison groups with the difference type of value difference in the same layer from the bottom layer of the merged tree structure, calculating the total similarity between the upper nodes of the comparison groups based on the similarity of the comparison groups, and transferring the upper nodes with higher total similarity to a difference tree; storing the remaining comparison groups with difference types in the difference tree, and outputting a comparison result. The application provides a data comparison rule customization service and improves data comparison efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data comparison technology, and in particular to a key-value pair difference comparison method and corresponding apparatus, key-value pair difference comparison device, computer-readable storage medium, and computer program product. Background Technology

[0002] During program development, after developers create a new interface, they typically push the requests responded to by the old interface to the new interface. They then compare the response results of the old and new interfaces to the same request to test whether the new interface meets expectations. The data in the response results is mostly JSON structure data, i.e., key-value pair data. When comparing key-value pair differences, existing key-value pair comparison methods are usually used. However, these methods often employ brute-force algorithms, enumerating each key-value pair for comparison. This results in high time complexity. Furthermore, existing key-value pair comparison methods often ignore the data type of the key-value pairs, simply comparing the differences in their values. Developers cannot customize comparison rules for different data types or key-value pairs, leading to redundant and inaccurate comparison results, thus impacting testing efficiency. Summary of the Invention

[0003] The purpose of this application is to solve the above-mentioned problems by providing a key-value pair difference comparison method and corresponding apparatus, key-value pair difference comparison device, computer-readable storage medium, and computer program product.

[0004] According to one aspect of this application, a key-value pair difference comparison method is provided, comprising the following steps: Obtain a first data tree and a second data tree. Each node in each data tree stores a single key-value pair. The key-value pairs of lower-level nodes belong to the member data of the key-value pairs of their upper-level nodes. Each node in the first data tree and the second data tree has a corresponding comparison rule. The tree structures of the first data tree and the second data tree are merged to generate a merged tree structure, in which each node stores the comparison rules corresponding to its key; Based on the node paths of the merged tree structure and the matching algorithm and similarity algorithm included in its comparison rules, the key-value pairs of nodes at the same level in the first data tree and the second data tree are cross-compared. The matching algorithm is used to match the comparison groups composed of two key-value pairs in the same level and their difference types, and the similarity of each comparison group is calculated according to the similarity algorithm. Starting from the bottom layer of the merged tree structure, identify comparison groups with value differences in the same layer. Based on the similarity of these comparison groups, calculate the total similarity between the parent nodes of these comparison groups, and transfer the parent nodes with higher total similarity to the difference tree. The remaining key-value pairs with different types are stored in the difference tree, and the comparison results are output. The comparison results include each node of the difference tree and its corresponding difference type.

[0005] According to another aspect of this application, a key-value pair difference comparison device is provided, comprising: The data tree acquisition module is used to acquire the first data tree and the second data tree. Each node of each data tree stores a single key-value pair. The key-value pair of the lower-level node belongs to the member data of the key-value pair of its upper-level node. Each node in the first data tree and the second data tree has a corresponding comparison rule. The merge tree generation module is used to merge the tree structures of the first data tree and the second data tree to generate a merge tree structure. Each node in the merge tree structure stores the comparison rules corresponding to its key. The key-value pair comparison module is used to cross-compare the key-value pairs of nodes at the same level in the first data tree and the second data tree based on the comparison rules of each node in the merged tree structure, match the comparison groups composed of two key-value pairs in the same level and their difference types according to the matching algorithm, and calculate the similarity of each comparison group according to the similarity algorithm. The parent node transfer module is used to determine, starting from the bottom layer of the merged tree structure, the comparison groups with value difference and parent nodes in the same layer, calculate the total similarity between the parent nodes of the comparison groups based on the similarity of these comparison groups, and transfer the parent nodes with higher total similarity to the difference tree. The comparison result output module stores the key-value pairs corresponding to the node paths where the difference type is added or removed into the difference tree, and then outputs the comparison result representing the difference type of the nodes based on the difference type of each node in the difference tree.

[0006] According to another aspect of this application, a key-value pair difference comparison device is provided, including a central processing unit and a memory, wherein the central processing unit is used to invoke and run a computer program stored in the memory to perform the steps of the key-value pair difference comparison method described in this application.

[0007] According to another aspect of this application, a computer-readable storage medium is provided that stores, in the form of computer-readable instructions, a computer program implemented according to the described key-value pair difference comparison method, which, when invoked by a computer, executes the steps included in the method.

[0008] According to another aspect of this application, a computer program product is provided, including a computer program / instructions that, when executed by a processor, implement the steps of the method described in any embodiment of this application.

[0009] Compared to existing technologies, this application can provide developers with custom key-value pair comparison rules. Developers can set corresponding comparison rules for key-value pair data that need to be compared according to the business scenario of key-value pair comparison. The comparison rules include a matching algorithm to determine key-value pair matching and a similarity algorithm to determine key-value pair similarity score. This allows for the design of a key-value pair comparison process that meets the needs of the business scenario and satisfies the testing requirements for key-value pair difference comparison.

[0010] Secondly, when comparing key-value pairs from different datasets, this application constructs the data trees of both datasets being compared, and merges nodes at the same level into a single node based on the node paths of each node in the data trees of both datasets, thereby outputting a merged tree structure. This allows for a recursive key-value pair difference comparison with low time complexity by utilizing the paths of each node in the merged tree structure. Furthermore, each node in the merged tree structure is pre-assigned its corresponding comparison rules, eliminating the need for comparison rule lookups during key-value pair difference comparisons, thus improving the efficiency of key-value pair difference comparisons.

[0011] In addition, the similarity of each node in this application can be customized, and different similarity scores can be customized by the developers so that the developers can use the key-value pairs they are mainly concerned with as the primary keys of key-value pairs of object type or numeric type. For example, the total similarity calculation and matching removal processing of different parent nodes in this application prevents the similarity of other key-value pairs in key-value pairs of object type or numeric type from affecting the prominence of the key-value pairs that need to be concerned, thus meeting the developers' needs for key-value pair difference comparison. Attached Figure Description

[0012] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, wherein: Figure 1 A typical network deployment architecture diagram related to the implementation of the technical solution of this application; Figure 2 This is a flowchart illustrating a typical embodiment of the key-value pair difference comparison method of this application; Figure 3 This is an exemplary diagram showing the paths of each node in the first data tree for the purposes of this application; Figure 4 This is an exemplary schematic diagram showing the paths of each node in the second data tree for the purposes of this application; Figure 5This is a schematic diagram illustrating the paths of each node in the merged tree structure, as exemplarily presented in this application. Figure 6 This is an exemplary schematic diagram showing the paths of each node in the difference tree in this application; Figure 7 This is a schematic diagram illustrating the process of merging the first data tree and the second data tree to generate the merged data structure in an embodiment of this application; Figure 8 This is a schematic diagram illustrating the process of comparing key-value pairs between the first data tree and the second data tree based on a merged tree structure in an embodiment of this application. Figure 9 This is a schematic diagram illustrating the process of calculating the total similarity between the parent nodes of the comparison group in an embodiment of this application; Figure 10 This is a flowchart illustrating the processing of combinations of parent nodes with different total similarities in an embodiment of this application. Figure 11 This is a schematic diagram illustrating the process of generating comparison results based on the difference tree and outputting them in an embodiment of this application; Figure 12 This is a schematic block diagram of a typical embodiment of the key-value pair difference comparison device of this application; Figure 13 This is a basic structural block diagram of a key-value pair difference comparison device according to an embodiment of this application. Detailed Implementation

[0013] The term "server" as used in this application can also be extended to situations applicable to service clusters. Based on network deployment principles understood by those skilled in the art, the servers should be logically divided; physically, these servers can be independent yet accessible through interfaces, or they can be integrated into a single physical computer or a cluster of computers. Those skilled in the art should understand this flexibility and should not use it to constrain the implementation of the network deployment method described in this application.

[0014] Those skilled in the art will understand that although the various methods in this application are described based on the same concept and thus present commonality among them, they can be performed independently unless otherwise specified. Similarly, the various embodiments disclosed in this application are all based on the same inventive concept; therefore, concepts expressed in the same way, as well as concepts that are appropriately changed for convenience but are expressed differently, should be understood equivalently.

[0015] Unless otherwise expressly stated, the various embodiments disclosed in this application can be combined in a cross-cutting manner to flexibly construct new embodiments, as long as such combination does not depart from the inventive spirit of this application and can meet the needs of the prior art or solve a certain deficiency in the prior art. Those skilled in the art should be aware of such modifications.

[0016] Please see Figure 1 The hardware infrastructure required for implementing the technical solutions of this application can be deployed according to the architecture shown in the figure. The server 80 mentioned in this application is deployed in the cloud as an online server. It can further connect to relevant data servers and other servers providing related support, thus forming a logically related service cluster to provide services to relevant terminal devices such as the smartphone 81 and personal computer 82 shown in the figure, or third-party servers (not shown). The smartphones and personal computers can both access the Internet through known network access methods and establish a data communication link with the cloud server 80 to run terminal applications related to the services provided by the server. For example, smartphones 81 and personal computers 82 are generally terminal devices that run applications to display the preview window or live stream interface of the target live room, while server 80 can provide the target live stream video data stream and business data stream to the terminal devices.

[0017] Please see Figure 2 A key-value pair difference comparison method according to this application, in a typical embodiment, includes the following steps: Step S11: Obtain the first data tree and the second data tree. Each node in each data tree stores a single key-value pair. The key-value pairs of lower-level nodes belong to the member data of the key-value pairs of their upper-level nodes. Each node in the first data tree and the second data tree has a corresponding comparison rule. The data tree is constructed based on the data structure of key-value pairs in the data set. Specifically, the data set stores multiple key-value pairs, which are generally JSON data structures. The data types of the key-value pairs include object type, array type, number type, integer type, and boolean type. Key-value pairs of array type or object type have multiple key-value pairs contained within them. Among them, the key-value pairs contained in object type key-value pairs are generally traditional key-value pairs composed of key data and value data, while the key data contained in array type key-value pairs are generally their array indices. Therefore, in generating the corresponding data tree based on the data set, key-value pairs of array type or object type will be the parent nodes with child nodes in addition to the root node, and the key-value pairs contained in them will be their member data. The corresponding node path is constructed by traversing the key-value pairs contained in the array type or object type key-value pairs.

[0018] When comparing key-value pairs, the comparison is generally based on the key-value pairs in the first data tree and the key-value pairs in the second data tree. In the scenario of comparing the response results of the old and new interfaces, the first data tree contains the key-value pair data in the response result of the old interface responding to the request, and the second data tree contains the key-value pair data in the response result of the new interface responding to the same request. Based on the first data tree containing the old key-value pair data, the comparison is made with the second data tree containing the new key-value pair data to compare the differences in the key-value pair data output by the old and new interfaces.

[0019] The comparison rule generally includes a matching algorithm and a similarity algorithm, and includes a parent node identifier to represent the parent node to which the key-value pair it applies belongs, and a key identifier to represent the key data of the key-value pair it applies to, so as to determine the node to which the comparison rule applies in the first data tree and the second data tree based on the parent node identifier and the key identifier.

[0020] In one embodiment, when the parent node of the comparison rule is identified as the root node of a first or second data tree, the nodes in the first or second data tree that store key-value pairs whose key data is identified by the key of the comparison rule will use the comparison rule to perform difference comparison.

[0021] The matching algorithm is used to compare key-value pairs for matching identical value data or key-value pairs. The algorithm types generally include unordered exact matching, unordered fuzzy matching, ordered exact matching, ordered fuzzy matching, and specified ignore algorithms. The unordered exact matching algorithm is generally used as the default matching algorithm, which matches key-value pairs with the same key for value data comparison. When the key-value pairs are array-type key-value pairs, the unordered exact matching algorithm matches elements with the same array index and stored data based on the storage location and sorting relationship of each element in both arrays. The unordered fuzzy matching algorithm generally applies to key-value pairs of data types or objects. It ignores the key data of the key-value pair and matches key-value pairs with the same value data. When applied to key-value pairs of data types, it ignores the storage index of each element in both comparisons and matches the stored data in both comparisons. The same elements; the ordered precise matching algorithm and the ordered fuzzy matching algorithm are generally set on key-value pairs of data types. The ordered precise matching algorithm will match the longest common subsequence between the two sides of the array for difference comparison. For example, the first key-value pair [1,2,3] and the second key-value pair [2,3,4]. When the matching algorithm set for the first key-value pair is the ordered precise matching algorithm, the matched common subsequence will be [2,3]. "1" and "4" will be the difference key-value pair between the first and second key-value pairs. Correspondingly, the ordered fuzzy matching algorithm will match the string with the longest distance between the same elements in the two sides of the array for difference comparison. For example, the first key-value pair [1,5,2,4,3] and the second key-value pair [6,2,3,4,7,8]. When the matching algorithm set for the first key-value pair is the ordered precise matching algorithm, the matched string will be [2,3,4].

[0022] The aforementioned similarity algorithm is used to determine the similarity of value data between key-value pairs undergoing difference comparison. Specifically, when the value data of the key-value pairs undergoing difference comparison are the same, the similarity of the comparison group of the key-value pairs will be the similarity set by the similarity algorithm. If the value data of the two pairs are different, the similarity of the comparison group is generally 0. The expression of the similarity algorithm is as follows: left$.a == right$.a?1:0 In this context, "left$.a" generally refers to the first key-value pair in the first data tree where the parent node is the root node and the key is 'a', and "right$.a" generally refers to the second key-value pair in the second data tree where the parent node is the root node and the key is 'a'. When the values ​​of the first key-value pair and the second key-value pair are the same, their similarity will be 1.

[0023] In one embodiment, the corresponding similarity algorithm can be edited to meet the comparison requirements of strict matching. For example, in the difference comparison of key-value pairs constructed based on JSON, the integer data type "1" or "0", the numeric data type 1 or 0, and the boolean data type true or false are usually considered to be the same value data. Therefore, in order to compare the three as different data, the corresponding similarity algorithm can be edited. The specific expression of the similarity algorithm is as follows: First expression: (left$.a == true && right$.a == true)||(left$.a == false && right$.a == false)?1:0 The second expression: (left$.a == 1 && right$.a == 1)||(left$.a == 0 && right$.a== 0)?1:0 The third expression: (left$.a == “1” && right$.a == “1”)||(left$.a == “0” &&right$.a == “0”)?1:0 The first expression distinguishes between true and false in Boolean data types and "1" or "0" in integer data types and 1 or 0 in numeric data types. Similarly, the second and third expressions distinguish between 1 and 0 in numeric data types and "1" and "0" in integer data types. Of course, any two expressions can be combined to distinguish between specific data in two data types at the same time to meet the matching comparison requirements.

[0024] In one embodiment, a corresponding function field can be added to the algorithm expression to allow key-value pairs to ignore null characters during difference comparison. For example, the function field ".trim()" can be added to the similarity algorithm to ignore null characters contained in the value data of both key-value pairs being compared. The specific algorithm expression is as follows: left$.a.trim() == right$.a.trim()?1:0 The comparison rules are generally divided into custom comparison rules and default comparison rules. Custom comparison rules are the comparison rules defined for the corresponding key-value pairs in the first data tree. These custom comparison rules can set the matching algorithm to any one of the following: unordered exact matching algorithm, unordered fuzzy matching algorithm, ordered exact matching algorithm, ordered fuzzy matching algorithm, and specified ignore algorithm, or other newly developed matching algorithms. The parent node identifier and key identifier of the custom comparison rule are also set to define the target key-value pairs to which the custom comparison rule applies. Furthermore, the similarity algorithm of the custom comparison rule can also be customized to achieve different similarity scores or meet specific comparison requirements, such as strict matching and ignoring empty characters. It can be seen that by providing developers with custom rules... The comparison rule setting service allows developers to customize key-value pair difference comparison schemes between different data trees, ensuring that the final comparison results meet their data comparison needs. Correspondingly, the default comparison rule generally applies to key-value pairs for which no custom comparison rule has been set. Its matching algorithm is generally the unordered exact matching algorithm, and its similarity algorithm is generally a similarity algorithm with a similarity score of 1. That is, if the values ​​of the compared key-value pairs are equal, the similarity between them is 1. By pre-setting a default comparison rule for key-value pairs for which no custom comparison rule has been set, the workload for developers is reduced. The default comparison rule is automatically applied to key-value pairs for comparison, eliminating the need for developers to set corresponding comparison rules for all key-value pairs.

[0025] Step S12: Merge the tree structures of the first data tree and the second data tree to generate a merged tree structure. Each node in the merged tree structure stores the comparison rules corresponding to its key. Obtain the first data tree and the second data tree, and according to the respective tree structures of the first data tree and the second data tree, merge nodes at the same level and with the same node path into the same node, thereby generating the merged tree structure containing each node in the first data tree and the second data tree.

[0026] Please refer to Figure 3 , Figure 4 and Figure 5 , Figure 3 The tree structure shown is the tree structure of the first data tree. Figure 4 The tree structure shown is the tree structure of the second data tree. Figure 5 To be Figure 3 and Figure 4 The tree structure generated by merging the tree structures, such as Figure 5 As shown, it will Figure 3 and Figure 4 Nodes on the same path at the same level are merged into a single node, and Figure 5 The merged tree structure shown contains Figure 3 and Figure 4 The nodes owned by each of the two parties, i.e., the merged tree structure includes the tree structures of the first data tree and the second data tree respectively.

[0027] After merging the tree structures of the first data tree and the second data tree to generate the merged tree structure, each node in the merged tree structure is marked with its corresponding comparison rule. Specifically, firstly, a set of custom comparison rules containing multiple custom comparison rules set for each node in the first or second data tree is obtained. The target node corresponding to each custom comparison rule in the set of custom comparison rules can be determined by the parent node identifier and key identifier in each custom comparison rule. Then, the rule identifier of the corresponding custom comparison rule is stored in these target nodes. For nodes in the merged tree structure that have not set the custom rules, the rule identifier of the default comparison rule is stored in these nodes.

[0028] Step S13: Based on the node paths of the merged tree structure and the matching and similarity algorithms included in its comparison rules, cross-compare the key-value pairs of nodes at the same level in the first data tree and the second data tree. The matching algorithm identifies comparison groups consisting of two key-value pairs at the same level and their difference types. The similarity of each comparison group is calculated using the similarity algorithm. When comparing the key-value pairs between the first and second data trees, the differences between each key-value pair are recursively compared based on the node paths in the merged tree structure and the comparison rules corresponding to each node. For details, please refer to [link / reference]. Figures 3 to 5 , Figure 5 Node 501 shown is the current node to be compared. Before performing key-value pair difference comparison on the node to be compared, it will be determined whether the node to be compared has subordinate nodes, such as... Figure 5 The node 501 shown has subordinate nodes 502, 503, and 504. Therefore, any one of the subordinate nodes 502, 503, or 504 will be used as the current node to be compared for key-value pair difference comparison. For example, when the shown subordinate node 502 is the node to be compared, the following will be obtained: Figure 3 The key-value pairs stored in node 301 shown are used as comparison key-value pairs, and... Figure 4The nodes 401 and 402 shown each have their own first key-value pairs and second key-value pairs. The key-value pair being compared with the first key-value pair forms a first comparison group, while the key-value pair being compared with the second key-value pair forms a second comparison group. Then, based on the comparison rule corresponding to the rule identifier in the lower-level node 502, the matching algorithm in the comparison rule determines whether there is a difference in value data between the key-value pairs in the first comparison group and the key-value pairs in the second comparison group. For key-value pairs where value data differs, the difference type between this key-value pair and the comparison key-value pair is classified as a value difference. The similarity between the comparison key-value pair and the first and second key-value pairs is calculated according to the similarity algorithm in the comparison rule. The similarity between key-value pairs with the same value data and the key-value pairs being compared will be the similarity set in the similarity algorithm, while the similarity between key-value pairs with different value data and the key-value pairs being compared will be 0. It can be seen that when performing key-value pair difference comparison processing on any node, it is first determined whether the node has a subordinate node. If it does, the subordinate node is taken as the node that needs to be processed for key-value pair difference comparison. If it does not exist, it is queried whether the node has a key-value pair with the same key at the same level in the second data tree, so as to determine the difference type and similarity between the key-value pair corresponding to the node in the first data tree and the key-value pair with the same key at the same level in the second data tree according to the comparison rules.

[0029] In completion of the shown Figure 5 After comparing the key-value pairs of the lower-level node 502, a key-value pair comparison will be performed on the lower-level node 503 or 504, thus completing the key-value pair comparison process for each lower-level node contained in node 501. Then, the comparison will be performed on... Figure 5 The key-value pair difference comparison is performed on any one of the nodes 508 to 510 in the merged tree structure shown. Generally, the key-value pair difference comparison of each node in the merged tree structure shown is performed from left to right.

[0030] Similarly, the key-value pair differences of each node in the merged tree structure are determined. For nodes in the same layer that do not have the same key, the difference type of the key-value pair will be either removal or addition, and these nodes will not have corresponding similarity. For nodes in the same layer that have the same key, the first key-value pair of the corresponding node path in the first data tree will be compared with the second key-value pair of the same key in each layer of the second data tree according to the comparison rules of the node. The difference type and similarity of the comparison groups formed by the pairs will be determined.

[0031] Step S14: Starting from the bottom layer of the merged tree structure, identify comparison groups with value differences at the same level. Based on the similarity of these comparison groups, calculate the total similarity between the parent nodes of these comparison groups, and transfer the parent nodes with higher total similarity to the difference tree. After comparing the key-value pairs of each node in the merged tree structure, starting from the bottom layer of the merged tree structure, the comparison groups with value differences in the same layer of the merged tree structure are determined. Then, based on the similarity of these comparison groups, the total similarity between the parent nodes of each comparison group is calculated.

[0032] The total similarity between any two parent nodes is generally the average of the similarities between the comparison groups of the lower nodes in the intersection of the two nodes. That is, the total similarity is the result of calculating the sum of the similarities and dividing it by the number of comparison groups. The lower nodes in the intersection refer to the nodes where the key-value pairs with the same key are located in the key-value pairs of the parent nodes that perform the total similarity calculation.

[0033] Please refer to Figures 3 to 5 , Figure 3 The key-value pairs of node 301 shown in the first data tree, and Figure 4 The key-value pair of node 401 shown in the second data tree is the first comparison group, and the key-value pair of node 402 is also the first comparison group, and from... Figure 3 and Figure 4It can be seen that the difference type of the first comparison group is value difference, and the difference type of the second comparison group is also value difference. Therefore, it is necessary to determine the total similarity between the parent nodes of each pair of key-value pairs in the first and second comparison groups. Specifically, the preset similarity in the similarity algorithm of the comparison rule for node 301 is 1, the preset similarity in the similarity algorithm of the comparison rule for node 304 is 0.2, and the preset similarity in the similarity algorithm of the comparison rule for node 305 is also 0.2. The similarity between the key-value pair of node 301 and the key-value pair of node 401 in the first comparison group is 0, and the similarity between the key-value pair of node 303 and the key-value pair of node 401 is 0. The similarity between the key-value pairs of node 404 is 0.2, and the similarity between the key-value pairs of node 304 and node 405 is 0.2. Therefore, the total similarity between the parent node 308 and parent node 408 is 0.4 / 3. Correspondingly, the similarity between the key-value pairs of node 301 and node 402 in the second pair of work groups is 0, the similarity between the key-value pairs of node 303 and node 406 is 0, and the similarity between the key-value pairs of node 304 and node 407 is 0. Therefore, the total similarity between the parent node 308 and parent node 409 is 0. Furthermore, it is necessary to calculate the total similarity between the parent node 309 of node 305 (which shares the same key as node 301) and the parent node 408, as well as between the parent node 309 and each of the parent nodes 305. Specifically, the similarity between the key-value pairs of node 305 and node 401 is 1; the similarity between the key-value pairs of node 306 and node 404 is 0; and the similarity between the key-value pairs of node 307 and node 405 is 0. Therefore, the total similarity between the parent node 308 and parent node 408 is 1 / 3. Correspondingly, the total similarity between the key-value pairs of node 305 and node 402 is... The similarity is 0. The similarity between the key-value pairs of node 306 and node 406 is 0, and the similarity between the key-value pairs of node 307 and node 407 is 0. Therefore, the total similarity between the parent node 308 and the parent node 409 is 0. It can be seen that the parent node 308 is in the same first data tree as the parent node 309, which has the same key-value pairs. Therefore, it is also necessary to calculate the total similarity between the parent node 309 and the parent node 408 in the second data tree. The total similarity between the parent node 308 and the parent node 409 is 0.4 / 3, the total similarity between parent node 308 and parent node 409 is 0, the total similarity between parent node 309 and parent node 408 is 1 / 3, and the total similarity between parent node 309 and parent node 409 is 0. Therefore, the parent node combination with the highest total similarity can be considered as 1 / 3 between parent node 309 and parent node 408. Thus, parent node 309 and parent node 408 will be transferred to the difference tree. It can be understood that by presetting different similarity values ​​for the similarity algorithms of different lower-level nodes, the key data of the key-value pairs of lower-level nodes with higher similarity values ​​is used as the primary key of their parent node. This allows developers to use the key-value pairs of primary interest as the primary keys of object-type or numeric key-value pairs when performing key-value pair difference comparisons, preventing the similarity of other key-value pairs in object-type or numeric key-value pairs from affecting the prominence of the key-value pairs to be focused on, thus meeting the developers' needs for key-value pair difference comparisons.

[0034] Please refer to Figure 3 and Figure 4 The parent node 309 and parent node 408 are respectively from Figure 3 The first data tree shown is Figure 4 After the second data tree transfer shown, Figure 3 and Figure 4 The total similarity between the remaining parent nodes 308 and 409 is 0. In cases where the total similarity is 0, the parent nodes 308 and 409 can generally be transferred to the difference tree as parent nodes with the difference type of value difference. Alternatively, a new difference type can be determined for the lower-level nodes contained between the two parent nodes with a total similarity of 0. Specifically, when the total similarity between the two parent nodes in the same layer that can be calculated is 0, and only the two parent nodes remain in the current layer, such as parent nodes 308 and 409, then for the parent node 309 in the first data tree, the difference type of its contained lower-level nodes can be determined as the removal type. For the parent node 409 in the second data tree, the difference type of its contained lower-level nodes can be determined as the addition type.

[0035] The difference tree refers to the key-value pairs whose difference types have been finally determined and their node paths. Each node in the difference tree will contain its corresponding key-value pair and its difference type. For details, please refer to [link / reference needed]. Figure 6 , Figure 6 for Figure 3 The first data tree and Figure 4 The difference tree is generated by comparing key-value pairs of differences in the second data tree. Figure 6The “Diff” field in the node shown represents its difference type, where “added” represents the added type, “removed” represents the removed type, “replaced” represents the value difference type, and “null” represents the no difference type. It can be seen that for nodes with the difference type of value difference, the key-value pairs of the nodes in the second data tree are generally stored in the difference tree so that the subsequent comparison results can represent the difference key-value pairs in the second data tree and prevent the comparison results from being too redundant.

[0036] Step S15: Store the remaining key-value pairs with different types into the difference tree, and output the comparison result. The comparison result includes each node of the difference tree and its corresponding difference type: In addition to storing key-value pairs with the difference type of value difference in the difference tree, key-value pairs with the difference type of addition or removal are also stored in the difference tree. Based on the difference type of the key-value pairs in each node of the difference tree, the comparison result containing the mapping relationship data composed of these key-value pairs and their difference types is generated and output.

[0037] Please refer to Figure 6 , Figure 6 To Figure 3 The first data tree represented by Figure 4 The difference tree generated after comparing key-value pairs of the second data tree that represents it. Figure 6 In the difference tree shown, each node's path is the same as its node path in the first or second data tree. Key-value pairs of the lower-level nodes of the same parent node will be stored in the same set in the comparison result, and each key-value pair and its corresponding difference type (i.e., Figure 6 The difference type represented by the "Diff" field in each node shown is stored in the comparison results.

[0038] Unlike existing key-value pair difference comparison techniques, this method provides developers with a service to customize key-value pair comparison rules. Developers can set corresponding comparison rules for each key-value pair data to be compared, based on the business scenario of the comparison. These rules include matching algorithms to determine key-value pair matches and similarity algorithms to determine key-value pair similarity scores, thereby designing a key-value pair comparison process that meets the needs of the business scenario and satisfies the testing requirements for key-value pair difference comparison. Secondly, when performing key-value pair difference comparisons on different datasets, this method constructs the data trees of both datasets being compared. Based on the node paths of each node in both datasets, nodes at the same level are merged into a single node, resulting in a merged tree structure. This allows for the utilization of the various nodes in the merged tree structure... The node path performs a recursive key-value pair difference comparison on both sides of the dataset with low time complexity. Furthermore, each node in the merged tree structure is pre-assigned its corresponding comparison rules, eliminating the need for rule lookups during key-value pair difference comparisons and improving comparison efficiency. Additionally, the similarity algorithm for each node in this method allows for customized similarity settings. Developers can define different similarity scores, enabling them to prioritize key-value pairs as primary keys for object-type or numeric key-value pairs. For example, the method includes total similarity calculation and match removal for different parent nodes, preventing the similarity of other key-value pairs in object-type or numeric key-value pairs from affecting the prominence of the key-value pairs being considered, thus meeting developers' needs for key-value pair difference comparisons.

[0039] According to another embodiment of this application, please refer to Figures 3 to 4 and Figure 7 The tree structures of the first data tree and the second data tree are merged to generate a merged tree structure. Each node in the merged tree structure stores the comparison rules corresponding to its key, including the following steps: Step S121: Merge the node paths of each node in the first data tree and the second data tree to generate a merged tree structure that is the union of the node paths of these nodes. Please refer to Figures 3 to 5 , Figure 3 Node 301 in the first data tree shown Figure 4 In the second data tree shown, node 401, node 301, and node 401 share the same node path and have key-value pairs with the same key. Therefore, node 301 and node 401 will be merged as follows: Figure 5 The node 502 in the merged tree structure shown.

[0040] Step S122: Determine the target nodes to which each custom comparison rule in the custom comparison rule set belongs, and store the rule identifiers of the corresponding custom comparison rules in these target nodes. The custom comparison rule set includes custom comparison rules preset for multiple nodes in the first data tree and the second data tree. After obtaining the custom comparison rule set, the target node to which each custom comparison rule belongs will be determined. Specifically, the target node corresponding to each custom comparison rule is determined by the parent node identifier and key identifier contained in each custom comparison rule, so that the rule identifiers of these custom comparison rules are stored in the corresponding target nodes, so that when performing key-value pair difference comparison, the custom comparison rule corresponding to the node can be determined according to the rule identifier of the node.

[0041] Step S123: Obtain the preset default comparison rule, and store the rule identifier of the default comparison rule in the merged tree for nodes that do not have the custom comparison rule: The default comparison rule is generally applied to key-value pairs for which no custom comparison rule is set. The matching algorithm it includes is generally the unordered exact matching algorithm, and the similarity algorithm it includes is generally a similarity algorithm with a similarity score of 1. That is, if the value data of the two key-value pairs being compared are equal, the similarity between the two pairs is 1. By setting a default comparison rule for key-value pairs for which no custom comparison rule is set, the development cost of setting corresponding custom comparison rules for all nodes is reduced.

[0042] In the embodiments disclosed above, by merging the first data tree and the second data tree into a merged tree structure, when comparing key-value pair differences between the first and second data trees, same-level verification and path backtracking can be performed based on the paths of each node in the merged tree structure. Furthermore, the corresponding comparison rules for each node in the merged tree structure can be preset to improve the efficiency of key-value pair difference comparison. Secondly, it can be seen that the comparison rules for each node can be designed by the developers themselves to customize the difference comparison method for each key-value pair and meet the data comparison needs of the developers.

[0043] According to another embodiment of this application, please refer to Figures 3 to 5 and Figure 8 Based on the node paths of the merged tree structure and the matching and similarity algorithms included in its comparison rules, the key-value pairs of nodes at the same level in the first data tree and the second data tree are cross-compared. The matching algorithm identifies comparison groups consisting of two key-value pairs at the same level and their difference types. The similarity of each comparison group is calculated using the similarity algorithm. The process includes the following steps: Step S131: Based on the node path of the merged tree, determine whether the node to be compared has subordinate nodes. If it does, then the subordinate nodes of the node to be compared are taken as the node to be compared. Please refer to Figure 5 ,like Figure 5When node 501 shown is the node to be compared, it will be determined whether node 501 has subordinate nodes, such as... Figure 5 As shown, 501 has subordinate nodes 502, 503 and 504. At this time, any one of the subordinate nodes 502, 503 and 504 will be used as the node to be compared.

[0044] Step S132: Query whether there is a second key-value pair with the same key in the same level of the second data tree for the first key-value pair corresponding to the node to be compared. If not, determine the difference type of the key-value pair as the removal type. Please refer to Figures 3 to 5 ,when Figure 5 When node 509 shown is the node to be compared, obtain the value of node 509 in the comparison. Figure 3 The key-value pair of node 302 in the first data tree shown is "d: "abc"", because in Figure 4 There are no key-value pairs with the same key in the hierarchy of the second data tree shown. Therefore, the difference type of the key-value pair of node 302 shown is the removal type, and the key-value pair of node 302 has been removed in the second data tree.

[0045] Step S133: If the first key value has corresponding pairs of second key values, then based on the matching algorithm and similarity algorithm in the comparison rules of the node to be compared, determine the difference type and similarity between the first key value pair and each second key value pair: Please refer to Figures 3 to 5 ,when Figure 5 When node 502 is the node to be compared, the following will be obtained: Figure 3 The key-value pairs stored in node 301 shown are used as comparison key-value pairs, and... Figure 4 The nodes 401 and 402 shown each have their own first key-value pairs and second key-value pairs. The key-value pair being compared with the first key-value pair forms a first comparison group, while the key-value pair being compared with the second key-value pair forms a second comparison group. Then, according to the comparison rule corresponding to the rule identifier in the lower-level node 502, the matching algorithm in the comparison rule determines whether there is a difference in the value data between the key-value pairs in the first comparison group and the second comparison group. For key-value pairs with different value data, the difference type between the key-value pair and the comparison key-value pair is value difference. The similarity between the comparison key-value pair and the first key-value pair and the second key-value pair is calculated according to the similarity algorithm in the comparison rule. The similarity between key-value pairs with the same value data and the comparison key-value pair will be the similarity set in the similarity algorithm, while the similarity between key-value pairs with different value data and the comparison key-value pair will be 0.

[0046] In completion of the shown Figure 5After comparing the key-value pairs of the lower-level node 502, a key-value pair comparison will be performed on the lower-level node 503 or 504, thus completing the key-value pair comparison process for each lower-level node contained in node 501. Then, the comparison will be performed on... Figure 5 The key-value pair difference comparison is performed on any one of the nodes 508 to 510 in the merged tree structure shown. Generally, the key-value pair difference comparison of each node in the merged tree structure shown is performed from left to right.

[0047] Step S134: If the node to be compared is a key-value pair that corresponds only to the second data tree, then the difference type of the key-value pair is determined as a new type: Please refer to Figures 3 to 5 ,when Figure 5 When node 510 is the node to be compared, since node 510 only exists... Figure 4 In node 403 of the second data tree shown, while Figure 3 Since there is no corresponding node in the first data tree shown, the difference type of the key-value pair corresponding to the node 510 to be compared is a newly added type.

[0048] In the embodiments disclosed above, when comparing key-value pair differences between the first data tree and the second data tree, a recursive key-value pair difference comparison is performed. First, it is determined whether the current node to be compared has a lower-level node. If it does, the lower-level node is used as the benchmark for key-value pair difference comparison. Key-value pairs that only exist in the first data tree are identified as key-value pairs that have been removed from the second data tree. Key-value pairs that only exist in the second data tree are identified as newly added key-value pairs relative to the first data tree. That is, different differences will have corresponding difference types for characterization. The key-value pair difference comparison is performed recursively, resulting in low time complexity.

[0049] According to another embodiment of this application, please refer to Figures 3 to 5 and Figure 9 Starting from the bottom layer of the merged tree structure, comparison groups with value differences within the same layer are identified. Based on the similarity of these comparison groups, the total similarity between the parent nodes of these comparison groups is calculated. Parent nodes with higher total similarity are then transferred to the difference tree, including the following steps: Step S141: Determine the parent nodes of each comparison group whose difference type is value difference in the current level, and use these parent nodes as the parent nodes to be compared: Please refer to Figures 3 to 5 , Figure 3 The key-value pairs of node 301 shown in the first data tree, and Figure 4 The key-value pair of node 401 shown in the second data tree is the first comparison group, and the key-value pair of node 402 is also the first comparison group, and from... Figure 3 and Figure 4 It can be seen that the difference type of the first comparison group is value difference, and the difference type of the second comparison group is also value difference. Therefore, it is necessary to determine the total similarity between the parent nodes of each pair of key-value pairs in the first and second comparison groups, wherein the parent node of node 301 is... Figure 3 The parent node shown is 308, and the parent node of node 401 is... Figure 4 The parent node 408 shown is the parent node of node 402. Figure 4 The parent node 409 is shown. Therefore, it is necessary to calculate the total similarity between parent node 308 and parent node 409. These parent nodes are the parent nodes to be compared.

[0050] Step S142: Determine key-value pairs with the same key in both the first and second parent nodes to be compared, obtain the similarity between these key-value pairs, and calculate the total similarity between the first and second parent nodes based on these similarities. Specifically, the preset similarity in the similarity algorithm for the comparison rule of node 301 is 1, the preset similarity in the similarity algorithm for the comparison rule of node 304 is 0.2, and the preset similarity in the similarity algorithm for the comparison rule of node 305 is also 0.2. In the first comparison group, the similarity between the key-value pairs of node 301 and node 401 is 0, the similarity between the key-value pairs of node 303 and node 404 is 0.2, and the similarity between the key-value pairs of node 304 and node 405 is 0.2. Therefore, the above... The total similarity between level node 308 and its parent node 408 is 0.4 / 3. Correspondingly, the similarity between the key-value pairs of node 301 and node 402 in the second pair of work groups is 0, the similarity between the key-value pairs of node 303 and node 406 is 0, and the similarity between the key-value pairs of node 304 and node 407 is 0. Therefore, the total similarity between parent node 308 and parent node 409 is 0. Step S143, and so on, calculate the total similarity between each of the parent nodes to be compared in the same layer: At this point, it is also necessary to calculate the total similarity between the parent node 309 of node 305 (which shares the same key as node 301) and the parent node 408, as well as between the parent node 309 and each of the parent nodes 309. Specifically, the similarity between the key-value pairs of node 305 and node 401 is 1; the similarity between the key-value pairs of node 306 and node 404 is 0; the similarity between the key-value pairs of node 307 and node 405 is 0. Therefore, the total similarity between the parent node 308 and parent node 408 is 1 / 3. Correspondingly, the similarity between the key-value pairs of node 305 and node 402 is 0; the similarity between the key-value pairs of node 306 and node 406 is 0; and the similarity between the key-value pairs of node 307 and node 408 is 0. The similarity between the key-value pair of node 308 and the key-value pair of node 407 is 0. Therefore, the total similarity between the parent node 308 and the parent node 409 is 0. It can be seen that the parent node 308 is in the same first data tree as the parent node 309, which has the same key-value pair. Therefore, it is also necessary to calculate the total similarity between the parent node 309 and the parent node 408 and the parent node 409 in the second data tree. The total similarity between the parent node 308 and the parent node 408 has been calculated to be 0.4 / 3, the total similarity between the parent node 308 and the parent node 409 is 0, the total similarity between the parent node 309 and the parent node 408 is 1 / 3, and the total similarity between the parent node 309 and the parent node 409 is 0.

[0051] In the embodiments disclosed above, by presetting different similarity values ​​for the similarity algorithms of different lower-level nodes, the key data of the key-value pairs of lower-level nodes with higher similarity values ​​is used as the primary key of their parent node. This allows developers to use the key-value pairs they are primarily interested in as the primary key of the key-value pairs of object types or numeric types when comparing key-value pairs, preventing the similarity of other key-value pairs in object types or numeric types from affecting the prominence of the key-value pairs that need to be focused on, thus meeting the developers' needs for key-value pair difference comparison.

[0052] According to another embodiment of this application, please refer to Figures 3 to 6 and Figure 10 The process of transferring parent nodes with higher overall similarity to the difference tree involves the following steps: Step S141': Identify the parent nodes with the highest total similarity among the current parent nodes in the same layer, and transfer the key-value pairs of both parent nodes and their child nodes to the difference tree. Repeat this process, transferring the key-value pairs of parent nodes and their child nodes to the difference tree one by one. Please refer to Figure 3 , Figure 4 and Figure 6The total similarity between parent node 308 and parent node 408 is calculated to be 0.4 / 3, the total similarity between parent node 308 and parent node 409 is 0, the total similarity between parent node 309 and parent node 408 is 1 / 3, and the total similarity between parent node 309 and parent node 409 is 0. Therefore, the parent node combination with the highest total similarity is 1 / 3 between parent node 309 and parent node 408. Parent node 309 and parent node 408 will be transferred to the difference tree, as follows. Figure 6 The key-value pairs of the child nodes of node 601 shown are as follows: Figure 4 As can be seen from nodes 401, 404, and 405 in the second data tree, for nodes with a difference type of value difference, the key-value pairs of the nodes in the second data tree are generally stored in the difference tree so that the subsequent comparison results can characterize the difference key-value pairs in the second data tree and prevent the comparison results from being too redundant.

[0053] Step S142': Identify the non-transferable parent nodes in the current same level, determine the difference type of the key-value pairs under the parent node corresponding to the first data tree as the removal type, and determine the difference type of the key-value pairs under the parent node corresponding to the second data tree as the addition type: Please refer to Figure 3 and Figure 4 The parent node 309 and parent node 408 are respectively from Figure 3 The first data tree shown is Figure 4 After the second data tree transfer shown, Figure 3 and Figure 4 The total similarity between the remaining parent nodes 308 and 409 is 0. In cases where the total similarity is 0, parent nodes 308 and 409 are generally considered non-transferable parent nodes. Specifically, when the total similarity between any two parent nodes in the same layer is 0, and only these two parent nodes remain in the current layer (e.g., parent nodes 308 and 409), then for parent node 308 in the first data tree, the difference types of its included lower-level nodes can be determined as removal types. For parent node 409 in the second data tree, the difference types of its included lower-level nodes can be determined as addition types. Parent node 308 is considered a non-transferable parent node. Figure 6 The difference tree shown below is for Figure 6 As shown in node 602, the corresponding parent node 409 is transferred to Figure 6 The difference tree shown below is for Figure 6 The node shown is 604.

[0054] In the embodiments disclosed above, parent nodes with high total similarity are identified as matching parent nodes, and parent node groups with value difference as the difference type are transferred to the difference tree. For parent node groups with total similarity of 0 that cannot be transferred, they can be identified as addition or removal type and transferred to the difference tree. Furthermore, the difference comparison results of each key-value pair are enriched by using custom similarity, thereby improving the reference value of the difference comparison results.

[0055] According to another embodiment of this application, please refer to Figure 6 and Figure 11 The comparison results are output, which include each node of the difference tree and its corresponding difference type, including the following steps: Step S151: Determine whether the node to be output in the difference tree has a lower-level node. If not, store the key-value pair of the lower-level node and its difference type in the comparison result. Please refer to Figure 6 ,when Figure 6 When the current output node in the difference tree is node 603, since node 603 does not have any lower-level nodes, the key-value pair "b":1" of node 603 corresponds to the difference type of value difference. Therefore, the key-value pair and the difference type will be used as the data storage value of the mapping relationship in the comparison result.

[0056] Step S152: When the node to be output has subordinate nodes, it is determined whether each subordinate node of the node to be output has a next-next-subordinate node. If none of the subordinate nodes have a next-next-subordinate node, the key-value pairs of these subordinate nodes and their difference types are encapsulated with the node to be output as mapping relationship data, and the mapping relationship data is stored in the comparison result. Please refer to Figure 6 ,when Figure 6 When the current output node in the difference tree is node 602, since node 602 has multiple subordinate nodes, and none of the subordinate nodes have any further subordinate nodes, the key-value pairs of each subordinate node and their corresponding difference types will be obtained. The text of the output mapping relationship data will be as follows: “a_1”:{ "id":1; / / diff:removed "name":"Tom"; / / diff:removed “age”:5; / / diff:removed } Of course, designers in this field can flexibly design the text output format of the comparison results, which will not be elaborated here.

[0057] Step S153, and so on, stores the key-value pairs and their corresponding difference types of all nodes in the difference tree into the comparison result, and then outputs the comparison result: According to steps S151 and S152, the node paths in the difference tree are traversed, and the key-value pairs and difference types of each lower-level node of the upper-level node are encapsulated and combined and stored in the comparison result for output. For nodes that do not have lower-level nodes, they are stored separately in the comparison result for output. In this way, the key-value pairs and their difference types of all nodes in the difference tree are stored in the comparison result to output the comparison result to show the key-value pair differences between the first and second data trees.

[0058] In the embodiments disclosed above, by traversing the path of each node in the difference tree, the key-value pairs of each node in the difference tree and their corresponding difference types are stored in the comparison results for output, which makes it easier for developers to browse the differences in key-value pair data between the first data tree and the second data tree.

[0059] Please see Figure 12 A key-value pair difference comparison device provided to meet one of the purposes of this application includes: a data tree acquisition module 11, used to acquire a first data tree and a second data tree, wherein each node of each data tree stores a single key-value pair, the key-value pair of a lower-level node belongs to the member data of the key-value pair of its upper-level node, and each node in the first data tree and the second data tree has a corresponding comparison rule; a merging tree generation module 12, used to merge the tree structures of the first data tree and the second data tree to generate a merged tree structure, wherein each node in the merged tree structure stores the comparison rule corresponding to its key; and a key-value pair comparison module 13, used to compare the key-value pairs of nodes at the same level in the first data tree and the second data tree based on the comparison rule of each node in the merged tree structure. Cross-comparison: Based on the matching algorithm, comparison groups consisting of two key-value pairs in the same layer and their difference types are matched, and the similarity of each comparison group is calculated based on the similarity algorithm. The parent node transfer module 14 is used to determine the comparison groups in the same layer whose difference type is value difference and which have parent nodes, starting from the bottom layer of the merged tree structure. Based on the similarity of these comparison groups, the total similarity between the parent nodes of these comparison groups is calculated, and the parent nodes with higher total similarity are transferred to the difference tree. The comparison result output module 15 stores the key-value pairs corresponding to the node paths of the key-value pairs whose difference type is added or removed into the difference tree, and then outputs the comparison results representing the difference type of each node in the difference tree based on the difference type of each node.

[0060] According to some embodiments of this application, the merging tree generation module 12 includes: a node merging submodule, used to merge the node paths of each node in the first data tree and the second data tree to generate a merging tree structure of the union of the node paths of these nodes; a custom rule storage submodule, used to determine the target node to which each custom comparison rule in the custom comparison rule set belongs, and store the rule identifier of the corresponding custom comparison rule in these target nodes; and a default rule storage submodule, used to obtain a preset default comparison rule and store the rule identifier of the default comparison rule in the merging tree for nodes that do not have the custom comparison rule.

[0061] According to some embodiments of this application, the key-value pair comparison module 13 includes: a lower-level node judgment submodule, used to determine whether the node to be compared has a lower-level node based on the node path of the merged tree; if so, the lower-level node of the node to be compared is taken as the node to be compared; a second key-value pair query submodule, used to query whether there is a second key-value pair with the same key in the same level of the second data tree for the first key-value pair corresponding to the node to be compared; if not, the difference type of the key-value pair is determined to be a removal type; and a key-value pair comparison submodule, used to determine whether there are corresponding second key-value pairs for the first key-value pair. Based on the matching algorithm and similarity algorithm in the comparison rules of the node to be compared, the difference type and similarity between the first key-value pair and each second key-value pair are determined; the new key-value pair submodule is used to determine the difference type of the key-value pair as a new type if the node to be compared is a key-value pair that only corresponds to the second data tree; the node comparison submodule is used to determine the difference type of the first key-value pair or the second key-value pair of the node to be compared, or to determine the difference type and similarity between the first key-value pair and the second key-value pair of the node to be compared. If the node to be compared is a lower-level node, then the key-value pair comparison is performed on its upper-level node or the lower-level node in the same group.

[0062] According to some embodiments of this application, the parent node transfer module 14 includes: a parent node determination submodule, used to determine the parent nodes of each comparison group whose difference type is value difference in the current level, and to take these parent nodes as parent nodes to be compared; a total similarity determination submodule, used to determine key-value pairs with the same key in both the first parent node to be compared and the second parent node to be compared, to obtain the similarity between these key-value pairs, and to calculate the total similarity between the first parent node to be compared and the second parent node to be compared based on these similarities; and a traversal calculation submodule, used to calculate the total similarity between each of the parent nodes to be compared in the same level in the same way.

[0063] According to some embodiments of this application, the parent node transfer module 14 further includes: a high similarity node transfer submodule, used to determine the parent nodes with the highest total similarity in the current same layer, and transfer the key-value pairs of both parent nodes and their subordinate nodes to the difference tree, and so on, transferring the key-value pairs of paired parent nodes and their subordinate nodes to the difference tree one by one; and a remaining node type determination submodule, used to determine the parent nodes that cannot be transferred in the current same layer, determine the difference type of the key-value pairs under the parent nodes corresponding to the first data tree as the removal type, and determine the difference type of the key-value pairs under the parent nodes corresponding to the second data tree as the addition type.

[0064] According to some embodiments of this application, the comparison result output module 15 further includes: a single node output submodule, used to determine whether the node to be output in the difference tree has a lower-level node; if not, the key-value pair and its difference type of the lower-level node are stored in the comparison result; a node encapsulation storage submodule, used to determine whether each lower-level node of the node to be output has a next-next-lower-level node when the node to be output has a lower-level node; if none of the lower-level nodes have a next-next-lower-level node, the key-value pair and its difference type of these lower-level nodes are encapsulated with the node to be output as mapping relationship data, and the mapping relationship data is stored in the comparison result; and a comparison result generation submodule, used to similarly store the key-value pairs and their difference types of all nodes in the difference tree in the comparison result, and then output the comparison result.

[0065] Another embodiment of this application also provides a key-value pair difference comparison device. For example... Figure 13 As shown, the key-value pair difference comparison device can be implemented by a computer device. This computer device includes a processor, a computer-readable storage medium, a memory, and a network interface connected via a system bus. The computer-readable storage medium stores an operating system, a database, and computer-readable instructions. The database may store control information sequences. When the computer-readable instructions are executed by the processor, the processor can implement a key-value pair difference comparison method. The processor of the computer device provides computing and control capabilities, supporting the operation of the entire computer device. The memory of the computer device may store computer-readable instructions. When these computer-readable instructions are executed by the processor, the processor can execute the key-value pair difference comparison method of this application. The network interface of the computer device is used for communication with a terminal. Those skilled in the art will understand that… Figure 13The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0066] In this embodiment, the processor is used to execute... Figure 13 The memory stores the specific functions of each module, and stores the program code and various data required to execute the above modules or sub-modules. The network interface is used for data transmission between the user terminal and the server. In this embodiment, the memory stores the program code and data required to execute all modules in the key-value pair difference comparison device of this application, and the server can call the server's program code and data to execute the functions of all modules.

[0067] This application also provides a storage medium storing computer-readable instructions, which, when executed by one or more processors, cause the one or more processors to perform the steps of the key-value pair difference comparison method of any embodiment of this application.

[0068] This application also provides a computer program product, including a computer program / instructions that, when executed by one or more processors, implement the steps of the method described in any embodiment of this application.

[0069] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. This computer program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. The aforementioned storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.

[0070] The above description is only a partial embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.

[0071] In summary, this application provides developers with a customizable comparison rule setting service, enabling them to customize key-value pair difference comparison schemes between different data trees, so that the final comparison results can meet the developers' data comparison needs.

Claims

1. A method for comparing key-value pairs, characterized in that, The response results applied to comparing the outputs of the old and new interfaces include the following steps: Obtain a first data tree and a second data tree. The first data tree contains key-value pairs in the response results of the old interface response to the request, and the second data tree contains key-value pairs in the response results of the new interface response to the same request. Each node in each data tree stores a single key-value pair. The key-value pairs of lower-level nodes belong to the member data of the key-value pairs of their upper-level nodes. Each node in the first and second data trees has a corresponding comparison rule, so that when comparing key-value pairs, it is not necessary to query the comparison rule, thereby improving the comparison efficiency of key-value pairs. The tree structures of the first data tree and the second data tree are merged to generate a merged tree structure, in which each node stores the comparison rules corresponding to its key; Based on the node paths of the merged tree structure and the matching algorithm and similarity algorithm included in its comparison rules, the key-value pairs of nodes at the same level in the first data tree and the second data tree are cross-compared. The matching algorithm is used to match the comparison groups composed of two key-value pairs in the same level and their difference types, and the similarity of each comparison group is calculated according to the similarity algorithm. Starting from the bottom layer of the merged tree structure, comparison groups with value differences within the same layer are identified. Based on the similarity of these comparison groups, the total similarity between their parent nodes is calculated. Parent nodes with higher total similarity are then transferred to the difference tree. This includes: identifying the parent nodes of each comparison group with value differences at the current level, and using these parent nodes as parent nodes to be compared; identifying key-value pairs with the same key between the first and second parent nodes to be compared, obtaining the similarity between these key-value pairs, and calculating the similarity between the first and second parent nodes to be compared based on these similarities. Total similarity; and so on, calculate the total similarity between each of the parent nodes to be compared in the same layer; determine the parent nodes with the highest total similarity in the current parent node in the current layer, and transfer the key-value pairs of both parent nodes and their child nodes to the difference tree, and so on, transfer the key-value pairs of parent nodes and their child nodes to the difference tree one by one; determine the parent nodes that cannot be transferred in the current layer, determine the difference type of the key-value pairs under the parent nodes of the first data tree as the removal type, and determine the difference type of the key-value pairs under the parent nodes of the second data tree as the addition type; The remaining key-value pairs with different types are stored in the difference tree, and the comparison result is output. The comparison result includes each node of the difference tree and its corresponding difference type. This comparison result is used to test whether the new interface meets expectations.

2. The method according to claim 1, characterized in that, The tree structures of the first data tree and the second data tree are merged to generate a merged tree structure. Each node in the merged tree structure stores the comparison rules corresponding to its key, including the following steps: Merge the node paths of each node in the first data tree and the second data tree to generate a merged tree structure that is the union of the node paths of these nodes. Identify the target nodes to which each custom comparison rule in the custom comparison rule set belongs, and store the rule identifiers of the corresponding custom comparison rules in these target nodes; Obtain the preset default comparison rule, and store the rule identifier of the default comparison rule in the nodes of the merged tree that do not have the custom comparison rule.

3. The method according to claim 1, characterized in that, Based on the node paths of the merged tree structure and the matching and similarity algorithms included in its comparison rules, the key-value pairs of nodes at the same level in the first data tree and the second data tree are cross-compared. The matching algorithm identifies comparison groups consisting of two key-value pairs at the same level and their difference types. The similarity of each comparison group is calculated using the similarity algorithm. This process includes the following steps: Based on the node path of the merged tree, determine whether the node to be compared has a subordinate node. If it does, then the subordinate node of the node to be compared is taken as the node to be compared. Query whether there is a second key-value pair with the same key in the same level of the second data tree for the first key-value pair corresponding to the node to be compared. If not, the difference type of the key-value pair is determined to be the removal type. If the first key value has corresponding pairs of second key values, then based on the matching algorithm and similarity algorithm in the comparison rules of the node to be compared, the difference type and similarity between the first key value pair and each second key value pair are determined. If the node to be compared is a key-value pair that corresponds only to the second data tree, then the difference type of the key-value pair is determined as a new type.

4. The method according to claim 1, characterized in that, Output the comparison results, which include each node of the difference tree and its corresponding difference type, including the following steps: Determine whether the node to be output in the difference tree has a subordinate node. If not, store the key-value pair of the node to be output and its difference type in the comparison result. When the node to be output has subordinate nodes, it will be determined whether each subordinate node of the node to be output has a next-next-next node. If none of the subordinate nodes have a next-next-next node, the key-value pairs of these subordinate nodes and their difference types are encapsulated with the node to be output as mapping relationship data, and the mapping relationship data is stored in the comparison result. Similarly, the key-value pairs and their corresponding difference types of all nodes in the difference tree are stored in the comparison result, and then the comparison result is output.

5. A key-value pair difference comparison device, characterized in that, The response results used to compare the outputs of the old and new interfaces include: The data tree acquisition module is used to acquire a first data tree and a second data tree. The first data tree contains key-value pair data in the response results output by the old interface response to the request, and the second data tree contains key-value pair data in the response results output by the new interface response to the same request. Each node of each data tree stores a single key-value pair. The key-value pairs of lower-level nodes belong to the member data of the key-value pairs of their upper-level nodes. Each node in the first data tree and the second data tree has a corresponding comparison rule, so that when comparing key-value pair differences, it is not necessary to query the comparison rule, thereby improving the comparison efficiency of key-value pair difference comparison. The merge tree generation module is used to merge the tree structures of the first data tree and the second data tree to generate a merge tree structure. Each node in the merge tree structure stores the comparison rules corresponding to its key. The key-value pair comparison module is used to cross-compare the key-value pairs of nodes at the same level in the first data tree and the second data tree based on the comparison rules of each node in the merged tree structure, match the comparison groups composed of two key-value pairs in the same level and their difference types according to the matching algorithm, and calculate the similarity of each comparison group according to the similarity algorithm. The parent node transfer module is used to determine, starting from the bottom layer of the merged tree structure, comparison groups with value differences at the same level; calculate the total similarity between the parent nodes of these comparison groups based on their similarity; and transfer parent nodes with higher total similarity to the difference tree. This includes: determining the parent nodes of each comparison group with value differences at the current level, and using these parent nodes as parent nodes to be compared; determining key-value pairs with the same key between the first and second parent nodes to be compared, obtaining the similarity between these key-value pairs, and calculating the similarity between the first and second parent nodes to be compared based on these similarities. The total similarity between parent nodes is calculated; similarly, the total similarity between each parent node to be compared in the same layer is calculated; the parent nodes with the highest total similarity with the current parent node in the current layer are identified, and the key-value pairs of both parent nodes and their child nodes are transferred to the difference tree; similarly, the key-value pairs of each pair of parent nodes and their child nodes are transferred to the difference tree; the parent nodes that cannot be transferred in the current layer are identified, and the difference type of the key-value pairs under the parent nodes corresponding to the first data tree is determined as the removal type, and the difference type of the key-value pairs under the parent nodes corresponding to the second data tree is determined as the addition type; The comparison result output module stores the key-value pairs corresponding to the node paths where the difference type is added or removed into the difference tree. Then, based on the difference type of each node in the difference tree, it outputs the comparison result representing the difference type of the nodes. The comparison result is used to test whether the new interface meets the expectations.

6. The key-value pair difference comparison device according to claim 5, characterized in that, The merged tree generation module includes: The node merging submodule is used to merge the node paths of each node in the first data tree and the second data tree to generate a merged tree structure that is the union of the node paths of these nodes. The custom rule storage submodule is used to determine the target nodes to which each custom comparison rule in the custom comparison rule set belongs, and to store the rule identifiers of the corresponding custom comparison rules in these target nodes; The default rule storage submodule is used to obtain the preset default comparison rule and store the rule identifier of the default comparison rule in the merged tree for nodes that do not have the custom comparison rule.

7. The key-value pair difference comparison device according to claim 5, characterized in that, The comparison result output module includes: The single-node output submodule is used to determine whether the node to be output in the difference tree has a subordinate node. If it does not, the key-value pair of the node to be output and its difference type are stored in the comparison result. The node encapsulation and storage submodule is used to determine whether each of the lower-level nodes of the node to be output has a next-next-lower-level node when the node to be output has lower-level nodes. If none of the lower-level nodes have a next-next-lower-level node, the key-value pairs of these lower-level nodes and their difference types are encapsulated with the node to be output as mapping relationship data, and the mapping relationship data is stored in the comparison result. The comparison result generation submodule is used to store the key-value pairs and their corresponding difference types of all nodes in the difference tree into the comparison result, and then output the comparison result.

8. A key-value pair difference comparison device, comprising a central processing unit and a memory, characterized in that, The central processing unit is used to invoke and run a computer program stored in the memory to perform the steps of the method as described in any one of claims 1 to 4.

9. A computer-readable storage medium, characterized in that, It stores, in the form of computer-readable instructions, a computer program implemented according to any one of claims 1 to 4, which, when invoked by a computer, executes the steps included in the corresponding method.

10. A computer program product comprising a computer program / instructions that, when executed by a processor, implement the steps of the method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Hierarchical data comparison and visualized analysis method based on HCT graphs

    CN108427765A

  • Artificial intelligence-based file verification method and device and computer device

    CN109542664A