CN111143359A - Query statement generation method and device - Google Patents

Query statement generation method and device Download PDF

Info

Publication number
CN111143359A
CN111143359A CN201911310576.7A CN201911310576A CN111143359A CN 111143359 A CN111143359 A CN 111143359A CN 201911310576 A CN201911310576 A CN 201911310576A CN 111143359 A CN111143359 A CN 111143359A
Authority
CN
China
Prior art keywords
query
condition
level
data
root node
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
Application number
CN201911310576.7A
Other languages
Chinese (zh)
Inventor
高泽锋
汪正光
范建文
薛超
罗亮
李昱
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Koubei Shanghai Information Technology Co Ltd
Original Assignee
Koubei Shanghai Information Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Koubei Shanghai Information Technology Co Ltd filed Critical Koubei Shanghai Information Technology Co Ltd
Priority to CN201911310576.7A priority Critical patent/CN111143359A/en
Publication of CN111143359A publication Critical patent/CN111143359A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2246Trees, e.g. B+trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • G06F16/244Grouping and aggregation

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the invention discloses a query statement generation method and a device, wherein the method comprises the following steps: receiving a query request sent by a front-end page; the query request carries query demand data selected by a user; the query demand data comprises query result data and query condition data; analyzing the query condition data to generate a query condition relation tree; the query condition relation tree comprises a plurality of leaf nodes and n-level root nodes; each level of root nodes comprises at least one root node, and a plurality of leaf nodes are the next level nodes of the nth level of root nodes; each leaf node is used for recording query condition fields and corresponding condition limiting data; the ith level root node is used for recording the logical operation relationship among a plurality of leaf nodes of the next level of the ith level root node or the logical operation relationship among the (i + 1) th level root nodes; and traversing the query condition relation tree, and splicing to generate corresponding query sentences according to the query result data. The generation of the query statement is transparent to the user, and the threshold of technical requirements on the user is greatly reduced.

Description

