CN115062046A - Database query method and device, electronic equipment and storage medium - Google Patents
Database query method and device, electronic equipment and storage medium Download PDFInfo
- Publication number
- CN115062046A CN115062046A CN202210730534.4A CN202210730534A CN115062046A CN 115062046 A CN115062046 A CN 115062046A CN 202210730534 A CN202210730534 A CN 202210730534A CN 115062046 A CN115062046 A CN 115062046A
- Authority
- CN
- China
- Prior art keywords
- query
- expression
- field
- condition information
- hierarchical
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 54
- 230000014509 gene expression Effects 0.000 claims abstract description 217
- 238000006243 chemical reaction Methods 0.000 claims description 18
- 230000004044 response Effects 0.000 claims description 5
- 238000004458 analytical method Methods 0.000 claims description 2
- 238000012545 processing Methods 0.000 abstract description 14
- 230000008859 change Effects 0.000 abstract description 8
- 239000003795 chemical substances by application Substances 0.000 description 13
- 238000004891 communication Methods 0.000 description 10
- 238000010586 diagram Methods 0.000 description 7
- 238000005516 engineering process Methods 0.000 description 7
- 230000006870 function Effects 0.000 description 6
- 230000003287 optical effect Effects 0.000 description 6
- 230000008569 process Effects 0.000 description 5
- 230000003993 interaction Effects 0.000 description 4
- 230000005236 sound signal Effects 0.000 description 4
- 230000001133 acceleration Effects 0.000 description 2
- 238000004590 computer program Methods 0.000 description 2
- 230000008878 coupling Effects 0.000 description 2
- 238000010168 coupling process Methods 0.000 description 2
- 238000005859 coupling reaction Methods 0.000 description 2
- 238000011161 development Methods 0.000 description 2
- 238000000605 extraction Methods 0.000 description 2
- 238000007726 management method Methods 0.000 description 2
- 238000013507 mapping Methods 0.000 description 2
- 239000000463 material Substances 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 230000002829 reductive effect Effects 0.000 description 2
- 230000002441 reversible effect Effects 0.000 description 2
- 230000009471 action Effects 0.000 description 1
- 230000004075 alteration Effects 0.000 description 1
- 238000003491 array Methods 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 238000007405 data analysis Methods 0.000 description 1
- 238000013500 data storage Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000003384 imaging method Methods 0.000 description 1
- 230000002452 interceptive effect Effects 0.000 description 1
- 230000000670 limiting effect Effects 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 230000002093 peripheral effect Effects 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/242—Query formulation
- G06F16/2433—Query languages
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2453—Query optimisation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2455—Query execution
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- Computational Linguistics (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Mathematical Physics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The disclosure provides a database query method, a database query device, electronic equipment and a storage medium, and relates to the technical field of data processing. The scheme is as follows: acquiring query condition information generated based on user operation; converting each target attribute in the query condition information into a query field, converting the attribute value of each target attribute into a field value of the query field corresponding to the target attribute, and obtaining a plurality of query fields and field values corresponding to the plurality of query fields; filling a plurality of query fields and field values corresponding to the query fields into a back-end expression template according to the association relation so as to obtain a back-end expression of the query condition information; according to the syntax tree of the rear-end expression, the query statement is generated to query the database by adopting the query statement, so that the query condition information is decoupled from the rear-end expression, the condition that the rear end cannot query the database due to the format change of the front-end query condition information is avoided, and the user experience is improved.
Description
Technical Field
The present disclosure relates to the field of data processing technologies, and in particular, to a database query method and apparatus, an electronic device, and a storage medium.
Background
With the continuous development of enterprises, enterprise related personnel can query databases according to business requirements to acquire and analyze related business data. In the related technology, enterprise related personnel send query condition information to a back end at a front end to perform data query to acquire related business data, but due to serious front-end and back-end business coupling, when the front-end query condition information changes, the situation that the back end cannot perform database query may occur, so that the related business data cannot be acquired, and user experience is reduced.
Disclosure of Invention
The disclosure provides a database query method, a database query device, electronic equipment and a storage medium.
According to an aspect of the present disclosure, there is provided a database query method, including: acquiring query condition information generated based on user operation; the query condition information comprises identifications of a plurality of target attributes, attribute values of each target attribute and incidence relations among the plurality of target attributes; converting each target attribute into a query field, converting the attribute value of each target attribute into the field value of the query field corresponding to the target attribute, and obtaining a plurality of query fields and field values corresponding to the plurality of query fields; filling the plurality of query fields and field values corresponding to the plurality of query fields into a back-end expression template according to the association relationship so as to obtain a back-end expression of the query condition information; and generating a query statement according to the syntax tree of the rear-end expression so as to query a database by adopting the query statement.
According to another aspect of the present disclosure, there is provided a database query apparatus including: the acquisition module is used for acquiring query condition information generated based on user operation; the query condition information comprises identifications of a plurality of target attributes, attribute values of each target attribute and incidence relations among the plurality of target attributes; a conversion module, configured to convert each target attribute into a query field, where an attribute value of each target attribute is converted into a field value of the query field corresponding to the target attribute, so as to obtain a plurality of query fields and field values corresponding to the plurality of query fields; the filling module is used for filling the query fields and the field values thereof into a rear-end expression template according to the incidence relation so as to obtain a rear-end expression of the query condition information; and the generating module is used for generating a query statement according to the syntax tree of the rear-end expression so as to query a database by adopting the query statement.
According to another aspect of the present disclosure, there is provided an electronic device including: at least one processor; and a memory communicatively coupled 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 perform the database query method according to the embodiment of the first aspect of the disclosure.
According to another aspect of the present disclosure, there is provided a non-transitory computer readable storage medium storing computer instructions for causing a computer to perform the database query method according to the embodiment of the first aspect of the present disclosure.
According to the technical scheme, the query condition information generated based on user operation is acquired; the query condition information comprises identifications of a plurality of target attributes, attribute values of each target attribute and incidence relations among the plurality of target attributes; converting each target attribute into a query field, converting the attribute value of each target attribute into the field value of the query field corresponding to the target attribute, and obtaining a plurality of query fields and field values corresponding to the plurality of query fields; filling the plurality of query fields and field values corresponding to the plurality of query fields into a back-end expression template according to the association relationship so as to obtain a back-end expression of the query condition information; and generating a query statement according to the syntax tree of the rear-end expression to query the database by adopting the query statement, thereby dynamically generating the rear-end expression based on the conversion of the query condition information, so as to generate the query statement of the database based on the dynamically generated rear-end expression and realize the query of the database, thereby decoupling the query condition information from the rear-end expression, avoiding the condition that the rear end cannot query the database due to the format change of the query condition information at the front end, and improving the user experience.
It should be understood that the statements in this section do not necessarily identify key or critical features of the embodiments of the present disclosure, nor do they limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description.
Drawings
The drawings are included to provide a better understanding of the present solution and are not intended to limit the present application. Wherein:
FIG. 1 is a schematic flow chart of a database query method in the related art;
fig. 2 is a schematic flowchart of a database query method according to an embodiment of the disclosure;
fig. 3 is a schematic flowchart of a database query method according to a second embodiment of the disclosure;
fig. 4 is a schematic flowchart of a database query method according to a third embodiment of the present disclosure;
FIG. 5 is a schematic flowchart illustrating parsing a backend expression to generate a corresponding syntax tree according to an embodiment of the present disclosure;
FIG. 6 is a diagram illustrating a structure of a syntax tree according to an embodiment of the present disclosure;
FIG. 7 is a diagram illustrating syntax tree parsing in accordance with an embodiment of the present disclosure;
fig. 8 is a schematic flowchart of a database query method according to an embodiment of the present disclosure;
FIG. 9 is a schematic diagram illustrating the effect of crowd extraction using the database query method according to the embodiment of the present disclosure;
fig. 10 is a schematic structural diagram of a database query device according to a fourth embodiment of the present disclosure;
FIG. 11 is a block diagram illustrating an electronic device in accordance with an example embodiment.
Detailed Description
The following description of the exemplary embodiments of the present application, taken in conjunction with the accompanying drawings, includes various details of the embodiments of the application for the understanding of the same, which are to be considered exemplary only. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present application. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
With the continuous development of enterprises, enterprise-related personnel can perform database query according to business requirements (such as crowd insights and user operations) to acquire and analyze relevant business data. In the related art, as shown in fig. 1, Structured Query Language (SQL) is directly queried based on a Clickhouse engine, that is, enterprise-related personnel send Query condition information to a back-end at a front-end to perform data analysis (ClickBI) and database Query (Clickhouse) to obtain related service data, but due to serious front-end and back-end service coupling, when the front-end Query condition information changes, a situation that the back-end cannot perform database Query may occur, so that the related service data cannot be obtained, and user experience is reduced.
In order to solve the above problems, the present disclosure provides a database query method, an apparatus, an electronic device, and a storage medium.
A database query method, an apparatus, an electronic device, and a storage medium according to embodiments of the present disclosure are described below with reference to the accompanying drawings.
Fig. 2 is a schematic flowchart of a database query method according to an embodiment of the disclosure.
The embodiment of the present disclosure is exemplified by the configuration of the database query method in the database query device, and the database query device can be applied to any electronic device, so that the electronic device can perform the database query function.
The electronic device may be any device having a computing capability, for example, a Personal Computer (PC), a mobile terminal, and the like, and the mobile terminal may be a hardware device having various operating systems, touch screens, and/or display screens, such as a mobile phone, a tablet Computer, a Personal digital assistant, and a wearable device.
As shown in fig. 2, the database query method may include the steps of:
in step 201, query condition information generated based on a user operation is acquired.
The query condition information comprises the identifications of a plurality of target attributes, the attribute value of each target attribute and the incidence relation among the plurality of target attributes.
As a possible implementation manner of the embodiment of the present disclosure, a front-end expression sent by a front-end page in response to a user operation is received; the front-end expression carries query condition information.
That is to say, a user may perform an operation on a front-end page (e.g., a front-end interactive interface) according to a service requirement, for example, select, click or drag a related control, or input related information on the front-end page, where the front-end page may generate a corresponding front-end expression in response to the user operation, send the front-end expression, and generate corresponding query condition information according to the front-end expression, where the front-end expression carries the query condition information.
It should be noted that the query condition information may include an identifier of a plurality of target attributes, an attribute value of each target attribute, and an association relationship between the plurality of target attributes.
As an example, the front-end expression is:
{
"operator":1,
"selectTagSet":[
{
"tagId":"xxxx",
"tagNamecn": age ",
"tagNameEn":"AGE",
}
]
}
the identifiers of the target attributes can be "" operator ": 1', the target attributes are" tagId, "" tagNamecn "and" tagNameEn respectively, the attribute value of the target attribute "tagId" is "xxxx", the attribute value of the target attribute "tagNamecn" is "AGE", the attribute value of the target attribute "tagNameEn" is "AGE", and the correlation among the target attributes is "and (and)".
In the embodiment of the present disclosure, in order to convert each target attribute and each attribute value into a field that can be recognized by a backend service, a conversion table may be queried and set according to each target attribute to convert each target attribute into a query field, and meanwhile, an attribute value of each target attribute is converted into a field value of the query field corresponding to each target attribute according to the attribute value query and set conversion table of each target attribute. The setting conversion table stores the mapping relation between each target attribute and the corresponding query field, and the mapping relation between the attribute value of each target attribute and the corresponding field value.
In order to decouple the front-end service from the back-end service, as a possible implementation manner of the embodiment of the present disclosure, the back-end expression of the query condition information may be obtained by filling the plurality of query fields and the field values corresponding to the plurality of query fields into the back-end expression template according to the association relationship.
As an example, the back-end expression may be
"opr":"diff",
"label_type":2,
"type":1,
"group":{},
"table":"xxxx",
"filter_expr":{
"type":2,
"opr":"and",
"sub_expr_list":[
{
"opr":"=",
"field":"text",
"values":[
"2"
],
"label_type":1,
"type":1,
"table":"xxxxx",
"opr_extra":"right"
}
]
}
}。
And step 204, generating a query statement according to the syntax tree of the rear-end expression so as to query the database by adopting the query statement.
In the embodiment of the present disclosure, the back-end expression may be parsed into a syntax tree, and each node in the syntax tree may be converted into a query sub-statement, and then, a query statement may be generated according to each query sub-statement, so that a database query is performed by using the query statement.
In conclusion, the back-end expression is dynamically generated based on the conversion of the query condition information, so that the query statement of the database is generated based on the dynamically generated back-end expression, the query of the database is realized, the query condition information and the back-end expression are decoupled, the condition that the back-end cannot perform database query due to the format change of the front-end query condition information is avoided, and the user experience is improved.
In order to more clearly illustrate how the above embodiments fill the plurality of query fields and the field values corresponding to the plurality of query fields into the back-end expression template according to the association relationship, so as to obtain the back-end expression of the query condition information, the present disclosure proposes another database query method.
Fig. 3 is a schematic flowchart of a database query method according to a second embodiment of the disclosure.
As shown in fig. 3, the database query method may include the steps of:
The query condition information comprises the identifications of a plurality of target attributes, the attribute value of each target attribute and the incidence relation among the plurality of target attributes.
Each first-level expression is filled with a query field and a field value corresponding to the query field.
In the embodiment of the present disclosure, each query field and the field value corresponding to the query field are filled in the back-end expression template, so as to obtain a plurality of first-level expressions.
As an example, the first hierarchy expression is: {
"sub_expr_list":[
{
"opr":"=",
"field":"text",
"values":[
"2"
]
}
]
};
The query field is "values", the field value of the query field is "2", and the other fields except the query field and the field value corresponding to the query field in the first-level expression are backend expression templates.
In the embodiment of the present disclosure, the association relationship may include "and", "or", "and" or ", etc., as an example, a second level expression indicating at least one operator is generated according to at least one operator between a plurality of query fields in the association relationship; and determining the hierarchical relationship among the second hierarchical expressions according to the execution sequence of at least one operator in the incidence relationship.
For example, the operator between the query fields is "and", and the corresponding second level expression can be:
{
"filter_expr":{
"type":2,
"opr":"and"
}
};
wherein, the term "opr": and "is used to indicate that the operator between the query fields is" and ", and the term" type ": 2" is used to indicate that the operator between the query fields is a simple combination type in the back-end expression template, for example, the operator between the query fields is single, the operator between the query fields is "and", or ", etc.
In an embodiment of the present disclosure, after determining an operator indicated by the second hierarchical expression, the first hierarchical expression having the operator may be taken as the first hierarchical expression of the second hierarchical expression sublayer.
E.g. a great curl
"filter_expr":{
"type":2,
"opr":"and"
}
"sub_expr_list":[
{
"opr":"=",
"field":"text",
"values":[
"2"
]
}
]
};
The "sub _ expr _ list" expression (first hierarchy expression) may be used as a first hierarchy expression of the "filter _ expr" expression (second hierarchy expression) sub-layer.
It should be noted that the number of the second hierarchical expressions may be one or more, and when the number of the second hierarchical expressions is multiple, the hierarchical relationship between the second hierarchical expressions is determined according to the sequence executed by at least one operator in the association relationship.
And 305, combining the second hierarchical expression with the first hierarchical expression serving as a second hierarchical expression sublayer to obtain a back-end expression of the query condition information.
And further, combining the second hierarchical expression with the first hierarchical expression serving as a second hierarchical expression sublayer, and taking the combined expression as a rear-end expression of the query condition information.
It should be noted that the execution processes of steps 301 to 302 and step 306 may be implemented by any one of the embodiments of the present disclosure, and the embodiments of the present disclosure do not limit this, and are not described again.
In summary, the plurality of query fields and the field values corresponding to the plurality of query fields are filled in the back-end expression template to obtain a plurality of first-level expressions; generating a second hierarchical expression according to the incidence relation, and determining a first hierarchical expression serving as a second hierarchical expression sublayer according to the query field with the incidence relation; the second hierarchical expression is combined with the first hierarchical expression serving as a second hierarchical expression sublayer to obtain a back-end expression of the query condition information, and therefore the back-end expression is dynamically generated based on the conversion of the query condition information, the generated back-end expression better focuses on the logic operation between the front-end query condition information, the back-end expression can be decoupled from the front-end service, the situation that the back-end cannot query the database due to the format change of the front-end query condition information is avoided, and the user experience is improved.
In order to generate a query statement more accurately, as shown in fig. 4, fig. 4 is a schematic flowchart of a database query method provided in a third embodiment of the present disclosure, in the embodiment of the present disclosure, a backend expression may be parsed into a syntax tree, and a query statement is generated according to the syntax tree of the backend expression, where the embodiment shown in fig. 4 may include the following steps:
The query condition information comprises the identifications of a plurality of target attributes, the attribute value of each target attribute and the incidence relation among the plurality of target attributes.
Each first-level expression is filled with a query field and a field value corresponding to the query field.
The method comprises the steps that leaf nodes in an abstract syntax tree (AST for short) are used for indicating a first level expression in a back-end expression, non-leaf nodes in the syntax tree are used for indicating a second level expression in the back-end expression, and the parent-child relationship of the nodes of the syntax tree is determined according to the level relationship between the second level expressions and the level relationship between the first level expression and the second level expression.
In the embodiment of the disclosure, the backend expression is parsed to generate a corresponding syntax tree, where a first hierarchical expression in the backend expression may correspond to a leaf node in the syntax tree, a second hierarchical expression in the backend expression may correspond to a non-leaf node in the syntax tree, and when there are multiple second hierarchical expressions in the backend expression, a node parent-child relationship of the syntax tree may be determined according to a hierarchical relationship between the second hierarchical expressions and a hierarchical relationship between the first hierarchical expression and the second hierarchical expression.
For example, as shown in fig. 5, fig. 5 is a schematic flow chart illustrating parsing a backend expression to generate a corresponding syntax tree according to an embodiment of the disclosure, where the backend expression is
{
"opr":"diff",
"label_type":2,
"type":1,
"group":{},
"table":"xxxx",
"filter_expr":{
"type":2,
"opr":"and"
"sub_expr_list":[
{
"opr":"=",
"field":"text",
"values":[
"2"
],
"label_type":1,
"type":1,
"table":"xxxxx",
"opr_extra":"right",
}
]
}
As an example, the method can be used,
the specific process of parsing the backend expression to generate the corresponding syntax tree may be as follows:
1. determining whether a difference set exists in the rear-end expression, if not, the right subtree is empty;
2. checking operators (e.g., secondary operators) between the query fields, e.g., checking the operator "filter _ expr" as "and (join)", the right subtree as null;
3. the node data (e.g., "TABLE", "FIELD", "VALUE", and "OPERATOR") under the three-level sub-tree (sub _ expr _ list) are obtained and parsed, and a corresponding syntax tree is generated (as shown in fig. 6).
It should be noted that, in the embodiment of the present disclosure, the syntax tree may be parsed into different SQL statements for different query engines, and the different SQL statements are executed in different query engines, so that a proxy (proxy) may be built on the query engine of each database, for example, a spark proxy may be built on the spark engine spark.
It should be noted that the execution processes of steps 401 to 405 may be implemented by any one of the embodiments of the present disclosure, and the embodiments of the present disclosure do not limit this and are not described again.
In the embodiment of the present disclosure, different call agents corresponding to different database types resolve each node of the syntax tree into different query sub-statements. As an example, according to the type of the database, an agent applicable to the type is called, and the agent converts each node in the syntax tree into a query sub-statement according to a conversion policy corresponding to the type of the database. As a possible implementation of the disclosed embodiments, as shown in fig. 7, each query engine implements a uniform application programming interface (e.g., AST API), and abstracts respective engine features through a decorator schema; according to the characteristics of each query engine, each agent executes customized business processing, for example, a spark agent analyzes diff operation into left anti join (left reverse connection), and meanwhile, catalog processing is added to leaf nodes on the bottom layer.
And further, splicing the converted query sub-sentences in each stage to generate a query sentence so as to query the database by using the query sentence.
In summary, the back-end expression is analyzed into a syntax tree; calling an agent suitable for the type according to the type of the database so that the agent converts each node in the syntax tree into a query sub-statement according to a conversion strategy corresponding to the type; the query statement is generated according to the query sub-statement converted by each node, so that a rear-end expression is dynamically generated based on the conversion of the query condition information, and the query statement is generated according to a syntax tree corresponding to the rear-end expression, so that when the format of the query condition information of the front end is changed, the query statement generated by the rear end is not influenced, and the query efficiency can be improved.
In order to more clearly illustrate the above embodiments, the description will now be made by way of example.
For example, as shown in fig. 8, fig. 8 is a schematic flow chart of a database query method provided in the embodiment of the present disclosure. In fig. 8, a front-end expression sent by a front-end interaction page (front-end page) is converted to generate a back-end expression, a proxy (proxy) is constructed on a query engine of each database, an SQL statement is analyzed by a syntax tree of the back-end expression, and then, after the query engine completes result query, a result is written into the database, and meanwhile, a back-end service pushes a query result to the front-end interaction page. It should be noted that, different agents are constructed on the query engines of different databases, and the agents may include: spark proxy, doris proxy, and ES proxy, etc. Furthermore, as shown in fig. 9, for different front-end expressions, by using the database query method according to the embodiment of the present disclosure, the extraction of the average daily population is greatly improved.
According to the database query method, query condition information generated based on user operation is acquired; the query condition information comprises identifiers of a plurality of target attributes, attribute values of each target attribute and incidence relations among the plurality of target attributes; converting each target attribute into a query field, converting the attribute value of each target attribute into a field value of the query field corresponding to the target attribute, and obtaining a plurality of query fields and field values corresponding to the plurality of query fields; filling the plurality of query fields and field values corresponding to the plurality of query fields into a back-end expression template according to the association relation so as to obtain a back-end expression of the query condition information; the query statement is generated according to the syntax tree of the rear-end expression so as to query the database by adopting the query statement, and therefore, the rear-end expression is dynamically generated based on the conversion of the query condition information, so that the query statement of the database is generated based on the dynamically generated rear-end expression, the query of the database is realized, the query condition information and the rear-end expression are decoupled, the condition that the rear-end cannot query the database due to the format change of the query condition information at the front end is avoided, and the user experience is improved.
In order to implement the above embodiments, the present disclosure further provides a database query device.
Fig. 10 is a schematic structural diagram of a database query device according to a fourth embodiment of the present disclosure.
As shown in fig. 10, the database query apparatus 1000 includes: an obtaining module 1010, a converting module 1020, a padding module 1030, and a generating module 1040.
The obtaining module 1010 is configured to obtain query condition information generated based on a user operation; the query condition information comprises identifiers of a plurality of target attributes, attribute values of each target attribute and incidence relations among the plurality of target attributes; a conversion module 1020, configured to convert each target attribute into a query field, where an attribute value of each target attribute is converted into a field value of the query field corresponding to the target attribute, so as to obtain multiple query fields and field values corresponding to the multiple query fields; a filling module 1030, configured to fill the multiple query fields and field values corresponding to the multiple query fields into the back-end expression template according to the association relationship, so as to obtain a back-end expression of the query condition information; the generating module 1040 is configured to generate a query statement according to the syntax tree of the backend expression, so as to query the database by using the query statement.
As a possible implementation manner of the embodiment of the present disclosure, the padding module 1030 is configured to: filling the plurality of query fields and field values corresponding to the plurality of query fields into a rear-end expression template respectively to obtain a plurality of first-level expressions; wherein each first hierarchical expression is filled with one query field and a field value corresponding to the one query field; generating a second hierarchical expression according to the incidence relation, and determining a first hierarchical expression serving as a second hierarchical expression sublayer according to the query field with the incidence relation; and combining the second level expression with the first level expression serving as a second level expression sublayer to obtain a back-end expression of the query condition information.
As a possible implementation manner of the embodiment of the present disclosure, the padding module 1030 is further configured to: generating a second level expression for indicating at least one operator according to at least one operator among the plurality of query fields in the incidence relation; and determining the hierarchical relationship among the second hierarchical expressions according to the execution sequence of the at least one operator in the incidence relationship.
As a possible implementation manner of the embodiment of the present disclosure, the database query apparatus further includes: and an analysis module.
The parsing module is used for parsing the rear-end expression into a syntax tree; the leaf nodes in the syntax tree are used for indicating a first level expression in the back-end expression, the non-leaf nodes in the syntax tree are used for indicating a second level expression in the back-end expression, and the parent-child relationship of the nodes in the syntax tree is determined according to the level relationship between the second level expressions and the level relationship between the first level expression and the second level expression.
As a possible implementation manner of the embodiment of the present disclosure, the generating module 1040 is configured to: calling an agent suitable for the type according to the type of the database so that the agent converts each node in the syntax tree into a query sub-statement according to a conversion strategy corresponding to the type; and generating a query statement according to the converted query sub-statement of each node.
As a possible implementation manner of the embodiment of the present disclosure, the obtaining module 1010 is configured to: receiving a front-end expression sent by a front-end page in response to user operation; wherein the front-end expression carries the query condition information.
The database query device of the embodiment of the disclosure acquires query condition information generated based on user operation; the query condition information comprises identifiers of a plurality of target attributes, attribute values of each target attribute and incidence relations among the plurality of target attributes; converting each target attribute into a query field, converting the attribute value of each target attribute into the field value of the query field corresponding to the target attribute, and obtaining a plurality of query fields and the field values corresponding to the plurality of query fields; filling the plurality of query fields and field values corresponding to the plurality of query fields into a back-end expression template according to the association relationship so as to obtain a back-end expression of the query condition information; the query statement is generated according to the syntax tree of the rear-end expression so as to query the database by adopting the query statement, and therefore, the rear-end expression is dynamically generated based on the conversion of the query condition information, so that the query statement of the database is generated based on the dynamically generated rear-end expression, the query of the database is realized, the query condition information and the rear-end expression are decoupled, the condition that the rear-end cannot query the database due to the format change of the query condition information at the front end is avoided, and the user experience is improved.
It should be noted that the foregoing explanation on the embodiment of the database query method is also applicable to the database query device of the embodiment, and is not described herein again.
In order to implement the above embodiments, the present disclosure also provides an electronic device, including: at least one processor; and a memory communicatively coupled to the at least one processor; 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 perform the database query method according to the embodiments of fig. 1 to 9 of the present disclosure.
In order to implement the above embodiments, the present disclosure also proposes a non-transitory computer-readable storage medium storing computer instructions for causing the computer to execute the database query method according to the embodiments of fig. 1 to 9.
In order to implement the foregoing embodiments, the present disclosure further provides a computer program product, where when being executed by an instruction processor in the computer program product, the database query method described in the embodiments of fig. 1 to 9 is implemented.
FIG. 11 is a block diagram illustrating an electronic device in accordance with an example embodiment. For example, the electronic device 1100 can be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, an exercise device, a personal digital assistant, and the like.
Referring to fig. 11, electronic device 1100 may include one or more of the following components: a processing component 1102, a memory 1104, a power component 1106, a multimedia component 1108, an audio component 1110, an input/output (I/O) interface 1112, a sensor component 1114, and a communications component 1116.
The processing component 1102 generally controls the overall operation of the electronic device 1100, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing components 1102 may include one or more processors 1120 to execute instructions to perform all or a portion of the steps of the methods described above. Further, the processing component 1102 may include one or more modules that facilitate interaction between the processing component 1102 and other components. For example, the processing component 1102 may include a multimedia module to facilitate interaction between the multimedia component 1108 and the processing component 1102.
The memory 1104 is configured to store various types of data to support operations at the electronic device 1100. Examples of such data include instructions for any application or method operating on the electronic device 1100, contact data, phonebook data, messages, pictures, videos, and so forth. The memory 1104 may be implemented by any type or combination of volatile or non-volatile memory devices 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 memory, flash memory, magnetic or optical disks.
The multimedia component 1108 includes a screen that provides an output interface between the electronic device 1100 and a 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 touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 1108 includes a front facing camera and/or a rear facing camera. The front camera and/or the rear camera may receive external multimedia data when the electronic device 1100 is in an operating mode, such as a shooting mode or a video mode. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
The audio component 1110 is configured to output and/or input audio signals. For example, the audio component 1110 includes a Microphone (MIC) configured to receive external audio signals when the electronic device 1100 is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may further be stored in the memory 1104 or transmitted via the communication component 1116. In some embodiments, the audio assembly 1110 further includes a speaker for outputting audio signals.
The I/O interface 1112 provides an interface between the processing component 1102 and peripheral interface modules, which may be keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to: a home button, a volume button, a start button, and a lock button.
The sensor assembly 1114 includes one or more sensors for providing various aspects of state assessment for the electronic device 1100. For example, the sensor assembly 1114 may detect an open/closed state of the electronic device 1100, the relative positioning of components, such as a display and keypad of the electronic device 1100, the sensor assembly 1114 may also detect a change in the position of the electronic device 1100 or a component of the electronic device 1100, the presence or absence of user contact with the electronic device 1100, orientation or acceleration/deceleration of the electronic device 1100, and a change in the temperature of the electronic device 1100. The sensor assembly 1114 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The 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, the sensor assembly 1114 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
The communication component 1116 is configured to facilitate wired or wireless communication between the electronic device 1100 and other devices. The electronic device 1100 may access a wireless network based on a communication standard, such as WiFi, 4G or 5G, or a combination thereof. In an exemplary embodiment, the communication component 1116 receives broadcast signals or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 1116 also includes a Near Field Communication (NFC) module to facilitate short-range communications. 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.
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, micro-controllers, microprocessors or other electronic components for performing the above-described methods.
In an exemplary embodiment, a non-transitory computer-readable storage medium comprising instructions, such as the memory 1104 comprising instructions, executable by the processor 1120 of the electronic device 1100 to perform the above-described method is also provided. For example, the non-transitory computer readable storage medium may be a ROM, a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
In the description herein, references to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the present disclosure. In this specification, the schematic representations of the terms used above are not necessarily intended to refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, various embodiments or examples and features of different embodiments or examples described in this specification can be combined and combined by one skilled in the art without contradiction.
Furthermore, the terms "first", "second" and "first" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. In the description of the present disclosure, "a plurality" means at least two, e.g., two, three, etc., unless explicitly specifically limited otherwise.
Any process or method descriptions in flow charts or otherwise described herein may be understood as representing modules, segments, or portions of code which include one or more executable instructions for implementing steps of a custom logic function or process, and alternate implementations are included within the scope of the preferred embodiment of the present disclosure in which functions may be executed out of order from that shown or discussed, including substantially concurrently or in reverse order, depending on the functionality involved, as would be understood by those reasonably skilled in the art of the embodiments of the present disclosure.
The logic and/or steps represented in the flowcharts or otherwise described herein, e.g., an ordered listing of executable instructions that can be considered to implement logical functions, can be embodied in any computer-readable medium for use by or in connection with an instruction execution system, apparatus, or device, such as a computer-based system, processor-containing system, or other system that can fetch the instructions from the instruction execution system, apparatus, or device and execute the instructions. For the purposes of this description, a "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of the computer-readable medium would include the following: an electrical connection (electronic device) having one or more wires, a portable computer diskette (magnetic device), a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disc read-only memory (CDROM). Additionally, the computer-readable medium could even be paper or another suitable medium upon which the program is printed, as the program can be electronically captured, via for instance optical scanning of the paper or other medium, then compiled, interpreted or otherwise processed in a suitable manner if necessary, and then stored in a computer memory.
It should be understood that portions of the present disclosure may be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, the various steps or methods may be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. If implemented in hardware, as in another embodiment, any one or combination of the following techniques, which are known in the art, may be used: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application specific integrated circuit having an appropriate combinational logic gate circuit, a Programmable Gate Array (PGA), a Field Programmable Gate Array (FPGA), or the like.
It will be understood by those skilled in the art that all or part of the steps carried by the method for implementing the above embodiments may be implemented by hardware related to instructions of a program, which may be stored in a computer readable storage medium, and when the program is executed, the program includes one or a combination of the steps of the method embodiments.
In addition, functional units in the embodiments of the present disclosure may be integrated into one processing module, or each unit may exist alone physically, or two or more units are integrated into one module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode. The integrated module, if implemented in the form of a software functional module and sold or used as a stand-alone product, may also be stored in a computer readable storage medium.
The storage medium mentioned above may be a read-only memory, a magnetic or optical disk, etc. Although embodiments of the present disclosure have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present disclosure, and that changes, modifications, substitutions and alterations may be made to the above embodiments by those of ordinary skill in the art within the scope of the present disclosure.
Claims (14)
1. A database query method, comprising:
acquiring query condition information generated based on user operation; the query condition information comprises identifications of a plurality of target attributes, attribute values of each target attribute and incidence relations among the plurality of target attributes;
converting each target attribute into a query field, converting the attribute value of each target attribute into the field value of the query field corresponding to the target attribute, and obtaining a plurality of query fields and field values corresponding to the plurality of query fields;
filling the plurality of query fields and field values corresponding to the plurality of query fields into a back-end expression template according to the association relationship so as to obtain a back-end expression of the query condition information;
and generating a query statement according to the syntax tree of the rear-end expression so as to query a database by adopting the query statement.
2. The method according to claim 1, wherein the populating a backend expression template with the plurality of query fields and field values corresponding to the plurality of query fields according to the association relationship to obtain a backend expression of the query condition information includes:
filling the plurality of query fields and field values corresponding to the plurality of query fields into the rear-end expression template respectively to obtain a plurality of first-level expressions; wherein each first hierarchical expression is filled with one query field and a field value corresponding to the one query field;
generating a second hierarchical expression according to the incidence relation, and determining a first hierarchical expression which is a sub-layer of the second hierarchical expression according to the query field with the incidence relation;
and combining the second hierarchical expression with the first hierarchical expression serving as the second hierarchical expression sublayer to obtain a back-end expression of the query condition information.
3. The method according to claim 2, wherein said generating a second hierarchical expression according to the association relationship comprises:
generating a second level expression for indicating at least one operator among the plurality of query fields in the incidence relation according to the at least one operator;
and determining the hierarchical relationship among the second hierarchical expressions according to the sequence of the execution of the at least one operator in the incidence relationship.
4. The method of claim 3, further comprising:
analyzing the rear-end expression into the syntax tree;
wherein leaf nodes in the syntax tree are used for indicating a first level expression in the backend expressions, non-leaf nodes in the syntax tree are used for indicating a second level expression in the backend expressions, and node parent-child relationships of the syntax tree are determined according to the level relationship between the second level expressions and the level relationship between the first level expression and the second level expression.
5. The method of any of claims 1-4, wherein generating a query statement from the syntax tree of the back-end expression comprises:
calling an agent suitable for the type according to the type of the database, so that the agent converts each node in the syntax tree into a query sub-statement according to a conversion strategy corresponding to the type;
and generating a query statement according to the query sub-statement converted by each node.
6. The method according to any one of claims 1 to 4, wherein the obtaining query condition information generated based on a user operation includes:
receiving a front-end expression sent by a front-end page in response to user operation;
wherein the front-end expression carries the query condition information.
7. A database query device, comprising:
the acquisition module is used for acquiring query condition information generated based on user operation; the query condition information comprises identifications of a plurality of target attributes, attribute values of each target attribute and incidence relations among the plurality of target attributes;
a conversion module, configured to convert each target attribute into a query field, where an attribute value of each target attribute is converted into a field value of the query field corresponding to the target attribute, so as to obtain a plurality of query fields and field values corresponding to the plurality of query fields;
a filling module, configured to fill the query fields and field values corresponding to the query fields into a back-end expression template according to the association relationship, so as to obtain a back-end expression of the query condition information;
and the generating module is used for generating a query statement according to the syntax tree of the rear-end expression so as to query a database by adopting the query statement.
8. The apparatus according to claim 7, wherein the filling module is specifically configured to:
filling the plurality of query fields and field values corresponding to the plurality of query fields into the rear-end expression template to obtain a plurality of first-level expressions; wherein each first hierarchical expression is filled with one query field and a field value corresponding to the one query field;
generating a second hierarchical expression according to the incidence relation, and determining a first hierarchical expression which is a sub-layer of the second hierarchical expression according to the query field with the incidence relation;
and combining the second hierarchical expression with the first hierarchical expression which is taken as the second hierarchical expression sublayer to obtain the back-end expression of the query condition information.
9. The apparatus of claim 8, wherein the fill module is further configured to:
generating a second level expression for indicating at least one operator among the plurality of query fields in the incidence relation according to the at least one operator;
and determining the hierarchical relationship among the second hierarchical expressions according to the sequence of the execution of the at least one operator in the incidence relationship.
10. The apparatus of claim 9, further comprising:
the analysis module is used for analyzing the rear-end expression into the syntax tree;
wherein leaf nodes in the syntax tree are used for indicating a first level expression in the backend expressions, non-leaf nodes in the syntax tree are used for indicating a second level expression in the backend expressions, and node parent-child relationships of the syntax tree are determined according to the level relationship between the second level expressions and the level relationship between the first level expression and the second level expression.
11. The apparatus according to any one of claims 7 to 10, wherein the generating module is specifically configured to:
calling an agent suitable for the type according to the type of the database, so that the agent converts each node in the syntax tree into a query sub-statement according to a conversion strategy corresponding to the type;
and generating a query statement according to the query sub-statement converted by each node.
12. The apparatus according to any one of claims 7 to 10, wherein the obtaining module is specifically configured to:
receiving a front-end expression sent by a front-end page in response to user operation;
wherein the front-end expression carries the query condition information.
13. An electronic device, comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-6.
14. A non-transitory computer readable storage medium having stored thereon computer instructions for causing the computer to perform the method of any one of claims 1-6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210730534.4A CN115062046A (en) | 2022-06-24 | 2022-06-24 | Database query method and device, electronic equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210730534.4A CN115062046A (en) | 2022-06-24 | 2022-06-24 | Database query method and device, electronic equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN115062046A true CN115062046A (en) | 2022-09-16 |
Family
ID=83201966
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210730534.4A Pending CN115062046A (en) | 2022-06-24 | 2022-06-24 | Database query method and device, electronic equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115062046A (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115630117A (en) * | 2022-12-21 | 2023-01-20 | 网易(杭州)网络有限公司 | Data analysis method, materialized view generation method and related equipment |
CN116680444A (en) * | 2023-08-03 | 2023-09-01 | 腾讯科技(深圳)有限公司 | Data processing method, device, equipment and storage medium |
WO2024088264A1 (en) * | 2022-10-28 | 2024-05-02 | 北京字跳网络技术有限公司 | Data query method and apparatus, electronic device, and storage medium |
-
2022
- 2022-06-24 CN CN202210730534.4A patent/CN115062046A/en active Pending
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2024088264A1 (en) * | 2022-10-28 | 2024-05-02 | 北京字跳网络技术有限公司 | Data query method and apparatus, electronic device, and storage medium |
CN115630117A (en) * | 2022-12-21 | 2023-01-20 | 网易(杭州)网络有限公司 | Data analysis method, materialized view generation method and related equipment |
CN116680444A (en) * | 2023-08-03 | 2023-09-01 | 腾讯科技(深圳)有限公司 | Data processing method, device, equipment and storage medium |
CN116680444B (en) * | 2023-08-03 | 2024-01-19 | 腾讯科技(深圳)有限公司 | Data processing method, device, equipment and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106569800B (en) | Front-end interface generation method and device | |
CN115062046A (en) | Database query method and device, electronic equipment and storage medium | |
CN106547547B (en) | data acquisition method and device | |
US20150350120A1 (en) | Method and device for managing instant message | |
CN111338971B (en) | Application testing method and device, electronic equipment and storage medium | |
CN109522286B (en) | Processing method and device of file system | |
CN110928854A (en) | Data import method and device and electronic equipment | |
CN111552688A (en) | Data export method and device and electronic equipment | |
CN113778398B (en) | Code generation method, device, electronic equipment and storage medium | |
CN112988822B (en) | Data query method, device, equipment, readable storage medium and product | |
CN114239531A (en) | Template recommendation method and device, electronic equipment and storage medium | |
CN114201484A (en) | Information processing method, information processing device, electronic equipment and storage medium | |
CN114219443A (en) | Document data processing method, device and equipment | |
CN114691104A (en) | Language conversion method and device, electronic equipment and storage medium | |
CN112732734A (en) | Information processing method and device | |
CN113420531A (en) | Code text conversion method and device and storage medium | |
CN108460128B (en) | Document management method and device, electronic device and readable storage medium | |
CN111736890A (en) | Data updating method and device, electronic equipment and storage medium | |
CN118170435B (en) | Instruction information processing method, device, equipment and storage medium | |
CN112380245A (en) | Execution method and device of HiveSQL task and storage medium | |
CN116582417B (en) | Data processing method, device, computer equipment and storage medium | |
CN110119471B (en) | Method and device for checking consistency of search results | |
CN115268935A (en) | Data processing method and device | |
CN114357052A (en) | Heterogeneous database object conversion method and device, electronic equipment and storage medium | |
CN113760960A (en) | Information generation method and device for generating information |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |