A data query method and device

By using preset interfaces and parsing strategies in the CMDB to generate a data query syntax tree and convert it into internal query statements, the problem of inflexible query functionality is solved, achieving more efficient query capabilities and lower risk of exposing internal implementation details.

CN116361310BActive Publication Date: 2025-12-19NETSUNION CLEARING CORP
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111614124.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-27
Publication Date
2025-12-19
Estimated Expiration
2041-12-27

AI Technical Summary

Technical Problem

Existing configuration management databases (CMDBs) have issues with the flexibility of data query functionality.

Method used

The system receives data query requests through a preset interface, generates a data query syntax tree using a preset parsing strategy, and converts it into an internal query statement for querying, thus avoiding exposing the internal implementation to the outside world.

Benefits of technology

It improves the flexibility and capability of database queries, meets the needs of different business scenarios, and reduces the risk of exposing internal implementations to the outside world.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116361310B_ABST
    Figure CN116361310B_ABST
Patent Text Reader

Abstract

The application discloses a data query method and device, the method is executed by a database application server, wherein the method comprises the following steps: receiving a data query request through a preset interface, the data query request matches an external query semantic predefined in the preset interface; analyzing the data query request by using a preset analysis strategy to obtain a data query syntax tree; generating an internal query statement according to the data query syntax tree; and performing data query according to the internal query statement to obtain a data query result. The data query method of the application uses the preset interface with the defined external query semantic to uniformly receive the external query request, avoids exposing the internal implementation of the data query to the outside, is more flexible, improves the query capability of the database query interface, and meets the requirements of different business scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of database, and particularly relates to a data query method and device. BACKGROUND

[0002] A configuration management database (CMDB) is a logical database containing information of a configuration item throughout its life cycle and relationships between configuration items, including physical relationships, real-time communication relationships, non-real-time communication relationships and dependency relationships.

[0003] With the continuous rise of business, the scale of data centers gradually expands, and the CMDB plays an important role in the management of infrastructure information. The CMDB can manage all infrastructure data of multiple data centers, such as racks, servers, switches, applications, virtual machines and the like.

[0004] However, the existing CMDB has problems such as inflexible query mode and inability to meet relatively complex query scenarios when providing data query functions. SUMMARY

[0005] Embodiments of the present application provide a data query method and device to improve the flexibility of database query and the query ability of the database.

[0006] Embodiments of the present application adopt the following technical solutions:

[0007] In a first aspect, the embodiments of the present application provide a data query method executed by a database application server, wherein the method comprises:

[0008] receiving a data query request through a preset interface, wherein the data query request matches an external query semantic predefined in the preset interface;

[0009] analyzing the data query request by using a preset analysis strategy to obtain a data query syntax tree;

[0010] generating an internal query statement according to the data query syntax tree;

[0011] performing data query according to the internal query statement to obtain a data query result.

[0012] Optionally, the data query request is a basic query request in json format, the data query syntax tree is a basic query syntax tree, and the analyzing the data query request by using a preset analysis strategy to obtain a data query syntax tree comprises:

[0013] The base query request is parsed by using a base query parser for a json format to obtain the base query syntax tree.

[0014] Optionally, the base query request is a request for querying configuration item information in a configuration management database, a structure of the base query syntax tree is defined according to attributes of configuration items in the configuration management database, and the base query request is parsed by using the base query parser for the json format to obtain the base query syntax tree, and the base query syntax tree includes:

[0015] The structure of the base query syntax tree is defined according to attributes of configuration items in the configuration management database;

[0016] The base query request is parsed by using the base query parser for the json format based on the structure of the base query syntax tree to obtain the base query syntax tree;

[0017] The structure of the base query syntax tree includes query conditions of a base query item, the query conditions of the base query item include field conditions and logic conditions, and the field conditions include at least one of a matching condition, a full-equality condition, a range condition, an interval condition, and a regular expression condition.

[0018] Optionally, the generating the internal query statement according to the data query syntax tree includes:

[0019] The base query syntax tree is converted into the internal query statement by using a syntax converter, the internal query statement includes an SQL query statement or an Elasticsearch query statement, and the syntax converter is configured based on a visitor mode.

[0020] Optionally, the data query request is a correlation query request, the data query syntax tree is a correlation query syntax tree, and the generating the internal query statement according to the data query syntax tree includes:

[0021] The internal query statements of multiple correlation query items are generated according to the correlation query syntax tree;

[0022] The data query according to the internal query statement to obtain a data query result includes:

[0023] The internal query statements of the multiple correlation query items are recursively queried to obtain query results of the multiple correlation query items;

[0024] The query results of the multiple correlation query items are associated to obtain a correlation query result.

[0025] Optionally, the internal query statement comprises a query condition, and the recursive querying according to the plurality of internal query statements comprises:

