A data query method and related apparatus

By using parsing rules specific to the target application scenario to parse and rewrite programming statements in NLTOSQL, more accurate structured query statements are generated, solving the problem of insufficient accuracy in existing technologies and achieving higher query statement precision.

CN122086928APending Publication Date: 2026-05-26KINGDEE SOFTWARE(CHINA) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
KINGDEE SOFTWARE(CHINA) CO LTD
Filing Date
2026-02-25
Publication Date
2026-05-26

AI Technical Summary

Technical Problem

Existing NLTOSQL technology has low accuracy when converting natural language queries into structured query language and cannot fully comply with business rules.

Method used

Using parsing rules set for the target application scenario, the target programming statement output by the natural language model is parsed and rewritten to generate a structured query statement, including input, output and related rule types. Data query tasks are generated based on the rule types, and the database is queried according to the tasks.

Benefits of technology

It improves the accuracy of structured query statements, ensuring that the model has a more accurate understanding of the target application scenario and that the generated query statements are more in line with user intent.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122086928A_ABST
    Figure CN122086928A_ABST
Patent Text Reader

Abstract

This invention provides a data query method and related apparatus to improve the accuracy of converting natural language data query questions into structured query statements. The method includes: using a natural language model to convert a received data query question related to a target application scenario into a target programming statement; parsing and rewriting the target programming statement using parsing rules set for the target application scenario to obtain a first structured query statement related to the target application scenario, wherein the first structured query statement includes at least an input, an output, and at least one rule associated with at least one of the input and output, as well as a rule type for the at least one rule; generating at least one data query task based on the rule type of the at least one rule; and querying a database according to the at least one data query task to obtain data corresponding to the data query question.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing technology, and in particular to a data query method and related apparatus. Background Technology

[0002] NLTOSQL (Natural Language to SQL) is a technology that transforms natural language queries into structured query language (SQL). It uses a large model to understand user semantics and combines specific prompts to output SQL queries that match the user's intent, allowing the user to retrieve the data they want.

[0003] When NLTOSQL (Natural Language to SQL) outputs query SQL that reflects the user's intent, it usually requires specific prompt words. However, when all business rules are implemented through prompt words, the model cannot always follow them 100%, resulting in lower accuracy of the SQL output by NLTOSQL. Summary of the Invention

[0004] This invention provides a data query method and related apparatus to improve the accuracy of converting natural language data query problems into structured query statements.

[0005] The first aspect of this application provides a data query method, including:

[0006] Using natural language models, the received data query questions related to the target application scenario are converted into target programming statements;

[0007] Using the parsing rules set for the target application scenario, the target programming statement is parsed and rewritten to obtain a first structured query statement associated with the target application scenario. The first structured query statement includes at least an input, an output, and at least one rule associated with at least one of the input and the output, as well as the rule type of the at least one rule.

[0008] Based on the rule type of the at least one rule, generate at least one data query task;

[0009] According to the at least one data query task, query the database to obtain data corresponding to the data query question.

[0010] As an optional embodiment, the first structured query statement also includes the dependency relationship between the output and the input;

[0011] If the first structured query statement includes multiple rules and multiple rule types, then generating at least one data query task based on the rule type of the at least one rule includes:

[0012] Based on the priority of the multiple rule types and the dependency relationship, the multiple rules are topologically sorted to generate multiple data tasks ordered in a first order, the multiple data tasks including data query tasks and data flow tasks;

[0013] The step of querying the database according to the at least one data query task to obtain data corresponding to the data query question includes:

[0014] In the first order, the data query task and the data flow task among the plurality of data tasks are executed to obtain data corresponding to the data query question.

[0015] As an optional embodiment, before parsing and rewriting the target programming statements, the method further includes:

[0016] The target programming statement is subjected to lexical analysis and syntax analysis. During the lexical analysis and syntax analysis, if it is determined that the target programming statement includes at least one of a compound function and a virtual index function, the target programming statement is parsed into multiple second structured query statements according to at least one of the compound function and the virtual index function.

[0017] The step of parsing and rewriting the target programming statement using parsing rules set for the target application scenario to obtain a first structured query statement associated with the target application scenario includes:

[0018] Using the parsing rules set for the target application scenario, the multiple second structured query statements are parsed and rewritten to obtain multiple first structured query statements associated with the target application scenario.

[0019] As an optional embodiment, the step of parsing and rewriting the plurality of second structured query statements using parsing rules set for the target application scenario to obtain a plurality of first structured query statements associated with the target application scenario includes:

[0020] If, according to the parsing rules, it is identified that the target data indicator included in the second structured query statement is associated with multiple calculated indicators, then the second structured query statement is rewritten as multiple first structured query statements including the multiple calculated indicators.

[0021] As an optional embodiment, the step of parsing and rewriting the plurality of second structured query statements using parsing rules set for the target application scenario to obtain a plurality of first structured query statements associated with the target application scenario includes:

[0022] If, according to the parsing rules, the second structured query statement is identified as containing a target computation function that cannot perform a data query, then the second structured query statement is rewritten into at least one first structured query statement that can perform a data query.

[0023] As an optional embodiment, before querying the database according to the at least one data query task to obtain data corresponding to the data query question, the method further includes:

[0024] Analyze multiple preset databases to obtain the data query logic supported by each database;

[0025] The step of querying the database according to the at least one data query task to obtain data corresponding to the data query question includes:

[0026] The data query logic of the database is obtained. If the data query task matches the data query logic, a pushdown strategy is adopted to send the data query task to the database for querying.

[0027] If the data query task does not match the data query logic, a pruning strategy is adopted to send the query subtasks in the data query task that match the data query logic to the database for querying.

[0028] A second aspect of this application provides a data query device, comprising:

[0029] The conversion unit is used to convert received data query questions related to the target application scenario into target programming statements using a natural language model;

[0030] The parsing unit is used to parse and rewrite the target programming statement using parsing rules set for the target application scenario to obtain a first structured query statement associated with the target application scenario. The first structured query statement includes at least an input, an output, and at least one rule associated with at least one of the input and the output, as well as the rule type of the at least one rule.

[0031] A generation unit is used to generate at least one data query task based on the rule type of the at least one rule;

[0032] The query unit is used to query the database according to the at least one data query task to obtain data corresponding to the data query question.

[0033] A third aspect of this application provides a computer device including a processor, which, when executing a computer program stored in a memory, implements the data query method provided in the first aspect of this application.

[0034] A fourth aspect of this application provides a computer-readable storage medium having a computer program stored thereon, characterized in that, when the computer program is executed by a processor, it is used to implement the data query method provided in the first aspect of this application.

[0035] The fifth aspect of this application provides a computer program product having a computer program stored thereon, characterized in that, when the computer program is executed by a processor, it is used to implement the data query method provided in the first aspect of this application.

[0036] As can be seen from the above technical solutions, the embodiments of the present invention have the following advantages:

[0037] The data query method provided in this application uses parsing rules set for the target application scenario to parse and rewrite the target programming statement output by the model to generate a structured query statement. Compared with the existing technology that uses prompt words to assist the model in outputting structured query statements, the pre-set parsing rules for the target application scenario have a more accurate understanding of the target application scenario than prompt words, so the structured query statement generated by this application is also more accurate. Attached Figure Description

[0038] Figure 1 This is an architecture diagram of the data query system in the embodiments of this application;

[0039] Figure 2 This is a schematic diagram of one embodiment of the data query method in this application;

[0040] Figure 3 This is a schematic diagram of another embodiment of the data query method in this application;

[0041] Figure 4 For this application Figure 3 Detailed steps of step 302 in the embodiment;

[0042] Figure 5 For this application Figure 2 Detailed steps of step 204 in the embodiment;

[0043] Figure 6 This is a schematic diagram of an embodiment of the data query device in this application. Detailed Implementation

[0044] This invention provides a data query method and related apparatus to improve the accuracy of converting natural language data query problems into structured query statements.

[0045] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0046] The terms "first," "second," "third," "fourth," etc., used in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0047] This application provides a data query method. The general principle of this method is as follows: Using a natural language model, a received data query question related to a target application scenario is converted into a target programming statement; using parsing rules set for the target application scenario, the target programming statement is parsed and rewritten to obtain a first structured query statement associated with the target application scenario. The first structured query statement includes at least an input, an output, and at least one rule associated with at least one of the input and the output, as well as a rule type for the at least one rule; based on the rule type of the at least one rule, at least one data query task is generated; according to the at least one data query task, a database is queried to obtain data corresponding to the data query question. The data query method provided in this application uses parsing rules set for the target application scenario to parse and rewrite the target programming statement output by the model to generate a structured query statement. Compared to the prior art method of using prompt words to assist the model in outputting structured query statements, the pre-set parsing rules for the target application scenario provide a more accurate understanding of the target application scenario than prompt words. Therefore, the structured query statement parsed and rewritten using the parsing rules in this application is also more accurate.

