Node Information Query Method, Device, Equipment, Medium and Program Product
By transforming the query condition format and using a unified separator to establish a query tree, the problem of low efficiency in node information query is solved, and more efficient query speed and space utilization is achieved.
Patent Information
- Application Number
- CN202310095733.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-07
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2043-02-07
AI Technical Summary
In the prior art, node information query efficiency is low, especially when processing a large number of configuration files, the existing query scheme cannot efficiently locate the same or similar locations, resulting in insufficient query efficiency and space efficiency.
Differentiated characters are used to determine the superior and subordinate relationship between the nodes to be queried, and the query condition format is transformed through unified separators, a query tree is established, and the query condition expression is optimized, and the query efficiency and spatial efficiency are improved.
Optimizing query condition expressions through unified separators has significantly improved the time and space efficiency of the query and improved the speed and accuracy of node information query.
Smart Images

Figure CN116049238B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technologies, and particularly to a method, apparatus, device, medium, and program product for querying node information. Background Art
[0002] Some platforms have thousands of components / modules, and each component / module uses a configuration file. There are often intricate relationships between different configuration files, and their structures are relatively similar. To facilitate horizontal and vertical analysis of these configuration files, and quickly locate the same or similar positions in multiple files, a query solution needs to be sorted out.
[0003] In the prior art, generally, all files are traversed one by one according to the corresponding path rules until all matching configuration files and node paths are found. Or by traversing all nodes of all configuration files, storing file names, node path expressions, node names, and other node characteristics in a two-dimensional matrix, and then traversing the two-dimensional matrix. Among them, the two-dimensional matrix can be a two-dimensional array, a database table, an excel table, and other types of storage methods.
[0004] However, in the prior art, the query solution that associates and models the path expression and all configuration files using a two-dimensional table usually has lower query efficiency. Summary of the Invention
[0005] In view of the above problems, the present disclosure provides a method, apparatus, device, medium, and program product for querying node information that improve query efficiency and space efficiency.
[0006] According to a first aspect of the present disclosure, there is provided a method for querying node information, including: obtaining a first query condition, the structural format of the first query condition being established based on a first structural format, the first structural format using differentiated characters to determine the hierarchical relationship between nodes to be queried; transforming the first query condition to obtain a second query condition, the format of the second query condition being established based on a second structural format, the second structural format using a unified delimiter to determine the hierarchical relationship between nodes to be queried; and querying a preset query tree based on the second query condition to obtain query files and corresponding node path information.
[0007] According to an embodiment of the present disclosure, wherein the transforming the first query condition to obtain a second query condition includes: identifying the differentiated characters in the first query condition; and in the case where the differentiated characters match preset special characters, transforming the first structural format into the second structural format through the unified delimiter according to a preset transformation rule.
[0008] According to an embodiment of the present disclosure, when the differentiated character matches a preset special character, the first structure format is transformed into the second structure format by the unified delimiter according to a preset transformation rule, including: separating the preset special character by the unified delimiter to use the preset special character as a node to be queried.
[0009] According to an embodiment of the present disclosure, the method for establishing the preset query tree includes: obtaining a configuration file, where the configuration file includes multiple node path information, and the node path information is composed of multiple nodes and the unified delimiter; based on the unified delimiter, extracting multiple nodes in the node path and storing them in the form of a first array in the order from top to bottom, where the first array includes multiple first element values, and one first element value corresponds to one node; and establishing the preset query tree based on the first element values in the first array in the order from top to bottom.
[0010] According to an embodiment of the present disclosure, the multiple first element values at least include a current first element value and a next first element value, and the preset query tree at least includes a first query node. Establishing the preset query tree based on the first element values in the first array in the order from top to bottom includes: matching the first element value with the first query node in the preset query tree; when the current first element value matches successfully, determining whether the next first element value exists in the child node list of the first query node; when the next first element value does not exist in the first query node, writing the next first element value into the child node list of the first query node; and establishing the child nodes of the first query node based on the next first element value.
[0011] According to an embodiment of the present disclosure, the node at least includes the preset special character.
[0012] According to an embodiment of the present disclosure, the preset query tree at least includes a second query node. Querying the preset query tree based on the second query condition to obtain a query file and corresponding node path information includes: based on the unified delimiter, extracting multiple nodes in the second query condition and storing them in the form of a second array in the order from top to bottom, where the second array includes multiple second element values, and the multiple second element values at least include a current second element value and a next second element value; determining whether the current second element is a wildcard; and when the current second element is a wildcard, obtaining the node path information of all child nodes of the current node corresponding to the current second element value.
[0013] The second aspect of the present disclosure provides a node information query device, including: a first query condition acquisition module, configured to acquire a first query condition, where the structural format of the first query condition is established based on a first structural format, and the first structural format uses differentiated characters to determine the superior-subordinate relationship between nodes to be queried; a format transformation module, configured to transform the first query condition to obtain a second query condition, where the format of the second query condition is established based on a second structural format, and the second structural format uses a unified delimiter to determine the superior-subordinate relationship between nodes to be queried; and a query module, configured to query a preset query tree based on the second query condition to obtain a query file and corresponding node path information.
[0014] According to an embodiment of the present disclosure, the transformation of the first query condition to obtain the second query condition includes: identifying the differentiated characters in the first query condition; and in the case where the differentiated characters match preset special characters, according to a preset transformation rule, transforming the first structural format into the second structural format through the unified delimiter.
[0015] According to an embodiment of the present disclosure, in the case where the differentiated characters match preset special characters, according to a preset transformation rule, transforming the first structural format into the second structural format through the unified delimiter includes: separating the preset special characters through the unified delimiter to use the preset special characters as nodes to be queried.
[0016] According to an embodiment of the present disclosure, the device further includes a query tree establishment module, configured to acquire a configuration file, where the configuration file includes multiple node path information, and the node path information is composed of multiple nodes and the unified delimiter; extracting multiple nodes in the node path based on the unified delimiter and storing them in the form of a first array in the order from top to bottom, where the first array includes multiple first element values, and one first element value corresponds to one node; and establishing the preset query tree based on the first element values in the first array in the order from top to bottom.
[0017] According to an embodiment of the present disclosure, wherein the multiple first element values at least include a current first element value and a next first element value, the preset query tree at least includes a first query node, and establishing the preset query tree based on the first element values in the first array in the order from top to bottom includes: matching the first element value with the first query node in the preset query tree; when the current first element value matches successfully, determining whether the next first element value exists in the child node list of the first query node; when the next first element value does not exist in the first query node, writing the next first element value into the child node list of the first query node; and establishing child nodes of the first query node based on the next first element value.
[0018] According to an embodiment of the present disclosure, wherein the node at least includes the preset special character.
[0019] According to an embodiment of the present disclosure, wherein the preset query tree at least includes a second query node, and querying the preset query tree based on the second query condition to obtain a query file and corresponding node path information includes: extracting multiple nodes in the second query condition based on the unified delimiter and storing them in the form of a second array in the order from top to bottom, where the second array includes multiple second element values, and the multiple second element values at least include a current second element value and a next second element value; determining whether the current second element is a wildcard; and when the current second element is a wildcard, obtaining the node path information of all child nodes of the current node corresponding to the current second element value.
[0020] A third aspect of the present disclosure provides an electronic device, including: one or more processors; a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors are caused to execute the above node information query method.
[0021] A fourth aspect of the present disclosure further provides a computer-readable storage medium, on which executable instructions are stored, and when the instructions are executed by a processor, the processor is caused to execute the above node information query method.
[0022] A fifth aspect of the present disclosure further provides a computer program product, including a computer program, and when the computer program is executed by a processor, the above node information query method is implemented.
[0023] In an embodiment of the present disclosure, the format of the query condition uses a unified delimiter to separate different nodes, and the expression of the query condition is optimized. Compared with the previous non-uniform query condition expressions, the unified query condition expression can greatly improve the query time efficiency and space efficiency when performing conditional queries. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Through the following description of the embodiments of the present disclosure with reference to the accompanying drawings, the above content and other objects, features, and advantages of the present disclosure will become clearer. In the drawings:
[0025] Figure 1 FIG. schematically shows an application scenario diagram of the node information query method according to an embodiment of the present disclosure.
[0026] Figure 2 FIG. schematically shows a flowchart of the node information query method according to an embodiment of the present disclosure.
[0027] Figure 3 FIG. schematically shows a flowchart of the node information query method according to an embodiment of the present disclosure.
[0028] Figure 4 FIG. schematically shows a flowchart of the query tree generation method according to an embodiment of the present disclosure.
[0029] Figure 5A FIG. schematically shows a flowchart of the query tree generation method according to an embodiment of the present disclosure.
[0030] Figure 5B FIG. schematically shows a program logic flowchart of a query tree generation method according to an embodiment of the present disclosure.
[0031] Figure 6 FIG. schematically shows a schematic diagram of a query tree structure according to an embodiment of the present disclosure.
[0032] Figure 7A FIG. schematically shows a schematic diagram of a node query method according to an embodiment of the present disclosure.
[0033] Figure 7B FIG. schematically shows a program logic flowchart of a node query method according to an embodiment of the present disclosure.
[0034] Figure 8 FIG. schematically shows a block diagram of the structure of the node information query device according to an embodiment of the present disclosure.
[0035] Figure 9 FIG. schematically shows a block diagram of an electronic device suitable for implementing the node information query method according to an embodiment of the present disclosure. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0036] Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are merely exemplary and are not intended to limit the scope of the present disclosure. In the following detailed description, for the sake of explanation, numerous specific details are set forth in order to provide a comprehensive understanding of the embodiments of the present disclosure. However, it is obvious that one or more embodiments can also be implemented without these specific details. In addition, in the following description, descriptions of well-known structures and technologies are omitted to avoid unnecessarily obscuring the concepts of the present disclosure.
[0037] The terms used herein are merely for describing specific embodiments and are not intended to limit the present disclosure. The terms "including", "comprising", etc. used herein indicate the presence of the described features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.
[0038] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification and should not be interpreted in an idealized or overly rigid manner.
[0039] In the case of using expressions such as "at least one of A, B, and C, etc.", generally, it should be interpreted according to the meaning commonly understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include, but not be limited to, a system having only A, only B, only C, having A and B, having A and C, having B and C, and / or having A, B, and C, etc.).
[0040] Before revealing the embodiments of the present disclosure in detail, the key technical terms to be used in the embodiments of the present disclosure will be explained one by one:
[0041] Tree: A data structure composed of a set of n (n >= 1) finite nodes with a hierarchical relationship. Each node has zero or at least one child node; a node without a parent node is called a root node; each non-root node has and only has one parent node; except for the root node, each child node can be divided into multiple disjoint subtrees.
[0042] JSON: A format used by JavaScript to process data and later widely used in other languages. Its structure has 2 types: namely, object structure and array structure. Among them, the object structure is enclosed in curly braces "{}", and inside the curly braces are composed of 0 or more "keyword: value" pairs (key: value) separated by English commas. The array structure is enclosed in square brackets "[]", and inside the square brackets is composed of a list of 0 or more values separated by the English comma ",".
[0043] YML: The YML file format is written in YAML (YAML Aint Markup Language). YAML is an intuitive data serialization format that can be recognized by computers, is easy for humans to read, and is easy to interact with scripting languages. It can be imported by different programming language programs that support the YAML library.
[0044] XML: XML stands for Extensible Markup Language, which is designed to transmit and store data. It is the most commonly used tool for data transmission between various applications.
[0045] Node: Nodes are divided into root nodes and ordinary nodes. The root node is the outermost structure. Taking Json as an example, the root node has no (key: value) pair, only child nodes; the ordinary structure has (key: value) pairs. Depending on the type of value, ordinary nodes include: object nodes, array nodes and value nodes. Value nodes have no subordinate nodes.
[0046] For example, {"id": "1", "name": {"firstName": "T", "lastName": "D"}, "scores": [{"Subject": "yu wen", "score": "80"}, {"subject": "Math", "score": "80"}], "hobbies": ["tennis", ""]}.
[0047] in,
[0048] ".id, .firstName, .lastName, .hobbies.[0], .hobbies.[1]" are value nodes
[0049] ".name, .scores.[0], .scores.[1]" is the object node
[0050] ".scores, .hobbies" are array nodes.
[0051] Node path: A path expression used to locate the location of a node in a configuration file. Take Json as an example. For example, for key1 in the JSON structure {"configs":[{"keyl":"valuef}]}, the existing JSON path expression is: .configs[0].key1.
[0052] In the prior art, when searching for a file path, the following method is usually used:
[0053] Method 1: Traverse all files one by one according to the corresponding path rules until all matching configuration files and node paths are found. However, this method has low efficiency.
[0054] Method 2: By traversing all nodes of all configuration files, store the file name, the JSON path expression of the node, the node name, and other node features in a two-dimensional matrix, and then traverse the two-dimensional matrix. This two-dimensional matrix can be stored in the form of a two-dimensional array, a database table, an Excel table, or other storage methods. Similarly, this method has low efficiency.
[0055] Method 3: Use ES for full-text search. However, ES is mainly applicable to full-text search, which is based on word segmentation rather than the structure of the file (for example, JSON structure), requires more additional processing, has the same problem as the hash table structure, has poor space efficiency, and is not portable enough, so it is not applicable to some scenarios.
[0056] To solve the technical problems existing in the prior art, an embodiment of the present disclosure provides a method for querying node information, obtaining a first query condition, the structural format of the first query condition is established based on a first structural format, and the first structural format uses different characters to determine the hierarchical relationship between the nodes to be queried; transform the first query condition to obtain a second query condition, the format of the second query condition is established based on a second structural format, and the second structural format uses a unified delimiter to determine the hierarchical relationship between the nodes to be queried; and query a preset query tree based on the second query condition to obtain query files and corresponding node path information.
[0057] In the embodiment of the present disclosure, the format of the query condition uses a unified delimiter to separate different nodes, and the expression of the query condition is optimized. Compared with the previous non-uniform query condition expressions. The unified query condition expression can greatly improve the query time efficiency and space efficiency when performing conditional queries.
[0058] Figure 1 Schematically shows an application scenario diagram of the node information query method according to an embodiment of the present disclosure.
[0059] As Figure 1 shown, the application scenario 100 according to this embodiment may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, etc.
[0060] Users can use terminal devices 101, 102, and 103 to interact with server 105 via network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, and 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (for example only).
[0061] Terminal devices 101, 102, and 103 can be various electronic devices with a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop computers, desktop computers, and so on.
[0062] Server 105 can be a server providing various services, such as a background management server that supports the websites browsed by users using terminal devices 101, 102, and 103 (for example only). The background management server can analyze and process data such as received user requests, and feedback the processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal device.
[0063] It should be noted that the node information query method provided by the embodiments of the present disclosure can generally be executed by server 105. Correspondingly, the node information query device provided by the embodiments of the present disclosure can generally be set in server 105. The node information query method provided by the embodiments of the present disclosure can also be executed by a server or a server cluster different from server 105 and capable of communicating with terminal devices 101, 102, 103 and / or server 105. Correspondingly, the node information query device provided by the embodiments of the present disclosure can also be set in a server or a server cluster different from server 105 and capable of communicating with terminal devices 101, 102, 103 and / or server 105.
[0064] It should be understood that Figure 1 the numbers of terminal devices, networks, and servers in
[0065] are merely illustrative. According to the implementation requirements, there can be any number of terminal devices, networks, and servers. Figure 1 Based on the Figures 2 to 7B scenario described below, the node information query method of the disclosed embodiments will be described in detail through
[0066] Figure 2 FIG. schematically shows a flowchart of the node information query method according to an embodiment of the present disclosure.
[0067] As Figure 2 shown, the node information query method of this embodiment includes operations S210 to S230, and this node information query method can be executed by server 105.
[0068] In operation S210, a first query condition is obtained. The structural format of the first query condition is established based on a first structural format, and the first structural format uses differentiated characters to determine the hierarchical relationship between nodes to be queried.
[0069] Specifically, the first query condition exists in the form of a path expression of a certain target node and / or certain target nodes. The first structural format adopted by the path expression of this node is generally in the form of "element" + "character" + "element". Among them, an element is a value with a specific meaning, and an element can be regarded as the key value of a certain node in the path expression. Generally, an element can be an English word. For example, an array can be "ID", "configs", or "name". For a character, it is a certain symbol, and this symbol can distinguish different relationships between different elements based on its different expressions. For example, when the character is ".", it can indicate that the relationship between element 1 and element 2 is a hierarchical relationship; or, when the character is "[]", it can indicate that the relationship between element 1 and element 2 is a hierarchical relationship, and element 2 is one of the multiple subordinates of element 1. Through different characters, the relationships between different elements can be expressed differentially and clearly.
[0070] For example, in JSON, when the JSON structure is {"configs": [{"key1": "valuef}]}, in order to represent "Key1" among them, the path expression adopted is.configs[0].keyl. This expression can clearly reflect the relationships between different arrays and different node types. Among them, "configs" is an array node, "configs[0]" is an object node, and "Keyl" is a value node. There are clear, differentiated, and hierarchical relationships between different nodes in the path expression. It should be noted that the above "array" has no association with the above "array node". The above "array" refers to a specific value (for example, the value of node 1 is array 1), and the above "array node" refers to a node type in JSON (for example, the node type of node 1 is an array node).
[0071] In operation S220, the first query condition is transformed to obtain a second query condition. The format of the second query condition is established based on a second structural format, and the second structural format uses a unified delimiter to determine the hierarchical relationship between nodes to be queried.
[0072] Specifically, different from the refined and detailed expression of the first structural format in the first query condition, the second structural format in the second query condition only needs to reflect the hierarchical relationship between different arrays through a unified delimiter. It should be noted that the unified delimiter is preset by the developer and can be, for example, ",", ".", etc. As long as the characters are consistent, it will not be elaborated here.
[0073] It can be understood that there are certain differences in the expression methods of the above-mentioned first structural format and the second structural format. Therefore, certain modifications need to be made to the "characters" and "delimiters".
[0074] Figure 3 Schematically shows a flowchart of a node information query method according to an embodiment of the present disclosure.
[0075] As Figure 3 shown, the node information query method of this embodiment includes operation S310 to operation S320.
[0076] In operation S310, identify the differentiated characters in the first query condition.
[0077] In operation S320, when the differentiated characters match the preset special characters, according to the preset transformation rules, transform the first structural format into the second structural format through the unified delimiter. Among them, the preset transformation rules include addition, deletion, and replacement.
[0078] For example, in JSON, when the JSON structure is {"configs": [{"key1": "valuef}]}, the expression of the first query condition is.configs[0].keyl, and the expression of the second query condition obtained after transforming the original first structural format is.configs.[0].key1. The preset special characters refer to "[]", and the corresponding preset transformation rule is to add "." before "[]" to represent the hierarchical relationship.
[0079] For another example, in JSON, when the JSON structure is {"id": "1", "name": {"firstName": "A", "lastName": "B"}, "scores": [{"subject": "yu wen", "score": "80"}, {"subject": "Math", "score": "80"}], "hobbies": ["tennis", ""]}, in the JSON path expression for describing the JSON node path with an array structure, the described structure is not conducive to the description of the JSON logical hierarchy, increasing the complexity of logical processing. For example, when describing the following JSON information, using the JSON path expression is:.scores[0].subject. It seems to have only two levels like this, but in fact, there should be another level which is an object between scores and subject. In this solution, the JSON node path is expressed as:.scores.[0].subject. This JSON path clearly represents three levels and is more convenient for subsequent data processing in the solution.
[0080] According to an embodiment of the present disclosure, wherein, in the case that the differentiated character matches a preset special character, according to a preset transformation rule, the first structure format is transformed into the second structure format through the unified separator, including: separating the preset special character through the unified separator to use the preset special character as a node to be queried.
[0081] Of course, when the expression of the first query condition is.configs[0].keyl, the expression of the transformed second query condition is.configs.[0].key1. Therefore, in the expression of the transformed second query condition, "[configs[0]]" is not regarded as an array (or the value of a node), but "[]" is regarded as an array (or the value of a node). Therefore, the query condition used for querying the node is not "[configs[0]]" either, but "[]".
[0082] In operation S230, a preset query tree is queried based on the second query condition to obtain a query file and corresponding node path information.
[0083] It should be noted that before revealing the query method in detail, the preset query tree needs to be described. Since the format of the query condition has been transformed, in the embodiments of the present disclosure, the query tree itself has also been correspondingly transformed.
[0084] Figure 4A flowchart of a query tree generation method according to an embodiment of the present disclosure is schematically shown.
[0085] As Figure 4 shown, the query tree generation method of this embodiment includes operations S410 to S430.
[0086] In operation S410, a configuration file is obtained, and the configuration file includes a plurality of node path information, and the node path information is composed of a plurality of nodes and the unified delimiter.
[0087] In operation S420, based on the unified delimiter, a plurality of nodes in the node path are extracted and stored in the form of a first array in the order from top to bottom, where the first array includes a plurality of first element values, and one of the first element values corresponds to one of the nodes.
[0088] Specifically, the above-mentioned first element value refers to the element value used in the process of establishing the query tree, and the following second element value refers to the element value used in the process of querying nodes.
[0089] It can be understood that the path node information is stored in the form of an array after being processed. Among them, there are multiple elements in an array, and each element corresponds to a node name. For example, for.configs.[0].keyl, after being stored in the form of an array, each element therein is respectively "configs", "[]", "key1".
[0090] In operation S430, in the order from top to bottom, based on the first element value in the first array, the preset query tree is established.
[0091] For example, a query tree is established according to the superior-subordinate node order of "configs" -> "[]" -> "key1".
[0092] Figure 5A A flowchart of a query tree generation method according to an embodiment of the present disclosure is schematically shown.
[0093] As Figure 5A shown, the query tree generation method of this embodiment includes operations S510 to S540.
[0094] In operation S510, the first query node in the preset query tree is matched based on the first element value.
[0095] In operation S520, when the current first element value matches successfully, it is determined whether the next first element value exists in the child node list of the first query node.
[0096] In operation S530, when the next first element value does not exist in the first query node, write the next first element value into the child node list of the first query node.
[0097] In operation S540, establish the child nodes of the first query node based on the next first element value.
[0098] Figure 6 A schematic diagram showing a query tree structure according to an embodiment of the present disclosure is schematically illustrated.
[0099] As Figure 6 shown, the query tree node is formed by a JSON file. There is a root node and multiple ordinary nodes in the query book in Figure 6 . Among them, the root node only includes Value, and the ordinary node includes Key and Value. Among them, Key refers to the upper-level node of the current node, and Value is the child node list and the node information table. Among them, the child node list stores the lower-level nodes of the current node, and the node information table stores the node path of the current node.
[0100] According to an embodiment of the present disclosure, wherein the node at least includes the preset special character.
[0101] It can be understood that the preset query tree assigns the preset special character as an array to the query tree node. When querying, there is no need to design corresponding query processes for some special characters, which speeds up the query efficiency.
[0102] As Figure 6 shown, both at the root node and the first-level child node include the "[ ]" node, which is an array node of the original JSON, that is, this node is a preset special character.
[0103] Figure 5B A program logic flowchart of a query tree generation method according to an embodiment of the present disclosure is schematically illustrated.
[0104] Specifically, as Figure 5B shown, Figure 5B Taking JSON as an example, the steps of query tree generation are as follows:
[0105] 1. When traversing each node of the JSON configuration file, record the real path of each accessed node (the array node should carry the subscript, e.g.:.configs.[0].userList.[0].name, which will be stored in the set of the node information table of the corresponding node).
[0106] 2. Then, use the "." dot separator to split the real path into an array, such as configs, [], userList, [], name. It should be noted that in the JSON search tree, the node name will not store array nodes with subscripts. For example, [0] is illegal, while [] is legal.
[0107] 3. Define the root node of the JSON search tree as the current node, and define the first element of the array element as the current element value.
[0108] 4. If the current element value is not in the child node table of the current node, create a node and add it to the child node table of the current node. Otherwise, the existing node becomes the current node.
[0109] 5. The next element of the array becomes the current element value, and the above operations are performed again on the current node, that is, whether the current element value is included in the child node table of the current node. Similarly, this is done in sequence until the node corresponding to the last data value is determined, which is the target node.
[0110] 6. Create a key / value pair in the node information of the target node (if it exists, it will not be created). The key is the current file name, and the value is a set. Add the real path to this list. Similarly, the above operations are completed for all nodes of all configuration files.
[0111] Figure 7A Schematically shows a schematic diagram of a node query method according to an embodiment of the present disclosure.
[0112] As Figure 7A shown, the node query method includes operation S710 to operation S730.
[0113] In operation S710, based on the unified separator, extract multiple nodes in the second query condition and save them in the form of a second array in the order from top to bottom. Wherein, the second array includes multiple second element values, and the multiple second element values at least include the current second element value and the next second element value.
[0114] In operation S720, determine whether the current second element is a wildcard.
[0115] In operation S730, when the current second element is a wildcard, obtain the node path information of all child nodes of the current node corresponding to the current second element value.
[0116] Combined with Figure 6As shown, for example, when the query condition is ".root.config.*", when the wildcard "*" is recognized, all child nodes of the node ".root.config" before the wildcard are obtained.
[0117] In the embodiments of the present disclosure, by splitting the query condition into elements and determining whether there is a wildcard, in the case where an element is a wildcard, all child nodes of the node matching the element before the wildcard are obtained, so that the embodiments of the present disclosure can support wildcard queries.
[0118] Figure 7B Schematically shows a program logic flow chart of a node query method according to an embodiment of the present disclosure.
[0119] Specifically, as Figure 7B shown Figure 7B Taking JSON as an example, the steps of node query are as follows:
[0120] 1. Split the input JSON node path using "." as a separator into an array, such as: [], *, userList.
[0121] 2. Define the root node of the JSON search tree as the current node, and the first element of the array as the current element value.
[0122] 3. If the current element value is the wildcard "*", then all child nodes under the current node are matched, and these child nodes are each defined as the current node. If the current element is not a wildcard, search for it in the child node table of the current node. If not found, directly end the search. If found, define the found child node as the current node.
[0123] 4. Define the next value in the array as the current element value and perform the previous step until the last element in the array finds the node to be matched, which is the target node.
[0124] 5. Return all the contents of the node information table of the target node, that is, the input JSON node path, all the files matched, and the specific paths in these files.
[0125] In the embodiments of the present disclosure, the format of the query condition uses a unified separator to separate different nodes, and the expression of the query condition is optimized. Compared with the previous non-uniform query condition expressions, the unified query condition expression can greatly improve the query time efficiency and space efficiency when performing conditional queries.
[0126] Based on the above node information query method, the present disclosure also provides a node information query device. The following will be combined with Figure 8 to describe this device in detail.
[0127] Figure 8 Schematically shows a structural block diagram of a node information query device according to an embodiment of the present disclosure.
[0128] As Figure 8 shown, the node information query device 800 of this embodiment includes a first query condition acquisition module 810, a format transformation module 820, and a query module 830.
[0129] The first query condition acquisition module 810 is used to acquire a first query condition. The structural format of the first query condition is established based on a first structural format, and the first structural format uses differentiated characters to determine the hierarchical relationship between nodes to be queried. In one embodiment, the first query condition acquisition module 810 may be used to perform the operation S210 described above, which will not be elaborated here.
[0130] The format transformation module 820 is used to transform the first query condition to obtain a second query condition. The format of the second query condition is established based on a second structural format, and the second structural format uses a unified delimiter to determine the hierarchical relationship between nodes to be queried. In one embodiment, the format transformation module 820 may be used to perform the operation S220 described above, which will not be elaborated here.
[0131] The query module 830 is used to query a preset query tree based on the second query condition to obtain a query file and corresponding node path information. In one embodiment, the query module 830 may be used to perform the operation S230 described above, which will not be elaborated here.
[0132] According to an embodiment of the present disclosure, wherein, transforming the first query condition to obtain a second query condition includes: identifying the differentiated characters in the first query condition; and in the case where the differentiated characters match preset special characters, according to a preset transformation rule, transforming the first structural format into the second structural format through the unified delimiter.
[0133] According to an embodiment of the present disclosure, wherein, in the case where the differentiated characters match preset special characters, according to a preset transformation rule, transforming the first structural format into the second structural format through the unified delimiter includes: separating the preset special characters through the unified delimiter to use the preset special characters as nodes to be queried.
[0134] According to an embodiment of the present disclosure, the apparatus further includes a query tree building module, configured to obtain a configuration file, where the configuration file includes a plurality of node path information, and the node path information is composed of a plurality of nodes and the unified delimiter; based on the unified delimiter, extract a plurality of nodes in the node path, and save them in the form of a first array in the order from top to bottom, where the first array includes a plurality of first element values, and one first element value corresponds to one of the nodes; and build the preset query tree based on the first element values in the first array in the order from top to bottom.
[0135] According to an embodiment of the present disclosure, the plurality of first element values at least include a current first element value and a next first element value, and the preset query tree at least includes a first query node. Building the preset query tree based on the first element values in the first array in the order from top to bottom includes: matching the first element value with the first query node in the preset query tree; when the current first element value matches successfully, determining whether the next first element value exists in the child node list of the first query node; when the next first element value does not exist in the first query node, writing the next first element value into the child node list of the first query node; and building a child node of the first query node based on the next first element value.
[0136] According to an embodiment of the present disclosure, the node at least includes the preset special character.
[0137] According to an embodiment of the present disclosure, the preset query tree at least includes a second query node. Querying the preset query tree based on the second query condition to obtain a query file and corresponding node path information includes: based on the unified delimiter, extracting a plurality of nodes in the second query condition, and saving them in the form of a second array in the order from top to bottom, where the second array includes a plurality of second element values, and the plurality of second element values at least include a current second element value and a next second element value; determining whether the current second element is a wildcard; and when the current second element is a wildcard, obtaining the node path information of all child nodes of the current node corresponding to the current second element value.
[0138] According to embodiments of the present disclosure, any combination of the first query condition acquisition module 810, the format transformation module 820, and the query module 830 may be combined and implemented in one module, or any one of them may be split into multiple modules. Alternatively, at least some functions of one or more of these modules may be combined with at least some functions of other modules and implemented in one module. According to embodiments of the present disclosure, at least one of the first query condition acquisition module 810, the format transformation module 820, and the query module 830 may be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on chip, a system on substrate, a system on package, an application specific integrated circuit (ASIC), or any other reasonable way of integrating or packaging circuits, etc., implemented by hardware or firmware, or implemented in any one of the three implementation manners of software, hardware, and firmware, or in any appropriate combination of several of them. Alternatively, at least one of the first query condition acquisition module 810, the format transformation module 820, and the query module 830 may be at least partially implemented as a computer program module, and when the computer program module is run, corresponding functions may be executed.
[0139] Figure 9 Schematically shows a block diagram of an electronic device suitable for implementing the node information query method according to an embodiment of the present disclosure.
[0140] As Figure 9 shown, the electronic device 900 according to an embodiment of the present disclosure includes a processor 901, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 902 or the program loaded from the storage section 908 into the random access memory (RAM) 903. The processor 901 may include, for example, a general microprocessor (such as a CPU), an instruction set processor, and / or a related chipset, and / or a dedicated microprocessor (such as an application specific integrated circuit (ASIC)), etc. The processor 901 may also include on-board memory for caching purposes. The processor 901 may include a single processing unit or multiple processing units for performing different actions of the method flow according to embodiments of the present disclosure.
[0141] In the RAM 903, various programs and data required for the operation of the electronic device 900 are stored. The processor 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. The processor 901 performs various operations of the method flow according to the embodiments of the present disclosure by executing programs in the ROM 902 and / or the RAM 903. It should be noted that the programs may also be stored in one or more memories other than the ROM 902 and the RAM 903. The processor 901 may also perform various operations of the method flow according to the embodiments of the present disclosure by executing programs stored in the one or more memories.
[0142] According to an embodiment of the present disclosure, the electronic device 900 may further include an input / output (I / O) interface 905, and the input / output (I / O) interface 905 is also connected to the bus 904. The electronic device 900 may further include one or more of the following components connected to the I / O interface 905: an input portion 906 including a keyboard, a mouse, etc.; an output portion 907 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage portion 908 including a hard disk, etc.; and a communication portion 909 including a network interface card such as a LAN card, a modem, etc. The communication portion 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to the I / O interface 905 as needed. A removable medium 911, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is mounted on the drive 910 as needed so that a computer program read therefrom is installed into the storage portion 908 as needed.
[0143] The present disclosure also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or may exist separately without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the one or more programs are executed, the method according to the embodiments of the present disclosure is implemented.
[0144] According to an embodiment of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, for example, it may include but is not limited to: portable computer disks, hard disks, random access memories (RAMs), read-only memories (ROMs), erasable programmable read-only memories (EPROMs or flash memories), portable compact disk read-only memories (CD-ROMs), optical storage devices, magnetic storage devices, or any suitable combination of the above. In the present disclosure, the computer-readable storage medium may be any tangible medium that contains or stores a program, and this program can be used by or in combination with an instruction execution system, device, or apparatus. For example, according to an embodiment of the present disclosure, the computer-readable storage medium may include the above-described ROM 902 and / or RAM 903 and / or one or more memories other than ROM 902 and RAM 903.
[0145] An embodiment of the present disclosure further includes a computer program product, which includes a computer program that contains program code for executing the method shown in the flowchart. When the computer program product runs in a computer system, the program code is used to enable the computer system to implement the item recommendation method provided by the embodiment of the present disclosure.
[0146] When the computer program is executed by the processor 901, it executes the above functions defined in the system / apparatus of the embodiment of the present disclosure. According to an embodiment of the present disclosure, the above-described systems, apparatuses, modules, units, etc. can be implemented by computer program modules.
[0147] In one embodiment, the computer program can rely on tangible storage media such as optical storage devices and magnetic storage devices. In another embodiment, the computer program can also be transmitted and distributed in the form of a signal on a network medium, and is downloaded and installed through the communication part 909, and / or installed from the removable medium 911. The program code contained in the computer program can be transmitted by any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0148] In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 909, and / or installed from the removable medium 911. When the computer program is executed by the processor 901, it executes the above functions defined in the system of the embodiment of the present disclosure. According to an embodiment of the present disclosure, the above-described systems, devices, apparatuses, modules, units, etc. can be implemented by computer program modules.
[0149] According to embodiments of the present disclosure, program code for executing the computer programs provided by the embodiments of the present disclosure can be written in any combination of one or more programming languages. Specifically, these computing programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. The programming languages include, but are not limited to, programming languages such as Java, C++, Python, the "C" language, or similar programming languages. The program code can be executed entirely on the user's computing device, partially on the user's device, partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device can be connected to the user's computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (for example, by using an Internet service provider to connect through the Internet).
[0150] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram can represent a module, a program segment, or a part of code that contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks can occur in a different order than that marked in the accompanying drawings. For example, two consecutive blocks shown can actually be executed substantially in parallel, and they can sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, and combinations of blocks in the block diagram or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0151] Those skilled in the art can understand that the features recited in the various embodiments and / or claims of the present disclosure can be combined or combined in various ways, even if such combinations or combinations are not explicitly recited in the present disclosure. In particular, without departing from the spirit and teachings of the present disclosure, the features recited in the various embodiments and / or claims of the present disclosure can be combined and combined in various ways. All such combinations and / or combinations fall within the scope of the present disclosure.
[0152] The embodiments of the present disclosure have been described above. However, these embodiments are for illustrative purposes only and are not intended to limit the scope of the present disclosure. Although the embodiments have been described separately above, this does not mean that the measures in each embodiment cannot be used advantageously in combination. The scope of the present disclosure is defined by the appended claims and their equivalents. Without departing from the scope of the present disclosure, those skilled in the art can make various substitutions and modifications, and all such substitutions and modifications should fall within the scope of the present disclosure.
Claims
1. A method for querying node information, characterized in that, The method includes: Obtaining a first query condition, the structural format of the first query condition is established based on a first structural format, and the first structural format uses differentiated characters to determine the hierarchical relationship between nodes to be queried; Transforming the first query condition to obtain a second query condition, the format of the second query condition is established based on a second structural format, and the second structural format uses a unified delimiter to determine the hierarchical relationship between nodes to be queried; and Querying a preset query tree based on the second query condition to obtain a query file and corresponding node path information; Wherein, the preset query tree at least includes a second query node, The querying the preset query tree based on the second query condition to obtain a query file and corresponding node path information includes: Based on the unified delimiter, extracting multiple nodes in the second query condition and saving them in the form of a second array in the order from top to bottom, wherein the second array includes multiple second element values, and the multiple second element values at least include a current second element value and a next second element value; Determining whether the current second element is a wildcard; and When the current second element is a wildcard, obtaining the node path information of all child nodes of the current node corresponding to the current second element value.
2. The method according to claim 1, wherein The transforming the first query condition to obtain a second query condition includes: Identifying the differentiated characters in the first query condition; and When the differentiated characters match preset special characters, transforming the first structural format into the second structural format according to preset transformation rules through the unified delimiter.
3. The method according to claim 2, wherein The when the differentiated characters match preset special characters, transforming the first structural format into the second structural format according to preset transformation rules through the unified delimiter includes: Separating the preset special characters through the unified delimiter to use the preset special characters as nodes to be queried.
4. The method according to claim 3, wherein, The method for establishing the preset query tree includes: Obtaining a configuration file, the configuration file includes multiple node path information, and the node path information is composed of multiple nodes and the unified delimiter; Based on the unified delimiter, extracting multiple nodes in the node path and saving them in the form of a first array in the order from top to bottom, wherein the first array includes multiple first element values, and one first element value corresponds to one node; and Establishing the preset query tree in the order from top to bottom based on the first element values in the first array.
5. The method according to claim 4, wherein, The multiple first element values at least include a current first element value and a next first element value, and the preset query tree at least includes a first query node, The establishing the preset query tree in the order from top to bottom based on the first element values in the first array includes: Matching the first query node in the preset query tree based on the first element value; When the current first element value matches successfully, determine whether the next first element value exists in the list of child nodes of the first query node; When the next first element value does not exist in the first query node, write the next first element value into the list of child nodes of the first query node; and Based on the next first element value, establish child nodes of the first query node.
6. The method according to claim 4 or 5, wherein, The node at least includes the preset special characters.
7. A node information query device, characterized in that, The device includes: A first query condition acquisition module, configured to acquire a first query condition, the structural format of the first query condition is established based on a first structural format, and the first structural format uses different characters to determine the superior-subordinate relationship between query nodes to be queried; A format transformation module, configured to transform the first query condition to obtain a second query condition, the format of the second query condition is established based on a second structural format, and the second structural format uses a unified delimiter to determine the superior-subordinate relationship between query nodes to be queried; and A query module, configured to query a preset query tree based on the second query condition to obtain a query file and corresponding node path information; Wherein, the preset query tree at least includes second query nodes, The querying the preset query tree based on the second query condition to obtain a query file and corresponding node path information includes: Based on the unified delimiter, extract multiple nodes in the second query condition and save them in the form of a second array in the order from top to bottom, where the second array includes multiple second element values, and the multiple second element values at least include a current second element value and a next second element value; Determine whether the current second element is a wildcard; and When the current second element is a wildcard, obtain the node path information of all child nodes of the current node corresponding to the current second element value.
8. An electronic device, including: One or more processors; A storage device, configured to store one or more programs, Wherein, when the one or more programs are executed by the one or more processors, the one or more processors are caused to execute the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, on which executable instructions are stored, and when the instructions are executed by a processor, the processor is caused to execute the method according to any one of claims 1 to 6.
10. A computer program product, including a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Method and device for key value data query
CN103246659A
Database query method and device, storage medium and electronic equipment
CN114996554A