[0026] querying data according to the query condition of the current associated query item to obtain a query result of the current associated query item;

[0027] combining the query condition of the current associated query item with a query condition of a next associated query item according to the query result of the current associated query item to obtain a combined query condition;

[0028] querying data according to the combined query condition to obtain a query result of the next associated query item.

[0029] Optionally, after obtaining the query result of the current associated query item, the method further comprises:

[0030] determining a data amount of the current associated query item according to the query result of the current associated query item;

[0031] in a case where the data amount of the current associated query item is less than a preset data amount threshold, combining the query condition of the current associated query item with the query condition of the next associated query item according to the query result of the current associated query item to obtain a combined query condition;

[0032] in a case where the data amount of the current associated query item is not less than the preset data amount threshold, directly querying data according to the query condition of the next associated query item to obtain a query result of the next associated query item.

[0033] Optionally, the associated query syntax tree comprises an association relationship, an association expression and an association type, the association relationship comprises an associated query item, a query condition of the associated query item and an associated list, the query condition of the associated query item comprises a field condition and a logic condition, and the field condition comprises at least one of a matching condition, a full-equality condition, a range condition, an interval condition and a regular expression condition.

[0034] Optionally, the method further comprises:

[0035] providing a front-end page;

[0036] the receiving of the data query request through the preset interface comprises:

[0037] the preset interface is called through the front-end page, so that the data query request is received through the preset interface.

[0038] In a second aspect, the embodiments of the present application further provide a data query apparatus applied to a database application server, wherein the apparatus is configured to implement any of the foregoing methods.

[0039] In a third aspect, the embodiments of the present application further provide an electronic device, comprising:

[0040] a processor; and

[0041] a memory arranged to store computer-executable instructions that, when executed, cause the processor to implement any of the foregoing methods.

[0042] In a fourth aspect, the embodiments of the present application further provide a computer-readable storage medium storing one or more programs, which, when executed by an electronic device comprising a plurality of applications, cause the electronic device to implement any of the foregoing methods.

[0043] The above at least one technical solution adopted by the embodiments of the present application can achieve the following beneficial effects: The data query method of the embodiments of the present application is executed by a database application server. When data query is performed, a data query request is first received through a preset interface, and the data query request matches an externally defined query semantic in the preset interface. The data query request is parsed using a preset parsing strategy to obtain a data query syntax tree. An internal query statement is generated according to the data query syntax tree. Data query is performed according to the internal query statement to obtain a data query result. The data query method of the embodiments of the present application uses a preset interface with an externally defined query semantic to uniformly receive external query requests, avoids exposing the internal implementation of data query to the outside, is more flexible, improves the query capability of the database query interface, and meets the needs of different business scenarios. BRIEF DESCRIPTION OF DRAWINGS

[0044] The accompanying drawings, which are included to provide a further understanding of the present application, constitute a part of the present application and illustrate the illustrative embodiments of the present application and their description serve to explain the present application, and do not constitute improper limitations on the present application. In the drawings:

[0045] Figure 1 FIG. 1 is a flowchart of a data query method according to an embodiment of the present application;

[0046] Figure 2 FIG. 2 is a structural diagram of a basic query syntax tree according to an embodiment of the present application;

[0047] Figure 3 FIG. 3 is a structural diagram of an associated query syntax tree according to an embodiment of the present application;

[0048] Figure 4 FIG. 4 is a basic query flowchart according to an embodiment of the present application;

[0049] Figure 5 A flowchart of an association query process in an embodiment of the present application

[0050] Figure 6 A structural diagram of a data query device in an embodiment of the present application

[0051] Figure 7 A structural diagram of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION

[0052] To make the objectives, technical solutions, and advantages of the present application clearer, the following will be a clear and complete description of the technical solutions of the present application in conjunction with the embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of protection of the present application.

[0053] The following will be a detailed description of the technical solutions provided by the embodiments of the present application in conjunction with the drawings.

[0054] The query function provided by the existing configuration management database has the following problems:

[0055] 1) Lack of query semantics, the common query method only supports the "and" relationship of multiple field values;

[0056] 2) Lack of association query semantics, the association relationship description is complex and not flexible. In actual business scenarios, business association queries are often more, such as association queries between virtual machines, servers, and applications to obtain application resource information. Therefore, the existing method cannot meet the query needs of different business scenarios.

[0057] 3) SQL structured query language is used as the query semantics, which is too flexible and complex, and will expose the internal implementation, at the same time, it will fall into the trap of binding relationship data, and is not suitable for document type data query.

[0058] Based on this, the embodiments of the present application provide a data query method, which is executed by a database application server, as shown in Figure 1 The present application provides a flowchart of a data query method in an embodiment of the present application, which includes at least the following steps S110 to S140:

[0059] Step S110, receiving a data query request through a preset interface, wherein the data query request matches the external query semantics predefined in the preset interface.