[0048] To better implement the above image detection scheme, this application provides a data query system. Please refer to [link / reference]. Figure 1 , Figure 1 This is a schematic diagram of the architecture of a data query system provided in an embodiment of this application. The data query system may include at least one terminal device 101 and a server 102; the terminal device 101 may be equipped with a natural language model; the terminal device 101 may be a smartphone, tablet, laptop, desktop computer, smart vehicle, etc. The server 102 may be used to store a database. The server 102 may be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms, etc.

[0049] The image detection scheme described above can be executed by terminal device 101. After generating a data query task, terminal device 101 can query the database in server 102. When terminal device 101 receives a data query question related to a target application scenario, input in natural language, it uses a natural language model (such as ChatGPT, Doubao, Deepseek, etc.) to convert the data query question into a target programming statement. Then, using parsing rules set for the target application scenario, it parses and rewrites the target programming statement to obtain a first structured query statement related to the target application scenario. The first structured query statement includes input, output, and at least one rule associated with at least one of the input and output, as well as the rule type of the at least one rule. Then, based on the rule type of the at least one rule, at least one data query task is generated. Finally, based on the at least one data query task, the database is queried to obtain the data corresponding to the data query question. Because this application uses parsing rules set for the target application scenario to parse and rewrite the target programming statement, the rewritten first structured query statement is more accurate than the first structured query statement generated by relying only on prompt words in the prior art.

[0050] For ease of understanding, the data query method in the embodiments of this application is described below. Please refer to [link / reference]. Figure 2 One embodiment of the data query method in this application includes:

[0051] 201. Using natural language models, convert the received data query questions related to the target application scenario into target programming statements;

[0052] Specifically, when this application is executed by a terminal device, the terminal device has a natural language model pre-installed. When the terminal device receives a data query question related to the target application scenario input by the user in natural language, it uses the natural language model to convert the data query question into target programming statements. Specifically, the natural language model in the embodiments of this application can be ChatGPT, deepseek, Doubao, large language model, etc., and the specific model content of the natural language model is not limited here.

[0053] Furthermore, the target application scenario in this application embodiment can be any application scenario related to the data query problem, such as a car sales scenario, a server sales scenario, a server data management scenario, etc. As long as there is a data query problem in the application scenario, the application scenario is within the scope of the target application scenario of this application.

[0054] Specifically, ChatDSL is a special descriptive language defined by ChatBI for intelligent data query scenarios. It can more concisely and accurately describe the business needs contained in the user's natural language, while facilitating collaborative processing in subsequent workflows. In this embodiment, after receiving the user's input data query question, a natural language model is used to convert the data query question expressed in natural language into ChatDSL.

[0055] For example, if a user's question is: "As of now, what is the ranking of subscription revenue for the sales staff of the Suzhou Central Branch this year?", then the target programming statement (ChatDSL) after conversion using a natural language model is: QUERY Date, Department, Organization, Salesperson, KC_Ranking(cumulative subscription revenue up to this month, NULL) FILTER (Department='Suzhou Central Branch' OR Organization='Suzhou Central') AND Date>= KC_StartOfCurrentYear() AND Date<= KC_CurrentDay() AND Salesperson='EVERY'.

[0056] 202. Using the parsing rules set for the target application scenario, the target programming statement is parsed and rewritten to obtain a first structured query statement associated with the target application scenario. The first structured query statement includes at least an input, an output, and at least one rule associated with at least one of the input and the output, as well as the rule type of the at least one rule.

[0057] After converting the data query problem into a target programming statement, the parsing rules set for the target application scenario are used to parse and rewrite the target programming statement to obtain the first structured query statement associated with the target application scenario.

[0058] If, in step 201, the above data query problem is converted into target programming statements, it is found that to query the payment ranking, the subscription payments of all sales personnel in all branches of the group for the current year must be queried. Then, the subscription payments of the sales personnel in the Suzhou branch and the subscription payment data of all sales personnel in the group are used to rank them respectively, so as to obtain the data corresponding to the data query problem.

[0059] Furthermore, after obtaining the first structured query statement, the first structured query statement generally includes input, output, and at least one rule associated with the input and / or output, as well as the rule type of the rule. For example, in the example of step 201, the rule is a ranking, and the rule type of the rule is a sorting function.

[0060] 203. Based on the rule type of the at least one rule, generate at least one data query task;

[0061] After obtaining the rule type in the first structured query statement, at least one data query task is generated based on the rule type. For example, after obtaining the ranking function in step 202, at least one data query task is generated based on the ranking function. The data query task may include: subscription collection of sales personnel of the "Suzhong" branch, and subscription collection of sales personnel of all branches within the group.

[0062] 204. Based on the at least one data query task, query the database to obtain data corresponding to the data query question.

[0063] After obtaining at least one data query task, the database is queried. For example, if the two data query questions in step 203 are generated: "Subscription revenue of sales personnel in the 'Suzhong' branch" and "Subscription revenue of sales personnel in all branches within the group", then the subscription revenue of sales personnel in the 'Suzhong' branch is sorted among the subscription revenue of sales personnel in all branches within the group to obtain the data corresponding to the data query question. For example, if the final ranking is 3, then the final data corresponding to "Subscription revenue ranking of sales personnel in the 'Suzhong' branch" is 3.

[0064] The data query method provided in this application uses parsing rules set for the target application scenario to parse and rewrite the target programming statement output by the model to generate a structured query statement. Compared with the existing technology that uses prompt words to assist the model in outputting structured query statements, the pre-set parsing rules for the target application scenario have a more accurate understanding of the target application scenario than prompt words, so the structured query statement generated by this application is also more accurate.

[0065] based on Figure 2 In the described embodiment, the first structured query statement includes not only rules related to the input and / or output, but also dependencies between the output and input. The following section details... Figure 2 Steps 203 and 204 in the embodiment are described in detail:

[0066] Specifically, when the first structured statement includes multiple rules, multiple rule types, and dependencies between output and input, this application performs topological sorting on the multiple rules based on their priority and dependencies to generate multiple data tasks ordered in a first order, wherein the multiple data tasks include data query tasks and data flow tasks.

[0067] To make it easier to understand, the following example is provided:

[0068] If the above example is changed to "What are the rankings of the sales personnel's subscription revenue this year and the percentage of the sales personnel's subscription revenue within the group?", the rules in this example are "ranking" and "percentage" calculations. The rule types are ranking function and percentage function. The dependencies between the output and input are that the ranking function depends on "the subscription revenue of the sales personnel in the Suzhou branch" and "the subscription revenue of the sales personnel in all branches within the group", while the percentage function depends on "the subscription revenue of the sales personnel in the Suzhou branch" and "the sum of the subscription revenue of the sales personnel in all branches within the group".

[0069] After obtaining the rule types and dependencies of the above rules, the rules can be sorted according to the priority of the rule types. For example, the "sorting" function and the "proportion" calculation function can be sorted to obtain multiple data tasks sorted in the first order.

[0070] If the above "sort" function and "percentage" calculation function are sorted, the resulting sorting is performed by first calculating the sorting function and then the percentage function. The resulting data tasks, arranged in the first order, are: querying the subscription payments of sales personnel in the Suzhou branch this year, querying the subscription payments of sales personnel in all branches within the group this year, calculating the sum of the subscription payments of sales personnel in all branches within the group this year, and then calculating the "sort" function and the "percentage" function.

[0071] After obtaining multiple data tasks sorted in the first order, the data query task and data flow task among the multiple data tasks are executed in the first order to obtain the data corresponding to the data query question.

[0072] For ease of understanding, we will continue to use the above example for explanation:

[0073] In the example above, the following tasks are obtained in the first order: query the subscription revenue of sales personnel in the Suzhou Central Branch this year, query the subscription revenue of sales personnel in all branches within the group this year, and calculate the total subscription revenue of sales personnel in all branches within the group this year. After calculating multiple data tasks for the "sorting" function and the "percentage" function, the tasks are executed in the first order to obtain the subscription revenue of sales personnel in the Suzhou Central Branch this year, the subscription revenue of sales personnel in each branch within the group this year, and the total subscription revenue of sales personnel in all branches within the group this year. Finally, the subscription revenue of sales personnel in the Suzhou Central Branch this year is sorted according to the sorting function in relation to the subscription revenue of each branch. Then, the percentage of the subscription revenue of sales personnel in the Suzhou Central Branch this year in the total subscription revenue of each branch is calculated according to the percentage function to obtain the values ​​of the sorting function and the percentage function.

[0074] based on Figure 2 In the embodiments described above, before rewriting the target programming statements using parsing rules set for the target scenario, the method of this application embodiment further includes the following steps, please refer to... Figure 3 :

