SQL statement generation method and device, equipment and storage medium
By automatically extracting conditional features and generating SQL statements using pre-trained large language models, the accuracy and efficiency problems when manually editing SQL statements are solved, and efficient cross-data table and cross-database query is achieved.
Patent Information
- Application Number
- CN202411636224.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-14
- Publication Date
- 2025-03-28
AI Technical Summary
During the data query process, there are accuracy and efficiency problems with manual editing of SQL statements, especially when querying across data tables and across databases, the complexity of SQL statements and the complexity of editing process leads to reduced accuracy and inefficiency.
By calling the pre-trained large language model, conditional features are extracted from the query text, the data table to be queryed is automatically determined, and structured query language SQL statements are generated. In the multi-data table query scenario, SQL statements can be called in the query order of the data table to realize automatic query.
It improves the editing efficiency and accuracy of SQL statements, breaks through the technical threshold for data table use, and enhances the efficiency in the process of querying data across data tables and across databases.
Smart Images

Figure CN119719130A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of artificial intelligence technology, and in particular to a method, apparatus, device and storage medium for generating a structured query language (SQL) statement. Background Art
[0002] In tasks such as application development and testing, data can be queried through SQL statements. Generally, for any data query task, SQL statements are manually edited to query data. In order to ensure that the corresponding data is accurately queried, the data storage location and name involved in the edited SQL statement should be accurate.
[0003] Usually, the storage location of task-related data is designed and deployed by technicians of relevant task lines, and it is difficult for technicians of non-related task lines to ensure the accuracy of the edited SQL statements. In addition, in the process of querying data across data tables and databases, the data and query steps involved are relatively large, so the complexity of the SQL statements to be edited and the complexity of the editing process are increased. This not only leads to the risk of further reduction in the accuracy of SQL statements, but also low editing efficiency, which leads to low efficiency of data query. Summary of the invention
[0004] To overcome the problems existing in the related art, the embodiments of the present application provide a method, apparatus, device and storage medium for generating a SQL statement.
[0005] According to a first aspect of an embodiment of the present application, a method for generating an SQL statement is provided, the method comprising:
[0006] In response to receiving a query text, calling a pre-trained large language model to extract at least one conditional feature from the query text, wherein the at least one conditional feature is used to indicate information of a data table to be queried, wherein the data table to be queried belongs to a target data table set, and the target data table set refers to a preset data table set that matches a query node corresponding to the query text;
[0007] Generate a structured query language SQL statement corresponding to the at least one data table respectively, and obtain at least one initial SQL statement, each initial SQL statement contains conditional features corresponding to the corresponding data table;
[0008] In the case where the at least one data table is implemented as at least two data tables, the callable SQL statements corresponding to the data tables are determined in sequence according to the initial SQL statements of each data table in accordance with the query order corresponding to the at least two data tables, so as to call the corresponding callable SQL statements to query the corresponding data tables to obtain the target query results.
[0009] According to a second aspect of an embodiment of the present application, a device for generating a SQL statement is provided, the device comprising:
[0010] an extraction module, configured to, in response to receiving a query text, call a pre-trained large language model to extract at least one conditional feature from the query text, wherein the at least one conditional feature is used to indicate information of a data table to be queried, wherein the data table to be queried belongs to a target data table set, and the target data table set refers to a preset data table set that matches a query node corresponding to the query text;
[0011] A generating module, configured to generate a structured query language SQL statement corresponding to the at least one data table, to obtain at least one initial SQL statement, each initial SQL statement including conditional features corresponding to the corresponding data table;
[0012] A determination module is used to determine the callable SQL statements corresponding to the data tables in sequence according to the initial SQL statements of each data table in the case where the at least one data table is implemented as at least two data tables, in accordance with the query order corresponding to the at least two data tables, so as to call the corresponding callable SQL statements to query the corresponding data tables to obtain target query results.
[0013] According to a third aspect of an embodiment of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method of the first aspect.
[0014] According to a seventh aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored, and the program is executed by a processor to implement the method of the first aspect.
[0015] According to an eighth aspect of an embodiment of the present application, a computer program product is provided, comprising a computer program, wherein the computer program is executed by a processor to implement the method of the first aspect.
[0016] The technical solution provided by the embodiments of the present application may have the following beneficial effects:
[0017] The technical solution of the embodiment of the present application pre-trains a large language model, and the pre-trained large language model can be called to generate SQL statements based on the query text, thereby supporting the understanding and reasoning ability of the large language model for natural language, identifying the intention of the query text, and then automatically generating SQL statements. In the implementation process, the large language model can determine the information of the data table to be queried from the data table set matching the query node according to at least one conditional feature contained in the query text, and generate a structured query language SQL statement for each corresponding data table to obtain at least one initial SQL statement. Further, in the case of at least two data tables to be queried, according to the query order corresponding to the at least two data tables, the callable SQL statement corresponding to the data table is determined in sequence according to the initial SQL statement of each data table, so as to call the corresponding callable SQL statement to query the corresponding data table to obtain the target query result. It can be seen that by adopting this technical solution, the large language model supports automatically determining the data table to be queried from the data table set matching the query node, and in the case of at least two data tables to be queried, it supports querying according to the query order of at least two data tables, and determining the callable SQL statement. In this way, not only can the technical threshold for using data tables be broken through, but also, in the process of querying data across data tables and across databases, it is helpful to edit SQL statements with higher accuracy with higher editing efficiency, thereby improving the efficiency of data query.
[0018] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments of the present application. It should be understood that for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative labor.
[0020] Figure 1 A schematic diagram of the architecture of an exemplary SQL statement generation system provided in an embodiment of the present application;
[0021] Figure 2 A schematic diagram of an exemplary method flow of a method for generating a SQL statement provided in an embodiment of the present application;
[0022] Figure 3A A schematic diagram of an exemplary display interface for creating a query node and selecting a database provided in an embodiment of the present application;
[0023] Figure 3B Based on the embodiments of the present application Figure 3A A schematic diagram of an exemplary display interface for selecting a database and a data table;
[0024] Figure 3C Provided in the embodiments of this application Figure 3B Schematic diagram of the display interface for the description information of the fields in the data table;
[0025] Figure 4A Schematic diagram of the display interface of the query scenario provided in the embodiment of the present application Figure 1 ;
[0026] Figure 4B Schematic diagram of the display interface of the query scenario provided in the embodiment of the present application Figure 2 ;
[0027] Figure 5 A schematic diagram of an exemplary composition of a SQL statement generating device provided in an embodiment of the present application;
[0028] Figure 6 An exemplary structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0029] The technical solution of the embodiment of the present application is described below in conjunction with the drawings in the embodiment of the present application.
[0030] The terms used in the following embodiments of the present application are for the purpose of describing specific embodiments, and are not intended to be used as limitations on the technical solutions of the present application. As used in the specification and the appended claims of the present application, the singular expressions "one", "a kind of", "said", "above", "the" and "this" are intended to also include plural expressions, unless there is a clear contrary indication in the context. It should also be understood that although the terms first, second, etc. may be used to describe a certain class of objects in the following embodiments, the objects should not be limited to these terms. These terms are used to distinguish the specific implementation objects of this class of objects. For example, the terms first, second, etc. are used in the following embodiments to describe prompt information, but the prompt information is not limited to these terms. These terms are only used to distinguish prompt information of different contents. The same is true for other classes of objects that may be described by the terms first, second, etc. in the following embodiments, which will not be repeated here.
[0031] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0032] First, the implementation scenarios and technical terms related to the embodiments of the present application are explained.
[0033] The implementation scenario related to the embodiment of the present application can be a data query scenario. For example, in tasks such as application development and testing, the relational database management system MySQL can be used to manage and query task-related data. The "SQL" in MySQL refers to the "Structured Query Language", and SQL statements can be directly entered according to the programming environment to perform operations. For example, during the testing phase of the application, the score of an item should be 100 points, but the client displays 90 points. In response to questions raised by users from the client, relevant technicians should investigate the cause. In this process, the relevant technicians locate the data related to the problem by searching the database related to the application to determine the cause of the problem.
[0034] MySQL is a relational database management system (RDBMS) that supports complex queries and large data sets, and is compatible with multiple operating systems (such as Linux, Windows, and mac). MySQL is widely used to maintain data for applications in various scenarios, such as websites, enterprise applications, and data warehouses.
[0035] SQL statements are standardized query languages in relational databases and can be used to access data, query, update, and manage relational databases. For example, an SQL statement is implemented as: SELECT * FROM customers WHERE customer_id = 000x.
[0036] The conventional query method is that the relevant technicians query the data in the corresponding data table contained in the database by typing SQL statements on the database management platform. In the actual implementation scenario, it is often necessary to query data across data tables or across databases. In the scenario of querying data across data tables, it is also necessary to write a join statement to combine rows or columns from two or more data tables and query data from the combined table. In the scenario of querying data across databases, it is necessary to type SQL in the interface window corresponding to a database, and after querying the results for the data table associated with the corresponding interface window, open the interface window corresponding to another database, use the previously queried results as conditions, and type in the SQL of the database corresponding to the window until the desired results are queried. As can be seen from the above examples of SQL statements, the data table name (such as "customers" in the above example) and the field in the data table (such as "customer_id=000x" in the above example) in an SQL statement should be accurate, otherwise the query will fail. It can be seen that the manual typing of SQL statements is not only inefficient in editing SQL statements and querying data, but also the design and deployment of databases and data tables related to any task are developed and designed by relevant technical personnel. Non-development and design personnel are not clear about the design of databases and data tables, resulting in a certain query threshold, which is not conducive to the technical advancement of the task.
[0037] In view of this, the technical solution of the embodiment of the present application can call the pre-trained large language model to generate SQL statements based on the query text, thereby supporting the understanding and reasoning ability of the large language model for natural language, identifying the intention of the query text, and then automatically generating SQL statements. Moreover, in the case of at least two data tables to be queried, according to the query order corresponding to the at least two data tables, the callable SQL statements corresponding to the data tables are determined in sequence according to the initial SQL statements of each data table, so as to call the corresponding callable SQL statements to query the corresponding data tables to obtain the target query results. Not only can it break through the technical threshold for the use of data tables, but also, in the process of querying data across data tables and across databases, it is conducive to editing SQL statements with higher accuracy with higher editing efficiency, thereby improving the efficiency of data query.
[0038] refer to Figure 1 , Figure 1 A SQL statement generation system involved in an embodiment of the present application is shown, and the SQL statement generation system can be used to execute the SQL statement generation method provided in an embodiment of the present application. The SQL statement generation system may include: a processor 10, a memory 20, a communication module 30, a large language model 40, a data query engine 50, and a display 60, etc. The server 10 and the client 20 are connected via network communication.
[0039] It is to be understood that the structure illustrated in the present application does not constitute a specific limitation on the SQL statement generation system. In other embodiments of the present application, the SQL statement generation system may include more or fewer components (e.g., power management components, external devices, etc.) than those illustrated, or combine certain components, or split certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0040] Large Language Models (LLMs) may include Generative Pre-trained Transformer (GPT) series models or other large language models. Other large language models may include, for example, autoencoder based models (ABM), sequence-to-sequence model (SSM), Transformer-Based Models (TBM), etc.
[0041] In some embodiments, before the large language model is deployed in the SQL statement generation system, the data definition language (DDL) involved in the application scenarios related to the embodiments of the present application and the prompt information corresponding to the SQL to be generated can be input into the large language model, so that the large language model responds to the query text input by the user and generates SQL statements that match various situations in the application scenario, so that the large language model can flexibly output matching SQL statements for different query situations.
[0042] The processor 10 is used to perform system scheduling, for example, calling the communication module 30 to receive the task domain information, query node information, query text, and description information of the data table associated with each query node information (i.e., the DDL matched by the query node) input by the user through the display 60; for another example, the processor 10 calls the communication module 30 to query the corresponding data from the database based on the DDL. The processor 10 is also used to call the large language model to extract conditional features from the query text in response to the query text input by the user, so as to determine the data table to be queried in the DDL based on the extracted conditional features, and then gradually generate SQL statements corresponding to each data table. The processor 10 can be used to call the callable SQL statement generated by the data query engine 50 based on the large language model to perform data query.
[0043] The memory 20 is used to store software programs and data. The processor 10 executes the various embodiments of the SQL statement generation method of the present application by running the software program. The data is used to provide support for the processor 110 to run the software program. The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function (such as a display function, a communication function, etc.); the data storage area may store information supporting the implementation of the technical solution of the present application and operating logic and data supporting a large language model, etc., and the information may include, for example, a pre-received task domain, each task domain information including a query node, and a data table description information corresponding to each query node. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as a disk storage device, a flash memory device, or other volatile solid-state storage device.
[0044] The communication module 30 can be used to provide a communication interface for information interaction with the user, and a communication interface layer for interacting with the data source. In some embodiments, the SQL statement generation system responds to the user's operation, so that the processor 10 can call the communication interface of the communication module 30 on the display 60 to implement the function of information interaction with the user. In other embodiments, after receiving the database description information input by the user, the processor 10 can call the communication interface layer of the communication module 30 to access the data source to read the description information of the data table corresponding to the database description information from the data source; in some other embodiments, after obtaining the callable SQL statement generated by the large language model, the processor 10 can trigger the data query engine 50 to call the communication interface layer of the communication module 30 to query and access the corresponding data in the data source, etc. Optionally, the communication interface layer can be, for example, a data access layer (Data Access Layer, DAL).
[0045] The SQL statement generation system can be carried on an electronic device provided with a display 60 to run. The display 60 is configured to display the user interface (User Interface, UI) of the SQL statement generation system, and to provide an interface for interaction and information exchange between the SQL statement generation system and the user. The UI involved in the embodiment of the present application is configured with a medium interface for user operation to interact with the application. As an interactive interface with the user, the UI can convert the computer language of the application into a form that the user can accept and recognize, including displayed pictures, text, buttons, etc. The commonly used form of UI can be a graphical user interface (Graphic User Interface, GUI), which refers to a user interface related to computer operation displayed in a graphical manner. It can be an interface element such as an icon, window, control, etc. displayed on the display screen of an electronic device, wherein the control can include visual interface elements such as icons, buttons, menus, tabs, text boxes, etc. For example, in the following embodiments of this specification, the user's query operation can input the corresponding query text to the SQL statement generation system through the control of the corresponding GUI, thereby triggering the SQL statement generation system to call a large language model, etc. to generate SQL statements, and display query results based on SQL statements.
[0046] Please refer to Figure 2 , Figure 2 An exemplary SQL statement generation method is shown. The SQL statement generation method can be Figure 1 The SQL statement generation system executes. The SQL statement generation method may include the following steps:
[0047] In step S101, in response to receiving a query text, a pre-trained large language model is called to extract at least one conditional feature from the query text, where the at least one conditional feature is used to indicate information of a data table to be queried.
[0048] In step S102, when at least one data table to be queried is determined according to the at least one conditional feature, an SQL statement is generated corresponding to each of the at least one data table to obtain at least one initial SQL statement.
[0049] In step S103, when the at least one data table is implemented as at least two data tables, the callable SQL statements corresponding to the data tables are determined in sequence according to the initial SQL statements of each data table in accordance with the query order corresponding to the at least two data tables, so as to call the corresponding callable SQL statements to query the corresponding data tables and obtain the target query results.
[0050] In some embodiments, the data table to be queried belongs to a target data table set, and the target data table set refers to a preset data table set that matches the query node corresponding to the query text.
[0051] In some embodiments, each initial SQL statement includes conditional features corresponding to the corresponding data table.
[0052] It can be seen that the technical solution of the embodiment of the present application pre-trains a large language model, thereby calling the pre-trained large language model to generate SQL statements based on the query text, thereby supporting the understanding and reasoning ability of the large language model for natural language, identifying the intention of the query text, and then automatically generating SQL statements. The technical solution of the embodiment of the present application can also pre-maintain a set of data tables matching each query node, so that in the implementation process, the large language model can determine the information of the data table to be queried from the data table set matching the query node according to at least one conditional feature contained in the query text, and generate a structured query language SQL statement for each corresponding data table to obtain at least one initial SQL statement. Further, in the case of at least two data tables to be queried, according to the query order corresponding to the at least two data tables, the callable SQL statement corresponding to the data table is determined in sequence according to the initial SQL statement of each data table, so as to call the corresponding callable SQL statement to query the corresponding data table to obtain the target query result. It can be seen that by adopting this technical solution, the large language model supports automatically determining the data table to be queried from the data table set matching the query node, and in the case of at least two data tables to be queried, it supports querying according to the query order of at least two data tables, and determining the callable SQL statement. In this way, not only can the technical threshold for using data tables be broken through, but also, in the process of querying data across data tables and across databases, it is helpful to edit SQL statements with higher accuracy with higher editing efficiency, thereby improving the efficiency of data query.
[0053] Among them, the data table set can be a collection of description information of multiple data tables. The query node can be any query node in a task domain. The task domain can be classified according to the task type contained in the application, and one type of task can be divided into a task domain. A task domain can contain at least one task scenario. In the embodiment of the present application, any task scenario is used as a query node, and a correspondence between any query node and its related data table description information can be established. These can be pre-created and set before receiving the query text. That is, in some embodiments, before responding to the receipt of the query text, the SQL statement generation system can create a task domain and at least one query node contained in the task domain in response to the received creation instruction. For any query node, in response to receiving at least one database identifier, the description information of the data table contained in the at least one database identifier is obtained from the pre-deployed data source to obtain a data table set; the description information of any data table includes all field names contained in the data table; and a matching relationship between the query node and the data table set is established.
[0054] In this way, at least one database identifier, a data table set, and the field names contained in each data table set can form a database structure corresponding to the query node, so that the large language model can access the database structure based on DDL to generate SQL statements.
[0055] Exemplarily, taking the application as a meal ordering platform, according to the task type of the meal ordering platform, it can be classified into task domains such as security management, logistics settlement, performance management, rider account infrastructure, and return order rate. Taking the task domain "rider account infrastructure" as an example, the rider account infrastructure can include query nodes such as service rating, delivery speed, and monthly order volume. For any query node, the SQL statement generation system can receive the database identifier entered by the user, and can call DAL to determine the database corresponding to the database identifier and the various data tables contained in the database from the data source, and read the description information of each data table. After that, the correspondence between the corresponding query node and the description information of each data table can be maintained locally to obtain a set of data tables that match the corresponding query node.
[0056] It should be understood that the above enumeration of task domains and query nodes is only a schematic description and does not constitute a limitation on the task domains and query nodes in the embodiments of the present application. In actual implementation scenarios, task domains and query nodes can be flexibly set according to different usage scenarios of the application, and the embodiments of the present application do not limit this.
[0057] The description information of the data table may include at least one of the table name and the data table annotation information, and the field name of each field included in the data table. The data table annotation information may be information for marking the function of the data table.
[0058] By adopting this implementation method, the data tables in the data source are divided into data table sets associated with the query nodes according to the task types of the application and the query nodes contained in each task type, thereby dividing the range of the data table based on the query nodes. In the process of generating SQL statements, it is beneficial to generate SQL statements based on the corresponding data table range, thereby improving the efficiency of generating SQL statements.
[0059] It should be pointed out that, corresponding to any query node, in an optional design, the correspondence between the query node and the description information of each data table maintained locally by the SQL statement generation system may not include the description information of all the data tables corresponding to the query node, but may only include the description information of some data tables related to the query scenario. For example, if the query scenario is a troubleshooting scenario in the process of using an application, then only the data tables related to the scenario of using the query node may be maintained, and the data tables related to the structure of the application during the development process may not be maintained. This is conducive to reducing the storage resource usage of the SQL statement generation system.
[0060] The technical solution of the embodiment of the present application supports users to query data in natural language. After the SQL statement generation system receives the query text input by the user, it can call the large language model to extract at least one conditional feature from the query text. The query text is an inquiry text input by the user and expressed in natural language. The conditional feature can be information that characterizes the query subject, query intent, etc. Among them, the query subject can refer to the type of information or data that the user wants to obtain, and the vocabulary or phrase that characterizes the query subject can be a noun, verb, phrase or sentence, which are usually located in a specific position in the query statement. The query intent can refer to the attributes of the target data that the user wants to query. For example, a query statement is "check the service score details of the rider ID 123", where the query subject is, for example, "the rider with ID 123"; for another example, the query statement is "check the service score of the rider ID 123", the query subject is, for example, "the rider with ID 123", and the query intent is, for example, "the service score on December 1, 2023". The embodiment of the present invention does not limit this.
[0061] Among them, the at least one conditional feature is used to indicate the information of the data table to be queried. According to the above-mentioned at least one conditional feature, the data table to be queried can be determined based on the aforementioned DDL. For example, any conditional feature can indicate a field name (such as rider ID, date, service points, service points details, etc.), after the pre-trained large language model is called to extract at least one conditional feature from the query text, the large language model determines the field name indicated by the conditional feature for any conditional feature; based on the DDL that matches the query node, the data table where the field name is located is searched from the data table set; and the data table where the field name is located is determined as the data table to be queried.
[0062] It should be pointed out that the data results that the user wants to query may be queried from one data table, or may need to be queried from multiple data tables. Correspondingly, if the data can be queried from one data table, at least one conditional feature contained in the query statement can indicate a data table, and the at least one conditional feature can be implemented as a conditional feature, for example. For example, the conditional features contained in the query statement "Check the service score of the rider ID 123" are "rider ID (knight_id): 123" and "service score", and the data you want to query can be queried from the data table service_score. For another example, the conditional features contained in the query statement "Query the service score details of rider ID 123" are "rider ID" and "service score details", "rider ID" and the task_id corresponding to the rider are maintained in the data table service_score, and "service score details" are maintained in the data table service_score_calculate_detail, so the two conditional features in this example can indicate two data tables, indicating that this example needs to query two data tables to query the data you want to query.
[0063] It should be understood that if there are at least two data tables to be queried, the at least two data tables may belong to one database or may respectively belong to multiple databases.
[0064] In other embodiments, if the large language model fails to extract conditional features from the query statement, or fails to find a corresponding data table based on the extracted conditional features, an error message may be output.
[0065] In the actual implementation scenario, when there is one data table to be queried, at least one conditional feature contains all the query conditions for querying the data table. Based on this, when at least one data table is implemented as one data table, the large language model can generate an initial SQL statement according to the at least one conditional feature. The initial SQL statement is a callable SQL statement, so as to call the callable SQL statement to query the data table and obtain the target query result. In the case of at least two data tables to be queried, the at least two data tables should generally be queried in a certain order, and the query result of one step should be used as the query condition of the next step of the step to generate an SQL statement for querying the data table to be queried in the next step. Accordingly, the SQL statement corresponding to the next step of the step is a SQL statement to be filled in, and the SQL statement to be filled in is a non-callable SQL statement. It can be seen that any initial SQL statement is a callable SQL statement or a SQL statement to be filled in.
[0066] For example, in the above example of "check the service score of the rider ID 123", it is indicated that the service score of the rider ID 123 should be found from the data table service_score. In this example, the rider ID is the field name in the conditional feature "rider ID is 123", and 123 is the field value of the field name, that is, the conditional feature "rider ID is 123" contains all the query conditions for querying the data table service_score, and can generate a callable SQL statement "SELECT * FROM service_score WHERE knight_id = '123' AND is_delete = 0 ORDER BY calculate_time DESC LIMIT 1".
[0067] In the case where at least one data table is implemented as at least two data tables, for any data table, the large language model can determine whether the conditional features corresponding to the data table include the field values in the data table, and if the conditional features corresponding to the data table include the field values in the data table, generate a callable SQL statement according to a preset SQL grammar structure, and set the data table as the first data table to be queried in the at least two data tables. If the conditional features corresponding to the data table do not include the field values in the data table, determine the source data table related to the field value according to the conditional features, generate a SQL statement to be filled according to a preset SQL grammar structure, and set the data table as the data table to be queried after and adjacent to the source data table.
[0068] The source data table belongs to the at least two data tables. The SQL statement to be filled includes a placeholder symbol, and the position of the placeholder symbol is the position of the field value to be filled. The placeholder symbol can be implemented as "?", for example.
[0069] For example, in the above example of "querying the service details of rider ID 123", the rider's task_id should be found in the data table service_score first, and then the corresponding service details should be found in the data table service_score_calculate_detail according to task_id. For each data table, the large language model can generate an SQL statement. Among them, the conditional feature "rider ID: 123", the rider ID is, for example, the field name, and 123 is the field value of the field name, that is, according to "rider ID: 123", a SQL statement for querying service_score can be generated, and the SQL statement is, for example, "SELECT * FROM service_score WHERE knight_id = '123' AND is_delete = 0 ORDER BY calculate_timeDESC LIMIT 1", which is a callable SQL statement. The conditional feature "Service score details" is a table name, and its fields should be, for example, knight_id and task_id, and the values of knight_id and task_id need the query results of the previous step. The SQL statement is, for example, "SELECT * FROM service_score_calculate_detail WHERE knight_id = ? and task_id = ?", where "?" is a placeholder, indicating that the SQL statement is a SQL statement to be filled.
[0070] In some embodiments, according to the query order corresponding to the at least two data tables, the callable SQL statement corresponding to the data table is determined in sequence according to the initial SQL statement of each data table, which can be implemented as follows: the large language model can transmit the i-1th callable SQL statement to the data query engine, so that the data query engine calls the i-1th callable SQL statement to query the i-1th data table to obtain the initial query result. If the i-1th data table is not the last data table of the at least two data tables, the large language model can fill the initial query result as a field value into the position of the placeholder symbol of the i-th SQL statement to be filled, obtain the i-th callable SQL statement, and call the i-th callable SQL statement to query the i-th data table. If the i-1th data table is the last data table of the at least two data tables, the SQL statement generation system determines the initial query result as the target query result. Among them, the i-1th data table is the data table ranked as the i-1th in the at least two data tables, and i is an integer greater than or equal to 2.
[0071] Still taking the above-mentioned data table service_score and data table service_score_calculate_detail to be queried as an example, the SQL statement for querying the data table service_score is a callable SQL statement, and the SQL statement for querying the data table service_score_calculate_detail is a SQL statement to be filled. The large language model can transmit the callable SQL statement to the data query engine, so that the data query engine calls the callable SQL statement, queries data from the data table service_score, and transmits the query result "task_id is 'xxx', 'xxxx'..." to the large language model. Furthermore, the large language model can use 'xxx', 'xxxx'... to replace the placeholder "?" of task_id in the above-mentioned SQL statement to be filled, and obtain the callable SQL for querying the data table service_score_calculate_detail.
[0072] It should be understood that the above is only a schematic description of generating SQL statements from two data tables as an example, and does not constitute a limitation on the implementation scenario of the embodiment of the present application where the data tables to be queried are at least two data tables. In another embodiment, if the number of data tables to be queried is three, then the large language model can generate three SQL statements, and the three SQL statements correspond to the three data tables one by one. The three SQL statements include one callable SQL statement and two SQL statements to be filled, and the three data tables correspond to a query order. In this embodiment, after calling the callable SQL statement to return the query result, the first SQL statement to be filled can be determined according to the query order of the three data tables, and after the first SQL statement to be filled is filled as a callable SQL statement, the second SQL statement to be filled is further filled according to the query result returned by the callable SQL statement obtained after the filling, so as to call the corresponding data table according to the callable SQL statement obtained after filling the second SQL statement to be filled, thereby obtaining the query result. For the embodiment in which the number of data tables to be queried is any number greater than 2, the above description can be referred to, and the embodiment of the present application will not be described in detail here.
[0073] It can be seen that by adopting this implementation, the conditional features in the query statement are automatically identified through the large language model, and then, based on the scenarios with different numbers of data tables, the corresponding SQL statement can be generated for each data table, thereby breaking through the technical threshold and efficiently generating SQL statements. In the case where there are at least two data tables to be queried, they can also be automatically spliced to generate a new callable SQL statement, thereby supporting automatic cross-database and cross-datatable queries.
[0074] It should be pointed out that the working mechanism of the large language model involved in the embodiment of the present application is to directly generate corresponding SQL statements through prompt information. Compared with traditional artificial intelligence (AI) tools, the large language model does not need to define functions and their parameters, nor does it need to generate calling functions for SQL queries, thereby avoiding the problem of inaccurate queried data due to inaccurate parameters of the calling function.
[0075] The prompt information may refer to the prompt word (prompt) of the pre-trained large language model. The prompt is the text or sentence input to the pre-trained large language model, which is used to guide the pre-trained large language model to generate response information or continue to generate the starting point of the text. The prompt can be a sentence, a question, a descriptive paragraph, or a series of instructions. In an embodiment of the present application, the prompt information can be a descriptive information for guiding the pre-trained large language model to generate the rules or generation steps of the initial SQL statement according to the number of data tables to be queried corresponding to the conditional features.
[0076] In some embodiments, the large language model may output a data object, which may be a json object. The json object may include multiple sets of key-value pair information, and any json object includes a SQL statement corresponding to the data table. In some embodiments, when a SQL statement is generated for at least one data table, for any data table, the data object (i.e., json object) generated by the large language model includes description data of the data table and the SQL statement. In other embodiments, the data object (i.e., json object) generated by the large language model also includes a source data table indication mark, and the source data table indication mark is used to indicate whether the SQL statement included in the data object needs to fill in the query results of the source data table.
[0077] Combined with the description of the foregoing embodiment, in the case of a data table to be queried, the format of the json object output by the large language model is: {database:'string 1', SQL:'string 2'}. It can be seen that in this example, the json object includes two attribute parameters, among which database:'string 1' is a key-value pair, and SQL:'string 2' is another key-value pair. The key "database" in database:'string 1' is used to represent the attribute parameter data table, and "string 1" is the value corresponding to the data table, which can be the description information of the data table. The key "SQL" in SQL:'string 2' is used to represent the attribute parameter SQL statement, and "string 2" is the value corresponding to the key, which can be the content of the SQL statement, such as the callable SQL statement in the foregoing example.
[0078] In the case where at least one data table is implemented as at least two data tables, for any data table, the format of the json object output by the large language model is: {database:'string 1', SQL:'string 2', 'condition_source': whether the result of the previous step is needed, return true or false}. In this example, the json object includes three attribute parameters. In addition to the above two attribute parameters, this example also includes the attribute of whether the SQL statement represented by condition_source needs to fill the query result of the source data table. If the SQL statement needs to fill the query result of the source data table, the value of condition_source is true, and the SQL statement indicated by string 2 includes a placeholder "?"; if the SQL statement does not need to fill the query result of the source data table, the value of condition_source is false, and the SQL statement indicated by string 2 is a callable SQL statement.
[0079] Exemplarily, the prompt in the embodiment of the present application may be:
[0080] “You are a MySQL database expert who can analyze database structure to answer user questions.
[0081] Here are the database structures you can query: ${databaseStructures}
[0082] Please first answer how many data tables need to be queried to solve the user's problem.
[0083] Then, find the data table that contains the user-supplied field values.
[0084] If you only need to query one data table, please return a JSON object containing two properties: database:'xxx',sql:'xxx'.
[0085] If you need to query multiple data tables, the query of each data table is a separate step. Each step corresponds to a separate SQL statement, and the SQL query conditions come from user input or the result of the previous SQL statement.
[0086] If the data table being queried contains field values provided by the user, then please put the field values provided by the user into the corresponding SQL query conditions.
[0087] Each step returns a JSON object containing three properties: 'database':'xxx', 'sql':'xxx', 'condition_source': whether the result of the previous step is needed, returning true or false.
[0088] Use a question mark where the result of a previous step is needed.
[0089] Please return only JSON objects."
[0090] Among them, ${databaseStructures} refers to the data structure of the data table set corresponding to the aforementioned query node.
[0091] Furthermore, for the SQL that needs to be filled, the large language model can also include the following prompts:
[0092] "You can fill the query results provided by the user into the SQL provided by the user to generate a complete SQL that conforms to MySQL syntax. The returned content is SQL in text format. Do not return other content. Please use the following information: ${JSON.stringify(result)} Fill in the following SQL: ${query}."
[0093] Among them, stringify(result) refers to the query result of the previous data table returned (for example, the i-1th data table mentioned above), and ${query} refers to the SQL statement to be filled (for example, the SQL statement corresponding to the i-th data table mentioned above).
[0094] It should be understood that the above examples of prompt information are merely illustrative descriptions and do not constitute a limitation on the prompt information of the embodiments of the present application.
[0095] It can be seen that in the embodiment of the present application, with the help of the understanding and reasoning ability, language generation ability, etc. of the large language model, it is possible to identify the intention of the query text input by the user, and then extract the conditional features therein, and then automatically generate SQL statements according to the preset SQL statement structure. In the case of at least two data tables to be queried, it is also possible to support automatic splicing of each SQL, which can not only break through the technical threshold for the use of data tables, but also, in the process of querying data across data tables and across databases, it is conducive to editing SQL statements with higher accuracy with higher editing efficiency, thereby improving the efficiency of data query.
[0096] In some embodiments, after the large language model generates the initial SQL statement, the generated initial SQL statement can be displayed (e.g. Figure 4B and Figure 4A ), and then, the SQL statement generation system can receive the user's editing operation on the initial SQL statement, and use the edited SQL statement as a new callable SQL statement. In this way, it is beneficial for the user to directly obtain SQL statements for similar query scenarios without having to repeatedly edit the query text, which can improve the efficiency of SQL statement generation.
[0097] In some embodiments, the SQL statement generation system can also receive a user's storage operation, thereby storing the query text and the SQL statement corresponding to the query text, and can use the query text as a link interface to call the corresponding SQL statement to facilitate reuse of the corresponding SQL statement.
[0098] This implementation supports modifying and saving SQL statements generated by a large language model. Therefore, when querying the same or similar data again, there is no need to repeatedly edit the query text. The SQL statement can be repeatedly called directly based on the query text, which is conducive to further improving query efficiency.
[0099] Combination Figure 1 From the description of the SQL statement generation system in the illustrated embodiment, it can be known that the SQL statement generation system can be a software program carried on an electronic device such as a mobile phone, a tablet computer or a personal computer (PC) provided with a display screen. The software program can display a GUI through the display screen of the electronic device. The media interfaces of various functional components can be set in the GUI. These media interfaces may include controls for calling various functional components and text boxes for receiving or displaying various types of information. Exemplarily, the functions of the large language model can be integrated into the AIQuery tool, which can be displayed in the GUI in the form of controls. The media interface for users to receive information input such as task domains, query nodes, query texts, etc. can be implemented as a text box, for example. The SQL statement generation system can respond to the corresponding operations of the user at different stages and can display different GUI interfaces to receive information input by the user or display information to the user.
[0100] The following describes an implementation scenario of the SQL statement generation method of the embodiment of the present application involving interaction with the user with reference to the exemplary GUI displayed on the display.
[0101] As described in the above embodiments, before receiving the query text and generating the SQL statement based on the query text, the SQL statement generation system can respond to the user's operation, create the task domain, the query node, and establish the corresponding relationship between the description information of each query node and the data table set. In some embodiments, the visual presentation of creating a task domain and creating a query node is similar. The embodiments of the present application only take the GUI for creating a query node as an example for explanation. The implementation scenario of creating a task domain and the corresponding GUI can refer to the scenario of creating a query node and the corresponding GUI, and the embodiments of the present application will not be repeated here.
[0102] like Figure 3A As shown, Figure 3A An exemplary GUI for creating a query node and selecting a database is illustrated. Figure 3AThe GUI shown includes a toolbar 30, a first information input interface 31, and a second information input interface 32. The toolbar 30 may include controls for multiple tools, which may be respectively the entry points for calling corresponding functions of the software program. For example, the toolbar 30 includes an AIQuery tool 301. In response to a user clicking on the AIQuery tool 301, the AIQuery interface may be entered. The AIQuery interface may include entry points for creating task domains and data queries. Figure 3A The illustrated GUI may be a display interface entered through the portal of creating a task domain. The first information input interface 31 may be an interface for inputting information related to a query node. The first information input interface 31 may include a text box 311 for inputting the Chinese name of the query node, a text box 312 for inputting the description information of the query node, and a text box 313 for inputting the member information of the query node. The member information may be, for example, the user name of a member who is granted data query permission for the query node. The user may enter matching information in the corresponding text box to create a query node. The second information input interface 32 may be an input interface for obtaining description information of a database and a data table set. The second information input interface 32 may include a text box 321 for inputting a database name and a menu entry for selecting a data table. Both the text box 321 and the menu entry 322 for selecting a data table may trigger the SQL statement generation system to read the description information in the data source. For example, the text box 321 and the menu entry 323 receive the user's operation, and the SQL statement generation system may respond to the instruction corresponding to the operation, read the names of each database in the data source, and display them on the interface for the user to select. Similarly, when the menu entry 322 receives the user's operation, the SQL statement generation system can respond to the instruction corresponding to the operation, read the name of the data table contained in the selected database in the text box 321 in the data source, and display it on the interface for the user to select. Figure 3B Schematic GUI.
[0103] Figure 3B Based on the embodiments of the present application Figure 3A Schematic diagram of an exemplary display interface for selecting a database and a data table. Figure 3A In the text box 321 in the database, in response to the user's click operation, the database name can be Figure 3B In the form of a drop-down menu as shown in (1), for example, in response to the user selecting the database name serviceDB, serviceDB is written into text box 321, and the data source code (dataSourceCode) of serviceDB is automatically filled in. Further, in response to the user clicking on menu entry 322, the name of the data table contained in serviceDB can be read and the data source code (dataSourceCode) of serviceDB can be automatically filled in. Figure 3BIn the example of the drop-down menu shown in (2), in response to the user selecting the data table name service_score, service_score is written into the text box corresponding to the menu entry 322, the table description information of service_score is automatically filled in, and the field names included in service_score are read and displayed. The display style of the field names included in service_score can be as follows: Figure 3C A schematic GUI is shown below.
[0104] It should be noted that Figure 3B and Figure 3C The databases and tables added in are all related to Figure 3A The user can use Figure 3B and Figure 3C The illustrated operation adds more data tables, which is not limited here. For example, in response to the user clicking "Submit", "Finish", "Create" or "Confirm" on the interface to indicate the completion of the trigger instruction of the query node creation, the AIQuery tool 301 can store the query node in the data structure. Figure 3B and Figure 3C The description information of all databases and tables entered in the stage Figure 3A The query node information input in is stored corresponding to the data structure.
[0105] Furthermore, according to FIG. 3A to FIG. 3C Schematic implementation steps After constructing multiple task domains, query nodes and data table sets, the user can use the AIQuery tool 301 to generate SQL statements for the SQL statement to generate system query data. The following two exemplary GUIs are used to illustrate the generation of SQL statements by the AIQuery tool 301.
[0106] like Figure 4A As shown, Figure 4A Schematic diagram of the display interface of the query scenario provided in the embodiment of the present application Figure 1 . Figure 4A The illustrated GUI includes a chat area 41, an SQL area 42, and a query result area 43. The chat area 41 can be used to receive a query text input by a user, and the query text can be a natural language. In response to the user clicking the send button in the chat area 41, after uploading the input query text, the AIQuery tool 301 can call the function of the large language model, process the query text according to the above prompt information, and after generating a JSON object, output the SQL statement in the JSON object to the SQL area 42 for display, and output the query result obtained by calling the corresponding SQL statement to the query result area 43 for display.
[0107] like Figure 4A In the illustrated implementation scenario, the query text input into the chat area 41 is, for example, "Check the service score of the rider whose ID is 123". In the stage of calling the large language model, the large language model can determine a data table to be queried based on the conditional feature "rider ID is 123" of "Check the service score of the rider whose ID is 123", and then generate a JSON object {database:'service_score',SQL:'SELECT*FROM service_score WHERE rider ID=123'}. Then, on the one hand, "SELECT*FROM service_score WHERE rider ID=123" can be output to the SQL area 42 for display, and on the other hand, the data query engine of the AIQuery tool 301 calls "SELECT*FROM service_score WHERE rider ID=123" to query data, and outputs the query results to the query result area 43 for display.
[0108] In other embodiments, Figure 4B Schematic diagram of the display interface of the query scenario provided in the embodiment of the present application Figure 2As shown, if the query text entered by the user in the chat area 41 is "check the service score details of the rider ID 123", the large language model can determine the two data tables to be queried according to the conditional features "rider ID is 123" and "service score details" of "check the service score details of the rider ID 123", and then generate two JSON objects {database:'service_score',SQL:'SELECT*FROM service_score WHERE knight_id='123'AND is_delete=0 ORDER BYcalculate_time DESC LIMIT 1':false} and {database:'service_score_calculate_detail',SQL:'SELECT*FROM service_score_calculate_detail WHERE knight_id=? andtask_id=? ';condition_source':true}. On the one hand, the SQL statements contained in the two JSON objects can be output to the SQL area 42 for display. On the other hand, the data query engine first calls "SELECT * FROM service_score WHERE knight_id = '123' AND is_delete = 0 ORDER BY calculate_time DESC LIMIT 1" to query data, and outputs the query result to the query result area 43 for display. In addition, the large language model replaces the value of task_id in the query result with task_id =? to obtain a callable SQL statement, and enables the data query engine to call the callable SQL statement to query data, and outputs the query result to the query result area 43 for display.
[0109] Understandably, FIG. 3A to FIG. 4B The GUI shown in the figure is only a schematic presentation and does not constitute a limitation on the embodiments of the present application. In the embodiments of the present application, the above-mentioned GUIs can display more or fewer interface elements than the illustrated ones according to the content input by the user. This is not limited here.
[0110] In addition, the above SQL statements are only exemplary descriptions and do not constitute a limitation on the embodiments of the present application. Figure 4A and Figure 4B The SQL statement displayed in the SQL area 42 may be different depending on the query text input.
[0111] In summary, the technical solution of the embodiment of the present application pre-trains a large language model, and the pre-trained large language model can be called to generate SQL statements based on the query text, thereby supporting the understanding and reasoning ability of the large language model for natural language, identifying the intention of the query text, and then automatically generating SQL statements. In the implementation process, the large language model can determine the information of the data table to be queried from the data table set matching the query node according to at least one conditional feature contained in the query text, and generate a structured query language SQL statement for each corresponding data table to obtain at least one initial SQL statement. Further, in the case of at least two data tables to be queried, according to the query order corresponding to the at least two data tables, the callable SQL statement corresponding to the data table is determined in sequence according to the initial SQL statement of each data table, so as to call the corresponding callable SQL statement to query the corresponding data table to obtain the target query result. It can be seen that by adopting this technical solution, the large language model supports automatically determining the data table to be queried from the data table set matching the query node, and in the case of at least two data tables to be queried, it supports querying according to the query order of at least two data tables, and determining the callable SQL statement. In this way, not only can the technical threshold for using data tables be broken through, but also, in the process of querying data across data tables and across databases, it is helpful to edit SQL statements with higher accuracy with higher editing efficiency, thereby improving the efficiency of data query.
[0112] The above embodiments introduce various implementation methods of the method provided by the embodiments of the present application from the perspectives of extracting conditional features, generating initial SQL statements, and splicing SQL statements in the query order of the data table. It should be understood that, corresponding to the above processing steps, the embodiments of the present application can implement the above functions in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0113] For example, if the above implementation steps implement the corresponding functions through software modules. Figure 5 As shown, a SQL statement generating device is provided, and the SQL statement generating device may include an extracting module 511, a generating module 512 and a determining module 513. The SQL statement generating device may be used to execute the above Figures 2 to 4B Some or all of the operations performed in .
[0114] For example: an extraction module 511 is used to, in response to receiving a query text, call a pre-trained large language model to extract at least one conditional feature from the query text, wherein the at least one conditional feature is used to indicate information of a data table to be queried, and the data table to be queried belongs to a target data table set, and the target data table set refers to a preset data table set that matches the query node corresponding to the query text; a generation module 512 is used to generate an SQL statement corresponding to the at least one data table, respectively, to obtain at least one initial SQL statement, and each initial SQL statement contains the conditional feature corresponding to the corresponding data table; a determination module 513 is used to, when the at least one data table is implemented as at least two data tables, determine the callable SQL statement corresponding to the data table in sequence according to the query order corresponding to the at least two data tables according to the initial SQL statements of each data table, so as to call the corresponding callable SQL statement to query the corresponding data table to obtain the target query result.
[0115] Optionally, any initial SQL statement is a callable SQL statement or a SQL statement to be filled, and when the at least one data table is implemented as at least two data tables, the generating module 512 is further used to:
[0116] For any data table, determine whether the conditional feature corresponding to the data table contains the field value in the data table;
[0117] If the conditional feature corresponding to the data table includes the field value in the data table, generating a callable SQL statement according to a preset SQL grammar structure, and setting the data table as the first data table to be queried among the at least two data tables;
[0118] If the conditional feature corresponding to the data table does not include the field value in the data table, determining a source data table related to the field value according to the conditional feature, the source data table belonging to the at least two data tables;
[0119] Generate an SQL statement to be filled according to a preset SQL grammar structure, and set the data table to be queried after the source data table and adjacent to the source data table;
[0120] The SQL statement to be filled includes a placeholder symbol, and the position of the placeholder symbol is the position where the field value is to be filled.
[0121] Optionally, the generating module 512 is further configured to:
[0122] Calling the i-1th callable SQL statement to query the i-1th data table to obtain an initial query result, wherein the i-1th data table is the data table ranked as the i-1th in the at least two data tables, and i is an integer greater than or equal to 2;
[0123] If the i-1th data table is not the last data table of the at least two data tables, fill the initial query result as a field value into the position of the placeholder symbol of the i-th SQL statement to be filled, obtain the i-th callable SQL statement, and call the i-th callable SQL statement to query the i-th data table;
[0124] If the (i-1)th data table is the last data table of the at least two data tables, the initial query result is determined as the target query result.
[0125] Optionally, in the case where the at least one data table is implemented as one data table, the generation module 512 is also used to: generate an initial SQL statement based on the at least one conditional feature, the initial SQL statement being a callable SQL statement, so as to call the callable SQL statement to query the data table to obtain the target query result.
[0126] Optionally, the generation module 512 is further used to: for any data table, call the pre-trained large language model to generate a data object according to conditional features corresponding to the data table, and the data object includes description data of the data table and the SQL statement.
[0127] Optionally, in the case where the at least one data table is implemented as at least two data tables, the data object further includes a source data table indication identifier, and the source data table indication identifier is used to indicate whether the SQL statement included in the data object needs to fill in the query result of the source data table.
[0128] Optionally, the device further comprises: a creation module, an acquisition module, and an establishment module, wherein:
[0129] The creation module is used to create a task domain and at least one query node included in the task domain in response to a received creation instruction;
[0130] The acquisition module is used for acquiring, for any query node, in response to receiving at least one database identifier, description information of a data table contained in the at least one database identifier from a pre-deployed data source to obtain a data table set; the description information of any data table includes all field names contained in the data table;
[0131] The establishing module is used to establish a matching relationship between the query node and the data table set.
[0132] Optionally, the device further comprises: a search module, wherein any condition feature indicates a field name,
[0133] The determination module 513 is further used to determine, for any condition feature, a field name indicated by the condition feature;
[0134] The search module is used to search the data table where the field name is located from the data table set that matches the query node;
[0135] The determining module 513 is further configured to determine the data table where the field name is located as the data table to be queried.
[0136] It can be understood that the division of the above modules is merely a division of logical functions. In actual implementation, the functions of the above modules can be integrated into the hardware entity implementation. For example, the functions of the extraction module 511, the generation module 512 and the determination module 513 can be integrated into the processor implementation, and the function of data or information transmission between the extraction module 511, the generation module 512 and the determination module 513 can be integrated into the transceiver implementation, etc.
[0137] Please refer to Figure 6 , Figure 6 An electronic device 6 is provided, which can be implemented as Figure 1 In the SQL statement generation system in the electronic device 6, a pre-trained large language model is deployed. The electronic device may include a processor 61, a transceiver 62, a memory 63 and a display 65, and these components are connected and communicated through a communication bus 64. Among them, the transceiver 62 can be used to communicate with the data source to access the data in the data source, and can also be used to receive information input by the user based on the display 65 and display information to the user. The memory 63 is used to store the application and the data generated during the SQL statement generation process. When the application is called, the processor 61 executes the above Figures 2 to 4B operation of part or all of the electronic equipment in the
[0138] For the specific implementation process, see Figures 2 to 4B The relevant description in is not repeated here.
[0139] It should be understood that in some possible implementations, Figure 6The processor illustrated in the figure may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. Figure 6 The memory illustrated in the figure may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory. For example, the memory may also store information on the device type, etc.
[0140] The present application also provides a computer-readable storage medium in which instructions for image processing are stored. When the instructions are executed on a computer, the computer executes the above-mentioned Figures 2 to 4B The illustrated embodiments describe some or all of the steps in the method.
[0141] The present application also provides a computer program product including instructions for image processing, which, when executed on a computer, enables the computer to execute the above-mentioned Figures 2 to 4B The illustrated embodiments describe some or all of the steps in the method.
[0142] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0143] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0144] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0145] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0146] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a smart phone or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
[0147] Although the optional embodiments of the present application have been described, those skilled in the art, once informed of the basic creative concept, may make additional changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiment and all changes and modifications falling within the scope of the present application.
[0148] The specific implementation methods described above further illustrate the purpose, technical solutions and beneficial effects of the present application in detail. It should be understood that the above description is only the specific implementation method of the present application and is not intended to limit the scope of protection of the present application. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solutions of the present application should be included in the scope of protection of the present invention.
Claims
1. A method for generating a SQL statement, characterized in that: The method comprises: In response to receiving a query text, calling a pre-trained large language model to extract at least one conditional feature from the query text, wherein the at least one conditional feature is used to indicate information of a data table to be queried, wherein the data table to be queried belongs to a target data table set, and the target data table set refers to a preset data table set that matches a query node corresponding to the query text; Generate a structured query language SQL statement corresponding to the at least one data table respectively, and obtain at least one initial SQL statement, each initial SQL statement contains conditional features corresponding to the corresponding data table; In the case where the at least one data table is implemented as at least two data tables, the callable SQL statements corresponding to the data tables are determined in sequence according to the initial SQL statements of each data table in accordance with the query order corresponding to the at least two data tables, so as to call the corresponding callable SQL statements to query the corresponding data tables to obtain the target query results.
2. The method according to claim 1, characterized in that Any initial SQL statement is a callable SQL statement or a SQL statement to be filled. When the at least one data table is implemented as at least two data tables, one SQL statement is generated for each of the at least one data tables to obtain at least one initial SQL statement, including: For any data table, determine whether the conditional feature corresponding to the data table contains the field value in the data table; If the conditional feature corresponding to the data table includes the field value in the data table, generating a callable SQL statement according to a preset SQL grammar structure, and setting the data table as the first data table to be queried among the at least two data tables; If the conditional feature corresponding to the data table does not include the field value in the data table, determining a source data table related to the field value according to the conditional feature, the source data table belonging to the at least two data tables; Generate an SQL statement to be filled according to a preset SQL grammar structure, and set the data table to be queried after the source data table and adjacent to the source data table; The SQL statement to be filled includes a placeholder symbol, and the position of the placeholder symbol is the position where the field value is to be filled.
3. The method according to claim 2, characterized in that The step of determining the callable SQL statements corresponding to the data tables in accordance with the query order corresponding to the at least two data tables and in sequence according to the initial SQL statements of each data table includes: Calling the i-1th callable SQL statement to query the i-1th data table to obtain an initial query result, wherein the i-1th data table is the data table ranked as the i-1th in the at least two data tables, and i is an integer greater than or equal to 2; If the i-1th data table is not the last data table of the at least two data tables, fill the initial query result as a field value into the position of the placeholder symbol of the i-th SQL statement to be filled, obtain the i-th callable SQL statement, and call the i-th callable SQL statement to query the i-th data table; If the (i-1)th data table is the last data table of the at least two data tables, the initial query result is determined as the target query result.
4. The method according to claim 1, characterized in that: In the case where the at least one data table is implemented as one data table, generating one SQL statement for each of the at least one data table to obtain at least one initial SQL statement includes: An initial SQL statement is generated according to the at least one conditional feature, and the initial SQL statement is a callable SQL statement, so as to call the callable SQL statement to query the data table and obtain the target query result.
5. The method according to any one of claims 1 to 4, characterized in that Generating a structured query language SQL statement corresponding to the at least one data table respectively includes: For any data table, the pre-trained large language model is called to generate a data object according to the conditional features corresponding to the data table, and the data object includes the description data of the data table and the SQL statement.
6. The method according to claim 5, characterized in that In the case where the at least one data table is implemented as at least two data tables, the data object further includes a source data table indication identifier, and the source data table indication identifier is used to indicate whether the SQL statement included in the data object needs to fill in the query result of the source data table.
7. The method according to claim 1, characterized in that Before responding to receiving the query text, the method further includes: In response to the received creation instruction, create a task domain and at least one query node included in the task domain; For any query node, in response to receiving at least one database identifier, obtaining description information of a data table contained in the at least one database identifier from a pre-deployed data source to obtain a data table set; the description information of any data table includes all field names contained in the data table; A matching relationship between the query node and the data table set is established.
8. A SQL statement generating device, characterized in that: The device comprises: an extraction module, configured to, in response to receiving a query text, call a pre-trained large language model to extract at least one conditional feature from the query text, wherein the at least one conditional feature is used to indicate information of a data table to be queried, wherein the data table to be queried belongs to a target data table set, and the target data table set refers to a preset data table set that matches a query node corresponding to the query text; A generating module, configured to generate a structured query language SQL statement corresponding to the at least one data table, to obtain at least one initial SQL statement, each initial SQL statement including conditional features corresponding to the corresponding data table; A determination module is used to determine the callable SQL statements corresponding to the data tables in sequence according to the initial SQL statements of each data table in the case where the at least one data table is implemented as at least two data tables, in accordance with the query order corresponding to the at least two data tables, so as to call the corresponding callable SQL statements to query the corresponding data tables to obtain target query results.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: The processor executes the program to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: The program is executed by a processor to implement the method according to any one of claims 1 to 7.