Database query method and apparatus, electronic device, and storage medium
By converting query conditions into query fields and field values, populating the backend expression template, and generating a syntax tree, the database query problem caused by front-end and back-end coupling is solved, improving user experience and query efficiency.
Patent Information
- Application Number
- CN202210730534.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-24
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2042-06-24
AI Technical Summary
In existing technologies, the tight coupling between front-end and back-end business processes means that when the front-end query conditions change, the back-end cannot perform database queries, resulting in a decline in user experience.
By acquiring query conditions generated by user operations, converting them into query fields and field values, and filling them into the backend expression template according to the relationships, a syntax tree of the backend expression is generated, and query statements are dynamically generated, thus achieving decoupling between the frontend and backend.
This avoids the impact of changes in the format of front-end query conditions on back-end queries, improves user experience, and ensures smooth database queries.
Smart Images

Figure CN115062046B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of data processing technology, and in particular to a database query method, apparatus, electronic device, and storage medium. Background Technology
[0002] As businesses grow, personnel will perform database queries based on business needs to obtain and analyze relevant business data. In this process, personnel send query conditions from the front end to the back end. However, due to the tight coupling between the front end and back end, changes to the front end's query conditions may prevent the back end from performing database queries, resulting in the inability to retrieve relevant business data and a degraded user experience. Summary of the Invention
[0003] This disclosure provides a database query method, apparatus, electronic device, and storage medium.
[0004] According to one aspect of this disclosure, a database query method is provided, comprising: obtaining query condition information generated based on user operations; wherein the query condition information includes identifiers of multiple target attributes, attribute values of each target attribute, and association relationships among the multiple target attributes; converting each target attribute into a query field, and converting the attribute value of each target attribute into a field value of the query field corresponding to the target attribute, thereby obtaining multiple query fields and field values corresponding to the multiple query fields; filling the multiple query fields and field values corresponding to the multiple query fields into a backend expression template according to the association relationships, to obtain a backend expression for the query condition information; and generating a query statement according to the syntax tree of the backend expression, thereby querying the database using the query statement.
[0005] According to another aspect of this disclosure, a database query apparatus is provided, comprising: an acquisition module, configured to acquire query condition information generated based on user operations; wherein the query condition information includes identifiers of multiple target attributes, attribute values of each target attribute, and association relationships among the multiple target attributes; a conversion module, configured to convert each target attribute into a query field, and convert the attribute value of each target attribute into a field value of the query field corresponding to the target attribute, thereby obtaining multiple query fields and field values corresponding to the multiple query fields; a filling module, configured to fill each query field and its field value into a backend expression template according to the association relationships, to obtain a backend expression for the query condition information; and a generation module, configured to generate a query statement according to the syntax tree of the backend expression, for querying the database using the query statement.
[0006] According to another aspect of this disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the database query method described in the first aspect embodiment of this disclosure.
[0007] According to another aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions for causing the computer to perform the database query method described in the first aspect embodiment of this disclosure.
[0008] The technical solution disclosed herein obtains query condition information generated based on user operations. This query condition information includes identifiers of multiple target attributes, attribute values for each target attribute, and relationships between the multiple target attributes. Each target attribute is converted into a query field, and the attribute value of each target attribute is converted into a field value for the corresponding query field, resulting in multiple query fields and their corresponding field values. Based on the relationships, the multiple query fields and their corresponding field values are filled into a backend expression template to obtain a backend expression for the query condition information. A query statement is generated based on the syntax tree of the backend expression, and this query statement is used to query the database. Therefore, based on the conversion of the query condition information, a backend expression is dynamically generated to generate a database query statement, thus decoupling the query condition information from the backend expression. This avoids situations where changes in the format of the frontend query condition information prevent the backend from performing database queries, improving the user experience.
[0009] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description
[0010] The accompanying drawings are provided for a better understanding of this solution and do not constitute a limitation of this application. Wherein:
[0011] Figure 1 This is a flowchart illustrating database query methods in related technologies;
[0012] Figure 2 This is a schematic flowchart of the database query method provided in Embodiment 1 of this disclosure;
[0013] Figure 3 This is a schematic flowchart of the database query method provided in Embodiment 2 of this disclosure;
[0014] Figure 4 This is a schematic flowchart of the database query method provided in Embodiment 3 of this disclosure;
[0015] Figure 5 This is a schematic diagram illustrating the process of parsing a backend expression to generate a corresponding syntax tree according to an embodiment of this disclosure;
[0016] Figure 6 This is a schematic diagram of the syntax tree structure provided in the embodiments of this disclosure;
[0017] Figure 7 This is a schematic diagram of syntax tree parsing in an embodiment of this disclosure;
[0018] Figure 8 This is a schematic flowchart of the database query method provided in the embodiments of this disclosure;
[0019] Figure 9 This is a schematic diagram illustrating the effect of using the database query method of this disclosure for crowd extraction;
[0020] Figure 10 This is a schematic diagram of the structure of the database query device provided in Embodiment 4 of this disclosure;
[0021] Figure 11 This is a block diagram illustrating an electronic device according to an exemplary embodiment. Detailed Implementation
[0022] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of this application, including various details to aid understanding. These should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this application. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0023] As businesses grow, relevant personnel will query databases based on business needs (such as audience insights and user operations) to obtain and analyze relevant business data. Related technologies include... Figure 1As shown, the system uses the ClickHouse engine to implement direct queries using Structured Query Language (SQL). This means that relevant personnel send query conditions from the front end to the back end for data analysis (ClickBI) and database queries (ClickHouse) to obtain relevant business data. However, due to the tight coupling between the front end and back end, changes to the front end's query conditions may prevent the back end from performing database queries, thus preventing the retrieval of relevant business data and reducing the user experience.
[0024] To address the aforementioned issues, this disclosure proposes a database query method, apparatus, electronic device, and storage medium.
[0025] The database query method, apparatus, electronic device, and storage medium of this disclosure are described below with reference to the accompanying drawings.
[0026] Figure 2 This is a schematic flowchart of the database query method provided in Embodiment 1 of this disclosure.
[0027] This disclosure illustrates the example of a database query method configured in a database query device, which can be applied to any electronic device to enable the electronic device to perform database query functions.
[0028] Among them, electronic devices can be any device with computing capabilities, such as personal computers (PCs), mobile terminals, etc. Mobile terminals can be hardware devices with various operating systems, touch screens and / or displays, such as mobile phones, tablets, personal digital assistants, wearable devices, etc.
[0029] like Figure 2 As shown, this database query method may include the following steps:
[0030] Step 201: Obtain query condition information generated based on user operations.
[0031] The query criteria include the identifiers of multiple target attributes, the attribute values of each target attribute, and the relationships between the multiple target attributes.
[0032] As one possible implementation of this disclosure, a front-end expression sent by the front-end page in response to a user operation is received; wherein the front-end expression carries query condition information.
[0033] In other words, users can perform operations on the front-end page (e.g., the front-end interactive interface) according to business needs. For example, they can select, click, or drag relevant controls, or enter relevant information on the front-end page. The front-end page can generate corresponding front-end expressions in response to user operations and send the front-end expressions. Based on the front-end expressions, corresponding query condition information is generated, where the front-end expressions carry the query condition information.
[0034] It should be noted that the query criteria information may include the identifiers of multiple target attributes, the attribute values of each target attribute, and the relationships between multiple target attributes.
[0035] As an example, the front-end expression is:
[0036] {
[0037] "operator":1,
[0038] "selectTagSet":[
[0039] {
[0040] "tagId":"xxxx",
[0041] "tagNameCn":"Age",
[0042] "tagNameEn":"AGE",
[0043] } ]
[0045] }
[0046] The identifier for multiple target attributes can be "operator":1", and the multiple target attributes are "tagId", "tagNameCn" and "tagNameEn". The attribute value of the target attribute "tagId" is "xxxx", the attribute value of the target attribute "tagNameCn" is "age", and the attribute value of the target attribute "tagNameEn" is "AGE". The association between the multiple target attributes is "and".
[0047] Step 202: Convert each target attribute into a query field, and convert the attribute value of each target attribute into the field value of the query field corresponding to the target attribute.
[0048] In this embodiment of the disclosure, in order to convert each target attribute and each attribute value into a field recognizable by the backend service, a conversion table can be queried according to each target attribute to convert each target attribute into a query field. Simultaneously, the conversion table can be queried according to the attribute value of each target attribute to convert the attribute value of each target attribute into the field value of the corresponding query field. The conversion table stores the mapping relationship between each target attribute and its corresponding query field, and the mapping relationship between the attribute value of each target attribute and its corresponding field value.
[0049] Step 203: Based on the association relationship, fill the backend expression template with multiple query fields and their corresponding field values to obtain the backend expression for the query conditions.
[0050] In order to decouple front-end business from back-end services, as a possible implementation of this disclosure, multiple query fields and their corresponding field values are filled into a back-end expression template according to the association relationship to obtain a back-end expression for query condition information.
[0051] As an example, the backend expression could be {
[0052] "opr":"diff",
[0053] "label_type":2,
[0054] "type":1,
[0055] "group":{},
[0056] "table":"xxxx",
[0057] "filter_expr":{
[0058] "type":2,
[0059] "opr":"and",
[0060] "sub_expr_list":[
[0061] {
[0062] "opr":"=",
[0063] "field":"text",
[0064] "values":[
[0065] "2"
[0066] ],
[0067] "label_type":1,
[0068] "type":1,
[0069] "table":"xxxxx",
[0070] "opr_extra":"right"
[0071] } ]
[0073] }
[0074] }
[0075] Step 204: Generate a query statement based on the syntax tree of the backend expression, and use the query statement to query the database.
[0076] In this embodiment of the disclosure, the backend expression can be parsed into a syntax tree, and each node in the syntax tree can be converted into a query sub-statement. Then, a query statement is generated based on each query sub-statement, and the query statement is used to perform a database query.
[0077] In summary, by transforming the query condition information, a backend expression is dynamically generated. This expression is then used to generate a database query statement, enabling database queries. This decouples the query condition information from the backend expression, preventing situations where changes to the format of the frontend query condition information prevent the backend from performing database queries and improving the user experience.
[0078] To more clearly illustrate how the above embodiments fill multiple query fields and their corresponding field values into the backend expression template based on the association relationship to obtain the backend expression for query condition information, this disclosure proposes another database query method.
[0079] Figure 3 This is a schematic flowchart of the database query method provided in Embodiment 2 of this disclosure.
[0080] like Figure 3 As shown, this database query method may include the following steps:
[0081] Step 301: Obtain query condition information generated based on user operations.
[0082] The query criteria include the identifiers of multiple target attributes, the attribute values of each target attribute, and the relationships between the multiple target attributes.
[0083] Step 302: Convert each target attribute into a query field, and convert the attribute value of each target attribute into the field value of the query field corresponding to the target attribute.
[0084] Step 303: Fill the backend expression template with multiple query fields and their corresponding field values to obtain multiple first-level expressions.
[0085] Each first-level expression is filled with a query field and a corresponding field value.
[0086] In this embodiment of the disclosure, each query field and its corresponding field value are filled into the backend expression template to obtain multiple first-level expressions.
[0087] As an example, the first-level expression is: {
[0088] "sub_expr_list":[
[0089] {
[0090] "opr":"=",
[0091] "field":"text",
[0092] "values":[
[0093] "2" ]
[0095] } ]
[0097] };
[0098] The query field is "values", and the value of the query field "values" is "2". In the first-level expression, all fields except the query field and its corresponding value are backend expression templates.
[0099] Step 304: Generate a second-level expression based on the association relationship, and determine the first-level expression as a sub-level of the second-level expression based on the query fields with the association relationship.
[0100] In this embodiment of the disclosure, the association relationship may include "and", "or", etc. As an example, a second-level expression for indicating at least one operator is generated based on at least one operator between multiple query fields in the association relationship; the hierarchical relationship between the second-level expressions is determined based on the order in which at least one operator in the association relationship is executed.
[0101] For example, if the operator between multiple query fields is "and", the corresponding second-level expression could be:
[0102] {
[0103] "filter_expr":{
[0104] "type":2,
[0105] "opr":"and"
[0106] }
[0107] };
[0108] Among them, ""opr":"and" indicates that the operator between multiple query fields is "and", and ""type":2" is a type of simple combination of multiple query fields in the backend expression template, such as "and" or "or" when the operator between multiple query fields is relatively simple.
[0109] In this embodiment of the disclosure, after determining the operator indicated by the second-level expression, the first-level expression having the operator can be used as the first-level expression of the sub-layer of the second-level expression.
[0110] for example,{
[0111] "filter_expr":{
[0112] "type":2,
[0113] "opr":"and"
[0114] }
[0115] "sub_expr_list":[
[0116] {
[0117] "opr":"=",
[0118] "field":"text",
[0119] "values":[
[0120] "2" ]
[0122] } ]
[0124] };
[0125] The expression “sub_expr_list” (first-level expression) can be used as the first-level expression of the sub-layer of the expression “filter_expr” (second-level expression).
[0126] It should be noted that there can be one or more second-level expressions. When there are multiple second-level expressions, the hierarchical relationship between the second-level expressions is determined according to the order in which at least one operator in the association is executed.
[0127] Step 305: Combine the second-level expression with the first-level expression, which is a sub-level of the second-level expression, to obtain the backend expression for the query condition information.
[0128] Furthermore, the second-level expression is combined with the first-level expression, which is a sub-level of the second-level expression, and the combined expression is used as the backend expression for query condition information.
[0129] Step 306: Generate a query statement based on the syntax tree of the backend expression, and use the query statement to query the database.
[0130] It should be noted that the execution processes of steps 301 to 302 and step 306 can be implemented in any of the embodiments of this disclosure. This disclosure does not limit these processes and will not elaborate further.
[0131] In summary, by filling multiple query fields and their corresponding values into a backend expression template, multiple first-level expressions are obtained. Second-level expressions are generated based on relationships, and first-level expressions, which are sub-layers of the second-level expressions, are determined based on the related query fields. The second-level expressions are then combined with the first-level expressions to obtain the backend expression for the query conditions. Thus, by dynamically generating backend expressions based on the transformation of query conditions, the generated backend expressions better focus on the logical operations between frontend query conditions, thereby decoupling them from frontend business logic. This avoids situations where changes to the format of frontend query conditions prevent the backend from performing database queries, improving the user experience.
[0132] To generate more accurate query statements, such as Figure 4 As shown, Figure 4 This is a flowchart illustrating the database query method provided in Embodiment 3 of this disclosure. In this embodiment, the backend expression can be parsed into a syntax tree, and a query statement can be generated based on the syntax tree of the backend expression. Figure 4 The illustrated embodiment may include the following steps:
[0133] Step 401: Obtain query condition information generated based on user operations.
[0134] The query criteria include the identifiers of multiple target attributes, the attribute values of each target attribute, and the relationships between the multiple target attributes.
[0135] Step 402: Convert each target attribute into a query field, and convert the attribute value of each target attribute into the field value of the corresponding query field, thus obtaining multiple query fields and the field values corresponding to the multiple query fields.
[0136] Step 403: Fill the backend expression template with multiple query fields and their corresponding field values to obtain multiple first-level expressions.
[0137] Each first-level expression is filled with a query field and a corresponding field value.
[0138] Step 404: Generate a second-level expression based on the association relationship, and determine the first-level expression as a sub-level of the second-level expression based on the query fields with the association relationship.
[0139] Step 405: Combine the second-level expression with the first-level expression, which is a sub-level of the second-level expression, to obtain the backend expression for the query condition information.
[0140] Step 406: Parse the backend expression into a syntax tree.
[0141] In the Abstract Syntax Tree (AST), leaf nodes indicate the first-level expressions in the backend expressions, while non-leaf nodes indicate the second-level expressions. The parent-child relationship of nodes in the AST is determined based on the hierarchical relationship between second-level expressions and between first-level and second-level expressions.
[0142] In this embodiment of the disclosure, the backend expression is parsed to generate a corresponding syntax tree. The first-level expression in the backend expression can correspond to a leaf node in the syntax tree, and the second-level expression in the backend expression can correspond to a non-leaf node in the syntax tree. When there are multiple second-level expressions in the backend expression, the parent-child relationship of the nodes in the syntax tree can be determined according to the hierarchical relationship between the second-level expressions and the hierarchical relationship between the first-level expression and the second-level expression.
[0143] For example, such as Figure 5 As shown, Figure 5 This is a flowchart illustrating the process of parsing a backend expression to generate a corresponding syntax tree according to an embodiment of this disclosure, using the backend expression as an example.
[0144] {
[0145] "opr":"diff",
[0146] "label_type":2,
[0147] "type":1,
[0148] "group":{},
[0149] "table":"xxxx",
[0150] "filter_expr":{
[0151] "type":2,
[0152] "opr":"and"
[0153] "sub_expr_list":[
[0154] {
[0155] "opr":"=",
[0156] "field":"text",
[0157] "values":[
[0158] "2"
[0159] ],
[0160] "label_type":1,
[0161] "type":1,
[0162] "table":"xxxxx",
[0163] "opr_extra":"right",
[0164] } ]
[0166] }
[0167] For example,
[0168] The specific process for parsing the backend expression to generate the corresponding syntax tree can be summarized as follows:
[0169] 1. Determine if a difference set exists in the backend expression. If not, the right subtree is empty.
[0170] 2. Check the operators between each query field (e.g., secondary operators). For example, check if the operator for "filter_expr" is "and(JOIN)" and the right subtree is empty.
[0171] 3. Retrieve the node data (e.g., "TABLE", "FIELD", "VALUE", and "OPERATOR") of the third-level subtree (sub_expr_list) and parse them to generate the corresponding syntax tree (e.g., ... Figure 6 (As shown).
[0172] Step 407: Based on the database type, invoke the appropriate agent for that type so that the agent can convert each node in the syntax tree into a query substatement according to the conversion strategy corresponding to the type.
[0173] It should be noted that, in this embodiment of the disclosure, the syntax tree can be parsed into different SQL statements for different query engines, and different SQL statements are executed in different query engines. Therefore, a proxy can be built on top of the query engine of each database, such as building a Spark proxy on top of the Spark query engine.
[0174] It should be noted that the execution process of steps 401 to 405 can be implemented in any of the embodiments of this disclosure. This disclosure does not limit this and will not elaborate further.
[0175] In this embodiment of the disclosure, different invocation proxies correspond to different database types, parsing each node of the syntax tree into different query substatements. As an example, based on the database type, an agent suitable for that type is invoked. This agent, according to the conversion strategy corresponding to the database type, converts each node in the syntax tree into a query substatement. As a possible implementation of this embodiment of the disclosure, such as... Figure 7 As shown, each query engine implements a unified application programming interface (e.g., AST API) and abstracts its own engine characteristics through the decorator pattern. Based on the characteristics of each query engine, each agent performs customized business processing. For example, the Spark agent parses the diff operation into a left anti join and adds catalog processing to the underlying leaf nodes.
[0176] Step 408: Generate a query statement based on the transformed query sub-statement of each node, and use the query statement to query the database.
[0177] Then, by concatenating the query sub-statements transformed at each stage, a query statement can be generated, which can then be used to query the database.
[0178] In summary, by parsing the backend expression into a syntax tree, and calling the appropriate proxy based on the database type, the proxy converts each node in the syntax tree into a query sub-statement according to the type's conversion strategy. Based on the converted query sub-statements, a query statement is generated. Thus, by dynamically generating the backend expression based on the conversion of query condition information, and generating the query statement based on the syntax tree corresponding to the backend expression, changes in the format of the query condition information on the frontend will not affect the query statement generated on the backend, thereby improving query efficiency.
[0179] To illustrate the above embodiments more clearly, examples are given below.
[0180] For example, such as Figure 8 As shown, Figure 8 This is a schematic flowchart illustrating the database query method provided in an embodiment of this disclosure. Figure 8 In this process, the front-end expression sent by the front-end interactive page (front-end page) is transformed into a back-end expression. A proxy is built on top of the query engines of various databases. The SQL statement is parsed using the syntax tree of the back-end expression. Then, after the query engine completes the query, it writes the results to the database. Simultaneously, the back-end service pushes the query results to the front-end interactive page. It should be noted that different proxies are built on different database query engines; these proxies can include Spark proxies, Doris proxies, and Elasticsearch proxies, etc. Furthermore, it should be noted that... Figure 9 As shown, the database query method of this disclosure embodiment significantly improves the extraction of daily user data for different front-end expressions.
[0181] The database query method of this disclosure obtains query condition information generated based on user operations. This query condition information includes identifiers of multiple target attributes, attribute values for each target attribute, and relationships between the multiple target attributes. Each target attribute is converted into a query field, and the attribute value of each target attribute is converted into the field value of the corresponding query field, resulting in multiple query fields and their corresponding field values. Based on the relationships, the multiple query fields and their corresponding field values are filled into a backend expression template to obtain a backend expression for the query condition information. A query statement is generated based on the syntax tree of the backend expression to query the database. Thus, based on the conversion of the query condition information, a backend expression is dynamically generated to generate a database query statement, thereby decoupling the query condition information from the backend expression. This avoids situations where changes in the format of the frontend query condition information prevent the backend from performing database queries, improving the user experience.
[0182] To implement the above embodiments, this disclosure also proposes a database query device.
[0183] Figure 10 This is a schematic diagram of the database query device provided in Embodiment 4 of this disclosure.
[0184] like Figure 10 As shown, the database query device 1000 includes: an acquisition module 1010, a conversion module 1020, a filling module 1030, and a generation module 1040.
[0185] The system includes: an acquisition module 1010 for acquiring query condition information generated based on user operations; wherein the query condition information includes identifiers of multiple target attributes, attribute values of each target attribute, and association relationships between the multiple target attributes; a conversion module 1020 for converting each target attribute into a query field, and converting the attribute values of each target attribute into field values of the corresponding query field, thereby obtaining multiple query fields and their corresponding field values; a filling module 1030 for filling the multiple query fields and their corresponding field values into a backend expression template according to the association relationships, to obtain a backend expression for the query condition information; and a generation module 1040 for generating a query statement based on the syntax tree of the backend expression, and using the query statement to query the database.
[0186] As one possible implementation of this disclosure, the filling module 1030 is configured to: fill a backend expression template with multiple query fields and their corresponding field values to obtain multiple first-level expressions; wherein each first-level expression is filled with one query field and its corresponding field value; generate a second-level expression based on the association relationship, and determine a first-level expression as a sub-layer of the second-level expression based on the query fields with the association relationship; and combine the second-level expression with the first-level expression as a sub-layer of the second-level expression to obtain a backend expression for query condition information.
[0187] As one possible implementation of this disclosure, the filling module 1030 is further configured to: generate a second-level expression for indicating at least one operator based on at least one operator among multiple query fields in the association relationship; and determine the hierarchical relationship between the second-level expressions based on the order in which the at least one operator in the association relationship is executed.
[0188] As one possible implementation of this disclosure, the database query device further includes a parsing module.
[0189] The parsing module is used to parse the backend expression into a syntax tree. The leaf nodes in the syntax tree indicate the first-level expressions in the backend expression, and the non-leaf nodes in the syntax tree indicate the second-level expressions in the backend expression. The parent-child relationship of the nodes in the syntax tree is determined based on the hierarchical relationship between the second-level expressions and the hierarchical relationship between the first-level expressions and the second-level expressions.
[0190] As one possible implementation of this disclosure, the generation module 1040 is configured to: call a proxy applicable to the type of database, so that the proxy converts each node in the syntax tree into a query substatement according to the conversion strategy corresponding to the type; and generate a query statement based on the query substatement converted by each node.
[0191] As one possible implementation of this disclosure, the acquisition module 1010 is configured to: receive a front-end expression sent by the front-end page in response to a user operation; wherein the front-end expression carries the query condition information.
[0192] The database query apparatus of this disclosure acquires query condition information generated based on user operations. This query condition information includes identifiers of multiple target attributes, attribute values for each target attribute, and relationships between the multiple target attributes. Each target attribute is converted into a query field, and the attribute value of each target attribute is converted into the field value of the corresponding query field, resulting in multiple query fields and their corresponding field values. Based on the relationships, the multiple query fields and their corresponding field values are filled into a backend expression template to obtain a backend expression for the query condition information. A query statement is generated based on the syntax tree of the backend expression to query the database. Thus, by dynamically generating the backend expression based on the conversion of the query condition information, a database query statement is generated based on the dynamically generated backend expression, enabling database queries. This decouples the query condition information from the backend expression, preventing situations where changes in the format of the frontend query condition information prevent the backend from performing database queries, thereby improving the user experience.
[0193] It should be noted that the foregoing explanation of the database query method embodiment also applies to the database query device of this embodiment, and will not be repeated here.
[0194] To implement the above embodiments, this disclosure also proposes an electronic device, including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute this disclosure. Figures 1 to 9 The database query method described in the embodiments.
[0195] To implement the above embodiments, this disclosure also proposes a non-transitory computer-readable storage medium storing computer instructions for causing the computer to execute... Figures 1 to 9 The database query method described in the embodiments.
[0196] To implement the above embodiments, this disclosure also proposes a computer program product that, when executed by an instruction processor in the computer program product, implements... Figures 1 to 9 The database query method described in the embodiments.
[0197] Figure 11 This is a block diagram illustrating an electronic device according to an exemplary embodiment. For example, the electronic device 1100 may be a mobile phone, computer, digital broadcasting terminal, messaging device, game console, tablet device, medical device, fitness equipment, personal digital assistant, etc.
[0198] Reference Figure 11 The electronic device 1100 may include one or more of the following components: processing component 1102, memory 1104, power component 1106, multimedia component 1108, audio component 1110, input / output (I / O) interface 1112, sensor component 1114, and communication component 1116.
[0199] Processing component 1102 typically controls the overall operation of electronic device 1100, such as operations associated with display, telephone calls, data communication, camera operation, and recording operations. Processing component 1102 may include one or more processors 1120 to execute instructions to perform all or part of the steps of the methods described above. Furthermore, processing component 1102 may include one or more modules to facilitate interaction between processing component 1102 and other components. For example, processing component 1102 may include a multimedia module to facilitate interaction between multimedia component 1108 and processing component 1102.
[0200] Memory 1104 is configured to store various types of data to support the operation of electronic device 1100. Examples of such data include instructions for any application or method operating on electronic device 1100, contact data, phonebook data, messages, pictures, videos, etc. Memory 1104 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0201] Power component 1106 provides power to various components of electronic device 1100. Power component 1106 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to electronic device 1100.
[0202] Multimedia component 1108 includes a screen that provides an output interface between the electronic device 1100 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touchscreen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors may sense not only the boundaries of the touch or swipe action but also the duration and pressure associated with the touch or swipe operation. In some embodiments, multimedia component 1108 includes a front-facing camera and / or a rear-facing camera. When the electronic device 1100 is in an operating mode, such as a shooting mode or a video mode, the front-facing camera and / or the rear-facing camera may receive external multimedia data. Each front-facing camera and rear-facing camera may be a fixed optical lens system or have focal length and optical zoom capabilities.
[0203] Audio component 1110 is configured to output and / or input audio signals. For example, audio component 1110 includes a microphone (MIC) configured to receive external audio signals when electronic device 1100 is in an operating mode, such as call mode, recording mode, and voice recognition mode. The received audio signals may be further stored in memory 1104 or transmitted via communication component 1116. In some embodiments, audio component 1110 also includes a speaker for outputting audio signals.
[0204] I / O interface 1112 provides an interface between processing component 1102 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to, home buttons, volume buttons, power buttons, and lock buttons.
[0205] Sensor assembly 1114 includes one or more sensors for providing state assessments of various aspects of electronic device 1100. For example, sensor assembly 1114 may detect the on / off state of electronic device 1100, the relative positioning of components such as the display and keypad of electronic device 1100, changes in position of electronic device 1100 or a component of electronic device 1100, the presence or absence of user contact with electronic device 1100, the orientation or acceleration / deceleration of electronic device 1100, and temperature changes of electronic device 1100. Sensor assembly 1114 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. Sensor assembly 1114 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, sensor assembly 1114 may also include an accelerometer, gyroscope, magnetometer, pressure sensor, or temperature sensor.
[0206] Communication component 1116 is configured to facilitate wired or wireless communication between electronic device 1100 and other devices. Electronic device 1100 can access wireless networks based on communication standards, such as WiFi, 4G, or 5G, or combinations thereof. In one exemplary embodiment, communication component 1116 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, communication component 1116 also includes a near-field communication (NFC) module to facilitate short-range communication. For example, the NFC module may be implemented based on radio frequency identification (RFID) technology, Infrared Data Association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0207] In an exemplary embodiment, the electronic device 1100 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the methods described above.
[0208] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 1104 including instructions, which can be executed by a processor 1120 of an electronic device 1100 to perform the above-described method. For example, the non-transitory computer-readable storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.
[0209] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this disclosure. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
[0210] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this disclosure, "a plurality of" means at least two, such as two, three, etc., unless otherwise explicitly specified.
[0211] Any process or method description in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing custom logic functions or processes, and the scope of preferred embodiments of this disclosure includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as will be understood by those skilled in the art to which embodiments of this disclosure pertain.
[0212] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include: an electrical connection having one or more wires (electronic device), a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Alternatively, the computer-readable medium may be paper or other suitable media on which the program can be printed, since the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in a computer memory.
[0213] It should be understood that various parts of this disclosure can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0214] Those skilled in the art will understand that all or part of the steps of the methods in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.
[0215] Furthermore, the functional units in the various embodiments of this disclosure can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.
[0216] The storage medium mentioned above can be a read-only memory, a disk, or an optical disk, etc. Although embodiments of the present disclosure have been shown and described above, it is to be understood that the above embodiments are exemplary and should not be construed as limiting the present disclosure. Those skilled in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of the present disclosure.
Claims
1. A database query method, characterized in that, include: Obtain query condition information generated based on user operations; wherein, the query condition information includes the identifiers of multiple target attributes, the attribute value of each target attribute, and the association relationship between the multiple target attributes; Each target attribute is converted into a query field, and the attribute value of each target attribute is converted into the field value of the query field corresponding to the target attribute, thus obtaining multiple query fields and multiple field values corresponding to the query fields; The multiple query fields and their corresponding field values are respectively filled into the backend expression template to obtain multiple first-level expressions; wherein each first-level expression is filled with one of the query fields and its corresponding field value. Based on the association, a second-level expression is generated, and based on the query fields with the association, a first-level expression is determined as a sub-layer of the second-level expression; The second-level expression is combined with the first-level expression, which is a sub-level of the second-level expression, to obtain the backend expression for the query condition information. Based on the syntax tree of the backend expression, a query statement is generated to query the database. The step of generating a second-level expression based on the association relationship includes: Based on at least one operator among the plurality of query fields in the association relationship, generate a second-level expression to indicate the at least one operator; In response to the presence of multiple second-level expressions, the hierarchical relationship between the second-level expressions is determined according to the execution order of at least one operator in the association relationship.
2. The method according to claim 1, characterized in that, The method further includes: The backend expression is parsed into the syntax tree; In this syntax tree, leaf nodes indicate first-level expressions in the backend expressions, and non-leaf nodes indicate second-level expressions in the backend expressions. The parent-child relationships of nodes in the syntax tree are determined based on the hierarchical relationships between the second-level expressions and between the first-level expressions and the second-level expressions.
3. The method according to claim 1 or 2, characterized in that, The step of generating a query statement based on the syntax tree of the backend expression includes: Based on the type of the database, an agent suitable for that type is invoked, so that the agent converts each node in the syntax tree into a query substatement according to the conversion strategy corresponding to the type; Generate a query statement based on the query sub-statement transformed by each of the nodes.
4. The method according to claim 1 or 2, characterized in that, The process of obtaining query condition information generated based on user operations includes: Receive the front-end expression sent by the front-end page in response to the user's operation; The front-end expression carries the query condition information.
5. A database query device, characterized in that, include: The acquisition module is used to acquire query condition information generated based on user operations; wherein, the query condition information includes the identifiers of multiple target attributes, the attribute value of each target attribute, and the association relationship between the multiple target attributes; The conversion module is used to convert each of the target attributes into query fields, and to convert the attribute value of each target attribute into the field value of the query field corresponding to the target attribute, thereby obtaining multiple query fields and multiple field values corresponding to the query fields; A fill module is used to fill the multiple query fields and their corresponding field values into a backend expression template to obtain multiple first-level expressions; wherein each first-level expression is filled with one query field and its corresponding field value; a second-level expression is generated based on the association relationship, and a first-level expression is determined as a sub-layer of the second-level expression based on the query fields with the association relationship; the second-level expression is combined with the first-level expression as a sub-layer of the second-level expression to obtain the backend expression for the query condition information; The generation module is used to generate a query statement based on the syntax tree of the backend expression, so as to query the database using the query statement; The filling module is further configured to: Based on at least one operator among the plurality of query fields in the association relationship, generate a second-level expression to indicate the at least one operator; In response to the presence of multiple second-level expressions, the hierarchical relationship between the second-level expressions is determined according to the execution order of at least one operator in the association relationship.
6. The apparatus according to claim 5, characterized in that, The device further includes: The parsing module is used to parse the backend expression into the syntax tree; In this syntax tree, leaf nodes indicate first-level expressions in the backend expressions, and non-leaf nodes indicate second-level expressions in the backend expressions. The parent-child relationships of nodes in the syntax tree are determined based on the hierarchical relationships between the second-level expressions and between the first-level expressions and the second-level expressions.
7. The apparatus according to claim 5 or 6, characterized in that, The generation module is specifically used for: Based on the type of the database, an agent suitable for that type is invoked, so that the agent converts each node in the syntax tree into a query substatement according to the conversion strategy corresponding to the type; Generate a query statement based on the query sub-statement transformed by each of the nodes.
8. The apparatus according to claim 5 or 6, characterized in that, The acquisition module is specifically used for: Receive the front-end expression sent by the front-end page in response to the user's operation; The front-end expression carries the query condition information.
9. An electronic device, characterized in that, include: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-4.
10. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-4.
Citation Information
Patent Citations
Data inquiry method, device and electronic device
CN109062952A
Data querying method and apparatus, server, and storage medium
WO2021189195A1