[0060] The data query method of the embodiment of the application can be executed by a database application server. The database can refer to a configuration management database, and can also be other databases providing query functions, which are not limited herein.

[0061] The embodiment of the application preconfigures a preset interface for receiving a data query request. The preset interface has pre-defined external query semantics. The data query request needs to match the pre-defined external query semantics. The external query semantics can be understood as a syntax structure or format of data query pre-defined for different types of data query scenarios. The external query semantics can meet the associated query requirements in different business scenarios. The query application exposes a unified form of the preset interface to users or other query applications. The query party can implement associated query without paying attention to the internal implementation of the interface, which is more flexible and reduces the risk of exposing the internal implementation of the data query.

[0062] When performing data query, the data query request can be received through the preset interface. The data query request refers to a request for querying item information in the database. For example, a user requests to query specific configuration information of application A and application B. Application A and application B can be regarded as query items in the data query request.

[0063] In step S120, a preset analysis strategy is used to analyze the data query request to obtain a data query syntax tree.

[0064] After receiving the data query request, the query information carried in the data query request needs to be parsed by using a preset analysis strategy to identify the internal syntax structure corresponding to the data query request, so as to convert the data query request into a data query syntax tree. The structure of the data query syntax tree can clearly and accurately determine the internal execution logic of the entire data query process, thereby improving the query efficiency and the query accuracy.

[0065] In step S130, an internal query statement is generated according to the data query syntax tree.

[0066] After obtaining the data query syntax tree, the data query syntax tree needs to be converted into an internal query statement executable in the database. The internal query statement is only obtained in the internal implementation of the data query and is not exposed to the outside, so the risk is lower and more flexible.

[0067] In step S140, data query is performed according to the internal query statement to obtain a data query result.

[0068] After obtaining the internal query statement, data query can be performed in the database according to the internal query statement to obtain a data query result.

[0069] The data query method of the embodiment of the application receives an external query request by using a preset interface with defined external query semantics, avoids exposing the internal implementation of data query to the outside, is more flexible, improves the query capability of the database query interface, and meets the needs of different business scenarios.

[0070] In an embodiment of the application, the data query request is a basic query request in json format, and the data query syntax tree is a basic query syntax tree. The step of parsing the data query request by using a preset parsing strategy to obtain a data query syntax tree includes: parsing the basic query request by using a basic query parser for json format to obtain the basic query syntax tree.

[0071] An application scenario of the embodiment of the application can be a basic query scenario, that is, querying the specific information of some query items, for example, querying the specific configuration information of applications A and B. Therefore, the above data query request can refer to a basic query request in json format, and the data query syntax tree can refer to a basic query syntax tree.

[0072] In the basic query scenario, the pre-defined external query semantics of the embodiment of the application can be in json format. Before parsing the basic query request by using a preset parsing strategy, a basic query parser can be configured based on the json format. The basic query parser is deployed in the storage layer of the database and can convert the json message carried in the basic query request into a basic query syntax tree.

[0073] The json message can be regarded as being composed of a json string. The configuration of the specific parameters in the json message can be defined according to actual business needs. For example, for a CMDB database, the configuration can include the configuration item name of the query and the query condition of the configuration item. Since the basic query parser is deployed in the storage layer of the database, the json message format used externally does not expose the internal implementation logic, isolates the presentation layer from the storage layer, provides a basis for subsequent optimization and modification of the database storage layer, and greatly reduces the risk of exposing the internal query semantics to the outside compared with the SQL query semantic method.

[0074] In an embodiment of the present application, the basic query request refers to a request for querying configuration item information in a configuration management database, the structure of the basic query syntax tree is defined according to attributes of the configuration items in the configuration management database, and the basic query request is parsed by using the basic query parser for the json format to obtain the basic query syntax tree, which includes defining the structure of the basic query syntax tree according to the attributes of the configuration items in the configuration management database, and parsing the basic query request by using the basic query parser for the json format based on the structure of the basic query syntax tree to obtain the basic query syntax tree, wherein the structure of the basic query syntax tree includes query conditions of a basic query item, the query conditions of the basic query item include field conditions and logical conditions, and the field conditions include at least one of a matching condition, a full-equality condition, a range condition, an interval condition, and a regular expression condition.

[0075] The basic query request of the embodiment of the present application can be a request for querying configuration item CI (Configuration Item) information in a CMDB database. CI is a general term for objects managed in a CMDB. For example, a server, a department, or a business system can be designed as a CI for configuration management, and the hardware configuration information of a server or the IP address of a device can be understood as specific attributes of the configuration item.

[0076] When the basic query request is parsed by using the basic query parser, the structure of the basic query syntax tree can be defined according to the attributes of the configuration items in the CMDB database, as shown in Figure 2 An example of the structure of the basic query syntax tree in the embodiment of the present application is provided.

[0077] As can be seen from Figure 2 , the structure of the basic query syntax tree in the embodiment of the present application is mainly defined according to the attributes of the configuration items in the configuration management database, and can be specifically composed of query conditions of the configuration items, which can specifically include field conditions FieldConditon and logical conditions such as OrConditon, AndConditon, NotConditon, etc. The field conditions include a matching condition MatchConditon, a full-equality condition EqualsConditon, a range condition InConditon, an interval condition RangeConditon, a regular expression condition RegexConditon, and the like. Different query conditions can be nested. The specific query conditions can be further expanded by those skilled in the art according to actual business requirements.

[0078] Based on the above basic query syntax tree structure, the query information carried in the basic query request is parsed by using the above json format basic query parser, and the parsed result is filled into the structure of the above basic query syntax tree, so that the final basic query syntax tree is obtained.

[0079] In an embodiment of the present application, the generating an internal query statement according to the data query syntax tree comprises: converting the basic query syntax tree into the internal query statement by using a syntax converter, wherein the internal query statement comprises a SQL query statement or an Elasticsearch query statement; and the syntax converter is configured based on a visitor mode.

[0080] When the query condition of the current associated query item is converted into a preset query statement by using a preset syntax conversion strategy, a syntax converter can be first constructed based on a visitor (Vistor) mode. The visitor mode can perform some operations on the parsed query syntax tree as shown in Figure 2 Therefore, the syntax converter constructed based on the Vistor mode can convert the query condition of each configuration item in the query syntax tree structure into an internal query statement by traversing.

[0081] The above internal query statement can be a SQL query statement. Compared with the existing way of implementing SQL query by directly designing SQL query semantics, the present application does not need to directly use SQL as the query semantics by using a unified preset interface, but obtains the SQL query statement by syntax conversion to achieve the query effect of SQL query, reduces the complexity of query semantic design, and avoids the risk of exposing the SQL query statement.

[0082] In addition to being converted into a SQL query statement, it can also be converted into an Elasticsearch query statement, so as to support the query of document data. Of course, the specific form of the query statement can be selected flexibly by a person skilled in the art according to actual needs, and is not limited here.

[0083] In an embodiment of the present application, the data query request is an associated query request, the data query syntax tree is an associated query syntax tree, and the generating an internal query statement according to the data query syntax tree comprises: generating internal query statements of a plurality of associated query items according to the associated query syntax tree; and the performing data query according to the internal query statement to obtain a data query result comprises: performing recursive query according to the internal query statements of the plurality of associated query items to obtain query results of the plurality of associated query items; and performing associated calculation on the query results of the plurality of associated query items to obtain an associated query result.

[0084] An application scenario of an embodiment of the present application can also be an association query scenario, that is, querying the association relationship between different query items, and therefore the data query request described above can be an association query request, and the data query syntax tree can be an association query syntax tree. For example, querying which servers application A is deployed on, and then the application and the server can be regarded as two association query items.

[0085] In the association query scenario, the association query parser can also be configured based on the json format first, and the association query parser is deployed in the storage layer of the database and can convert the json message carried in the association query request into an association query syntax tree.

[0086] The association query items involved in the association query syntax tree obtained by conversion are multiple, and the syntax converter constructed by the foregoing embodiment can convert the conditions of each association query item involved in the association query syntax tree into an internal query statement corresponding to each association query item, and then recursively query the internal query statements of the multiple association query items one by one, so as to obtain the query result of each association query item, and finally, according to the association field and the association type and other information in the association query syntax tree, the query results of the association query items are associated and calculated to obtain the final association query result.

[0087] For example, if the servers associated with application A are to be queried, then two association query items of the application and the server are involved, and an internal query statement of each association query item can be generated for querying, and then the internal query statement of each association query item is executed respectively, so as to obtain the query result of each association query item, and finally, the query results of the two are matched with each other, so as to determine which servers application A is deployed on.

[0088] In an embodiment of the present application, the internal query statement includes a query condition, and the recursive querying according to the multiple internal query statements to obtain the query results of the multiple internal query statements includes: querying data according to the query condition of the current association query item to obtain the query result of the current association query item; combining the query condition of the current association query item with the query condition of the next association query item to obtain a combined query condition according to the query result of the current association query item; and querying data according to the combined query condition to obtain the query result of the next association query item.

[0089] The internal query statement of the association query item can specifically include a query condition of the association query item. In the association query scenario, the query condition of each association query item is necessary, that is, the association query result obtained under the condition of simultaneously satisfying the query condition of each association query item is correct, which leads to a problem that the above-mentioned embodiment may face in the actual application scenario, that is, the query condition of the multiple association query items is recursively queried, and then the query result of each association query item is associated and calculated. In the case that the data quantity of the query result of the current association query item is very small and the data quantity of the next association query item is large, if the query condition is still executed respectively, the query work of the current association query item obviously consumes a large amount of unnecessary resources, because only a small part of the query result of the next association query item with a large data quantity may satisfy the query condition of the current association query item. Therefore, this query mode may have the problems of low efficiency and waste of server resources.

[0090] Based on this, the embodiment of the present application can dynamically adjust the query condition of the next association query item according to the query result of the current association query item when recursively querying the query condition of the multiple association query items. Specifically, after obtaining the query result of the current association query item, the query condition of the current association query item is attached to the query condition of the next current association query item, so as to obtain a new query condition, and then the query result of the next current association query item is obtained by executing the new query condition.

[0091] For example, if it is required to query which servers the application A, the application B and the application C are respectively deployed on, the query condition of the current current association query item can be set as the application name A or B or C, and the query condition of the next current association query item can be set as the server information containing the application A or the application B or the application C in the application configuration information on the basis of the original application configuration information of all the servers. In this way, by increasing the query condition of the attribute corresponding to the application, the query of all the server information is avoided, which can save the calculation cost and reduce the query result set.

[0092] It should be noted that if the query result of the association query item finally obtained by the above-mentioned dynamic adjustment of the query condition has considered the query condition of each previous association query item, the query result can be directly used as the final association query result, without the need of associating and calculating the query result of each previous association query item.

[0093] In an embodiment of the present application, after obtaining the query result of the current associated query item, the method further comprises: determining the data volume of the current associated query item according to the query result of the current associated query item; in the case that the data volume of the current associated query item is less than a preset data volume threshold, combining the query condition of the current associated query item with the query condition of the next associated query item according to the query result of the current associated query item to obtain the combined query condition; in the case that the data volume of the current associated query item is not less than the preset data volume threshold, directly performing data query according to the query condition of the next associated query item to obtain the query result of the next associated query item.

[0094] As can be seen from the above embodiments, by dynamically adjusting the query condition, the computing resources can be saved in some cases and the query efficiency can be improved. However, when the data volume in the query result of the current associated query item is large, it is not very necessary to query the next associated query item by using the data volume as additional query condition.

[0095] Based on this, in order to meet the actual needs of different scenarios, the embodiments of the present application can determine the data volume in the query result of the current associated query item. If the data volume of the current associated query item is not large, for example, less than a preset data volume threshold of 100, the attribute information of the current associated query item can be added as additional query condition to the query condition of the next associated query item, so as to narrow the query range and improve the query efficiency. If the data volume of the current associated query item is large, for example, equal to or greater than the preset data volume threshold, the original query condition can be directly executed for the next associated query item, and there is no need to add the query condition of the current associated query item. The size of the preset data volume threshold can be flexibly adjusted according to the actual business scenario, which is not limited here.

[0096] In an embodiment of the present application, the associated query syntax tree comprises an association relationship, an association expression and an association type, the association relationship comprises an associated query item, a query condition of the associated query item and an association list, the query condition of the associated query item comprises a field condition and a logic condition, and the field condition comprises at least one of a matching condition, a full condition, a range condition, an interval condition and a regular expression condition.

[0097] As shown in FIG. 1, Figure 3 As shown in FIG. 1, a structure diagram of an associated query syntax tree in an embodiment of the present application is provided, and the associated query syntax tree in the embodiment of the present application comprises association relationship Join, association expression JoinExpress, association type JoinType and association field JoinItem, wherein the association relationship Join further comprises an associated query item, a query condition Query of the associated query item and an association list JoinList.

[0098] The query condition Query of the associated query item in the embodiments of the present application can be regarded as the query condition in the basic query syntax tree in the above embodiments in essence, and thus can include the field condition FieldConditon and the logical conditions such as OrConditon, AndConditon, NotConditon and the like.

[0099] In an embodiment of the present application, the method further includes providing a front-end page; and the receiving of the data query request through the preset interface includes calling the preset interface through the front-end page to receive the data query request through the preset interface.

[0100] The preset associated query interface provided by the embodiments of the present application can be used to receive the query request of a user. Specifically, a front-end page for query can be configured for the user, and the front-end page can be specifically configured with a query box and the like to facilitate the user to input relevant query information. For example, the user can input the configuration item name as application A and the query condition as the server associated with the application A. The front-end page calls the preset query interface in the back end through the query information input by the user, so as to convert the query information input by the user into an associated query request in the form of a json message through the preset query interface.

[0101] Of course, in addition to providing the query function for the user, the above associated query interface can also be opened to an upper-layer application and the like. The upper-layer application can trigger the associated query request according to the format of the associated query semantics defined in the associated query interface.

[0102] It should be noted that the above two query scenarios can be configured as the preset basic query interface and the preset associated query interface respectively in specific applications. Both interfaces can adopt the standard REST (Representational State Transfer, presentation layer state transfer) interface form, and the external syntax of the interface is in the form of json, which isolates the presentation layer and the storage layer and provides a basis for subsequent optimization and modification of the database storage layer.