[0075] 301. Perform lexical analysis and syntax analysis on the target programming statement, and if it is determined that the target programming statement includes at least one of a compound function and a virtual index function during the lexical analysis and syntax analysis, then parse the target programming statement into multiple second structured query statements according to at least one of the compound function and the virtual index function;

[0076] Specifically, to avoid the problem of multiple parallel functions in the above embodiments, the embodiments of this application can also perform lexical analysis and syntax analysis on the target programming statement. During the lexical analysis and syntax analysis process, if it is determined that the target programming statement includes at least one of a composite function and a virtual index function, then the target programming statement is parsed into multiple second structured query statements according to at least one of the composite function and the virtual index function.

[0077] To make it easier to understand, the following example is provided:

[0078] After obtaining the target programming statement, lexical analysis and syntax analysis, which are currently available technologies, can be used to convert the target programming statement into a syntax tree. During the conversion of the target programming statement into a syntax tree, if it is determined that the target programming statement includes composite functions and virtual index functions, where composite functions refer to multiple parallel functions, such as when querying the data question "What are the rankings of subscription revenue collection by sales personnel of the Suzhou Central Branch this year and the percentage of subscription revenue collection by sales personnel of the Suzhou Central Branch within the group?", multiple parallel functions "sorting" and "percentage" functions will appear. In this case, it is necessary to split the composite function into multiple functions. For example, the target programming statement containing the "sorting" function and the "percentage" function can be split into a second structured query statement containing the "sorting" function and a second structured query statement containing the "percentage" function, respectively.

[0079] Furthermore, the virtual indicator function in this application embodiment refers to a virtual indicator. For example, if the user question is "How is the business performance of the Suzhou Central Branch this year?", then the business performance is a virtual indicator function. Involving this virtual indicator function, it is necessary to calculate multiple functions related to the business performance, such as calculating "the sales revenue of the Suzhou Central Branch this year", calculating "the gross profit of the Suzhou Central Branch this year", and calculating "the net profit of the Suzhou Central Branch this year". That is, when the target programming statement includes a virtual indicator function, it is necessary to determine multiple calculation indicators related to the virtual indicator function, and then rewrite the target programming statement containing the virtual indicator function into multiple second structured query statements containing multiple calculation indicators. For example, the target programming statement containing "business performance" is rewritten into multiple second structured query statements containing "sales revenue", "gross profit", and "net profit".

[0080] 302. Using the parsing rules set for the target application scenario, the plurality of second structured query statements are parsed and rewritten to obtain a plurality of first structured query statements associated with the target application scenario.

[0081] After obtaining multiple second-structured query statements, the parsing rules set for the target application scenario can be used to parse and rewrite the multiple second-structured query statements to obtain multiple first-structured query statements associated with the target application scenario.

[0082] Specifically, how to use parsing rules to parse and rewrite the second structured query statement will be described in the following examples, and will not be repeated here.

[0083] In this embodiment of the application, in order to simplify the data query task, after the data query problem in natural language is transformed into a target programming statement, if the target programming statement contains a composite function and / or a virtual index function, the target programming statement containing the composite function and / or virtual index function is rewritten into multiple second structured query statements, and further, the multiple second structured query statements are rewritten into multiple first structured query statements. This improves the efficiency and accuracy of performing time queries using multiple first structured query statements compared to the target programming statement containing "composite function and virtual index function".

[0084] based on Figure 3 The embodiment described above will now be described in detail below, focusing on step 302. Please refer to [link / reference]. Figure 4 , Figure 4 The detailed steps for step 302 are as follows:

[0085] 401. If, according to the parsing rules, it is identified that the target data indicator included in the second structured query statement is associated with multiple calculated indicators, then the second structured query statement is rewritten into multiple first structured query statements that include multiple calculated indicators.

[0086] Specifically, after obtaining the second structured query statement, if the parsing rules set for the target application scenario identify that the target data indicators included in the second structured query statement are associated with multiple calculated indicators, then the second structured query statement is rewritten into multiple first structured query statements that include multiple calculated indicators. For example, when the second structured query statement is "Query the sales profit of the Suzhou-Zhongshan branch this year", it may involve "sales amount" and "sales quantity". Therefore, the second structured query statement "Query the sales profit of the Suzhou-Zhongshan branch this year" needs to be rewritten into "Query the sales amount of the Suzhou-Zhongshan branch this year" and "Query the sales quantity of the Suzhou-Zhongshan branch this year", as well as the formula for calculating sales profit using sales amount and sales quantity.