Query statement generation method and device
Technical Field
The embodiment of the invention relates to the technical field of databases, in particular to a query statement generation method and device.
Background
Structured Query Language (sql) can conveniently provide a data Query function to Query the corresponding Query result from the data stored in the database. When the data query function is realized by using the sql query statement, the user needs to know the sql to a certain extent, so that the correct sql query statement can be used for querying, and the technical threshold requirement on the user is high. Particularly, when the sql query statement relates to the related query of a plurality of database tables, if the user does not have a certain sql technology, the user cannot query to obtain the required query result.
For business personnel or operators, the sql technology is not available, but the business personnel or operators often need to query data due to business needs and other reasons, so that a query statement generation method is needed to help users to quickly query data.
Disclosure of Invention
In view of the above, embodiments of the present invention are proposed to provide a query statement generation method and apparatus that overcome the above problems or at least partially solve the above problems.
According to an aspect of the embodiments of the present invention, there is provided a query statement generation method, including:
receiving a query request sent by a front-end page; the query request carries query demand data selected by a user; the query demand data comprises query result data and query condition data;
analyzing the query condition data to generate a query condition relation tree; the query condition relation tree comprises a plurality of leaf nodes and n-level root nodes; each level of root nodes comprises at least one root node, and a plurality of leaf nodes are the next level nodes of the nth level of root nodes; each leaf node is used for recording query condition fields and corresponding condition limiting data; the ith level root node is used for recording the logical operation relationship among a plurality of leaf nodes of the next level of the ith level root node or the logical operation relationship among the (i + 1) th level root nodes of the next level;
and traversing the query condition relation tree, and splicing to generate corresponding query sentences according to the query result data.
Optionally, the query result data comprises a query result field; the query condition data comprises query condition fields, corresponding condition limiting data and logical operation relations among the query condition fields.
Optionally, parsing the query condition data, and generating the query condition relationship tree further includes:
generating a plurality of leaf nodes of a query condition relation tree according to the query condition fields and the corresponding condition limiting data; wherein, a leaf node records a query condition field and corresponding condition limiting data;
generating an i-th level root node of the query condition relation tree according to the logic operation relation between the query condition fields, and setting the superior-inferior level relation of the i-th level root node according to the query condition fields related to the logic operation relation between the query condition fields; and the ith-level root node records the logical operation symbol of the logical operation relation between the query condition fields.
Optionally, the generating an i-th level root node of the query condition relation tree according to the logical operation relation between the query condition fields, and setting the upper and lower level relations of the i-th level root node according to the query condition fields related to the logical operation relation between the query condition fields further includes:
if the logic operation relation among the query condition fields is an OR relation OR an AND relation, the leaf node corresponding to the query condition field related to the logic operation relation among the query condition fields is the next level of the ith level root node; or the root node of the (i + 1) th level corresponding to the query condition field related to the logic operation relation between the query condition fields is the next level of the (i) th level root node; the logical operation symbol recorded by the ith level root node is an OR logical operation symbol OR an AND logical operation symbol;
if the logic operation relation between the query condition fields is an exclusion relation, acquiring a query exclusion field and a query condition field corresponding to the exclusion relation; the leaf node corresponding to the query condition field is the next level of the ith level root node; or the (i + 1) th level root node corresponding to the query condition field is the next level of the (i) th level root node; and recording leaf nodes of the next level or root nodes of the (i + 1) th level as exclusion nodes; the logical operation symbol recorded by the ith level root node is an excluded logical operation symbol; the query condition data also includes a query exclusion field.
Optionally, traversing the query condition relationship tree, and generating a corresponding query statement by splicing according to the query result data further includes:
determining a data table to be queried in the data query set and each field in the corresponding data table according to the query result field and/or the query condition field;
traversing the query condition relation tree from leaf nodes in a middle-order traversal mode to generate query condition statements;
and generating corresponding query sentences by splicing according to the query selection sentences, the data tables to be queried and the query condition sentences generated by the query result fields.
Optionally, traversing the query conditional relationship tree in a middle-ordered traversal manner starting from the leaf nodes, and generating the query conditional statement further includes:
step S1, acquiring query condition fields recorded by leaf nodes and corresponding condition limiting data, and generating query sub-condition statements corresponding to the leaf nodes;
step S2, acquiring the j-th level root node of the previous level of the leaf node to obtain the logic operation symbol recorded by the j-th level root node;
step S3, acquiring other leaf nodes at the next level of the j-th level root node, generating corresponding query sub-condition statements, and splicing a plurality of query sub-condition statements of a plurality of leaf nodes at the next level of the j-th level root node by using the logical operation symbols recorded by the j-th level root node to obtain the query sub-condition statements corresponding to the j-th level root node;
step S4, sequentially acquiring the j-1 th level root node of the previous level from the j-level root node upwards in a circulating mode, splicing a plurality of query sub-condition statements generated by a plurality of j-level root nodes by using the logical operation symbol recorded by the j-1 th level root node, and obtaining the query sub-condition statements corresponding to the j-1 th level root node;
and repeatedly executing the step S4 until the step is traversed to the 1 st level root node of the query condition relation tree, and obtaining the spliced query condition statement.
Optionally, the query result data further comprises a query result definition tag;
generating a corresponding query statement by splicing according to the query selection statement, the data table to be queried and the query condition statement generated by the query result field, further comprises:
generating a query selection statement and a query label condition statement according to the query result field and the query result limit label; the query result limit labels comprise a summation label, a de-duplication label, a grouping label, an ordering label, a quantity limit label and/or a quantity skipping label; the query label conditional statement restricts label generation according to the query result;
and generating corresponding query sentences by splicing according to the query selection sentences, the data table to be queried, the query condition sentences and the query label condition sentences.
Optionally, traversing the query conditional relationship tree in a middle-ordered traversal manner starting from the leaf nodes, and generating the query conditional statement further includes:
if the logical operation symbol recorded by the root node is an OR logical operation symbol OR an AND logical operation symbol, generating a query sub-condition statement of the root node by using the logical operation symbol;
if the logical operation symbol recorded by the root node is an excluded logical operation symbol, acquiring a query excluded field and a data table corresponding to each query condition field under an excluded node at the next level of the root node; generating a sub-query statement of the exclusion relationship of the root node according to the query exclusion field, the data table and the query sub-conditional statement generated by the exclusion node; AND splicing the sub-query statement AND the query sub-conditional statement generated by the non-exclusive node at the next stage of the root node by using an AND logical operation symbol to generate the query conditional statement.
Optionally, the method further comprises:
judging whether the data tables to be inquired are a plurality of data tables or not;
if yes, generating data table aliases for the multiple data tables to be queried, and generating data table association query condition statements according to table association relations among the multiple data tables to be queried;
traversing the query condition relation tree, and generating corresponding query statements by splicing according to the query result data further comprises:
and generating a corresponding query statement according to the alias of the data table and the associated query condition statement of the data table.
Optionally, the method further comprises:
selecting a plurality of data tables from a database as a data query set in advance;
one data table in the data query set is set as a query main data table, and table association relations between other data tables and the query main data table are set.
Optionally, the method further comprises:
and presetting the corresponding relation between each field in the front-end page and each field in each data table in the data query set.
Optionally, the query conditional relationship tree is in json format.
According to another aspect of the embodiments of the present invention, there is provided a query statement generating apparatus, including:
the receiving module is suitable for receiving a query request sent by a front-end page; the query request carries query demand data selected by a user; the query demand data comprises query result data and query condition data;
the analysis module is suitable for analyzing the query condition data to generate a query condition relation tree; the query condition relation tree comprises a plurality of leaf nodes and n-level root nodes; each level of root nodes comprises at least one root node, and a plurality of leaf nodes are the next level nodes of the nth level of root nodes; each leaf node is used for recording query condition fields and corresponding condition limiting data; the ith level root node is used for recording the logical operation relationship among a plurality of leaf nodes of the next level of the ith level root node or the logical operation relationship among the (i + 1) th level root nodes of the next level;
and the generating module is suitable for traversing the query condition relation tree and generating the corresponding query statement by splicing according to the query result data.
Optionally, the query result data comprises a query result field; the query condition data comprises query condition fields, corresponding condition limiting data and logical operation relations among the query condition fields.
Optionally, the parsing module includes:
the leaf node generating module is suitable for generating a plurality of leaf nodes of the query condition relation tree according to the query condition fields and the corresponding condition limiting data; wherein, a leaf node records a query condition field and corresponding condition limiting data;
the root node generation module is suitable for generating the ith root node of the query condition relation tree according to the logic operation relation among the query condition fields, and setting the superior-inferior relation of the ith root node according to the query condition fields related to the logic operation relation among the query condition fields; and the ith-level root node records the logical operation symbol of the logical operation relation between the query condition fields.
Optionally, the root node generation module is further adapted to:
if the logic operation relation among the query condition fields is an OR relation OR an AND relation, the leaf node corresponding to the query condition field related to the logic operation relation among the query condition fields is the next level of the ith level root node; or the root node of the (i + 1) th level corresponding to the query condition field related to the logic operation relation between the query condition fields is the next level of the (i) th level root node; the logical operation symbol recorded by the ith level root node is an OR logical operation symbol OR an AND logical operation symbol;
if the logic operation relation between the query condition fields is an exclusion relation, acquiring a query exclusion field and a query condition field corresponding to the exclusion relation; the leaf node corresponding to the query condition field is the next level of the ith level root node; or the (i + 1) th level root node corresponding to the query condition field is the next level of the (i) th level root node; and recording leaf nodes of the next level or root nodes of the (i + 1) th level as exclusion nodes; the logical operation symbol recorded by the ith level root node is an excluded logical operation symbol; the query condition data also includes a query exclusion field.
Optionally, the generating module is further adapted to:
determining a data table to be queried in the data query set and each field in the corresponding data table according to the query result field and/or the query condition field;
traversing the query condition relation tree from leaf nodes in a middle-order traversal mode to generate query condition statements;
and generating corresponding query sentences by splicing according to the query selection sentences, the data tables to be queried and the query condition sentences generated by the query result fields.
Optionally, the generating module further comprises:
the first statement module is suitable for acquiring query condition fields recorded by leaf nodes and corresponding condition limiting data and generating query sub-condition statements corresponding to the leaf nodes;
the logical operation symbol module is suitable for acquiring a j-th level root node of the previous level of the leaf node to obtain a logical operation symbol recorded by the j-th level root node;
the second statement module is suitable for acquiring other leaf nodes at the next level of the j-th level root node, generating corresponding query sub-condition statements, and splicing a plurality of query sub-condition statements of a plurality of leaf nodes at the next level of the j-th level root node by using the logical operation symbols recorded by the j-th level root node to obtain the query sub-condition statements corresponding to the j-th level root node;
the third statement module is suitable for sequentially acquiring the j-1 th-level root node of the previous level from the j-level root node upwards in a circulating mode, and splicing a plurality of query sub-condition statements generated by a plurality of j-level root nodes by using the logical operation symbols recorded by the j-1 th-level root node to obtain the query sub-condition statements corresponding to the j-1 th-level root node;
and repeatedly executing the third statement module until the third statement module is traversed to the 1 st level root node of the query condition relation tree, and obtaining the spliced query condition statement.
Optionally, the query result data further comprises a query result definition tag;
the generation module is further adapted to:
generating a query selection statement and a query label condition statement according to the query result field and the query result limit label; the query result limit labels comprise a summation label, a de-duplication label, a grouping label, an ordering label, a quantity limit label and/or a quantity skipping label; the query label conditional statement restricts label generation according to the query result;
and generating corresponding query sentences by splicing according to the query selection sentences, the data table to be queried, the query condition sentences and the query label condition sentences.
Optionally, the generating module is further adapted to:
if the logical operation symbol recorded by the root node is an OR logical operation symbol OR an AND logical operation symbol, generating a query sub-condition statement of the root node by using the logical operation symbol;
if the logical operation symbol recorded by the root node is an excluded logical operation symbol, acquiring a query excluded field and a data table corresponding to each query condition field under an excluded node at the next level of the root node; generating a sub-query statement of the exclusion relationship of the root node according to the query exclusion field, the data table and the query sub-conditional statement generated by the exclusion node; AND splicing the sub-query statement AND the query sub-conditional statement generated by the non-exclusive node at the next stage of the root node by using an AND logical operation symbol to generate the query conditional statement.
Optionally, the apparatus further comprises:
the judging module is suitable for judging whether the data tables to be inquired are a plurality of data tables; if yes, generating data table aliases for the multiple data tables to be queried, and generating data table association query condition statements according to table association relations among the multiple data tables to be queried;
the generation module is further adapted to: and generating a corresponding query statement according to the alias of the data table and the associated query condition statement of the data table.
Optionally, the apparatus further comprises:
the selection module is suitable for selecting a plurality of data tables from the database in advance as a data query set;
and the incidence relation setting module is suitable for setting one data table in the data query set as a query main data table and setting the table incidence relation between other data tables and the query main data table.
Optionally, the apparatus further comprises:
and the corresponding relation setting module is suitable for presetting the corresponding relation between each field in the front-end page and each field in each data table in the data query set.
Optionally, the query conditional relationship tree is in json format.
According to still another aspect of an embodiment of the present invention, there is provided a computing device including: the processor, the memory and the communication interface complete mutual communication through the communication bus;
the memory is used for storing at least one executable instruction, and the executable instruction enables the processor to execute the operation corresponding to the query statement generation method.
According to a further aspect of the embodiments of the present invention, there is provided a computer storage medium, in which at least one executable instruction is stored, and the executable instruction causes a processor to perform an operation corresponding to the query statement generating method.
According to the query statement generation method and device provided by the embodiment of the invention, a query request sent by a front-end page is received; the query request carries query demand data selected by a user; the query demand data comprises query result data and query condition data; analyzing the query condition data to generate a query condition relation tree; the query condition relation tree comprises a plurality of leaf nodes and n-level root nodes; each level of root nodes comprises at least one root node, and a plurality of leaf nodes are the next level nodes of the nth level of root nodes; each leaf node is used for recording query condition fields and corresponding condition limiting data; the ith level root node is used for recording the logical operation relationship among a plurality of leaf nodes of the next level of the ith level root node or the logical operation relationship among the (i + 1) th level root nodes of the next level; and traversing the query condition relation tree, and splicing to generate corresponding query sentences according to the query result data. The user can directly select the data to be queried and the query conditions on the front-end page, the query conditions are recorded by utilizing the query condition relation tree according to the query request of the front-end page, and the query statements are obtained by splicing. In the whole process, a user does not need to pay attention to the specific generation of the query statement, the generation of the query statement is transparent to the user, and the threshold of technical requirements on the user is greatly reduced. Furthermore, the query condition can be more accurately sorted by utilizing the query condition relation tree, and the logical operation relation among the query condition fields, the condition limiting data and the query conditions is recorded, so that the accuracy of generating the query statement is improved.
The foregoing description is only an overview of the technical solutions of the embodiments of the present invention, and the embodiments of the present invention can be implemented according to the content of the description in order to make the technical means of the embodiments of the present invention more clearly understood, and the detailed description of the embodiments of the present invention is provided below in order to make the foregoing and other objects, features, and advantages of the embodiments of the present invention more clearly understandable.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the embodiments of the invention. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
FIG. 1 shows a flow diagram of a query statement generation method according to one embodiment of the invention;
FIG. 2 is a flow diagram illustrating a process of traversing a query relationship tree to generate a query condition statement according to an embodiment of the invention;
FIG. 3 shows a flow diagram of a query statement generation method according to another embodiment of the invention;
FIG. 4 is a block diagram showing the structure of a query statement generation apparatus according to an embodiment of the present invention;
FIG. 5 illustrates a schematic structural diagram of a computing device, according to an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
Fig. 1 is a flowchart illustrating a query statement generation method according to an embodiment of the present invention, and as shown in fig. 1, the method includes the following steps:
step S101, receiving a query request sent by a front-end page.
In this embodiment, a user can select data to be queried through a front-end page, a query request is triggered on the front-end page, a specific query statement is delivered to a back end according to the query request, and the user does not need to directly write an actual query statement, that is, the user only needs to provide a query requirement. The front page provides a page for the user to select the data required by the query directly, for example, a plurality of fields are listed in the front page, various limiting conditions for the fields can be selected, and the like, each field listed in the front page can be selected by the user, and the user selects the data required by the query according to the requirement of the user. The query requirement data comprises query result data and query condition data. The query result data is data which is selected by the user according to the self requirement and is obtained according to the query requirement, and the query condition data is limited condition data which is selected by the user according to the self requirement and is used in the query.
The display mode of the front-end page is not specifically limited, and any page which is convenient for a user to select simply and does not need the user to input query statements directly can be applied to the embodiment of the invention. The user selects and determines the query demand data from the front-end page, the query request carries the query demand data selected by the user, and the query demand data can be conveniently analyzed subsequently to obtain the query statement.
The query requirement data comprises query result data and query condition data. Specifically, the query result data includes a query result field, and if the data that the user wants to obtain is the name of each customer, the user selects the name of the customer on the front-end page, and the name of the customer can be placed in the query result field to obtain the query result data; the query condition data comprises query condition fields, corresponding condition limiting data, logical operation relations among the query condition fields and the like. If the user wants to obtain the name of the male customer with the age of 20-30. The query condition data comprises an age field selected by the user, the condition limit data of the age field is 20-30, and a sex field selected by the user, and the condition limit data of the sex field is male. After the user selects the two query fields, the sum relationship between the age field AND the gender field in the query fields is set, namely the logical operation relationship between the age field AND the gender field is the AND relationship. The query result data and the query condition data can be determined by simply selecting the fields by the user, and the user does not need to select the data table, the data fields (the data fields defined in the data table) and the table association relationship among the data tables, the mutual limiting relationship existing among the data fields and the like which are required to be queried specifically.
Further, the query requirement data sent by the received front-end page may be data in a List manner, such as storing query result data and query condition data selected by the user in a List manner, such as List. Specifically, when the user selects a field as the query condition data in the front-end page, the selected field may be placed in the selected query condition area of the front-end page. In the selected query condition area, the user may set condition defining data for each field, AND may select a logical operation relationship among a plurality of fields, such as an AND relationship, an OR relationship, AND the like. When the query condition data selected by the user is stored, the data are sequentially stored into the List List according to the fields, the condition limiting data of the fields and the logical operation relation among the fields, so that the query condition data can be conveniently analyzed subsequently and the like.
Step S102, analyzing the query condition data to generate a query condition relation tree.
The query condition relation tree is generated by analyzing the query condition data corresponding to the query condition data.
The query conditional relationship tree may be recorded in json format. The query condition relationship tree includes a plurality of leaf nodes and n-level root nodes, where all nodes except the leaf nodes are root nodes, the query condition relationship tree includes n-level root nodes, each level of root node includes at least one root node, for example, the 1-level root node includes one 1-level root node, the 2-level and 3-level … … n-level root nodes include two or more root nodes of each level, and the leaf nodes are the next-level nodes of the nth-level root node. Each leaf node is used for recording the query condition field and the corresponding condition limiting data. If the next level of the ith level root node is a leaf node, the ith level root node is used for recording the logical operation relationship among a plurality of leaf nodes of the next level of the ith level root node; and if the next level of the ith level root node is the (i + 1) th level root node, the ith level root node is used for recording the logical operation relationship between the (i + 1) th level root nodes of the next level of the ith level root node.
Specifically, the fields included in the query condition data are analyzed one by one, for example, a list storing the query condition data is received, the query condition fields and the corresponding condition limiting data are sequentially acquired from the list, and a plurality of leaf nodes of the query condition relation tree are generated according to the query condition fields and the corresponding condition limiting data. A leaf node records a query condition field and corresponding condition defining data. And for the root node, acquiring the query condition fields stored in the list and the logic operation relation between the query condition fields, generating the ith level root node of the query condition relation tree according to the logic operation relation between the query condition fields, and recording the logic operation symbol of the logic operation relation between the query condition fields by the ith level root node. When generating the ith-level root node, the superior-inferior relation of the ith-level root node also needs to be set. Specifically, when the query condition relation tree is generated, after the leaf node is generated, the upper-level root node of the leaf node is determined according to the logical operation relation between the query condition fields, and then the upper-level and lower-level relations between the plurality of the upper-level root nodes are sequentially set upwards along with the logical operation relation between the plurality of the query condition fields. If the query condition data comprises an age field selected by the user, the condition limit data of the age field is 20-30, and the condition limit data of the sex field selected by the user is male. The relation between the age field AND the gender field in the query field is AND, namely the logical operation relation between the age field AND the gender field is AND. Here, for example, an age field and condition definition data 20 to 30 are recorded in one leaf node, and a gender field and condition definition data man are recorded in one leaf node. The root node at the upper level of the 2 leaf nodes records that the logical operation sign between the 2 leaf nodes is AND. The query condition relationship tree recorded in json format may be as follows:
Figure BDA0002324403990000111
Figure BDA0002324403990000121
the above is an example, and the specific recording form is set according to the implementation, and is not limited herein. Further, the query condition relationship tree generated according to the query condition data may include a plurality of leaf nodes and a plurality of root nodes at different levels, for example, the query condition data includes an age field selected by the user, the condition limit data of the age field is 20-30, a sex field selected by the user, the condition limit data of the sex field is male, an identity field selected by the user, and the condition limit data of the identity field is student. The relation between the age field, the gender field and the identity field in the query field is AND, and the query condition relation tree is as follows:
Figure BDA0002324403990000122
Figure BDA0002324403990000131
IN the above query condition relation tree, "biamperor" is a logical operator symbol corresponding to a root node record, "customTagCode" is a query field recorded IN a leaf node, "opertor" is a definition rule of condition definition data recorded IN the leaf node, and includes arithmetic operators (which may correspond to query operators of a query statement, and is NOT limited here) such as betweeen, EQ, LT, GT, LE, GE, NE, IN, and NOT IN, and "values" is a specific value of the condition definition data recorded IN the leaf node. And converting into a query statement according to the correspondence between the operator and the values.
AND regarding the logic operation relationship among the query condition fields as an OR relationship OR an AND relationship, AND regarding the logic operation symbol recorded by the ith-level root node as an OR logic operation symbol OR an AND logic operation symbol. For the OR logical operation symbol OR the AND logical operation symbol, when the query statement is generated, the OR OR AND logical operation symbol does not limit the front-back sequence of the query field, AND the query field does not influence the execution result of the query statement before OR after. Therefore, the leaf node corresponding to the query condition field related to the logical operation relationship between the query condition fields can be directly set as the next level of the i-th level root node; or, the i +1 th level root node corresponding to the query condition field related to the logical operation relationship between the query condition fields is set as the next level of the i th level root node, without considering the position of the leaf node or the i +1 th level root node at the next level of the i th level root node, for example, a leaf node may be set as the left side node or the right side node of the next level of the i th level root node.
However, the logical operation relationship between the query condition fields is an exclusion relationship, the logical operation sign recorded by the i-th level root node is an exclusion logical operation sign, and a specific exclusion field needs to be defined for the exclusion logical operation sign, so that the query exclusion field included in the query condition data and the query condition field corresponding to the exclusion relationship need to be obtained first. Setting a leaf node corresponding to the query condition field as the next level of the ith level root node; or, the root node of the i +1 th level corresponding to the query condition field is set as the next level of the i-th level root node. It should be noted that, for the leaf node of the next level or the root node of the i +1 th level, the leaf node of the next level or the root node of the i +1 th level needs to be an excluding node, that is, the excluding relationship is marked as an excluding relationship for the excluding node.
The query condition relation tree generated above may be a binary tree or a multi-branch tree, and a corresponding query condition relation tree needs to be generated according to various data, such as query condition fields, logical operation relations between the query condition fields, and the like, included in the query condition data. If the query condition data contains 6 query condition fields, the logic operation relationship selected among the query condition fields according to the user requirements is an AND relationship, AND the query condition relationship tree to be generated is a multi-way tree. For example, when there are more query condition fields in the query condition data, the query condition may be recorded by using a multi-way tree, which is not limited herein.
The query condition relation tree can be used for combing the query condition data, the query conditions are clearly arranged one by one, the relation among all query fields in the query sentence is convenient to determine, and the correct query sentence can be obtained when the query sentence is generated by subsequent splicing.
And step S103, traversing the query condition relation tree, and generating corresponding query statements according to the query result data in a splicing manner.
After the query condition relation tree is obtained, traversing the query condition relation tree from leaf nodes in a middle-order traversal mode, and generating query condition statements from data recorded by the query condition relation tree. During the middle-order traversal, the left subtree, the root node, and the right subtree are sequentially obtained, starting from the left leaf node of the query condition relationship tree, and the nodes of the query condition relationship tree are sequentially obtained in a middle-order traversal manner to generate a query condition statement, which is specifically executed according to the following steps shown in fig. 2:
step S1031, obtaining the query condition field and the corresponding condition limiting data recorded by the leaf node, and generating the query sub-condition statement corresponding to the leaf node.
And starting from the left leaf node of the query condition relation tree, acquiring the query condition fields recorded by the leaf node and corresponding condition limiting data, and generating the query sub-condition statements corresponding to the leaf nodes according to the generation rules of the query statements. If the leaf node records the condition limit data of the age field as 20-30, the generated query sub-condition statement is age between 20and 30.
Step S1032, a j-th root node of a previous level of the leaf node is obtained, and a logical operation symbol recorded by the j-th root node is obtained.
And acquiring a j-th level root node of the previous level of the leaf node to obtain a logic operation symbol recorded by the j-th level root node. Such as obtaining AND logical operation signs of the logical operation signs recorded by the j-th level root node.
Step S1033, acquiring other leaf nodes at the next level of the j-th level root node, generating corresponding query sub-condition statements, and splicing a plurality of query sub-condition statements of a plurality of leaf nodes at the next level of the j-th level root node to obtain a query sub-condition statement corresponding to the j-th level root node.
And acquiring other leaf nodes except the leaf node in the step S1 in the next level of the j-level root node, and generating corresponding query sub-condition statements for each leaf node. The query sub-conditional statement of the leaf node is generated with reference to the description of step S1. After the query sub-condition statements corresponding to each leaf node of the next level of the j-th level root node are obtained, the logical operation symbols recorded by the j-th level root node are utilized to splice a plurality of query sub-condition statements of a plurality of leaf nodes of the next level of the j-th level root node, and the query sub-condition statements corresponding to the j-th level root node are obtained. For example, the query sub-condition sentences of the leaf nodes are age > -20 AND age < (30) AND sex ═ male, AND the query sub-condition sentences corresponding to the j-th-level root nodes obtained by concatenation using AND logical operation signs are (age > -20 AND age < (30) AND (sex ═ male).
And S1034, sequentially and circularly acquiring the j-1 th level root node of the previous level from the j-1 th level root node upwards, and splicing a plurality of query sub-condition statements generated by a plurality of j-1 th level root nodes by using the logical operation symbol recorded by the j-1 th level root node to obtain the query sub-condition statements corresponding to the j-1 th level root node.
And after the query sub-condition statement corresponding to the j-th level root node is obtained, continuously circulating upwards according to a middle-sequence traversal mode, sequentially obtaining the j-1-th level root node of the previous level of the j-th level root node, and splicing a plurality of query sub-condition statements generated by a plurality of j-th level root nodes by using the logical operation symbols recorded by the j-1-th level root node to obtain the query sub-condition statement corresponding to the j-1-th level root node.
When the logical operation symbols recorded by the root nodes are used for splicing the query sub-condition statements, if the logical operation symbols recorded by the root nodes are OR logical operation symbols OR AND logical operation symbols, the logical operation symbols can be directly used for directly splicing the query sub-condition statements of the leaf nodes at the next level of the root nodes OR the query sub-condition statements of other root nodes at the next level of the root nodes to generate the query sub-condition statements of the root nodes.
If the logical operation symbol recorded by the root node is an excluded logical operation symbol, the excluded logical operation symbol has specificity, and the query sub-condition statement generated by the excluded node needs to be acquired according to the excluded node marked at the next level. Meanwhile, the exclusion logical operator needs to acquire the query exclusion field for the query exclusion field. And generating a sub-query statement of the exclusion relation of the root node according to the query exclusion field, the data table corresponding to each query condition field under the acquired exclusion node at the next stage of the root node (if the data table comprises a plurality of data tables, an associated condition statement is required to be generated according to the table association relation of the plurality of data tables), and the query sub-condition statement generated by the exclusion node. If the query exclusion field is a user tag, determining a data field (user id, existing in the a table) of a data table corresponding to the query exclusion field, wherein the data table related to the exclusion node includes the a table AND the B table, an association relationship between the two tables is that a.a corresponds to b.b, AND a query sub-condition statement generated by the exclusion node is a. The sub-query statement of the exclusion relationship of the root node generated from the above data is userID not in (select a. userID from a LEFT OUTER JOIN B ON a.a ═ B. B where a. student ═ 1 'andb. member ═ false'). AND splicing the generated sub query statement with a query sub condition statement generated by a non-exclusive node at the next level of the root node by using an AND logical operation sign, wherein the query sub condition statement generated by the non-exclusive node is (age > -20 AND age < -30) AND (sex ═ ma), AND the generated query condition statement is (age > -20 AND age < -30) AND (sex ═ ma) AND userID not in (select from A. userID A LEFT OUTER JOIN B ON A.a.B.B.come A.STUDENT: ' 1 ' AND B.M.media ').
In step S1035, it is determined whether the current root node is the level 1 root node of the query condition relationship tree.
After the steps are executed, whether the current root node is the 1 st level root node of the query condition relation tree is judged. If yes, finishing the execution, and obtaining a query condition statement of the query condition relation tree; if not, the step S1034 is repeatedly executed until the level 1 root node of the query condition relationship tree is traversed.
After traversing the query condition relation tree and generating the query condition statement, determining the data table to be queried in the data query set and each field in the corresponding data table according to the query result field and the query condition field. According to the query selection statement generated by the query result field, that is, the SELECT query result field 1 and the query result field 2 … …, if there are a plurality of associated data tables to be queried, such as table 1, table 2, table 3, etc., it is further necessary to generate an associated query statement according to the table association relationship of the plurality of data tables, such as table 1 LEFT output JOIN table 2ON table 1.a ═ table 2.b, etc. And splicing the sentences according to the generation rule of the query sentence to generate the corresponding query sentence. For example, SELECT query result field 1, query result field 2from table 1 LEFT output JOIN table 2ON table 1. a-table 2.b where query condition statement. The specific generation is generated according to actual query requirement data, and the generated query statement needs to accord with a query statement generation rule.
According to the query statement generation method provided by the embodiment of the invention, a query request sent by a front-end page is received; the query request carries query demand data selected by a user; the query demand data comprises query result data and query condition data; analyzing the query condition data to generate a query condition relation tree; the query condition relation tree comprises a plurality of leaf nodes and n-level root nodes; each level of root nodes comprises at least one root node, and a plurality of leaf nodes are the next level nodes of the nth level of root nodes; each leaf node is used for recording query condition fields and corresponding condition limiting data; the ith level root node is used for recording the logical operation relationship among a plurality of leaf nodes of the next level of the ith level root node or the logical operation relationship among the (i + 1) th level root nodes of the next level; and traversing the query condition relation tree, and splicing to generate corresponding query sentences according to the query result data. The user can directly select the data to be queried and the query conditions on the front-end page, the query conditions are recorded by utilizing the query condition relation tree according to the query request of the front-end page, and the query statements are obtained by splicing. In the whole process, a user does not need to pay attention to the specific generation of the query statement, the generation of the query statement is transparent to the user, and the threshold of technical requirements on the user is greatly reduced. Furthermore, the query condition can be more accurately sorted by utilizing the query condition relation tree, and the logical operation relation among the query condition fields, the condition limiting data and the query conditions is recorded, so that the accuracy of generating the query statement is improved.
Fig. 3 is a flowchart illustrating a query statement generation method according to another embodiment of the present invention, and as shown in fig. 3, the method includes the following steps:
step S301, a number of data tables are selected from the database in advance as a data query set.
In order to better provide for a user to directly select query demand data according to the display of a front-end page, a plurality of data tables can be selected from a database as a data query set, namely, a query range is set as the data tables in the data query set, so that the problems that selection errors possibly caused when the user selects the data tables are caused by too many data tables, the generated query statement writes the irrelevant data tables, the query statement is redundant and the like are avoided.
When the data tables are selected in advance, according to actual conditions, for example, according to the data tables related to the services, a plurality of data tables related to one service are selected together to be used as one data query set, and according to different dimensions required by a user, the specific selection can be performed by selecting the corresponding data tables to be used as the data query set. The number of the data query sets can be multiple, and a user can select the data query set in the front-end page according to the requirement of the user, and then select query requirement data from the selected data query set.
Further, when the data query set is selected, one data table in the data query set is set as a query main data table according to the data table during selection, and table association relations between other data tables and the query main data table are set. And the query main data table is determined according to the circled dimension when the circled data is queried and collected.
Further, in order to directly correspond to the query demand data selected by the user in the front-end page, the corresponding relationship between each field in the front-end page and each field in each data table in the data query set may be preset. After receiving the query requirement data, the fields in the data table can be determined directly according to the corresponding relation.
Step S302, receiving an inquiry request sent by the front-end page.
The user can select the data query set to be queried in the front-end page, and query required data is selected from the data query set according to each field displayed in the front-end page. And after the user finishes selecting, triggering the front-end page to send a query request. The query request carries query requirement data.
Step S303, determine whether the data table to be queried is a plurality of data tables.
According to the data such as the query result field and the query condition field in the query demand data, whether the data table to be queried is a plurality of data tables can be judged. That is, whether data such as a query result field and a query condition field are distributed in different data tables or not is judged, if yes, the data table to be queried is judged to be a plurality of data tables, and step S304 is executed to set alias names for the plurality of data tables, so that on one hand, the finally obtained query statement can be simplified, the direct use of the data table name for multiple times is reduced, and on the other hand, the analysis execution efficiency of the query statement can be improved.
If the data table to be queried is determined to be a data table, the alias does not need to be set for the data table, and step S305 may be directly performed.
Step S304, generating data table aliases for the plurality of data tables to be queried, and generating data table association query condition statements according to the table association relation among the plurality of data tables to be queried.
Generating data table aliases for a plurality of data tables to be queried, and generating the data table aliases of the plurality of data tables to be queried on the premise of simplifying the data table names. The data table alias can be used in various query statements such as a subsequently generated query selection statement, a query condition statement, a data table association query condition statement and the like to simplify each query statement.
Further, for a plurality of data tables to be queried, generating data table association query condition statements according to the table association relationship between the circled data table and the query main data table. When the data table association query condition statement is generated, for example, a plurality of data tables to be queried may be stored in the array first, the query main data table is stored in the array first, and other data tables to be queried are stored in sequence. Traversing the array, associating other data tables to be inquired with the main data table to be inquired by utilizing a table external connection mode of LEFT OUTER JOIN, and connecting according to the table association relation between the data tables to be inquired during external connection.
In step S305, the query condition data is analyzed to generate a query condition relation tree.
When analyzing the query condition data, if the data table to be queried relates to a plurality of data tables, the leaf node needs to record the alias of the data table and the query condition field when recording the query condition field, and if the data table to be queried relates to one data table, the leaf node records the query condition field.
The specific generation process of the query condition relationship tree refers to the description of step S102 in fig. 1, and is not described herein again.
And S306, traversing the query condition relation tree, and splicing to generate a corresponding query statement according to the query result data.
And traversing the query condition relation tree from leaf nodes in a middle-order traversal mode, and generating query condition statements from the data recorded in the query condition relation tree.
When generating the query statement, if the data table to be queried relates to a data table, determining the data table to be queried in the data query set and each field in the corresponding data table according to the query result field and the query condition field. And generating a query selection statement according to the query result field, namely a SELECT query result field 1 and a query result field 2 … …, and a data table to be queried, such as table 1. And splicing the sentences according to the generation rule of the query sentence to generate the corresponding query sentence. Such as SELECT query result field 1, query result field 2from table 1 where query condition statement. The specific generation is generated according to actual query requirement data, and the generated query statement conforms to the query statement generation specification.
If the data table to be queried relates to a plurality of data tables, query condition statements, query result fields, the data table to be queried and the query condition statements are needed to be associated according to the data table alias and the data table, and the corresponding query statements are generated together. And simplifying the generation of query statements by using the generated data table aliases, such as a SELECT alias a. query result field 1, an alias a. query result field 2from table 1, an alias a LEFT exit JOIN table 2, an alias B ON alias a.a ═ an alias b.b where query condition statements are generated. And each data table field in the query condition statement is expressed in a data table alias field name mode, and the generated query statement conforms to the query statement generation specification.
Furthermore, when the user selects the query result data, a certain field in the data table can be directly selected as the query result data, and a limited tag can be added to the field after the certain field is selected. I.e., the query result data also includes query result definition tags. The query result restriction labels include, for example, a sum label, a deduplication label, a group label, an order label, a number restriction label, a number skip label, and the like. Such as summing, deduplication, grouping, etc. of the fields; the obtained query results need to be sorted for a certain field, a certain number of query results obtained, and so on. And generating a query selection statement and a query label conditional statement according to the query result field selected by the user and the query result limiting label. Generating a select sum as a sum tag; the de-duplication label generates a select distintint (field); the grouping label generates a select guoup by (field); sorting the labels to generate order by fields; a number limit tag, a number skip tag generates a corresponding limit number or offset number, etc. When generating the query statement, the query selection statement, the data table to be queried, the query condition statement and the query tag condition statement are required to be generated according to the query statement, so that the statements are spliced at corresponding positions to obtain the query statement according with the query statement generation specification.
According to the query statement generation method provided by the embodiment of the invention, a plurality of data tables are selected from the database as a data query set in advance, and when a user selects the data query set from a front-end page, the user is helped to remove irrelevant data tables, so that the problems of wrong selection, selection omission and the like caused by the fact that fields selected by the user do not accord with actual requirements are avoided. When the pre-circled data query set is convenient for generating query statements, the association relationship among the data tables can be directly confirmed. Further, for a plurality of data tables to be queried, data table aliases are generated, and the generated query statement can be effectively simplified. The user does not need to pay attention to the specific generation of the query statement in the whole query statement generation process based on the embodiment of the invention, so that the user is transparent, and the threshold of the technical requirements of the user is greatly reduced.
Fig. 4 is a block diagram showing a structure of a query statement generation apparatus according to an embodiment of the present invention, and as shown in fig. 4, the apparatus includes:
a receiving module 410, adapted to receive a query request sent by a front-end page; the query request carries query demand data selected by a user; the query demand data comprises query result data and query condition data;
the analysis module 420 is adapted to analyze the query condition data to generate a query condition relation tree; the query condition relation tree comprises a plurality of leaf nodes and n-level root nodes; each level of root nodes comprises at least one root node, and a plurality of leaf nodes are the next level nodes of the nth level of root nodes; each leaf node is used for recording query condition fields and corresponding condition limiting data; the ith level root node is used for recording the logical operation relationship among a plurality of leaf nodes of the next level of the ith level root node or the logical operation relationship among the (i + 1) th level root nodes of the next level;
the generating module 430 is adapted to traverse the query condition relation tree and generate corresponding query statements according to the query result data in a splicing manner.
Optionally, the parsing module 420 includes:
a leaf node generating module 421, adapted to generate a plurality of leaf nodes of the query condition relation tree according to the query condition fields and the corresponding condition defining data; wherein, a leaf node records a query condition field and corresponding condition limiting data;
a root node generating module 422, adapted to generate the i-th level root node of the query condition relation tree according to the logical operation relation between the query condition fields, and set the superior-inferior relation of the i-th level root node according to the query condition fields related to the logical operation relation between the query condition fields; and the ith-level root node records the logical operation symbol of the logical operation relation between the query condition fields.
Optionally, the root node generating module 422 is further adapted to: if the logic operation relation among the query condition fields is an OR relation OR an AND relation, the leaf node corresponding to the query condition field related to the logic operation relation among the query condition fields is the next level of the ith level root node; or the root node of the (i + 1) th level corresponding to the query condition field related to the logic operation relation between the query condition fields is the next level of the (i) th level root node; the logical operation symbol recorded by the ith level root node is an OR logical operation symbol OR an AND logical operation symbol; if the logic operation relation between the query condition fields is an exclusion relation, acquiring a query exclusion field and a query condition field corresponding to the exclusion relation; the leaf node corresponding to the query condition field is the next level of the ith level root node; or the (i + 1) th level root node corresponding to the query condition field is the next level of the (i) th level root node; and recording leaf nodes of the next level or root nodes of the (i + 1) th level as exclusion nodes; the logical operation symbol recorded by the ith level root node is an excluded logical operation symbol; the query condition data also includes a query exclusion field.
Optionally, the generating module 430 is further adapted to: determining a data table to be queried in the data query set and each field in the corresponding data table according to the query result field and/or the query condition field; traversing the query condition relation tree from leaf nodes in a middle-order traversal mode to generate query condition statements; and generating corresponding query sentences by splicing according to the query selection sentences, the data tables to be queried and the query condition sentences generated by the query result fields.
Optionally, the generating module 430 further includes:
a first statement module 431, adapted to obtain query condition fields and corresponding condition defining data recorded by leaf nodes, and generate query sub-condition statements corresponding to the leaf nodes;
a logical operation symbol module 432, adapted to obtain a j-th level root node of a previous level of the leaf node, to obtain a logical operation symbol recorded by the j-th level root node;
the second statement module 433 is adapted to obtain other leaf nodes at the next level of the j-th level root node, generate corresponding query sub-condition statements, and splice a plurality of query sub-condition statements of a plurality of leaf nodes at the next level of the j-th level root node by using the logical operation symbols recorded by the j-th level root node to obtain the query sub-condition statements corresponding to the j-th level root node;
the third statement module 434 is adapted to sequentially obtain the j-1 th root node of the previous level from the j-level root node in an upward circulation manner, and splice a plurality of query sub-condition statements generated by a plurality of j-level root nodes by using the logical operation symbols recorded by the j-1 th root node to obtain the query sub-condition statements corresponding to the j-1 th root node;
and repeatedly executing the third statement module 434 until traversing to the 1 st level root node of the query condition relation tree to obtain the spliced query condition statement.
Optionally, the generating module 430 is further adapted to: generating a query selection statement and a query label condition statement according to the query result field and the query result limit label; the query result limit labels comprise a summation label, a de-duplication label, a grouping label, an ordering label, a quantity limit label and/or a quantity skipping label; the query label conditional statement restricts label generation according to the query result; and generating corresponding query sentences by splicing according to the query selection sentences, the data table to be queried, the query condition sentences and the query label condition sentences.
Optionally, the generating module 430 is further adapted to: if the logical operation symbol recorded by the root node is an OR logical operation symbol OR an AND logical operation symbol, generating a query sub-condition statement of the root node by using the logical operation symbol; if the logical operation symbol recorded by the root node is an excluded logical operation symbol, acquiring a query excluded field and a data table corresponding to each query condition field under an excluded node at the next level of the root node; generating a sub-query statement of the exclusion relationship of the root node according to the query exclusion field, the data table and the query sub-conditional statement generated by the exclusion node; AND splicing the sub-query statement AND the query sub-conditional statement generated by the non-exclusive node at the next stage of the root node by using an AND logical operation symbol to generate the query conditional statement.
Optionally, the apparatus further comprises:
the judging module 440 is adapted to judge whether the data table to be queried is a plurality of data tables; if yes, generating data table aliases for the multiple data tables to be queried, and generating data table association query condition statements according to table association relations among the multiple data tables to be queried;
the generation module 430 is further adapted to: and generating a corresponding query statement according to the alias of the data table and the associated query condition statement of the data table.
Optionally, the apparatus further comprises:
the selection module 450 is adapted to select a plurality of data tables from the database in advance as a data query set;
the association relation setting module 460 is adapted to set one data table in the data query set as a query main data table, and set table association relations between other data tables and the query main data table.
Optionally, the apparatus further comprises:
the corresponding relation setting module 470 is adapted to preset the corresponding relation between each field in the front-end page and each field in each data table in the data query set.
The descriptions of the modules refer to the corresponding descriptions in the method embodiments, and are not repeated herein.
According to the query statement generation device provided by the embodiment of the invention, a query request sent by a front-end page is received; the query request carries query demand data selected by a user; the query demand data comprises query result data and query condition data; analyzing the query condition data to generate a query condition relation tree; the query condition relation tree comprises a plurality of leaf nodes and n-level root nodes; each level of root nodes comprises at least one root node, and a plurality of leaf nodes are the next level nodes of the nth level of root nodes; each leaf node is used for recording query condition fields and corresponding condition limiting data; the ith level root node is used for recording the logical operation relationship among a plurality of leaf nodes of the next level of the ith level root node or the logical operation relationship among the (i + 1) th level root nodes of the next level; and traversing the query condition relation tree, and splicing to generate corresponding query sentences according to the query result data. The user can directly select the data to be queried and the query conditions on the front-end page, the query conditions are recorded by utilizing the query condition relation tree according to the query request of the front-end page, and the query statements are obtained by splicing. In the whole process, a user does not need to pay attention to the specific generation of the query statement, the generation of the query statement is transparent to the user, and the threshold of technical requirements on the user is greatly reduced. Furthermore, the query condition can be more accurately sorted by utilizing the query condition relation tree, and the logical operation relation among the query condition fields, the condition limiting data and the query conditions is recorded, so that the accuracy of generating the query statement is improved.
The embodiment of the invention also provides a nonvolatile computer storage medium, wherein the computer storage medium stores at least one executable instruction, and the executable instruction can execute the query statement generation method in any method embodiment.
Fig. 5 is a schematic structural diagram of a computing device according to an embodiment of the present invention, and a specific embodiment of the present invention does not limit a specific implementation of the computing device.
As shown in fig. 5, the computing device may include: a processor (processor)502, a Communications Interface 504, a memory 506, and a communication bus 508.
Wherein:
the processor 502, communication interface 504, and memory 506 communicate with one another via a communication bus 508.
A communication interface 504 for communicating with network elements of other devices, such as clients or other servers.
The processor 502 is configured to execute the program 510, and may specifically execute relevant steps in the foregoing query statement generation method embodiment.
In particular, program 510 may include program code that includes computer operating instructions.
The processor 502 may be a central processing unit CPU, or an application specific Integrated circuit asic, or one or more Integrated circuits configured to implement embodiments of the present invention. The computing device includes one or more processors, which may be the same type of processor, such as one or more CPUs; or may be different types of processors such as one or more CPUs and one or more ASICs.
And a memory 506 for storing a program 510. The memory 506 may comprise high-speed RAM memory, and may also include non-volatile memory (non-volatile memory), such as at least one disk memory.
The program 510 may specifically be configured to enable the processor 502 to execute the query statement generation method in any of the above-described method embodiments. For specific implementation of each step in the program 510, reference may be made to corresponding steps and corresponding descriptions in units in the foregoing query statement generation embodiment, which are not described herein again. It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described devices and modules may refer to the corresponding process descriptions in the foregoing method embodiments, and are not described herein again.
The algorithms and displays presented herein are not inherently related to any particular computer, virtual machine, or other apparatus. Various general purpose systems may also be used with the teachings herein. The required structure for constructing such a system will be apparent from the description above. In addition, embodiments of the present invention are not directed to any particular programming language. It is appreciated that a variety of programming languages may be used to implement the teachings of embodiments of the present invention as described herein, and any descriptions of specific languages are provided above to disclose the best modes of embodiments of the invention.
In the description provided herein, numerous specific details are set forth. It is understood, however, that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the embodiments of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: that is, the claimed embodiments of the invention require more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of an embodiment of this invention.
Those skilled in the art will appreciate that the modules in the device in an embodiment may be adaptively changed and disposed in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and furthermore they may be divided into a plurality of sub-modules or sub-units or sub-components. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or elements are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments described herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of and form different embodiments of the invention. For example, in the following claims, any of the claimed embodiments may be used in any combination.
The various component embodiments of the invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art will appreciate that a microprocessor or Digital Signal Processor (DSP) may be used in practice to implement some or all of the functionality of some or all of the components in accordance with embodiments of the present invention. Embodiments of the invention may also be implemented as apparatus or device programs (e.g., computer programs and computer program products) for performing a portion or all of the methods described herein. Such programs implementing embodiments of the present invention may be stored on computer-readable media or may be in the form of one or more signals. Such a signal may be downloaded from an internet website or provided on a carrier signal or in any other form.
It should be noted that the above-mentioned embodiments illustrate rather than limit the embodiments of the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. Embodiments of the invention may be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by one and the same item of hardware. The usage of the words first, second and third, etcetera do not indicate any ordering. These words may be interpreted as names.

Claims (10)

1.A query statement generation method, comprising:
receiving a query request sent by a front-end page; the query request carries query demand data selected by a user; the query demand data comprises query result data and query condition data;
analyzing the query condition data to generate a query condition relation tree; the query condition relation tree comprises a plurality of leaf nodes and n-level root nodes; each level of root nodes comprises at least one root node, and a plurality of leaf nodes are the next level nodes of the nth level of root nodes; each leaf node is used for recording query condition fields and corresponding condition limiting data; the ith-level root node is used for recording the logical operation relationship among a plurality of leaf nodes of the next level of the ith-level root node or the logical operation relationship among the (i + 1) th-level root nodes of the next level;
and traversing the query condition relation tree, and splicing and generating corresponding query statements according to the query result data.
2. The method of claim 1, wherein the query result data includes a query result field; the query condition data comprises query condition fields, corresponding condition limiting data and a logical operation relation between the query condition fields.
3. The method of claim 2, wherein the parsing the query condition data to generate a query condition relationship tree further comprises:
generating a plurality of leaf nodes of a query condition relation tree according to the query condition fields and the corresponding condition limiting data; wherein, a leaf node records a query condition field and corresponding condition limiting data;
generating an i-th level root node of a query condition relation tree according to the logic operation relation among the query condition fields, and setting the superior-inferior level relation of the i-th level root node according to the query condition fields related to the logic operation relation among the query condition fields; and the ith-level root node records the logical operation symbol of the logical operation relation between the query condition fields.
4. The method of claim 3, wherein the generating an i-th level root node of a query condition relationship tree according to the logic operation relationship between the query condition fields, and setting the upper and lower level relationships of the i-th level root node according to the query condition fields related to the logic operation relationship between the query condition fields further comprises:
if the logic operation relation among the query condition fields is an OR relation OR an AND relation, the leaf node corresponding to the query condition field related to the logic operation relation among the query condition fields is the next level of the ith level root node; or the root node of the (i + 1) th level corresponding to the query condition field related to the logic operation relation between the query condition fields is the next level of the (i) th level root node; the logical operation symbol recorded by the ith-level root node is an OR logical operation symbol OR an AND logical operation symbol;
if the logic operation relation between the query condition fields is an exclusion relation, acquiring a query exclusion field and a query condition field corresponding to the exclusion relation; the leaf node corresponding to the query condition field is the next level of the ith level root node; or the (i + 1) th level root node corresponding to the query condition field is the next level of the (i) th level root node; and recording leaf nodes of the next level or root nodes of the (i + 1) th level as exclusion nodes; the logical operation symbol recorded by the i-th level root node is an excluded logical operation symbol; the query condition data further includes a query exclusion field.
5. The method of claim 3, wherein said traversing said query conditional relationship tree and generating corresponding query statements from said query result data by concatenation further comprises:
determining a data table to be queried in a data query set and each field in the corresponding data table according to the query result field and/or the query condition field;
traversing the query condition relation tree from a leaf node in a middle-order traversal mode to generate a query condition statement;
and generating corresponding query sentences by splicing according to the query selection sentences, the data tables to be queried and the query condition sentences generated by the query result fields.
6. The method of claim 5, wherein traversing the query conditional relationship tree in a medium-ordered traversal starting from a leaf node, generating a query conditional statement further comprises:
step S1, acquiring query condition fields recorded by leaf nodes and corresponding condition limiting data, and generating query sub-condition statements corresponding to the leaf nodes;
step S2, acquiring the j-th level root node of the previous level of the leaf node to obtain the logic operation symbol recorded by the j-th level root node;
step S3, acquiring other leaf nodes at the next level of the j-th level root node, generating corresponding query sub-condition statements, and splicing a plurality of query sub-condition statements of a plurality of leaf nodes at the next level of the j-th level root node by using the logical operation symbols recorded by the j-th level root node to obtain the query sub-condition statements corresponding to the j-th level root node;
step S4, sequentially acquiring the j-1 th level root node of the previous level from the j-level root node upwards in a circulating mode, splicing a plurality of query sub-condition statements generated by a plurality of j-level root nodes by using the logical operation symbol recorded by the j-1 th level root node, and obtaining the query sub-condition statements corresponding to the j-1 th level root node;
and repeatedly executing the step S4 until the step is traversed to the 1 st level root node of the query condition relation tree, and obtaining the spliced query condition statement.
7. The method of claim 5, wherein the query result data further comprises a query result definition tag;
the generating of the corresponding query statement by splicing according to the query selection statement, the data table to be queried and the query condition statement generated by the query result field further comprises:
generating a query selection statement and a query label condition statement according to the query result field and the query result limit label; the query result limit labels comprise a summation label, a de-duplication label, a grouping label, an ordering label, a quantity limit label and/or a quantity skipping label; the query label conditional statement restricts label generation according to the query result;
and generating corresponding query sentences by splicing according to the query selection sentences, the data table to be queried, the query condition sentences and the query label condition sentences.
8. A query statement generation apparatus, comprising:
the receiving module is suitable for receiving a query request sent by a front-end page; the query request carries query demand data selected by a user; the query demand data comprises query result data and query condition data;
the analysis module is suitable for analyzing the query condition data to generate a query condition relation tree; the query condition relation tree comprises a plurality of leaf nodes and n-level root nodes; each level of root nodes comprises at least one root node, and a plurality of leaf nodes are the next level nodes of the nth level of root nodes; each leaf node is used for recording query condition fields and corresponding condition limiting data; the ith-level root node is used for recording the logical operation relationship among a plurality of leaf nodes of the next level of the ith-level root node or the logical operation relationship among the (i + 1) th-level root nodes of the next level;
and the generating module is suitable for traversing the query condition relation tree and generating corresponding query statements in a splicing manner according to the query result data.
9. A computing device, comprising: the system comprises a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface complete mutual communication through the communication bus;
the memory is used for storing at least one executable instruction, and the executable instruction causes the processor to execute the operation corresponding to the query statement generation method according to any one of claims 1 to 7.
10. A computer storage medium having stored therein at least one executable instruction for causing a processor to perform operations corresponding to the query statement generation method as claimed in any one of claims 1 to 7.
CN201911310576.7A 2019-12-18 2019-12-18 Query statement generation method and device Pending CN111143359A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911310576.7A CN111143359A (en) 2019-12-18 2019-12-18 Query statement generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911310576.7A CN111143359A (en) 2019-12-18 2019-12-18 Query statement generation method and device

Publications (1)

Publication Number Publication Date
CN111143359A true CN111143359A (en) 2020-05-12

Family

ID=70518795

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911310576.7A Pending CN111143359A (en) 2019-12-18 2019-12-18 Query statement generation method and device

Country Status (1)

Country Link
CN (1) CN111143359A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112199577A (en) * 2020-12-09 2021-01-08 浙江口碑网络技术有限公司 Data query method and device and electronic equipment
CN112749185A (en) * 2021-01-20 2021-05-04 青岛以萨数据技术有限公司 SQL language generation system and method
CN113051287A (en) * 2021-06-01 2021-06-29 北京达佳互联信息技术有限公司 Query statement generation method, device, equipment and storage medium
CN113220714A (en) * 2021-05-29 2021-08-06 五八到家有限公司 Configurable data query platform and method, electronic equipment and readable medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1484174A (en) * 2002-09-21 2004-03-24 鸿富锦精密工业(深圳)有限公司 Universal inquiry statement dynamic generation system and method
JP2015090622A (en) * 2013-11-06 2015-05-11 日本電信電話株式会社 Shortened sentence generation device, method, and program
CN105335402A (en) * 2014-07-23 2016-02-17 阿里巴巴集团控股有限公司 Search method, index data generation method and device on the basis of static Cache
CN107368578A (en) * 2017-07-20 2017-11-21 山东合天智汇信息技术有限公司 A kind of method and system for quickly generating ES query statements
CN110362591A (en) * 2018-04-02 2019-10-22 北京神州泰岳软件股份有限公司 A kind of report form showing method and device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1484174A (en) * 2002-09-21 2004-03-24 鸿富锦精密工业(深圳)有限公司 Universal inquiry statement dynamic generation system and method
JP2015090622A (en) * 2013-11-06 2015-05-11 日本電信電話株式会社 Shortened sentence generation device, method, and program
CN105335402A (en) * 2014-07-23 2016-02-17 阿里巴巴集团控股有限公司 Search method, index data generation method and device on the basis of static Cache
CN107368578A (en) * 2017-07-20 2017-11-21 山东合天智汇信息技术有限公司 A kind of method and system for quickly generating ES query statements
CN110362591A (en) * 2018-04-02 2019-10-22 北京神州泰岳软件股份有限公司 A kind of report form showing method and device

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112199577A (en) * 2020-12-09 2021-01-08 浙江口碑网络技术有限公司 Data query method and device and electronic equipment
CN112199577B (en) * 2020-12-09 2021-04-02 浙江口碑网络技术有限公司 Data query method and device and electronic equipment
CN112749185A (en) * 2021-01-20 2021-05-04 青岛以萨数据技术有限公司 SQL language generation system and method
CN113220714A (en) * 2021-05-29 2021-08-06 五八到家有限公司 Configurable data query platform and method, electronic equipment and readable medium
CN113051287A (en) * 2021-06-01 2021-06-29 北京达佳互联信息技术有限公司 Query statement generation method, device, equipment and storage medium
CN113051287B (en) * 2021-06-01 2021-08-20 北京达佳互联信息技术有限公司 Query statement generation method, device, equipment and storage medium

Similar Documents

Publication Publication Date Title
CN110633292B (en) Query method, device, medium, equipment and system for heterogeneous database
CN111143359A (en) Query statement generation method and device
US9858270B2 (en) Converting data into natural language form
CN111506608B (en) Structured text comparison method and device
US20220129491A1 (en) Method for supporting agent and computing device thereof
CN110928893B (en) Label query method, device, equipment and storage medium
US7756798B2 (en) Extensible mechanism for detecting duplicate search items
CN113760839A (en) Log data compression processing method and device, electronic equipment and storage medium
CN111414410A (en) Data processing method, device, equipment and storage medium
CN111435406A (en) Method and device for correcting database statement spelling errors
US20190228100A1 (en) Systems and methods for high efficiency data querying
CN109241511B (en) Electronic report generation method and equipment
US20090100039A1 (en) Extensible mechanism for grouping search results
CN112199483B (en) Information input assisting method and device, electronic equipment and storage medium
US20190340179A1 (en) Result set output criteria
CN116561181A (en) Data query method, device, computer equipment and computer readable storage medium
KR100709984B1 (en) Query matching method and system for outputting results matched to query by processing the query according to various logics
CN113626558B (en) Intelligent recommendation-based field standardization method and system
CN113779362A (en) Data searching method and device
KR101105947B1 (en) Commodity information registering method and system which automatically matches commodity model with the commodity information
CN106570004A (en) Data management method device
CN110750569A (en) Data extraction method, device, equipment and storage medium
CN111159205A (en) Data processing method and system
KR101638048B1 (en) Sql query processing method using mapreduce
CN118069919A (en) Signboard data query method and system

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20200512

RJ01 Rejection of invention patent application after publication