[0103] In order to facilitate the understanding of the above embodiments, as shown in Figure 4 A basic query flow diagram in the embodiments of the present application is provided. First, a data query request is received through a preset interface, and then a basic query parser is used to parse the data query request to obtain a basic query syntax tree. Then, a syntax converter is used to convert the basic query syntax tree into an internal SQL query statement or an Elasticsearch query statement. Finally, data query is performed in the database according to the internal query statement to obtain a data query result.

[0104] AsFigure 5 As shown in the figure, a schematic diagram of an association query process in an embodiment of the present application is provided. First, an association query request is received through a preset interface, then the association query request is parsed by using an association query parser to obtain an association query syntax tree, after that, according to the association query syntax tree, an internal query statement of each association query item is executed by using a recursive query strategy based on dynamic programming to obtain query results of the plurality of association query items, finally, the query results of the plurality of association query items are associated to obtain the final association query result.

[0105] The embodiment of the present application further provides a data query device 600, which is applied to a database application server, such as Figure 6 As shown in the figure, a schematic diagram of a data query device in an embodiment of the present application is provided, the device 600 comprises a receiving unit 610, an analyzing unit 620, a generating unit 630 and a querying unit 640, wherein:

[0106] The receiving unit 610 receives a data query request through a preset interface, wherein the data query request matches an external query semantic predefined in the preset interface;

[0107] The analyzing unit 620 parses the data query request by using a preset analysis strategy to obtain a data query syntax tree;

[0108] The generating unit 630 is used for generating an internal query statement according to the data query syntax tree;

[0109] The querying unit 640 performs data query according to the internal query statement to obtain a data query result.

[0110] In an embodiment of the present application, the data query request is a basic query request in a json format, the data query syntax tree is a basic query syntax tree, and the analyzing unit 620 is specifically used for parsing the basic query request by using a basic query parser for the json format to obtain the basic query syntax tree.

[0111] In an embodiment of the present application, the base query request refers to a request for querying configuration item information in a configuration management database, the structure of the base query syntax tree is defined according to attributes of configuration items in the configuration management database, and the parsing unit 620 is specifically configured to: define the structure of the base query syntax tree according to attributes of configuration items in the configuration management database; and parse the base query request by using a base query parser for a json format based on the structure of the base query syntax tree, to obtain the base query syntax tree; wherein the structure of the base query syntax tree includes query conditions of a base query item, the query conditions of the base query item include field conditions and logical conditions, and the field conditions include at least one of a matching condition, a full-equality condition, a range condition, an interval condition, and a regular expression condition.

[0112] In an embodiment of the present application, the generating unit 630 is specifically configured to: convert the base query syntax tree into the internal query statement by using a syntax converter, wherein the internal query statement includes an SQL query statement or an Elasticsearch query statement; and the syntax converter is configured based on a visitor pattern.

[0113] In an embodiment of the present application, the data query request is a correlation query request, the data query syntax tree is a correlation query syntax tree, and the generating unit 630 is specifically configured to: generate internal query statements of multiple correlation query items according to the correlation query syntax tree; and the querying unit 640 is specifically configured to: perform recursive querying according to the internal query statements of the multiple correlation query items, to obtain query results of the multiple correlation query items; and perform correlation calculation on the query results of the multiple correlation query items, to obtain a correlation query result.

[0114] In an embodiment of the present application, the internal query statement includes a query condition, and the querying unit 640 is specifically configured to: perform data querying according to a query condition of a current correlation query item, to obtain a query result of the current correlation query item; combine the query condition of the current correlation query item with a query condition of a next correlation query item, to obtain a combined query condition; and perform data querying according to the combined query condition, to obtain a query result of the next correlation query item.

[0115] In an embodiment of the present application, the apparatus further comprises a determining unit configured to determine the data volume of the current associated query item according to the query result of the current associated query item; and the query unit 640 is specifically configured to: in a case where the data volume of the current associated query item is less than a preset data volume threshold, combine the query condition of the current associated query item with the query condition of the next associated query item according to the query result of the current associated query item, to obtain a combined query condition; and in a case where the data volume of the current associated query item is not less than the preset data volume threshold, directly perform data query according to the query condition of the next associated query item, to obtain the query result of the next associated query item.

[0116] In an embodiment of the present application, the associated query syntax tree comprises an association relationship, an associated expression and an association type, the association relationship comprises an associated query item, a query condition of the associated query item and an association list, the query condition of the associated query item comprises a field condition and a logic condition, and the field condition comprises at least one of a matching condition, a full equality condition, a range condition, an interval condition and a regular expression condition.

[0117] In an embodiment of the present application, the apparatus further comprises a providing unit configured to provide a front-end page; and the receiving unit 610 is specifically configured to: call the preset interface through the front-end page, to receive the data query request through the preset interface.