[0087] 402. If, according to the parsing rules, it is identified that the second structured query statement includes a target computation function that cannot perform data query, then the second structured query statement is rewritten into at least one first structured query statement that can perform data query.

[0088] Specifically, after obtaining the second structured query statement, if the parsing rules identify that the second structured query statement includes a target calculation function that cannot perform data query, then the second structured query statement is rewritten into at least one first structured query statement that can perform data query.

[0089] If the second structured query statement is: Query KC_Ratio(Institution='Guangzhou', Institution='ALL', Monthly Subscription Payment) Filter Institution='Guangzhou', where KC_Ratio is a function to calculate the percentage, then the second structured query statement can be rewritten into at least one first structured query statement that can perform data queries.

[0090] After obtaining the aforementioned second structured query statement, this application rewrites the second structured query statement according to the aforementioned percentage function as follows: SELECT Monthly Subscription Revenue_Guangzhou, Subscription Revenue_Overall, Subscription Revenue_Percentage WHERE Institution='Guangzhou' AND Date=KC_CurrentMonth(), thereby rewriting the second structured query statement, which contains data query and data calculation that cannot be performed, into at least one first structured query statement that can perform data query.

[0091] In this embodiment of the application, the process of rewriting a second structured query statement into a first structured query statement using parsing rules set for the target application scenario is described in detail. This rewriting process can convert a second structured query statement that cannot be executed accurately into a first structured query statement that can be executed accurately, or a second structured query statement that cannot execute data queries into a first structured query statement that can be executed accurately, thereby improving the accuracy and convenience of obtaining data corresponding to the data query problem after rewriting.

[0092] based on Figure 2 In the embodiments described above, to maximize the computational advantages of each database before executing step 204, the following steps may also be performed before executing step 204:

[0093] Analyze multiple pre-defined databases to obtain the data query logic supported by each database.

[0094] For relational databases, MySQL's data query logic supports high-frequency point queries and simple range queries, PostgreSQL's data query logic supports complex logical operations and complex aggregation of multiple tables, while data warehouse / OLAP databases' data query logic supports multi-dimensional offline aggregation operations on massive amounts of data, and Clickhouse's data query logic supports real-time data retrieval and high-speed aggregation.

[0095] After obtaining the data query logic supported by each database, follow these steps to execute the 204 response. Please refer to [link / reference]. Figure 5 , Figure 5 The following are the detailed steps for step 204:

[0096] 501. Obtain the data query logic from the database. If the data query task matches the data query logic, then use a pushdown strategy to send the data query task to the database for querying.

[0097] Specifically, when querying the database based on a data query task, the data query logic of the database to be queried can be obtained. If the data query task matches the data query logic, and if the data query task involves complex logical operations and complex aggregation of multiple tables, and the database being queried is PostgreSQL, that is, the data query task matches the database's data query logic, then a pushdown strategy is adopted to send the data query task to the database for querying. Specifically, pushdown here refers to sending the data query logic directly to the database for execution, so that the complex logical operations and multi-table aggregation operations are completed in the database.

[0098] 502. If the data query task does not match the data query logic, a pruning strategy is adopted to send the query subtasks in the data query task that match the data query logic to the database for querying.

[0099] If the data query task does not match the data query logic, a pruning strategy is adopted. The query subtasks in the data query task that match the data query logic are sent to the database for querying. For example, if the data query task involves complex logical operations and complex aggregation of multiple tables, and the database is MySQL, and MySQL's data query logic supports high-frequency point queries and simple range queries, then in this embodiment, the query subtasks in the data query task that match the data query logic are sent to the database for querying, while the computational logic that does not match the database capabilities is pruned and executed on the terminal, thereby improving the data query efficiency.

[0100] In this embodiment, based on the database query logic and the matching degree between the database and the data query task, a pushdown strategy or a pruning strategy is adopted to send the data query task to the database for querying, thereby leveraging the advantages of each database, reducing data query latency, and thus improving data query efficiency.

[0101] It is understood that, in various embodiments of the present invention, the order of the steps does not imply the order of execution. The execution order of each step should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0102] The data query method in the embodiments of this application has been described in detail above. The data query device in the embodiments of this application will be described below. Please refer to [link / reference]. Figure 6 One embodiment of the data query device in this application includes:

[0103] The conversion unit 601 is used to convert the received data query question related to the target application scenario into target programming statements using a natural language model;

