SQL (Structured Query Language) statement generation method and device, equipment, storage medium and product
By generating big model SQL statements to generate prompts and using big model matching to generate SQL matching statements, the problem of users in BI tools that need to have high technical capabilities is solved, and non-technical users can obtain information more efficiently in the big data environment.
Patent Information
- Application Number
- CN202411519957.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-29
- Publication Date
- 2025-03-25
AI Technical Summary
Existing business intelligence (BI) tools require users to have high technical capabilities, especially SQL writing capabilities, which limits the difficulty of business personnel with non-technical backgrounds to obtain information in a big data environment.
By obtaining the user's natural language input data, generating a big model SQL statement to generate prompts, and using big model matching to generate corresponding SQL matching statements, thereby assisting the user in generating SQL statements.
It reduces the difficulty of non-technical users to obtain information in a big data environment and improves the efficiency of business personnel in obtaining and applying information of BI tool.
Smart Images

Figure CN119691008A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of large-model question-answering technology, and in particular to a method, apparatus, device, storage medium and product for generating SQL statements. Background Art
[0002] In the field of Business Intelligence (BI), the technical architecture usually covers multiple modules such as data acquisition, data storage, data processing and analysis, data visualization, and permission and security management. These modules jointly support the extraction of data from different data sources, cleaning, conversion and loading, and finally storing it in a data warehouse or data lake. The data is analyzed and processed through SQL queries, OLAP tools or data mining algorithms, and the analysis results are displayed to users in the form of charts, dashboards, etc. through data visualization tools, so that users can intuitively understand the data and make decisions.
[0003] However, despite the relatively mature functions of these technical modules, existing BI products still face some challenges in practical applications. The main problem is that these tools usually require users to have certain technical capabilities, especially SQL writing capabilities. But in fact, the main user group of BI tools is often business personnel with non-technical backgrounds, who may not have deep programming skills. This technical threshold limits the widespread application and efficient use of BI tools, making it difficult for business personnel to extract the required information from massive data.
[0004] Specifically, the defects of existing technologies are mainly reflected in two aspects: first, business personnel need to master the complex SQL language, which is a big challenge for users with non-technical backgrounds; second, BI tools lack sufficient flexibility and ease of use, and are difficult to adapt to the rapidly changing data query needs of business personnel. These problems have led to low efficiency of BI tools in actual applications and unsatisfactory user experience.
[0005] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention
[0006] The main purpose of this application is to provide a SQL statement generation method, apparatus, device, storage medium and computer program product, aiming to improve the efficiency of business personnel in acquiring and applying BI tool information.
[0007] To achieve the above purpose, the present application proposes a method for generating SQL statements, the method comprising:
[0008] Obtain natural language input data entered by the user;
[0009] Generate a large model SQL statement based on the natural language input data to generate a prompt;
[0010] Based on the large model input prompt, a large model matching generation is performed to obtain an SQL matching statement.
[0011] In one embodiment, the step of generating a large model SQL statement generation prompt based on the natural language input data includes:
[0012] Determine target data set association information according to the natural language input data, wherein the data set association information includes data set ID information;
[0013] splicing the target data set associated information and the natural language input data into natural language data set associated input data;
[0014] Performing a user-defined function (UDF) search based on the natural language data set and associated input data to obtain target user-defined function information;
[0015] Perform metadata information retrieval based on the natural language data set and associated input data to obtain target metadata information;
[0016] A large model input prompt is generated according to the target custom function information, the target metadata information and the target data set association information.
[0017] In one embodiment, the step of performing a user-defined function (UDF) search based on the natural language data set and associating the input data to obtain target user-defined function information includes:
[0018] Generate a function retrieval instruction based on the natural language data set and associated input data;
[0019] Calculating a vector representation of the function retrieval instruction according to a preset vector embedding model;
[0020] Calculating vector similarity between the vector representation and a plurality of stored knowledge vectors in a preset vector database;
[0021] Determine the stored knowledge vector whose vector similarity is greater than a preset similarity threshold as a target knowledge vector;
[0022] Obtain the user-defined function information corresponding to the target knowledge vector.
[0023] In one embodiment, the process of constructing the vector database includes:
[0024] Acquire predefined custom function information, wherein the custom function information includes at least one of a function name, a function usage description, and parameter meaning information;
[0025] Generate a function knowledge document according to the custom function information;
[0026] Calculate the document vector representation corresponding to the function knowledge document;
[0027] The function knowledge document and the document vector representation are stored in a pre-built vector source database to obtain a vector database.
[0028] In one embodiment, the step of performing metadata information retrieval based on the natural language data set in association with the input data to obtain target metadata information includes:
[0029] Obtaining data set ID information in the input data associated with the natural language data set;
[0030] The target dataset metadata is searched in a preset metadata information library according to the dataset ID information, where the dataset metadata includes dataset description information and field annotation information.
[0031] In one embodiment, the step of performing large model matching generation based on the large model input prompt to obtain the SQL matching statement further includes:
[0032] Submitting and executing the SQL matching statement, obtaining an execution preview result and displaying the execution preview result through the system front end, wherein the execution preview result includes the data set description information and field annotation information;
[0033] In response to a user confirmation result instruction, determining the SQL matching statement as a target SQL statement; or,
[0034] In response to the user editing input instruction, the step of obtaining natural language input data input by the user is executed.
[0035] In addition, to achieve the above purpose, the present application also proposes a SQL statement generation device, the SQL statement generation device comprising:
[0036] An acquisition module, used to acquire natural language input data input by a user;
[0037] A generation module, used for generating a large model SQL statement generation prompt based on the natural language input data;
[0038] The matching module is used to generate a large model match based on the large model input prompt to obtain an SQL matching statement.
[0039] In addition, to achieve the above-mentioned purpose, the present application also proposes a SQL statement generation device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the SQL statement generation method described above.
[0040] In addition, to achieve the above objectives, the present application also proposes a storage medium, which is a computer-readable storage medium, and stores a computer program on the storage medium. When the computer program is executed by a processor, the steps of the SQL statement generation method described above are implemented.
[0041] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the SQL statement generation method described above are implemented.
[0042] One or more technical solutions proposed in this application obtain natural language input data input by the user; generate a large model SQL statement generation prompt based on the natural language input data; perform large model matching generation based on the large model input prompt to obtain SQL matching statements. Through the above solutions, users input queries in natural language, and the system can assist in generating corresponding SQL statements, reducing the difficulty for non-technical users to obtain information in a big data environment. This improves the efficiency of business personnel in obtaining and applying BI tool information. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0044] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0045] Figure 1 A flowchart of the first embodiment of the SQL statement generation method of the present application is provided;
[0046] Figure 2 This is the overall process and architecture diagram of the SQL statement generation method for this application;
[0047] Figure 3 A schematic diagram of the input and output of a large model prompt for the SQL statement generation method of this application;
[0048] Figure 4A flowchart of the second embodiment of the SQL statement generation method of the present application is provided;
[0049] Figure 5 This is a schematic diagram of the module structure of the SQL statement generating device according to the embodiment of the present application;
[0050] Figure 6 This is a schematic diagram of the device structure of the hardware operating environment involved in the SQL statement generation method in the embodiment of the present application.
[0051] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0052] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0053] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0054] The main solution of the embodiment of the present application is to enhance the data acquisition capability of business intelligence (BI) by using a large language model, aiming to reduce the threshold of use for non-technical users and improve data processing efficiency. The solution guides the large model to understand the business scenario and data field meaning of the user query by designing a suitable prompt (Prompt), thereby assisting in generating corresponding SQL statements. In addition, in order to support custom functions, such as desensitization processing, the solution includes maintaining a vector knowledge base, which stores the relevant information of the custom function through vector representation, and retrieves the most similar custom function when the user queries, to enrich the generated SQL statements. In order to ensure that the generated SQL statements meet expectations, the solution also provides a query preview function and a user editing function, allowing users to preview and modify SQL statements before execution. Finally, by converting the user's natural language query into Spark SQL and submitting it to the computing engine, the system can return the query results in the form of a data table, thereby achieving fast and accurate data acquisition. This solution aims to solve the problem that the existing BI tools have high requirements for technical knowledge and are not easy to use, so that business personnel can perform data analysis and decision-making more efficiently.
[0055] Existing technologies still face some challenges in practical applications. The main problem is that these tools usually require users to have certain technical skills, especially SQL writing skills. But in fact, the main user group of BI tools is often business people with non-technical backgrounds, who may not have deep programming skills. This technical threshold limits the widespread application and efficient use of BI tools, making it difficult for business people to extract the required information from massive data.
[0056] Specifically, the defects of existing technologies are mainly reflected in two aspects: first, business personnel need to master the complex SQL language, which is a big challenge for users with non-technical backgrounds; second, BI tools lack sufficient flexibility and ease of use, and are difficult to adapt to the rapidly changing data query needs of business personnel. These problems have led to low efficiency of BI tools in actual applications and unsatisfactory user experience.
[0057] This application provides a solution, which obtains natural language input data input by the user; generates a large model SQL statement generation prompt based on the natural language input data; performs large model matching generation based on the large model input prompt to obtain SQL matching statements. Through the above solution, the user inputs a query in natural language, and the system can assist in generating corresponding SQL statements, reducing the difficulty for non-technical users to obtain information in a big data environment. Thereby improving the efficiency of business personnel in obtaining and applying BI tool information.
[0058] It should be noted that the execution subject of this embodiment may be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, an SQL statement generation system, etc. The following takes the SQL statement generation system as an example to illustrate this embodiment and the following embodiments.
[0059] Based on this, the embodiment of the present application provides a method for generating SQL statements, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the SQL statement generation method of the present application.
[0060] In this embodiment, the SQL statement generation method includes steps S1000 to S3000:
[0061] Step S1000: obtaining natural language input data input by a user;
[0062] It should be noted that current business intelligence (BI) solutions often require users to have a technical background, especially to master the SQL language. However, the main user groups of these tools are usually employees of business departments, who may not have deep programming skills. This technical gap limits the widespread application and efficient use of BI tools in actual operations. The present application embodiment proposes a solution, which can be specifically referred to in Figure 2 , Figure 2This is the overall process and architecture diagram of the SQL statement generation method of this application. This application uses a large language model to enhance the data acquisition capability of business intelligence (BI), aiming to lower the usage threshold for non-technical users and improve data processing efficiency. The solution guides the large model to understand the business scenario and data field meaning of the user query by designing appropriate prompts, thereby assisting in generating corresponding SQL statements. In addition, in order to support custom functions, such as desensitization processing, the solution includes maintaining a vector knowledge base, which stores relevant information of custom functions through vector representation, and retrieves the most similar custom functions when the user queries to enrich the generated SQL statements. In order to ensure that the generated SQL statements meet expectations, the solution also provides query preview functions and user editing functions, allowing users to preview and modify SQL statements before execution. Finally, by converting the user's natural language query into Spark SQL and submitting it to the computing engine, the system can return the query results in the form of a data table, thereby achieving fast and accurate data acquisition. This solution aims to solve the problem that existing BI tools have high technical knowledge requirements and are not easy to use, so that business personnel can perform data analysis and decision-making more efficiently.
[0063] First, the system receives questions or query requests from users in natural language. Natural language input data can be spoken inquiries, such as "What is the total sales in the first quarter of this year?" or "Show the number of orders for all customers in Shanghai." The purpose of this step is to enable the system to understand the user's needs and convert them into database query language, namely SQL statements. This process requires the system to have natural language processing capabilities and be able to extract key information from the user's inquiries, such as time range, specific indicators or geographic location.
[0064] In addition, it should be noted that the implementation of this step depends on the system's ability to parse natural language, which is usually accomplished through an integrated natural language processing module. This module can recognize and understand the user's query intent and convert it into a structured query request.
[0065] For example, in one specific embodiment, the system receives input through a user-friendly interface, and the user can enter "I want to see the sales data for the first quarter of this year." The system then parses this sentence and identifies the time range as "the first quarter of this year" and the query target as "sales data."
[0066] This embodiment provides a solution, where the system can assist in generating corresponding SQL queries by allowing users to input queries in natural language, thereby reducing the difficulty for non-technical users to obtain information in a big data environment, thereby improving the efficiency of business personnel in analyzing reports and accelerating the decision-making process.
[0067] Step S2000: Generate a large model SQL statement generation prompt based on the natural language input data;
[0068] It should be noted that in this embodiment, the system can convert the user's natural language query into a series of prompts, which will guide the large language model to generate corresponding SQL statements. Prompts are carefully designed inputs to stimulate the large model to produce specific types of outputs, such as reference Figure 3 , Figure 3 This is a schematic diagram of the input and output of the big model prompt of the SQL statement generation method of this application. In this embodiment, the prompt includes not only the user's query request, but also may include the associated information of the target data set, the relevant information of the user-defined function, and metadata information to help the big model generate SQL statements more accurately.
[0069] In addition, it should be noted that in the process of generating prompts, the system will analyze the user's natural language input, determine the required data set, and retrieve the relevant metadata information library to obtain the data set description and field annotations. At the same time, the system will also retrieve the custom function knowledge base to determine the custom functions that may need to be used. All of this information will be integrated into the prompt so that the big model can generate accurate SQL statements.
[0070] For example, in a specific implementation, the system receives a user query "total sales in the first quarter of this year", and then generates a prompt including a data set ID, data set description, field annotations, and related custom function information, such as the use of desensitizing functions, and then submits it to the big model to generate an SQL statement.
[0071] Step S3000: Perform large model matching generation based on the large model input prompt to obtain an SQL matching statement.
[0072] It should be noted that in this embodiment, the big model can match and generate corresponding SQL statements based on the prompts generated by the system. The big model can understand the instructions and context information in the prompts by learning a large amount of corpus, and generate SQL statements that meet the database query specifications accordingly. The purpose of this step is to convert the user's natural language query into a query language that the database can execute, thereby realizing data retrieval.
[0073] In addition, it should be noted that the SQL statements generated by the large model may need further optimization or adjustment to ensure their accuracy. Therefore, the system may also provide a query preview function, allowing users to preview and modify the generated SQL statements before final execution.
[0074] For example, in a specific implementation, after receiving the prompt, the big model analyzes the instructions and context information therein and generates a corresponding SQL statement, such as "SELECT SUM(sales) FROM sales_data WHERE quarter = 'Q1' AND year = '2024'". The system then submits this SQL statement to the database for execution and displays a preview of the execution result to the user. After the user confirms that it is correct, the system executes the SQL statement to retrieve data.
[0075] In a feasible implementation manner, step S2000 may include steps S2100 to S2500:
[0076] Step S2100: determining target data set association information according to the natural language input data, wherein the data set association information includes data set ID information;
[0077] Step S2200: splicing the target data set associated information and the natural language input data into natural language data set associated input data;
[0078] Step S2300: performing a user-defined function (UDF) search based on the natural language data set and associated input data to obtain target user-defined function information;
[0079] Step S2400: performing metadata information retrieval according to the natural language data set associated with the input data to obtain target metadata information;
[0080] Step S2500: Generate a large model input prompt according to the target custom function information, target metadata information and target data set association information.
[0081] It should be noted that in this embodiment, the system can convert the user's natural language query into a detailed prompt, which will guide the large model to generate accurate SQL query statements. This process begins with determining the dataset ID information related to the user's query, which is key metadata that helps the system identify the specific dataset that the user wants to query. The dataset ID information is a bridge between the user's query and the backend data, ensuring the accuracy and relevance of the query.
[0082] In addition, it should be noted that after the system determines the data set association information, it can combine this information with the user's original natural language query to form natural language data set associated input data. This merged data provides rich context, making subsequent custom function retrieval and metadata retrieval more accurate. In this embodiment, the user-defined function (UDF) can perform specific processing on the data, such as desensitization or complex data conversion. In this embodiment, the system generates function retrieval instructions based on the natural language data set associated input data, and uses the vector embedding model to calculate the vector representation of these instructions. By comparing the similarity between these vector representations and the stored knowledge vectors in the vector database, the system can retrieve the custom function information that is most relevant to the user query.
[0083] The construction of the vector database is a preliminary preparation step that involves collecting information about custom functions, such as function name, usage description, and parameter meaning, and generating vector representations for this information for subsequent similarity calculation and retrieval.
[0084] The metadata information retrieval step ensures that the system can understand the specific content and structure of the dataset. By using the dataset ID information, the system can retrieve the dataset description and field annotations from the metadata repository, which is crucial for generating accurate SQL statements.
[0085] Finally, the system will combine the target custom function information, target metadata information and target data set association information to generate a large model input prompt. This prompt is the medium for the system to communicate with the large model and can be used to guide the large model to generate SQL statements that meet user needs.
[0086] For example, in a feasible implementation, when a user enters the query "show sales data for the Shanghai region in the first quarter of this year", the system first identifies and extracts the data set ID information, and merges this information with the user's query. Next, the system retrieves custom functions related to "the first quarter of this year" and "Shanghai region" in the vector database, such as date range filter functions and geographic location filter functions that may be required. At the same time, the system also retrieves metadata for related data sets, including data set descriptions and field annotations, to ensure that the specific meaning of the data is understood. All of this information is combined to form a large model input prompt to guide the large model to generate accurate SQL query statements. Finally, the system executes the generated SQL statement and displays the query results to the user in a preview form. The user can confirm or edit the query to ensure the accuracy of the query and that the user's needs are met.
[0087] In a feasible implementation manner, step S2300 may include steps S2310 to S2350:
[0088] Step S2310: Generate a function search instruction according to the natural language data set and associated input data;
[0089] Step S2320: Calculate the vector representation of the function retrieval instruction according to a preset vector embedding model;
[0090] Step S2330: Calculating the vector similarity between the vector representation and a number of stored knowledge vectors in a preset vector database;
[0091] Step S2340: determining the stored knowledge vector whose vector similarity is greater than a preset similarity threshold as a target knowledge vector;
[0092] Step S2350: Obtain the user-defined function information corresponding to the target knowledge vector.
[0093] It should be noted that the process of converting natural language input to technical language (SQL) output is accomplished through the collaborative work of multiple modules within the system. First, the system generates function retrieval instructions based on the user's natural language query and related data set information. This instruction is to quickly locate functions that may be related to the user's query among a large number of custom functions. The vector embedding model can convert text-based function retrieval instructions into vector form, allowing the system to use the similarity between vectors to find matching custom functions.
[0094] In addition, it should be noted that the vector database stores a large amount of predefined custom function information, which includes not only the function name and usage description, but also the meaning of the parameters. The system finds the most relevant custom function by comparing the similarity between the vector representation of the search instruction and the vector in the vector database. This process is similar to searching for information in a huge knowledge base. After finding the custom functions most relevant to the user's query, the system will obtain detailed information about these functions and use them as an important reference for generating SQL statements.
[0095] In this embodiment, for example, when a user makes a query request such as "show the sales data of the Shanghai area in the first quarter of this year", the system first analyzes the user's natural language input, extracts key information such as time range, region and data requirements, and matches this information with relevant data sets to determine the custom functions that need to be called, such as the date range filter function and geographic location filter function that may be involved. The system uses a vector embedding model to convert these instructions into vector form and retrieves the custom functions with the highest similarity in the vector database. In this way, the system can accurately identify which custom functions are needed to process the user's query and ultimately generate accurate SQL query statements. This process not only improves the accuracy of the query, but also greatly reduces the difficulty for non-technical users to use BI tools, allowing them to perform data analysis and decision-making more efficiently.
[0096] This embodiment provides a method for generating SQL statements, which obtains natural language input data input by a user; generates a large model SQL statement generation prompt based on the natural language input data; performs large model matching generation based on the large model input prompt to obtain an SQL matching statement. Through the above solution, the user inputs a query in natural language, and the system can assist in generating a corresponding SQL statement, which reduces the difficulty for non-technical users to obtain information in a big data environment. This improves the efficiency of business personnel in obtaining and applying BI tool information.
[0097] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 4 , the process of constructing the vector database may include steps A1000 to A4000:
[0098] Step A1000: obtaining predefined user-defined function information, wherein the user-defined function information includes at least one of a function name, a function usage description, and parameter meaning information;
[0099] Step A2000: Generate a function knowledge document according to the user-defined function information;
[0100] Step A3000: Calculate the document vector representation corresponding to the function knowledge document;
[0101] Step A4000: storing the function knowledge document and the document vector representation into a pre-built vector source database to obtain a vector database.
[0102] It should be noted that the process of building a vector database aims to convert the information of custom functions into a machine-understandable vector form and store it in the database for subsequent retrieval. This process first involves collecting detailed information about custom functions, such as function names, descriptions of usage, and parameter meanings, which are key information for understanding how functions are applied and their functions. This information will be organized into a structured function knowledge document, laying the foundation for the next step of vectorization.
[0103] In addition, it should be noted that each function knowledge document is then converted into a unique vector representation through a preset vector embedding model, which captures the semantic features of the document. The calculation of the vector representation is a key step in achieving efficient similarity retrieval, because it enables the system to evaluate the similarity between different functions by calculating the distance between vectors. Once the vector representation of the document is calculated, these vectors are stored in the vector database together with the corresponding function knowledge document, providing a basis for subsequent customized function retrieval.
[0104] For example, in a feasible implementation, the system first collects information on a series of custom functions, such as mask_card_number and mask_org_name, which are used for desensitization of specific data. The information of each function is organized into a knowledge document, vectorized, and stored in a vector database. When a user makes a query request in natural language, the system can use this vector database to quickly retrieve the custom function most relevant to the user's query, such as retrieving the mask_card_number function when the bank card number needs to be desensitized in the query. This retrieval process relies on the calculation of vector similarity. The system incorporates the retrieved custom function information into the prompt for generating SQL statements, and finally uses a large model to generate SQL query statements that meet user needs, realizing the technical conversion from natural language to SQL. This process not only improves the accuracy of the query, but also greatly improves the user experience, allowing users with non-technical backgrounds to easily query and analyze data.
[0105] In a feasible implementation manner, step S2400 may include steps S24100 to S2420.
[0106] Step S2400: Obtaining data set ID information in the natural language data set associated input data;
[0107] Step S2400: searching for target dataset metadata in a preset metadata information library according to the dataset ID information, wherein the dataset metadata includes dataset description information and field annotation information.
[0108] It should be noted that metadata information is data that describes data, including data set descriptions and field annotation information, which provide the system with the business context of the data set and the specific meaning of each field. By using the data set ID information, the system can quickly locate relevant metadata in the preset metadata information library. This process is the key to achieving accurate matching between user query intent and data set content.
[0109] In addition, it should be noted that the dataset ID information, as the unique identifier of the dataset, enables the system to effectively retrieve the dataset description and field annotations related to the user's query from the metadata information library. This metadata information is then integrated into the input prompts of the big model to guide the big model to generate SQL statements that meet the user's query intent. This process not only improves the accuracy of the query, but also enables non-technical users to understand the query results more intuitively, because they can view the dataset description and field annotation information, thereby better understanding the meaning of the data.
[0110] For example, in a feasible implementation, when a user makes a query request, such as "I want to know the sales situation in Shanghai in the first quarter of this year", the system first extracts key information from the user's query, including time range, region, and data requirements. Then, the system uses this information, combined with the dataset ID, to retrieve the relevant dataset description and field annotations in the metadata information library. This metadata information is used to enrich the input prompts and guide the large model to generate accurate SQL query statements. Finally, the system executes the generated SQL statement and displays the query results to the user in a preview form, including dataset description and field annotation information, so that the user can confirm whether the query results meet their expectations. If the user is satisfied with the results, the system will execute the SQL statement; if the user needs to adjust the query, the system will allow the user to edit the input data and regenerate the SQL query statement. This process shows how the system can achieve seamless conversion from natural language to SQL by combining metadata information and user input, while ensuring the accuracy of the query and user understanding.
[0111] In a feasible implementation manner, step S3000 may further include steps S3100 to S3300:
[0112] Step S3100: submitting and executing the SQL matching statement, obtaining an execution preview result and displaying the execution preview result through the system front end, wherein the execution preview result includes the data set description information and field annotation information;
[0113] Step S3200: In response to a user confirmation result instruction, determining the SQL matching statement as a target SQL statement; or,
[0114] Step S3300: In response to the user editing input instruction, execute step: obtain the natural language input data input by the user.
[0115] It should be noted that, in this embodiment, in order to ensure that the actual needs of users are met, SQL matching statements are also executed to verify whether the SQL statements generated by the system can accurately return the data expected by users. The display of the execution preview results, including data set description information and field annotation information, enables users to intuitively understand the data content to be queried by the SQL statement to be executed, so as to have a preliminary judgment on the accuracy of the query.
[0116] In addition, it should be noted that after viewing the execution preview results, the user has two options: confirm the results or edit the input. If the user is satisfied with the preview results, the system will determine the SQL matching statement as the target SQL statement based on the user's instruction to confirm the results, which means that the system will execute the statement and return the final query results. If the user needs to adjust the query, such as changing the query conditions or fields, the system will respond to the user's editing input instructions, re-acquire the user's natural language input data, and restart the entire SQL statement generation process. This design makes the system flexible and user-friendly, ensuring that users can easily obtain the data they need.
[0117] For example, in a feasible implementation, when a user makes a query request, such as "What is the total sales in Shanghai in the first quarter of this year?", the system first generates an SQL matching statement based on the user's natural language input. Subsequently, the system executes the statement and displays the execution preview result, including the relevant data set description and field annotation information. After viewing the preview results, the user can choose to confirm the result, at which point the system will execute the SQL statement and display the final query result; or, the user can choose to edit the input, at which point the system will return to the natural language input acquisition stage, allowing the user to adjust their query request. This process not only ensures the accuracy of the query, but also improves the user experience, allowing even non-technical users to easily perform complex data queries. In this way, the system effectively converts the user's natural language query into an accurate SQL query statement and provides an intuitive feedback mechanism that enables users to quickly obtain the information they need.
[0118] This embodiment provides a method for generating SQL statements, by obtaining pre-defined custom function information, the custom function information including at least one of function name, function usage description, and parameter meaning information; generating a function knowledge document according to the custom function information; calculating a document vector representation corresponding to the function knowledge document; storing the function knowledge document and the document vector representation in a pre-built vector source database to obtain a vector database, so that the system can query the pre-built vector database according to the user's natural language input and generate corresponding SQL statements, thereby reducing the difficulty for non-technical users to obtain information in a big data environment. This improves the efficiency of business personnel in obtaining and applying BI tool information.
[0119] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the SQL statement generation method of the present application. More simple transformations based on this technical concept are all within the protection scope of the present application.
[0120] Please refer to Figure 5 The present application also provides a SQL statement generating device, the SQL statement generating device comprising:
[0121] An acquisition module 51 is used to acquire natural language input data input by a user;
[0122] A generating module 52, used for generating a large model SQL statement generation prompt based on the natural language input data;
[0123] The matching module 53 is used to perform large model matching generation based on the large model input prompt to obtain an SQL matching statement.
[0124] The SQL statement generation device provided by the present application adopts the SQL statement generation method in the above embodiment, which can solve the technical problem of SQL statement generation. Compared with the prior art, the beneficial effects of the SQL statement generation device provided by the present application are the same as the beneficial effects of the SQL statement generation method provided by the above embodiment, and other technical features in the SQL statement generation device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0125] The present application provides a SQL statement generation device, which includes: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the SQL statement generation method in the above-mentioned embodiment 1.
[0126] Reference below Figure 5, which shows a schematic diagram of the structure of a SQL statement generation device suitable for implementing the embodiments of the present application. The SQL statement generation device in the embodiments of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The SQL statement generating device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0127] like Figure 5 As shown, the SQL statement generating device may include a processing device 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the SQL statement generating device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the SQL statement generation device to communicate wirelessly or wired with other devices to exchange data. Although the figure shows a SQL statement generation device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or provided instead.
[0128] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0129] The SQL statement generation device provided in the present application adopts the SQL statement generation method in the above-mentioned embodiment. Compared with the prior art, the beneficial effects of the SQL statement generation device provided in the present application are the same as the beneficial effects of the SQL statement generation method provided in the above-mentioned embodiment, and other technical features in the SQL statement generation device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0130] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0131] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0132] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the SQL statement generation method in the above-mentioned embodiment.
[0133] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0134] The computer-readable storage medium may be included in the SQL statement generating device; or may exist independently without being assembled into the SQL statement generating device.
[0135] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0136] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0137] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0138] The readable storage medium provided in the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned SQL statement generation method, and can solve the technical problem of SQL statement generation. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the present application are the same as the beneficial effects of the SQL statement generation method provided in the above-mentioned embodiment, and will not be repeated here.
[0139] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned SQL statement generation method when executed by a processor.
[0140] The computer program product provided by this application can solve the technical problem of SQL statement generation. Compared with the prior art, the beneficial effects of the computer program product provided by this application are the same as the beneficial effects of the SQL statement generation method provided by the above embodiment, which will not be repeated here.
[0141] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A method for generating a database query language SQL statement, characterized in that: The method comprises: Obtain natural language input data entered by the user; Generate a large model SQL statement based on the natural language input data to generate a prompt; Based on the large model input prompt, a large model matching generation is performed to obtain an SQL matching statement.
2. The method according to claim 1, characterized in that The step of generating a large model SQL statement generating prompt based on the natural language input data comprises: Determine target data set association information according to the natural language input data, wherein the data set association information includes data set ID information; splicing the target data set associated information and the natural language input data into natural language data set associated input data; Performing a user-defined function (UDF) search based on the natural language data set and associated input data to obtain target user-defined function information; Perform metadata information retrieval based on the natural language data set and associated input data to obtain target metadata information; A large model input prompt is generated according to the target custom function information, the target metadata information and the target data set association information.
3. The method according to claim 2, characterized in that The step of performing a user-defined function (UDF) search based on the natural language data set and associating the input data to obtain target user-defined function information comprises: Generate a function retrieval instruction based on the natural language data set and associated input data; Calculating a vector representation of the function retrieval instruction according to a preset vector embedding model; Calculating vector similarity between the vector representation and a plurality of stored knowledge vectors in a preset vector database; Determine the stored knowledge vector whose vector similarity is greater than a preset similarity threshold as a target knowledge vector; Obtain the user-defined function information corresponding to the target knowledge vector.
4. The method according to claim 3, characterized in that The process of constructing the vector database includes: Acquire predefined custom function information, wherein the custom function information includes at least one of a function name, a function usage description, and parameter meaning information; Generate a function knowledge document according to the custom function information; Calculate the document vector representation corresponding to the function knowledge document; The function knowledge document and the document vector representation are stored in a pre-built vector source database to obtain a vector database.
5. The method according to claim 2, characterized in that The step of performing metadata information retrieval according to the natural language data set and associating the input data to obtain target metadata information comprises: Obtaining data set ID information in the input data associated with the natural language data set; The target dataset metadata is searched in a preset metadata information library according to the dataset ID information, where the dataset metadata includes dataset description information and field annotation information.
6. The method according to claim 4, characterized in that After the step of performing large model matching generation based on the large model input prompt to obtain the SQL matching statement, the following steps are further included: Submitting and executing the SQL matching statement, obtaining an execution preview result and displaying the execution preview result through the system front end, wherein the execution preview result includes the data set description information and field annotation information; In response to a user confirmation result instruction, determining the SQL matching statement as a target SQL statement; or, In response to the user editing input instruction, the step of obtaining natural language input data input by the user is executed.
7. A SQL statement generating device, characterized in that: The device comprises: An acquisition module, used to acquire natural language input data input by a user; A generation module, used for generating a large model SQL statement generation prompt based on the natural language input data; The matching module is used to generate a large model match based on the large model input prompt to obtain an SQL matching statement.
8. A device for generating SQL statements, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the SQL statement generating method according to any one of claims 1 to 6.
9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the SQL statement generation method according to any one of claims 1 to 6 are implemented.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the SQL statement generating method according to any one of claims 1 to 6 are implemented.
Citation Information
Cited By
Data query method, electronic equipment and storage medium
CN121387947A