[0118] It can be understood that the above data query apparatus can implement each step of the data query method performed by the database application server provided in the foregoing embodiments, and the related explanations about the data query method are all applicable to the data query apparatus, which will not be described herein again.

[0119] Figure 7 FIG. 1 is a structural schematic diagram of an electronic device according to an embodiment of the present application. Please refer to Figure 7 At the hardware level, the electronic device comprises a processor, and optionally further comprises an internal bus, a network interface and a memory. The memory can contain a memory, such as a high-speed random-access memory (RAM), and can also comprise a non-volatile memory, such as at least one disk memory. Of course, the electronic device can also comprise other hardware required by the business.

[0120] The processor, the network interface and the memory can be connected with each other through an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the convenience of representation, Figure 7 Only one bidirectional arrow is used to represent the bus, but it does not mean that there is only one bus or only one type of bus.

[0121] The memory is used to store a program. Specifically, the program can include program code including computer operation instructions. The memory can include an internal memory and a non-volatile memory, and provide instructions and data for the processor.

[0122] The processor reads the corresponding computer program from the non-volatile memory into the internal memory and then runs, and forms a data query device at a logical level. The processor executes the program stored in the memory, and is specifically used for executing the following operations:

[0123] Receive a data query request through a preset interface, wherein the data query request matches an external query semantic predefined in the preset interface;

[0124] Parse the data query request by using a preset parsing strategy to obtain a data query syntax tree;

[0125] Generate an internal query statement according to the data query syntax tree;

[0126] Perform data query according to the internal query statement to obtain a data query result.

[0127] The above as described in the present application Figure 1The method performed by the data query apparatus disclosed in the embodiments shown can be applied to a processor or implemented by the processor. The processor can be an integrated circuit chip having a processing capability of signals. In the implementation, each step of the method can be completed by integrated logic circuits of hardware in the processor or instructions in the form of software. The processor can be a general processor, including a central processing unit (CPU), a network processor (NP), etc.; or a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. Each method, step and logic block disclosed in the embodiments of the present application can be implemented or executed. The general processor can be a microprocessor or any conventional processor. The steps of the method disclosed in combination with the embodiments of the present application can be directly embodied as a hardware coding processor for execution, or a combination of hardware and software modules in the coding processor for execution. The software module can be located in a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, or other mature storage media in the art. The storage medium is located in the storage, and the processor reads the information in the storage and combines the hardware to complete the steps of the method.

[0128] The electronic device can further execute Figure 1 the method performed by the data query apparatus in the method, and implement the functions of the data query apparatus in the Figure 1 embodiments shown. The embodiments of the present application will not be described here.

[0129] The embodiments of the present application further propose a computer readable storage medium storing one or more programs, the one or more programs including instructions capable of causing an electronic device including a plurality of application programs to execute Figure 1 the method performed by the data query apparatus in the embodiments shown, and specifically for executing

[0130] receiving a data query request through a preset interface, the data query request matching an external query semantic predefined in the preset interface;

[0131] parsing the data query request by using a preset parsing strategy to obtain a data query syntax tree;

[0132] generating an internal query statement according to the data query syntax tree;

[0133] performing data query according to the internal query statement to obtain data query result.

[0134] Those skilled in the art will understand that embodiments of the present application can be provided as methods, systems, or computer program products. Accordingly, the present application can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage devices, etc.) embodying computer readable program code.

[0135] The present application is described in reference to the flowchart and / or block diagrams of the method, apparatus (system) and computer program product according to embodiments of the present application. It should be understood that each flow and / or block in the flowchart and / or block diagrams, and a combination of flows and / or blocks in the flowchart and / or block diagrams can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, a special purpose computer, an embedded processor, or other programmable data processing apparatus to produce a machine, so that the instructions, which are executed via the processor of the computer or other programmable data processing apparatus, generate a means for implementing the functions specified in the flowchart and / or block diagrams. Figure 1 one or more flows and / or blocks Figure 1 means for carrying out the function specified in the flow(s) or block(s).

[0136] These computer program instructions can also be stored in a computer readable memory that can direct a computer or other programmable data processing apparatus to work in a specific manner, so that the instructions stored in the computer readable memory produce a manufacture including instruction means, which implement the functions specified in the flowchart and / or block diagrams. Figure 1 one or more flows and / or blocks Figure 1 means for carrying out the function specified in the flow(s) or block(s).

[0137] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus, so that a series of operational steps are performed on the computer or other programmable data processing apparatus to generate a computer implemented process, so that the instructions executed on the computer or other programmable data processing apparatus provide a process for implementing the functions specified in the flowchart and / or block diagrams. Figure 1 one or more flows and / or blocks Figure 1 means for carrying out the function specified in the flow(s) or block(s).