[0104] The parsing unit 602 is used to parse and rewrite the target programming statement using parsing rules set for the target application scenario to obtain a first structured query statement associated with the target application scenario. The first structured query statement includes at least an input, an output, and at least one rule associated with at least one of the input and the output, as well as the rule type of the at least one rule.

[0105] The generation unit 603 is used to generate at least one data query task based on the rule type of the at least one rule;

[0106] The query unit 604 is used to query the database according to the at least one data query task to obtain data corresponding to the data query question.

[0107] As an optional embodiment, the first structured query statement also includes the dependency relationship between the output and the input;

[0108] If the first structured query statement includes multiple rules and multiple rule types, then generation unit 603 is specifically used for:

[0109] Based on the priority of the multiple rule types and the dependency relationship, the multiple rules are topologically sorted to generate multiple data tasks ordered in a first order, the multiple data tasks including data query tasks and data flow tasks;

[0110] Query unit 604 is specifically used for:

[0111] In the first order, the data query task and the data flow task among the plurality of data tasks are executed to obtain data corresponding to the data query question.

[0112] As an optional embodiment, the parsing unit 602 is specifically used for:

[0113] The target programming statement is subjected to lexical analysis and syntax analysis. During the lexical analysis and syntax analysis, if it is determined that the target programming statement includes at least one of a compound function and a virtual index function, the target programming statement is parsed into multiple second structured query statements according to at least one of the compound function and the virtual index function.

[0114] Using the parsing rules set for the target application scenario, the multiple second structured query statements are parsed and rewritten to obtain multiple first structured query statements associated with the target application scenario.

[0115] As an optional embodiment, the parsing unit 602 is specifically used for:

[0116] If, according to the parsing rules, it is identified that the target data indicator included in the second structured query statement is associated with multiple calculated indicators, then the second structured query statement is rewritten as multiple first structured query statements including the multiple calculated indicators.

[0117] As an optional embodiment, the parsing unit 602 is specifically used for:

[0118] If, according to the parsing rules, the second structured query statement is identified as containing a target computation function that cannot perform a data query, then the second structured query statement is rewritten into at least one first structured query statement that can perform a data query.

[0119] As an optional embodiment, the data query device further includes:

[0120] The acquisition unit 605 is used to analyze multiple preset databases to obtain the data query logic supported by each database before querying the database according to the at least one data query task to obtain data corresponding to the data query problem.

[0121] Query unit 604 is specifically used for:

[0122] The data query logic of the database is obtained. If the data query task matches the data query logic, a pushdown strategy is adopted to send the data query task to the database for querying.

[0123] If the data query task does not match the data query logic, a pruning strategy is adopted to send the query subtasks in the data query task that match the data query logic to the database for querying.

[0124] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0125] The data query device in the embodiments of the present invention has been described above from the perspective of modular functional entities. The computer device in the embodiments of the present invention will now be described below from the perspective of hardware processing.

[0126] One embodiment of the computer device in this invention includes:

[0127] Processor and memory;

[0128] The memory is used to store computer programs, and when the processor executes the computer programs stored in the memory, it can implement the various steps in the above method embodiments.

[0129] It is understood that when the processor in the computer device described above executes the computer program, it can also implement the functions of each unit in the corresponding data query device embodiment described above, which will not be repeated here. For example, the computer program can be divided into one or more modules / units, which are stored in the memory and executed by the processor to complete the present invention. The one or more modules / units can be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program in the gateway device / browser. For example, the computer program can be divided into units in the aforementioned gateway device, and each unit can implement the specific functions described in the corresponding gateway device above.

[0130] The computer device may be a desktop computer, laptop, handheld computer, or cloud server, etc. The computer device may include, but is not limited to, a processor and memory. Those skilled in the art will understand that the processor and memory are merely examples of a computer device and do not constitute a limitation on the computer device. It may include more or fewer components, or a combination of certain components, or different components. For example, the computer device may also include input / output devices, network access devices, buses, etc.

[0131] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor. The processor is the control center of the computer device, connecting various parts of the computer device via various interfaces and lines.

[0132] The memory can be used to store the computer programs and / or modules. The processor implements various functions of the computer device by running or executing the computer programs and / or modules stored in the memory and by calling data stored in the memory. The memory may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function, etc.; the data storage area may store data created according to the use of the terminal, etc. In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as hard disk, RAM, plug-in hard disk, smart media card (SMC), secure digital card (SD card), flash card, at least one disk storage device, flash memory device, or other volatile solid-state storage device.

