SQL query statement generation method, device, storage medium, and program product
By generating table and column annotation descriptions in the target database, the problem of inaccurate SQL query statements caused by missing database schema information is solved, resulting in more accurate SQL query results.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- CLOUD INTELLIGENCE ASSETS HOLDING (SINGAPORE) PTE LTD
- Filing Date
- 2025-12-11
- Publication Date
- 2026-07-23
AI Technical Summary
In existing technologies, due to missing or incomplete database schema information of the target database, the conversion of user questions described in natural language into SQL query statements is inaccurate, affecting the query results.
By using annotations to understand the model, table and column annotations for the target database are generated, enriching the original database schema information and thus generating more accurate SQL query statements.
It improves the accuracy of SQL query statements, ensuring that user questions are accurately mapped to the relevant data tables and columns in the target database, and generates correct SQL query statements.
Smart Images

Figure CN2025141631_23072026_PF_FP_ABST
Abstract
Description
SQL query generation methods, devices, storage media, and program products Technical Field
[0001] This disclosure relates to the field of artificial intelligence technology, and in particular to a method, device, storage medium, and program product for generating SQL query statements. Background Technology
[0002] Relational database systems typically use Structured Query Language (SQL) to query structured data. However, using SQL requires users to have a certain level of database expertise, making it unfriendly to non-experts. To meet the application requirement of users retrieving query results from the database simply by inputting user questions in natural language, a solution called Natural Language to SQL (NL2SQL) has been proposed. This involves converting user questions described in natural language into SQL query statements, and then using the converted SQL queries to query the database.
[0003] However, in the process of converting user questions described in natural language into SQL query statements, the lack of information to describe the database structure often leads to inaccurate SQL query statements, which in turn affects the query results. Summary of the Invention
[0004] This disclosure provides a method, device, storage medium, and program product for generating SQL query statements, in order to improve the accuracy of SQL query statements generated in NL2SQL.
[0005] In a first aspect, embodiments of this disclosure provide a method for generating SQL query statements, the method comprising:
[0006] Obtain the original database schema information of the target database;
[0007] The model is understood through annotations, and table annotation descriptions of data tables in the target database and column annotation descriptions of different data columns in the data tables are generated based on the original database schema information.
[0008] The table comment description and the column comment description are added to the original database schema information to obtain the target database schema information;
[0009] The user's question, described in natural language, and the target database schema information are input into the SQL statement generation model, so that the SQL statement generation model generates the SQL query statement corresponding to the user's question.
[0010] Secondly, embodiments of this disclosure provide an SQL query statement generation apparatus, the apparatus comprising:
[0011] The acquisition module is configured to acquire the raw database schema information of the target database;
[0012] The processing module is configured to understand the model through annotations, generate table annotation descriptions for the data tables in the target database and column annotation descriptions for different data columns in the data tables based on the original database schema information; and add the table annotation descriptions and column annotation descriptions to the original database schema information to obtain the target database schema information.
[0013] The generation module is configured to input a user question described in natural language and the target database schema information into an SQL statement generation model, so that the SQL statement generation model generates an SQL query statement corresponding to the user question.
[0014] Thirdly, embodiments of this disclosure provide an electronic device, including: a memory, a processor, and a communication interface; wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor can at least implement the SQL query statement generation method as described in the first aspect.
[0015] Fourthly, embodiments of this disclosure provide a computer-readable storage medium storing a computer program that, when executed by a processor of an electronic device, enables the processor to at least implement the SQL query statement generation method as described in the first aspect.
[0016] Fifthly, embodiments of this disclosure provide a computer program product, including: a computer program or instructions that, when executed by a processor of an electronic device, enable the processor to at least implement the SQL query statement generation method as described in the first aspect.
[0017] In the solution provided in this embodiment, taking the querying of structured data in a target database as an example, before generating the SQL query statement corresponding to the user question described in natural language, the original database schema information of the target database is first obtained. Then, through an annotation understanding model, table annotation descriptions of the data tables in the target database and column annotation descriptions of different data columns in the data tables are generated based on the original database schema information. These table annotation descriptions and column annotation descriptions are then added to the original database schema information to obtain the target database schema information. Finally, the user question described in natural language and the target database schema information are input into the SQL statement generation model to generate the SQL query statement corresponding to the user question. Compared to the original database schema information, the target database schema information contains table annotation descriptions of the data tables in the target database and column annotation descriptions of different data columns, providing richer semantic information to the SQL statement generation model to help it understand the target database. Therefore, the SQL statement generation model can accurately map the user question to the relevant data tables and data columns in the target database, thereby generating an accurate SQL query statement. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of this disclosure, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 is a flowchart of an SQL query statement generation method provided in an embodiment of this disclosure;
[0020] Figure 2 is a schematic diagram of an SQL query statement generation process provided in an embodiment of this disclosure;
[0021] Figure 3 is a schematic diagram of database schema information provided in an embodiment of this disclosure;
[0022] Figure 4 is a flowchart of a method for generating table annotation descriptions and column annotation descriptions according to an embodiment of this disclosure;
[0023] Figure 5 is a schematic diagram of a table annotation description and column annotation description generation process provided in an embodiment of this disclosure;
[0024] Figure 6 is a schematic diagram of another table annotation description and column annotation description generation process provided in an embodiment of this disclosure;
[0025] Figure 7 is a flowchart of an initial table annotation description generation method provided in an embodiment of this disclosure;
[0026] Figure 8 is a flowchart of a column annotation description generation method provided in an embodiment of this disclosure;
[0027] Figure 9 is a schematic diagram of the structure of an SQL query statement generation device provided in an embodiment of this disclosure;
[0028] Figure 10 is a schematic diagram of the structure of an electronic device corresponding to the SQL query statement generation device provided in the embodiment shown in Figure 9. Detailed Implementation
[0029] To make the objectives, technical solutions, and advantages of this disclosure clearer, the technical solutions of this disclosure will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without creative effort are within the scope of protection of this disclosure.
[0030] It should be noted that, in the cases involving user information in the embodiments of this disclosure, 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 the embodiments of this disclosure are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use, and processing of related data must comply with the relevant laws, regulations, and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse. In addition, the various models involved in this disclosure (including but not limited to language models or large models) comply with relevant laws and standards.
[0031] Furthermore, the timing of the steps in the following method embodiments is merely an example and not a strict limitation.
[0032] The following is a brief explanation of the relevant concepts involved in the embodiments of this disclosure.
[0033] Database schema information refers to the collection of metadata contained in a database, including tables, fields, relationships, and constraints. It defines the structure and organization of data in the database, specifies the relationships and constraints between tables, and provides information such as field names, field types, field lengths, and example values for the fields used to represent data columns.
[0034] The original database schema information refers to the database schema information of the target database before it is processed by the SQL query statement generation method provided in this embodiment. The target database refers to a relational database used for structured data queries through SQL query statements generated based on user questions described in natural language.
[0035] The target database schema information refers to the database schema information of the target database after processing by the SQL query statement generation method provided in this embodiment. Compared with the original database schema information, the target database schema information adds: table comment descriptions of the data tables in the target database, and column comment descriptions of different data columns in the data tables.
[0036] Table annotations describe the contents of a data table and its significance in the database (e.g., which application scenarios it stores data for). They guide the SQL statement generation model to select the data table that matches the user's question from the database when generating SQL queries corresponding to the user's question in natural language.
[0037] Column annotations describe the semantics of the data contained in the columns of the data table, guiding the SQL statement generation model to select data columns from the data table that match the user's question when generating SQL query statements corresponding to the user's question in natural language.
[0038] Large Language Models (LLMs) are large-scale parametric language models learned using deep learning frameworks and large-scale data corpora. They can be used to handle various natural language tasks such as text classification, question answering, and dialogue. In practice, LLMs understand user intent through pre-set prompts and output predictions.
[0039] Annotation comprehension model, a large language model used to generate table annotation descriptions for data tables, and column annotation descriptions for different data columns in the data table.
[0040] The SQL statement generation model is a large language model used to generate SQL query statements corresponding to user questions described in natural language.
[0041] Optionally, in this embodiment of the disclosure, the annotation understanding model and the SQL statement generation model can be implemented as the same or different large language models. Different large language models can have different parameter scales. In specific implementation, the appropriate model can be flexibly selected based on actual needs.
[0042] In scenarios where user questions described in natural language are transformed into SQL query statements, the common approach is to match the user questions with the database schema information (i.e., the original database model information) of the target database to determine the data tables and columns in the target database that correspond to the user questions, and then generate the SQL query statements.
[0043] However, in practical applications, the original database model information may contain incomplete table names or column names (e.g., the table name or column name is abbreviated and lacks the full name), or missing descriptions of the table or column. These issues may not adequately reflect the semantics of the table or column, potentially leading to inaccurate SQL queries generated for user questions and thus affecting the query results.
[0044] To address the technical problem of inaccurate SQL query statements generated for user questions in existing solutions, this disclosure provides an SQL query statement generation method. The basic idea is as follows: First, through an annotation understanding model, table annotation descriptions for the data tables and column annotation descriptions for different data columns in the target database are generated based on the original database schema information. Then, the generated table annotation descriptions and column annotation descriptions are added to the original database schema information to obtain the target database schema information. Finally, through an SQL statement generation model, based on the target database schema information containing table and column annotation descriptions, and the user question described in natural language, the corresponding SQL query statement is generated. In this solution, because the target database schema information contains table annotation descriptions for the data tables and column annotation descriptions for different data columns in the target database, it provides richer semantic information to the SQL statement generation model to help it understand the target database. Therefore, the SQL statement generation model can accurately map user questions to relevant data tables and columns in the target database, thereby generating accurate SQL query statements.
[0045] The SQL query statement generation method provided in this disclosure will be described in detail below with reference to specific embodiments.
[0046] The SQL query statement generation method provided in this disclosure can be executed by an electronic device, which can be a terminal device such as a PC, laptop, or smartphone, or a server. The server can be a physical server containing an independent host, a virtual server, a cloud server, or a server cluster.
[0047] Figure 1 is a flowchart of an SQL query statement generation method provided in an embodiment of this disclosure. As shown in Figure 1, it may include the following steps:
[0048] 101. Obtain the original database schema information of the target database.
[0049] 102. Understand the model through annotations, and generate table annotation descriptions for the data tables in the target database and column annotation descriptions for different data columns in the data tables based on the original database schema information.
[0050] 103. Add table comment descriptions and column comment descriptions to the original database schema information to obtain the target database schema information.
[0051] 104. Input the user question described in natural language and the target database schema information into the SQL statement generation model so that the SQL statement generation model can generate the SQL query statement corresponding to the user question.
[0052] In this embodiment, the natural language processing capabilities of the SQL statement generation model are utilized to generate SQL query statements corresponding to user questions described in natural language. To improve the accuracy of the generated SQL query statements, before generating the SQL query statements, table comment descriptions of the data tables and column comment descriptions of different data columns in the target database are additionally obtained based on the original database schema information corresponding to the target database. This provides the SQL statement generation model with richer semantic information related to the target database, helping the model to accurately generate SQL query statements corresponding to user questions.
[0053] To facilitate understanding, the embodiment shown in Figure 1 will be described in detail with reference to Figure 2.
[0054] Figure 2 is a schematic diagram of an SQL query statement generation process provided in an embodiment of this disclosure. As shown in Figure 2, firstly, the original database schema information of the target database is obtained. The target database is a relational database used for structured data querying through SQL query statements generated based on user questions described in natural language. The original database schema information of the target database helps the annotation understanding model understand the database structure of the target database. It includes the table names of the data tables in the target database, and information such as the field names, field types, field lengths, and example values of the fields representing data columns. In short, the original database schema information informs the annotation understanding model which data tables are contained in the target database, which data columns are contained in each data table, and what kind of data each data column stores.
[0055] It should be noted that the target database may contain several different data tables, each with different data columns. Since the processing procedure for any data table in the target database is the same in this solution, we will use one data table from the target database as an example for illustration, but this is not a limitation.
[0056] Optionally, prompt words can be generated based on the original database schema information, and these prompt words can be input into the annotation understanding model. Through prompt word engineering, the annotation understanding model can generate table annotation descriptions for the data tables in the target database and column annotation descriptions for different data columns in the data tables under the guidance of the prompt words.
[0057] The table comments describe the contents of the table and its significance within the database (e.g., which application scenarios it stores data for). Optionally, the table comments may include the semantics of each data column in the table and the purpose of the table.
[0058] The column comments of a data column are used to describe the semantics of the data contained in the data column in the data table. For example, the data in the data column named 'name' contains student names, etc.
[0059] In the specific implementation process, the original database schema information may have some table annotation descriptions or column annotation descriptions corresponding to some data tables or data columns in advance. Optionally, corresponding table annotation descriptions and column annotation descriptions can be generated for all data tables and data columns in the target database, or corresponding table annotation descriptions and column annotation descriptions can be generated only for data tables or data columns that lack table annotation descriptions or column annotation descriptions.
[0060] Next, the table annotation descriptions and column annotation descriptions generated by the annotation comprehension model are added to the original database schema information to obtain the target database schema information.
[0061] Optionally, if the original database schema information does not contain table and column comment descriptions, the table and column comment descriptions generated by the annotation understanding model can be directly added to the original database schema information to obtain the target database schema information. If the original database schema information contains table comment descriptions for some data tables or column comment descriptions for some data columns, the original table and column comment descriptions in the original database schema information can be retained, and the corresponding table and column comment descriptions for data tables or data columns lacking table or column comment descriptions in the original database schema information can be supplemented based on the table and column comment descriptions generated by the annotation understanding model to obtain the target database schema information; or, the original table and column comment descriptions in the original database schema information can be deleted, and the table and column comment descriptions generated by the annotation understanding model can be added to the original database schema information to obtain the target database schema information.
[0062] Therefore, when table and column comment descriptions are missing from the original database schema information, they can be added using the methods generated in this solution. Conversely, when some table and column comment descriptions already exist in the original database schema information, the existing descriptions can be retained or replaced, and missing descriptions can be added. This results in richer semantics for the target database schema information corresponding to the original database schema information, and can meet the diverse generation needs of database schema information in practical applications.
[0063] Finally, the user's question described in natural language and the target database schema information are combined into corresponding prompt words, which are then input into the SQL statement generation model. Guided by these prompt words, the SQL statement generation model matches the user's question with the target database schema information, thereby determining the data table and data column in the target database that correspond to the user's question and generating an SQL query statement.
[0064] For ease of understanding, let's take Figure 3 as an example. Figure 3 is a schematic diagram of database schema information provided by an embodiment of this disclosure. As shown in Figure 3, assume that the target database contains a data table named "cards", which contains multiple data columns: "id (Identifier)", "isOversized", "isPromo", and "promoTypes". Figure 3 illustrates the original database schema information without table and column comment descriptions, and the target database schema information with table and column comment descriptions.
[0065] As shown in Figure 3, the original database schema information includes the table name "cards", as well as the column name, data type, and example values of each data column in the table. For example, the "id" column contains: column name id, data type INTEGER (integer), primary key, and example values Examples: [41138, 1349, 23810]); the "isOversized" column contains: column name isOversized, data type INTEGER, and example values Examples: [0, 1]; the "isPromo" column contains: column name isPromo, data type INTEGER, and example values Examples: [0, 1]; the "promoTypes" column contains: column name promoteTypes, data type TEXT (text), and example values Examples: [release (release), buyabox (whole box promotion)].
[0066] Unlike the original database schema information, the target database schema information, in addition to containing the information included in the original database schema information, also includes table comments for the "cards" table, as well as column comments for the "id," "isOversized," "isPromo," and "promoTypes" columns (highlighted in bold in Figure 3). Specifically, for example, the table comments for the "cards" table describe "detailed card attributes, including their release date, availability, design features, game mechanics, and unique identifiers across multiple platforms and formats"; the "id" column comments describe "the unique identifier for each card"; the "isOversized" column comments describe "the card is an oversized version"; the "isPromo" column comments describe "the card is a promotional version"; and the "promoTypes" column comments describe "the promotional type or category of the card release."
[0067] Suppose the user's question is "How many cards are oversized and printed for promotions?". The correct SQL query for this question should be "SELECT COUNT(id) FROM cards WHERE isOversized = 1 AND isPromo = 1;".
[0068] As shown in Figure 3, the SQL query statement generated by the SQL statement generation model based on the original database schema information is "SELECT COUNT(*) FROM cards WHERE isOversized=1 AND promoTypes LIKE '%promotion%';", which is inconsistent with the correct SQL query statement. However, the SQL query statement generated based on the target database schema information is "SELECT COUNT(id) FROM cards WHERE isOversized=1 AND isPromo=1;", which is consistent with the correct SQL query statement.
[0069] As can be seen, when generating SQL queries based on the original database schema information, the SQL query generation model cannot correctly understand the semantics of the "isPromo" column because the original database schema information does not contain column comment descriptions. This leads to an incorrect association of the user's keyword "promotions" with the "promoTypes" column, resulting in an incorrect SQL query. However, when generating SQL queries based on the target database schema information provided in this solution, because the target database schema information includes table and column comment descriptions, the SQL query generation model can infer that "isPromo" is an abbreviation of "isPromotional," indicating "whether there is a promotion." Therefore, it correctly associates the user's keyword "promotions" with the "isPromo" column, generating a correct SQL query.
[0070] In summary, in this embodiment of the present disclosure, by generating table annotation descriptions for data tables and column annotation descriptions for different data columns in the target database based on the original database schema information of the target database, and adding the generated table annotation descriptions and column annotation descriptions to the original database schema information, the target database schema information used to generate the SQL query statement corresponding to the user's question contains rich semantic information related to the target database. This helps the SQL statement generation model better understand the target database, accurately map the user's question to the relevant data tables and data columns in the target database, and generate accurate SQL query statements.
[0071] The above describes the overall process of generating the SQL query statement corresponding to the user's question. The following describes the process of generating table comment descriptions for the data tables in the target database and column comment descriptions for different data columns in the data tables based on the original database schema information of the target database.
[0072] Figure 4 is a flowchart of a method for generating table annotation descriptions and column annotation descriptions according to an embodiment of this disclosure. As shown in Figure 4, the method may include the following steps:
[0073] 401. Understand the model through annotations. Based on the original database schema information of the target database, generate initial table annotation descriptions for the data tables in the target database.
[0074] 402. Based on the initial table annotation description, the initial table schema information of the data table, and the attribute information of different data columns in the data table, the model is understood through annotations, and column annotation descriptions of different data columns in the data table are generated. The initial table schema information of the data table is extracted from the original database schema information.
[0075] 403. Update the initial table schema information according to the column comment description to obtain the target table schema information.
[0076] 404. Understand the model through annotations and generate target table annotation descriptions for the data tables based on the target table schema information.
[0077] In summary, the table annotation description and column annotation description generation scheme provided in this disclosure includes two stages:
[0078] The first stage begins with the original database schema information corresponding to the target database. It first generates initial table annotation descriptions for the data tables in the target database, and then generates column annotation descriptions for the data columns based on these initial table annotation descriptions. That is, it guides the annotation understanding model to perform the initial table annotation description generation task from the database dimension to the data table dimension and then to the data column dimension, from coarse-grained to fine-grained. In this first stage, by proceeding from the whole to the parts, it ensures that the annotation understanding model operates within a consistent context, understanding the database structure of the target database from a macro perspective, and generating accurate initial table annotation descriptions and column annotation descriptions.
[0079] In the second stage, based on the column annotation descriptions generated in the first stage, the target table annotation description of the data table is generated. That is, the process is to fall back from the column dimension to the table dimension. The fine-grained column annotation description corrects the anomalies in the coarse-grained initial table annotation description, so as to obtain a more accurate target table annotation description of the table dimension and achieve a more accurate understanding of the target database.
[0080] To facilitate understanding, the embodiment shown in Figure 4 will be described in detail with reference to Figure 5.
[0081] Figure 5 is a schematic diagram of the table annotation description and column annotation description generation process provided in an embodiment of this disclosure. As shown in Figure 5, firstly, the original database schema information of the target database is input into the annotation understanding model, so that the annotation understanding model generates initial table annotation descriptions of the data tables in the target database based on the original database schema information of the target database. The initial table annotation descriptions may include the semantics of each data column in the data table, as well as the purpose of the data table, etc.
[0082] Next, the initial table annotation description of the data table, the initial table schema information of the data table, and the attribute information of different data columns in the data table are input into the annotation understanding model, so as to generate column annotation descriptions for different data columns in the data table through the annotation understanding model.
[0083] Since the initial table annotations are generated based on the original database schema information of the target database, they contain database-level context information inherited from the original schema, as well as column-level context information. Guided by this database-level and column-level context information, the annotation understanding model can better understand the semantics of different data columns within the table. For example, given the same column name "name," based on the initial table annotations, the annotation understanding model can determine that its semantics in the student grades table are student names, and in the employee statistics table, it's employee names. In other words, it can understand the more accurate semantics of the "name" column, rather than simply assuming it represents a name.
[0084] In the process of generating column annotation descriptions, in addition to the initial table annotation descriptions of the data table that provide macro-level guidance for the annotation understanding model, detailed information for generating column annotation descriptions is also provided to the annotation understanding model, namely the initial table schema information of the data table and the attribute information of different data columns in the data table.
[0085] In this embodiment, the initial table schema information of the data tables is extracted from the original database schema information. In practical applications, a database contains different data tables, and correspondingly, the database schema information naturally contains the table schema information corresponding to each of the different data tables. For ease of distinction, in this embodiment, the table schema information corresponding to the data tables in the original database schema information of the target database is referred to as the initial table schema information, and the initial table schema information updated based on column description information is referred to as the target table schema information.
[0086] It's easy to understand that when generating column comment descriptions for different columns in a data table, the focus is on the data table and its columns, with little relation to other tables in the target database. Therefore, when generating column comment descriptions for different columns in a data table, the table schema information of that data table can be used as a reference, rather than the original database schema information of the target database. This effectively reduces the amount of data that needs to be processed when generating column comment descriptions.
[0087] The attribute information of a data column in a data table can be divided into two types based on whether it is statistically analyzed: basic information and statistical information. Basic information includes: field name, field type, whether it is a primary key, whether it is nullable, whether it is unique, and field examples, etc.; statistical information includes: quantity, distinct count (duplicate count), maximum / minimum / average, maximum and minimum string length, etc.
[0088] The attribute information of different data columns in the data table is extracted from the target database. In the specific implementation process, various SQL queries can be used, such as: count query, unique query, example query, max / min / avg query, max / min length query, etc., to extract the attribute information of different data columns from the target database.
[0089] Based on the initial table annotation description, the initial table schema information, and the attribute information of different data columns in the data table, the annotation understanding model can more accurately and precisely understand the semantics of different data columns in the data table from both macroscopic and detailed perspectives, thereby generating column annotation descriptions for different data columns in the data table.
[0090] Finally, the column annotation descriptions of different data columns in the data table are updated to the initial table schema information (for example, the column annotation descriptions of different data columns in the data table are added to the initial table schema information) to obtain the target table schema information; the target table schema information is then input into the annotation understanding model so that the annotation understanding model can generate the target table annotation description of the data table.
[0091] Understandably, compared to the initial table schema information, the target table schema information contains richer semantics corresponding to the data table—column annotation descriptions of different data columns in the data table. Based on the target table schema information, the annotation understanding model can understand the data table from the fine-grained column-level column annotation descriptions, thereby discovering and correcting anomalies or errors in the aforementioned coarse-grained table-level initial table annotation descriptions, and thus generating more accurate target table annotation descriptions at the table level.
[0092] The target table annotation description, which is the table annotation description corresponding to the data table, is used to add the original database schema information to the target database to generate the target database schema information.
[0093] In summary, in this embodiment, the accuracy of the generated table and column annotations is ensured by employing a dual process of "from coarse to fine" and then "from fine to coarse." Specifically, in the "from coarse to fine" process, initial table annotations and column annotations for different data columns in the target database are generated sequentially based on the original database schema information. This ensures that the annotation understanding model uses a consistent context in generating the initial and column annotations, improving their accuracy. In the "from fine to coarse" process, target table annotations are generated based on the column annotations from the previous process. By backtracking from the column dimension to the table dimension, anomalies or errors in the initial, coarse-grained table-level annotations are identified and corrected, resulting in more accurate target table annotations. Accurate table annotations facilitate matching user queries to the correct table when generating SQL queries, thus generating accurate SQL queries.
[0094] The above provides an overall description of the process for generating table annotations and column annotations for different data columns in the data table provided in the embodiments of this disclosure.
[0095] The following description, in conjunction with Figure 6, details the process of generating table annotations for the data table and the process of generating column annotations for different data columns within the data table. Figure 6 is a schematic diagram illustrating another process for generating table annotations and column annotations according to an embodiment of this disclosure.
[0096] First, the process of generating the initial table comments for the data table will be explained.
[0097] Figure 7 is a flowchart of an initial table annotation description generation method provided in an embodiment of this disclosure. As shown in Figure 7, it may include the following steps:
[0098] 701. Input the original database schema information of the target database into the annotation understanding model so that the annotation understanding model can generate database understanding information of the target database.
[0099] 702. Obtain the initial table schema information of the data table from the original database schema information, and obtain the column example value information of the data table from the target database.
[0100] 703. Input the database understanding information, the initial table schema information of the data table, and the column example value information of the data table into the annotation understanding model so that the annotation understanding model can generate the initial table annotation description of the data table.
[0101] As shown in Figure 6, the process of generating the initial table comment description of the data table can be summarized into two parts: the first part is to generate the database understanding information of the target database based on the original database schema information of the target database; the second part is to generate the initial table comment description of the data table based on the generated database understanding information, combined with the initial table schema information and the column example value information of the data table.
[0102] In detail, in the first part, the annotation understanding model understands the target database holistically based on the original database schema information of the input target database and generates database understanding information. This database understanding information provides contextual information for the annotation understanding model to perform subsequent, more granular understanding, and forms the basis for subsequent understanding of data tables and columns.
[0103] Optionally, the database understanding information of the target database may include, but is not limited to, the following types of information: (1) the table structure information and example value information of the target database, wherein the table structure information is used to describe which data tables are contained in the target database and which data columns are contained in each data table, and the example value information is a value example for each data column; (2) the application field of the target database, such as: the power field, the human resource management field, etc.; (3) the dimensions and measures that are of interest in the application field of the target database, wherein the dimensions are used to describe data category attributes, such as: time, product name, commodity category, etc., and the measures are numerical values that can be mathematically aggregated or analyzed, such as: click rate, sales volume, etc.
[0104] Specifically, by analyzing the table structure and sample values of the target database, we can obtain its overall architecture and internal data distribution, gaining a macro-level understanding of its data characteristics and providing a clear perspective for further comprehension. Furthermore, by identifying the target database's application domain and the dimensions and metrics within that domain, we can obtain other relevant and important information beyond data characteristics. Based on these dimensions and metrics, we can achieve a more targeted understanding of the target database.
[0105] For example, in one alternative embodiment, at least one field category can be determined based on dimensions and metrics of interest within the application domain. The field category is used to determine the column relationship description of the data columns. This embodiment focuses first on the generation process of the initial table annotation description; the application of dimensions and metrics of interest within the application domain in the column annotation description generation process will be explained in detail in subsequent embodiments.
[0106] In the specific implementation process, optionally, prompt words can be generated based on the original database schema information of the target database, and the prompt words can be input into the annotation understanding model. Under the guidance of the prompt words, the annotation understanding model can obtain the table structure information and example value information of the target database from the original database schema information, and use the prior knowledge accumulated during the training phase to identify the application domain of the target database, as well as the dimensions and metrics of interest in that application domain. For example, when the application domain of the target database is identified as the inverter domain, based on prior knowledge, it can be determined that the dimensions and metrics of interest in the inverter domain include daily power generation, power generation duration, etc.
[0107] In the second part, based on the comprehensive understanding of the target database in the first part (i.e., based on the database understanding information), each data table in the target database is further analyzed separately.
[0108] To better understand the data tables and reduce the amount of data that the annotation understanding model needs to process, on the one hand, the initial table schema information of the data tables was obtained from the original database schema information of the target database; on the other hand, example column value information of the data tables was obtained from the target database through methods such as example queries.
[0109] It is worth emphasizing that the column example value information of the data table obtained from the target database is the actual column example value information, while the example value information in the database understanding information generated in the first part is generated by the annotation understanding model based on the original database schema information. The two are not equivalent.
[0110] In the specific implementation process, database understanding information, initial table schema information of the data table, and column example value information of the data table are input into the annotation understanding model. Based on the context information provided by the database understanding information, the annotation understanding model predicts the semantics of each data column in the data table and the purpose of the data table through the initial table schema information and column example value information of the data table, thereby generating an initial table annotation description of the data table.
[0111] In this embodiment of the disclosure, an initial table annotation description for a single data table is generated based on the context information provided by the database understanding information. The initial table annotation description of the data table does not deviate from the overall target database, thereby effectively improving the correctness of the generated initial table annotation description.
[0112] After generating the initial table comment description for the data table, the next step is to generate column comment descriptions for different data columns in the data table based on the initial table comment description, and then update the initial table comment description using the generated column comment descriptions to generate the final target table comment description. The specific generation process of the target table comment description can be found in the aforementioned embodiments and will not be repeated here.
[0113] Next, the process of generating column comments for different data columns in the data table will be explained.
[0114] Figure 8 is a flowchart of a column annotation description generation method provided in an embodiment of this disclosure. As shown in Figure 8, it may include the following steps:
[0115] 801. Based on the initial table comment description, the initial table schema information, and the attribute information of different data columns in the data table, use the comment understanding model to identify the column relationship description of similar data columns in different data columns of the data table.
[0116] 802. Based on the initial table comment description of the data table, the column relationship description corresponding to the target data column, and the attribute information of the target data column, generate the column comment description of the target data column through the comment understanding model. The target data column is a data column contained in the data table that has a column relationship description with other data columns.
[0117] In practical applications, data tables may contain columns with similar data, meaning that different columns may be semantically related and similar, but their actual semantic meanings within the data table may differ. The existence of similar columns can lead to the user's question being matched to the wrong data column during the generation of the corresponding SQL query, resulting in an incorrect SQL query.
[0118] For example, in Figure 3, both the "isPromo" and "promoTypes" columns are related to promotion. However, the true meaning of the "isPromo" column is "whether there is a promotion," while the true meaning of the "promoTypes" column is "promotion type." When generating the SQL query statement corresponding to the user's question, because the "isPromo" and "promoTypes" columns are similar, it is easy to mistakenly match "promotions" in the user's question ("How many cards are oversized and printed for promotions?") with the "promoTypes" column, thus generating an incorrect SQL query statement.
[0119] In this embodiment of the disclosure, in order to solve the above-mentioned technical problems and improve the accuracy of the generated SQL query statements, during the process of generating column annotation descriptions for data columns, for similar data columns in different data columns of the data table, column relationship descriptions for these similar data columns are first generated, wherein the column relationship descriptions are used to explain the differences or relationships between similar data columns; then, column annotation descriptions corresponding to these data columns are generated using the column relationship descriptions, thereby distinguishing the semantic differences between different data columns based on the column annotation descriptions, matching the user's question to the correct data column, and generating accurate SQL query statements.
[0120] Generally, data columns in a data table are represented by fields. For example, the field name is the column name, and the field type is the data type of the data column. In short, a field in a data table refers to a data column. Statistical analysis of similar data columns in a data table reveals that data columns with the same field characteristics are more likely to be similar data columns.
[0121] As an optional method for determining similar data columns among different data columns in a data table, multiple different field categories can be predefined, where different field categories correspond to different field characteristics; then, the field categories corresponding to different data columns in the data table are identified through the annotation understanding model; subsequently, data columns belonging to the same field category among different data columns are identified as similar data columns.
[0122] Optionally, based on the dimensions and metrics of interest within the application domain contained in the database understanding information in the embodiment shown in Figure 7, corresponding field categories can be preset. Specifically, if the database understanding information includes multiple dimension categories and at least one metric category commonly found in the application domain corresponding to the target database, then the preset field categories include these multiple dimension categories and at least one metric category.
[0123] For ease of understanding, let's take an example. Suppose that the database understands information containing four dimensions: Code, Enum, DateTime, and Text, as well as one metric. Then, the preset fields can be five types, corresponding to the following categories: Code, Enum, DateTime, Text, and Metric.
[0124] The data categories are categorized as follows: Code category: Data containing identifiers or codes used to uniquely identify an entity or object in the database, such as user ID or ID number. Enumeration category: Data belonging to an enumeration type, where values are limited to a predefined finite set, such as user status being "active" or "inactive." Time category: Data related to a specific point in time or time period, organized according to different time granularities (e.g., hours, days, months, or years), used for time-related analysis, such as determining the timestamp of an event. Text category: Unstructured or semi-structured text data used for qualitative analysis based on textual information (e.g., name and description).
[0125] Based on pre-defined field categories, embodiments of this disclosure provide two optional methods for identifying the field categories corresponding to different data columns in a data table through annotation understanding models:
[0126] In an optional embodiment, several data tables contained in the target database can be determined first. Then, for a certain data table, the attribute information of different data columns in the data table can be obtained, and the attribute information of different data columns in the data table can be input into the annotation understanding model so that the annotation understanding model can identify the field categories corresponding to different data columns in the data table.
[0127] The method for obtaining the attribute information of different data columns in the data table can be described in the aforementioned embodiments, and will not be repeated here.
[0128] In another alternative embodiment, instead of determining the number of data tables contained in the target database, one can start from the perspective of the entire database and first obtain the field information of multiple fields contained in the target database. Then, the field information of multiple fields is input into the annotation understanding model so that the annotation understanding model can identify the field categories corresponding to the multiple fields respectively. Finally, based on the correspondence between the multiple fields and different data columns in the data table, the field categories corresponding to the different data columns in the data table are determined.
[0129] It is understandable that data columns exist relative to data tables; that is, fields in a data table are described as data columns only if a data table exists. Therefore, in this embodiment, when considering the entire database, the information used to determine the field category is referred to as: field information of multiple fields contained in the target database. It should be understood that a data column in a certain data table of the target database corresponds to at least some of the fields among multiple fields; that is, the fields used to represent data columns in a certain data table of the target database are included among the multiple fields contained in the target database. When the concept of a data table exists, the field information of the fields is also the attribute information of the data column.
[0130] In the methods for determining the field categories corresponding to different data columns in a data table provided in the two embodiments above, the determination can be performed either table by table or in batches on all data tables in the target database. In practical applications, the specific determination method can be customized, and this embodiment does not impose any restrictions on this.
[0131] It's easy to understand that time often has different time granularities (e.g., year, month, day, week, etc.), and these time granularities play a negligible role in the annotation understanding model's understanding of the semantics of time-related data columns in a data table. To improve the accuracy of the annotation understanding model's understanding of time-related data columns, optionally, attribute information of data columns whose field category belongs to the time category can be input into the annotation understanding model, enabling the model to recognize the time unit corresponding to the time-category data column. Then, the time unit corresponding to the time-category data column is updated in the attribute information of the time-category data column to help the annotation understanding model correctly understand the time-related data column later.
[0132] After identifying the field categories corresponding to different data columns in the data table through the annotation understanding model, data columns belonging to the same field category are identified as similar data columns. Further, a column relationship description for these similar data columns is generated.
[0133] In practice, the initial table annotation description of the data table, the initial table schema information of the data table, and the attribute information of the data columns belonging to the same field category can be input into the annotation understanding model. This allows the annotation understanding model to generate column relationship descriptions corresponding to the data columns belonging to the same field category based on the context information provided by the initial table annotation description of the data table, and according to the initial table schema information of the data table and the attribute information of the data columns belonging to the same field category.
[0134] It should be noted that if different data columns in a data table correspond to more than one field category, then column relationship descriptions for each field category will be generated separately. For example, if there are M data columns belonging to field category 1 and N data columns belonging to field category 2 (where M and N are integers greater than 1), then column relationship descriptions for the M data columns and column relationship descriptions for the N data columns will be determined separately.
[0135] After determining the column relationship descriptions corresponding to data columns belonging to the same field category, the column annotation descriptions corresponding to each data column are further generated.
[0136] It is understandable that in different data columns in a data table, there may be target data columns that belong to the same field category as other data columns, that is, target data columns that have column relationship descriptions with other data columns, and there may also be isolated data columns that do not belong to the same field category as other data columns, that is, isolated data columns that do not have column relationship descriptions with other data columns.
[0137] For a target data column, the initial table annotation description of the data table, the column relationship description corresponding to the target data column, and the attribute information of the target data column can be input into the annotation understanding model. This allows the annotation understanding model to generate a column annotation description for the target data column based on the context information provided by the initial table annotation description of the data table, and according to the column relationship description and attribute information of the target data column.
[0138] For isolated data columns, the initial table annotation description of the data table and the attribute information of the target data column can be input into the annotation understanding model. This allows the annotation understanding model to generate a column annotation description for the target data column based on the context information provided by the initial table annotation description and the attribute information of the target data column.
[0139] Optionally, in order to improve the accuracy of the SQL query statements corresponding to user questions generated by the SQL statement generation model, the generated column comment descriptions can be limited to a set number of characters, such as 20 characters.
[0140] In this embodiment of the disclosure, during the process of generating column annotation descriptions for different data columns in a data table, on the one hand, based on the contextual information provided by the initial table annotation description of the data table, it can be ensured that the annotation understanding model's understanding of the semantics of the data columns does not deviate from the overall target database and data table, thus ensuring the accuracy of the generated column annotation descriptions; on the other hand, by determining the column relationship descriptions of similar data columns in the data table, it can be ensured that the annotation understanding model correctly understands the differences or relationships between similar data columns, correctly understands the semantics of the data columns, improves the accuracy of the generated column annotation descriptions of the data columns, and ensures that when generating the SQL query statement corresponding to the user's question, the user's question is matched to the correct data column, and an accurate SQL query statement is generated.
[0141] The SQL query statement generation apparatus of one or more embodiments of the present disclosure will be described in detail below. Those skilled in the art will understand that these apparatuses can be configured using commercially available hardware components through the steps taught in this solution.
[0142] Figure 9 is a schematic diagram of the structure of an SQL query statement generation device provided in an embodiment of this disclosure. As shown in Figure 9, the device includes: an acquisition module 11, a processing module 12, and a generation module 13.
[0143] Module 11 is configured to obtain the raw database schema information of the target database.
[0144] The processing module 12 is configured to understand the model through annotations, generate table annotation descriptions for the data tables in the target database and column annotation descriptions for different data columns in the data tables based on the original database schema information, and add the table annotation descriptions and column annotation descriptions to the original database schema information to obtain the target database schema information.
[0145] The generation module 13 is configured to input the user question described in natural language and the target database schema information into the SQL statement generation model, so that the SQL statement generation model generates the SQL query statement corresponding to the user question.
[0146] Optionally, the processing module 12 is specifically configured to: generate an initial table annotation description for the data table based on the original database schema information using the annotation understanding model; generate column annotation descriptions for different data columns in the data table based on the initial table annotation description, the initial table schema information of the data table, and the attribute information of different data columns in the data table using the annotation understanding model, wherein the initial table schema information of the data table is extracted from the original database schema information; update the initial table schema information based on the column annotation descriptions to obtain target table schema information; and generate a target table annotation description for the data table based on the target table schema information using the annotation understanding model.
[0147] Optionally, the processing module 12 is further configured to input the original database schema information into the annotation understanding model, so that the annotation understanding model generates database understanding information of the target database; obtain the initial table schema information of the data table from the original database schema information, and obtain the column example value information of the data table from the target database; input the database understanding information, the initial table schema information, and the column example value information of the data table into the annotation understanding model, so that the annotation understanding model generates the initial table annotation description of the data table.
[0148] Optionally, the processing module 12 is further configured to: identify the column relationship description of similar data columns in different data columns of the data table based on the initial table annotation description, the initial table schema information of the data table, and the attribute information of different data columns in the data table, using the annotation understanding model; and generate a column annotation description of the target data column based on the initial table annotation description, the column relationship description corresponding to the target data column, and the attribute information of the target data column, using the annotation understanding model, wherein the target data column is a data column in the data table that has the column relationship description with other data columns.
[0149] Optionally, the processing module 12 is further configured to identify the field categories corresponding to different data columns in the data table through the annotation understanding model; determine the data columns belonging to the same field category among the different data columns; and input the initial table annotation description, the initial table schema information of the data table, and the attribute information of the data columns belonging to the same field category into the annotation understanding model, so that the annotation understanding model generates column relationship descriptions corresponding to the data columns belonging to the same field category.
[0150] Optionally, the processing module 12 is further configured to input the attribute information of different data columns in the data table into the annotation understanding model, so that the annotation understanding model can identify the field categories corresponding to the different data columns respectively.
[0151] Optionally, the processing module 12 is further configured to: obtain field information of multiple fields contained in the target database, wherein the data columns in the data table correspond to at least some of the multiple fields; input the field information of the multiple fields into the annotation understanding model so that the annotation understanding model can identify the field categories corresponding to the multiple fields respectively; and determine the field categories corresponding to the different data columns in the data table according to the correspondence between the multiple fields and the different data columns in the data table.
[0152] Optionally, the processing module 12 is further configured to input the attribute information of the data column belonging to the time category into the annotation understanding model, so that the annotation understanding model can identify the time unit corresponding to the data column of the time category; and update the time unit corresponding to the data column of the time category into the attribute information of the data column of the time category.
[0153] Optionally, the database understanding information includes multiple dimension categories and at least one metric category commonly found in the application domain corresponding to the target database, and the field category includes the multiple dimension categories and the at least one metric category.
[0154] The device shown in Figure 9 can perform the steps described in the foregoing embodiments. For detailed execution process and technical effects, please refer to the description in the foregoing embodiments, which will not be repeated here.
[0155] In one possible design, the structure of the SQL query statement generation device shown in Figure 9 can be implemented as an electronic device, as shown in Figure 10. This electronic device may include: a memory 21, a processor 22, and a communication interface 23. The memory 21 stores a computer program, which, when executed by the processor 22, enables the processor 22 to at least implement the SQL query statement generation method provided in the foregoing embodiments.
[0156] The aforementioned memory 21 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random-Access Memory (SRAM), Electrically Erasable Programmable Read Only Memory (EEPROM), Erasable Programmable Read Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0157] Accordingly, this disclosure also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, enables the processor to implement the steps in the above-described method embodiments. The computer-readable storage medium includes volatile or non-volatile or a combination thereof, and may be removable or non-removable. Examples of computer-readable storage media include, but are not limited to, phase-change random access memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random-access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), flash memory or other memory technologies, CD-ROM, Digital Video Disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium.
[0158] Accordingly, this disclosure also provides a computer program product, which includes a computer program or instructions that, when executed by a processor, cause the processor to implement the steps in the above-described method embodiments. It should be understood that each step or combination of steps in the above-described method flow can be implemented by the computer program or instructions. Furthermore, these computer programs or instructions can be applied to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable SQL query generation device, enabling the processor of such a device to function as an apparatus for implementing the corresponding functions in the above-described method embodiments.
[0159] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separate. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0160] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of a necessary general-purpose hardware platform, or by a combination of hardware and software. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a computer product. This disclosure can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0161] Finally, it should be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0162] The above are merely embodiments of this disclosure and are not intended to limit the scope of this disclosure. Various modifications and variations can be made to this disclosure by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this disclosure should be included within the scope of the claims of this disclosure.
Claims
1. A method for generating an SQL query statement, comprising: obtaining original database schema information of a target database; generating table annotation descriptions of data tables in the target database and column annotation descriptions of different data columns in the data tables according to the original database schema information through an annotation understanding model; adding the table annotation descriptions and the column annotation descriptions to the original database schema information to obtain target database schema information; inputting a user question described in natural language and the target database schema information into an SQL statement generation model to enable the SQL statement generation model to generate an SQL query statement corresponding to the user question.
2. The method of claim 1, wherein, The generating, by the annotation understanding model, of the table annotation descriptions of the data tables and the column annotation descriptions of the different data columns in the data tables according to the original database schema information comprises: generating, by the annotation understanding model, initial table annotation descriptions of the data tables according to the original database schema information; generating, by the annotation understanding model, column annotation descriptions of different data columns in the data tables according to the initial table annotation descriptions, initial table schema information of the data tables and attribute information of the different data columns in the data tables, wherein the initial table schema information of the data tables is extracted from the original database schema information; updating the initial table schema information according to the column annotation descriptions to obtain target table schema information; generating, by the annotation understanding model, target table annotation descriptions of the data tables according to the target table schema information.
3. The method of claim 2, wherein, The generating, by the annotation understanding model, of the initial table annotation descriptions of the data tables according to the original database schema information comprises: inputting the original database schema information into the annotation understanding model to enable the annotation understanding model to generate database understanding information of the target database; obtaining initial table schema information of the data tables from the original database schema information and column example value information of the data tables from the target database; inputting the database understanding information, the initial table schema information and the column example value information of the data tables into the annotation understanding model to enable the annotation understanding model to generate the initial table annotation descriptions of the data tables.
4. The method of claim 2, wherein, The generating, by the annotation understanding model, of the column annotation descriptions of the different data columns in the data tables according to the initial table annotation descriptions, the initial table schema information of the data tables and the attribute information of the different data columns in the data tables comprises: identifying, by the annotation understanding model, column relationship descriptions of similar data columns in the different data columns of the data tables according to the initial table annotation descriptions, the initial table schema information of the data tables and the attribute information of the different data columns in the data tables; generating, by the annotation understanding model, column annotation descriptions of target data columns according to the initial table annotation descriptions of the data tables, column relationship descriptions corresponding to the target data columns and attribute information of the target data columns, wherein the target data columns are data columns in the data tables that contain the column relationship descriptions with other data columns.
5. The method of claim 4, wherein, The step of identifying the column relationship description of similar data columns in different data columns of the data table based on the initial table annotation description, the initial table schema information of the data table, and the attribute information of different data columns in the data table, through the annotation understanding model, includes: The annotation understanding model identifies the field categories corresponding to different data columns in the data table. Identify the data columns that belong to the same field category among the different data columns; The initial table annotation description, the initial table schema information of the data table, and the attribute information of the data columns belonging to the same field category are input into the annotation understanding model so that the annotation understanding model generates column relationship descriptions corresponding to the data columns belonging to the same field category.
6. The method of claim 5, wherein, The process of identifying the field categories corresponding to different data columns in the data table through the annotation understanding model includes: The attribute information of different data columns in the data table is input into the annotation understanding model so that the annotation understanding model can identify the field categories corresponding to the different data columns.
7. The method of claim 5, wherein, The process of identifying the field categories corresponding to different data columns in the data table through the annotation understanding model includes: Obtain field information for multiple fields contained in the target database, wherein the data columns in the data table correspond to at least some of the multiple fields; The field information of the multiple fields is input into the annotation understanding model so that the annotation understanding model can identify the field categories corresponding to the multiple fields respectively; Based on the correspondence between the multiple fields and different data columns in the data table, determine the field categories corresponding to the different data columns in the data table.
8. The method of claim 5, wherein, The field categories include a time category, and the method further includes: The attribute information of the data column belonging to the time category is input into the annotation understanding model so that the annotation understanding model can identify the time unit corresponding to the data column of the time category; Update the time unit corresponding to the data column of the time category to the attribute information of the data column of the time category.
9. The method of claim 5, wherein, The database understanding information includes multiple dimension categories and at least one metric category that are common in the application domain corresponding to the target database. The field category includes the multiple dimension categories and the at least one metric category.
10. An electronic device comprising: The system includes a memory, a processor, and a communication interface. The memory stores a computer program that, when executed by the processor, causes the processor to perform the following methods: obtaining the original database schema information of the target database; generating table annotation descriptions for the data tables in the target database and column annotation descriptions for different data columns in the data tables based on the original database schema information using an annotation understanding model; adding the table annotation descriptions and column annotation descriptions to the original database schema information to obtain the target database schema information; and inputting a user question described in natural language and the target database schema information into an SQL statement generation model to generate an SQL query statement corresponding to the user question.
11. The electronic device of claim 10, wherein, When the computer program is executed by the processor, the processor also performs the following methods: generating an initial table annotation description for the data table based on the original database schema information using the annotation understanding model; generating column annotation descriptions for different data columns in the data table based on the initial table annotation description, the initial table schema information of the data table, and the attribute information of different data columns in the data table using the annotation understanding model, wherein the initial table schema information of the data table is extracted from the original database schema information; updating the initial table schema information based on the column annotation descriptions to obtain target table schema information; and generating a target table annotation description for the data table based on the target table schema information using the annotation understanding model.
12. The electronic device of claim 11, wherein, When the computer program is executed by the processor, the processor also performs the following method: inputting the original database schema information into the annotation understanding model to generate database understanding information of the target database; obtaining the initial table schema information of the data table from the original database schema information, and obtaining the column example value information of the data table from the target database; inputting the database understanding information, the initial table schema information, and the column example value information of the data table into the annotation understanding model to generate an initial table annotation description of the data table.
13. The electronic device of claim 11, wherein, When the computer program is executed by the processor, the processor also performs the following method: based on the initial table annotation description, the initial table schema information of the data table, and the attribute information of different data columns in the data table, the annotation understanding model identifies the column relationship description of similar data columns in different data columns of the data table; based on the initial table annotation description of the data table, the column relationship description corresponding to the target data column, and the attribute information of the target data column, the annotation understanding model generates a column annotation description of the target data column, wherein the target data column is a data column in the data table that has the column relationship description with other data columns.
14. The electronic device of claim 13, wherein, When the computer program is executed by the processor, the processor also performs the following method: identifying the field categories corresponding to different data columns in the data table through the annotation understanding model; determining the data columns belonging to the same field category among the different data columns; inputting the initial table annotation description, the initial table schema information of the data table, and the attribute information of the data columns belonging to the same field category into the annotation understanding model, so that the annotation understanding model generates column relationship descriptions corresponding to the data columns belonging to the same field category.
15. The electronic device of claim 14, wherein, When the computer program is executed by the processor, the processor also performs the following method: inputting attribute information of different data columns in the data table into the annotation understanding model, so that the annotation understanding model can identify the field categories corresponding to the different data columns respectively.
16. The electronic device of claim 14, wherein, When the computer program is executed by the processor, the processor also performs the following method: obtaining field information of multiple fields contained in the target database, wherein the data columns in the data table correspond to at least some of the multiple fields; inputting the field information of the multiple fields into the annotation understanding model so that the annotation understanding model can identify the field categories corresponding to the multiple fields respectively; and determining the field categories corresponding to the different data columns in the data table according to the correspondence between the multiple fields and the different data columns in the data table.
17. The electronic device of claim 14, wherein, When the computer program is executed by the processor, the processor also performs the following method: inputting attribute information of the data column belonging to the time category into the annotation understanding model so that the annotation understanding model can identify the time unit corresponding to the data column of the time category; and updating the time unit corresponding to the data column of the time category into the attribute information of the data column of the time category.
18. The electronic device of claim 14, wherein, When the computer program is executed by the processor, the processor also performs the following method: the database understanding information includes multiple dimension categories and at least one metric category that are common in the application domain corresponding to the target database, and the field category includes the multiple dimension categories and the at least one metric category.
19. A computer-readable storage medium storing a computer program that, when executed by a processor of an electronic device, causes the processor to perform the following method: obtaining original database schema information of a target database; generating table annotation descriptions of data tables and column annotation descriptions of different data columns in the target database based on the original database schema information using an annotation understanding model; adding the table annotation descriptions and column annotation descriptions to the original database schema information to obtain target database schema information; and inputting a user question described in natural language and the target database schema information into an SQL statement generation model to generate an SQL query statement corresponding to the user question.
20. The computer-readable storage medium of claim 19, wherein, When the computer program is executed by the processor, the processor also performs the following methods: generating an initial table annotation description for the data table based on the original database schema information using the annotation understanding model; generating column annotation descriptions for different data columns in the data table based on the initial table annotation description, the initial table schema information of the data table, and the attribute information of different data columns in the data table using the annotation understanding model, wherein the initial table schema information of the data table is extracted from the original database schema information; updating the initial table schema information based on the column annotation descriptions to obtain target table schema information; and generating a target table annotation description for the data table based on the target table schema information using the annotation understanding model.