[0138] In a typical configuration, the computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.

[0139] Memory can include non-persistent memory, such as volatile random access memory (RAM) and / or non-volatile memory, such as read only memory (ROM), electrically erasable read only memory (EEPROM), flash memory, or the like. Memory is an example of computer readable media.

[0140] Computer readable media includes permanent and non-permanent, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory (ROM), electrically erasable programmable read only memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital versatile discs (DVDs) or other optical storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information accessible to a computing device. According to the definition herein, computer readable media does not include transitory media, such as modulated data signals and carrier waves.

[0141] It should also be noted that the terms "comprising," "including," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without limitation, an element preceded by "comprises a" does not, without more constraints, foreclose the existence of additional identical elements in the process, method, article, or apparatus that comprises the identified element.

[0142] Those skilled in the art will understand that embodiments of the present application can be provided as a method, a system or a computer program product. Accordingly, the present application can take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage devices, and the like) embodying computer readable program code.

[0143] The embodiments of the present application described above are merely given as examples of the application, but are not intended to limit the present application. Various modifications and changes can be made by those skilled in the art without departing from the spirit and scope of the present application. Any modification, equivalent replacement, improvement, and the like made within the spirit and principle of the present application should be included in the scope of claims of the present application.

Claims

1. A data query method, performed by a database application server, wherein, The method comprises: receiving a data query request through a preset interface, the data query request matching a predefined external query semantic in the preset interface; parsing the data query request using a preset parsing strategy to obtain a data query syntax tree; generating an internal query statement according to the data query syntax tree; performing data query according to the internal query statement to obtain a data query result; the data query request is a correlation query request, the data query syntax tree is a correlation query syntax tree, and the generating an internal query statement according to the data query syntax tree comprises: generating an internal query statement of a plurality of correlation query items according to the correlation query syntax tree; the performing data query according to the internal query statement to obtain a data query result comprises: performing recursive query according to the internal query statement of the plurality of correlation query items to obtain query results of the plurality of correlation query items; performing correlation calculation on the query results of the plurality of correlation query items according to information in the correlation query syntax tree to obtain a correlation query result, the information in the correlation query syntax tree comprising at least one of a correlation field and a correlation type.

2. The method of claim 1, wherein, the internal query statement comprises a query condition, and the performing recursive query according to the plurality of internal query statements to obtain query results of the plurality of internal query statements comprises: performing data query according to the query condition of a current correlation query item to obtain a query result of the current correlation query item; combining the query condition of the current correlation query item with a query condition of a next correlation query item according to the query result of the current correlation query item to obtain a combined query condition; performing data query according to the combined query condition to obtain a query result of the next correlation query item.

3. The method of claim 2, wherein, after obtaining the query result of the current correlation query item, the method further comprises: determining a data volume of the current correlation query item according to the query result of the current correlation query item; in a case where the data volume of the current correlation query item is less than a preset data volume threshold, combining the query condition of the current correlation query item with a query condition of a next correlation query item according to the query result of the current correlation query item to obtain a combined query condition; in a case where the data volume of the current correlation query item is not less than the preset data volume threshold, directly performing data query according to the query condition of the next correlation query item to obtain a query result of the next correlation query item.

4. The method of claim 1, wherein, the correlation query syntax tree comprises a correlation relationship, a correlation expression and a correlation type, the correlation relationship comprising a correlation query item, a query condition of the correlation query item and a correlation list, the query condition of the correlation query item comprising a field condition and a logic condition, and the field condition comprising at least one of a matching condition, a full-equality condition, a range condition, an interval condition and a regular expression condition.

5. The method of claim 1, wherein, the method further comprises: providing a front-end page; the receiving a data query request through a preset interface comprises: calling the preset interface through the front-end page to receive the data query request through the preset interface.

6. A data query apparatus applied to a database application server, wherein, the apparatus comprises: The receiving unit receives a data query request through a preset interface, wherein the data query request matches a predefined external query semantic in the preset interface; The parsing unit parses the data query request by using a preset parsing strategy to obtain a data query syntax tree; The generating unit is configured to generate an internal query statement according to the data query syntax tree; The query unit performs data query according to the internal query statement to obtain a data query result. The data query request is a correlation query request, the data query syntax tree is a correlation query syntax tree, and the generating unit is specifically configured to: generate an internal query statement of a plurality of correlation query items according to the correlation query syntax tree; The query unit is specifically configured to: perform recursive query according to the internal query statement of the plurality of correlation query items to obtain query results of the plurality of correlation query items; perform correlation calculation on the query results of the plurality of correlation query items according to information in the correlation query syntax tree to obtain a correlation query result, wherein the information in the correlation query syntax tree includes at least one of a correlation field and a correlation type.

Citation Information

Patent Citations

  • Data query method and device, electronic equipment and storage medium

    CN113672781A