[0133] The present invention also provides a computer-readable storage medium for implementing the function of a data query device, wherein a computer program is stored thereon, and when the computer program is executed by a processor, the processor can be used to perform the various steps in the above method embodiments.

[0134] It is understood that if the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a corresponding computer-readable storage medium. Based on this understanding, all or part of the processes in the above-described embodiments of the present invention can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the above-described method embodiments. The computer program includes computer program code, which can be in the form of source code, object code, executable file, or some intermediate form. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drive, portable hard drive, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.

[0135] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.

[0136] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0137] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0138] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A data query method, characterized in that, include: Using natural language models, the received data query questions related to the target application scenario are converted into target programming statements; Using the parsing rules set for the target application scenario, the target programming statement is parsed and rewritten to obtain a first structured query statement associated with the target application scenario. The first structured query statement includes at least an input, an output, and at least one rule associated with at least one of the input and the output, as well as the rule type of the at least one rule. Based on the rule type of the at least one rule, generate at least one data query task; According to the at least one data query task, query the database to obtain data corresponding to the data query question.

2. The method according to claim 1, characterized in that, The first structured query statement also includes the dependency relationship between the output and the input; If the first structured query statement includes multiple rules and multiple rule types, then generating at least one data query task based on the rule type of the at least one rule includes: Based on the priority of the multiple rule types and the dependency relationship, the multiple rules are topologically sorted to generate multiple data tasks ordered in a first order, the multiple data tasks including data query tasks and data flow tasks; The step of querying the database according to the at least one data query task to obtain data corresponding to the data query question includes: In the first order, the data query task and the data flow task among the plurality of data tasks are executed to obtain data corresponding to the data query question.

3. The method according to claim 1, characterized in that, Before parsing and rewriting the target programming statement, the method further includes: The target programming statement is subjected to lexical analysis and syntax analysis. During the lexical analysis and syntax analysis, if it is determined that the target programming statement includes at least one of a compound function and a virtual index function, the target programming statement is parsed into multiple second structured query statements according to at least one of the compound function and the virtual index function. The step of parsing and rewriting the target programming statement using parsing rules set for the target application scenario to obtain a first structured query statement associated with the target application scenario includes: Using the parsing rules set for the target application scenario, the multiple second structured query statements are parsed and rewritten to obtain multiple first structured query statements associated with the target application scenario.

4. The method according to claim 3, characterized in that, The step of parsing and rewriting the multiple second structured query statements using parsing rules set for the target application scenario to obtain multiple first structured query statements associated with the target application scenario includes: If, according to the parsing rules, it is identified that the target data indicator included in the second structured query statement is associated with multiple calculated indicators, then the second structured query statement is rewritten as multiple first structured query statements including the multiple calculated indicators.

5. The method according to claim 3, characterized in that, The step of parsing and rewriting the multiple second structured query statements using parsing rules set for the target application scenario to obtain multiple first structured query statements associated with the target application scenario includes: If, according to the parsing rules, the second structured query statement is identified as containing a target computation function that cannot perform a data query, then the second structured query statement is rewritten into at least one first structured query statement that can perform a data query.

6. The method according to claim 1, characterized in that, Before querying the database to obtain data corresponding to the data query question based on the at least one data query task, the method further includes: Analyze multiple preset databases to obtain the data query logic supported by each database; The step of querying the database according to the at least one data query task to obtain data corresponding to the data query question includes: The data query logic of the database is obtained. If the data query task matches the data query logic, a pushdown strategy is adopted to send the data query task to the database for querying. If the data query task does not match the data query logic, a pruning strategy is adopted to send the query subtasks in the data query task that match the data query logic to the database for querying.

7. A data query device, characterized in that, include: The conversion unit is used to convert received data query questions related to the target application scenario into target programming statements using a natural language model; The parsing unit is used to parse and rewrite the target programming statement using parsing rules set for the target application scenario to obtain a first structured query statement associated with the target application scenario. The first structured query statement includes at least an input, an output, and at least one rule associated with at least one of the input and the output, as well as the rule type of the at least one rule. A generation unit is used to generate at least one data query task based on the rule type of the at least one rule; The query unit is used to query the database according to the at least one data query task to obtain data corresponding to the data query question.

8. A computer device comprising a processor, characterized in that, When the processor executes a computer program stored in the memory, it is used to implement the data query method as described in any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it is used to implement the data query method as described in any one of claims 1 to 6.

10. A computer program product having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it is used to implement the data query method as described in any one of claims 1 to 6.