SQL completion method, device, electronic device and computer program product

By analyzing SQL context and related information, using language models to generate high-quality SQL completion fragments, it solves the problem that existing tools are difficult to cope with complex SQL requirements and improves writing efficiency and accuracy.

CN119149577BActive Publication Date: 2025-02-21BEIJING VOLCANO ENGINE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411657976.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-19
Publication Date
2025-02-21
Estimated Expiration
2044-11-19

AI Technical Summary

Technical Problem

Existing SQL completion tools are difficult to cope with complex and changeable SQL syntax and business needs, resulting in high burdens and inefficiency when writing complex queries.

Method used

By analyzing the SQL context, determine similar SQL fragments, related data tables, their table creation statements, and associated SQL fragments, generate prompt words containing predetermined indicators, and use the SQL completion model based on the language model to generate high-quality complement Fragment.

Benefits of technology

It effectively reduces the burden of users writing SQL manually, significantly improves writing efficiency and accuracy, and the generated SQL fragments are accurate and easy to execute.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149577B_ABST
    Figure CN119149577B_ABST
Patent Text Reader

Abstract

Embodiments of the present disclosure relate to a method, apparatus, electronic device, and computer program product for SQL completion. The method includes determining similar SQL fragments based on SQL context, and determining associated data tables and table creation statements. The method also includes determining associated SQL fragments of the SQL context based on the data table. The method also includes generating prompt words including predetermined indicators based on the SQL context, similar SQL fragments, table creation statements, and associated SQL fragments. The method also includes generating a benchmark completion fragment using a SQL completion model based on a language model, and generating a target completion fragment using the SQL context and the benchmark completion fragment. Thus, through the embodiments of the present disclosure, high-quality SQL completion fragments can be generated, effectively reducing the burden of users manually writing SQL, and significantly improving writing efficiency and accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and more particularly to a method, device, electronic device, and computer program product for completing a structured query language (SQL). Background Art

[0002] With the explosive growth of data volume, the speed and scale of massive data generation are increasing day by day, and data from multiple sources such as IoT devices, social media platforms, and enterprise operation systems are rapidly accumulating. This growth not only drives the innovation of storage and computing technologies, but also makes data processing efficiency and analysis capabilities become key factors.

[0003] With the rapid expansion of data, SQL can help users quickly obtain key information from massive data with its concise syntax and powerful query capabilities, and implement complex operations such as data screening, aggregation, and analysis. Whether it is a traditional database or a modern big data platform, SQL has shown strong adaptability and scalability, becoming a key support tool for data-driven decision-making and business innovation. Summary of the invention

[0004] Embodiments of the present disclosure provide a method, apparatus, electronic device, and computer program product for SQL completion.

[0005] According to a first aspect of the present disclosure, a method for SQL completion is provided. The method includes determining similar SQL fragments similar to the SQL context based on the SQL context, where the SQL context is the SQL code to be completed. The method also includes determining a data table and a table creation statement of the data table associated with the SQL context based on the SQL context, where the table creation statement at least indicates the table annotation, field and field annotation of the data table. The method also includes determining an associated SQL fragment associated with the SQL context based on the data table. The method also includes generating a prompt word including a predetermined indicator based on the SQL context, the similar SQL fragment, the table creation statement and the associated SQL fragment, where the predetermined indicator indicates a prefix part, a suffix part and a part to be completed in the SQL context. The method also includes generating a benchmark completion fragment based on the prompt word using a SQL completion model based on a language model. In addition, the method also includes generating a target completion fragment based on the SQL context and the benchmark completion fragment.

[0006] According to a second aspect of the present disclosure, a device for SQL completion is provided. The device includes a similar fragment determination module, which is configured to determine similar SQL fragments similar to the SQL context based on the SQL context, and the SQL context is the SQL code to be completed. The device also includes a data information determination module, which is configured to determine the data table and the table creation statement of the data table associated with the SQL context based on the SQL context, and the table creation statement at least indicates the table comment, field and field comment of the data table. The device also includes an associated fragment determination module, which is configured to determine the associated SQL fragment associated with the SQL context based on the data table. The device also includes a prompt content generation module, which is configured to generate a prompt word including a predetermined indicator based on the SQL context, the similar SQL fragment, the table creation statement and the associated SQL fragment, and the predetermined indicator indicates the prefix part, the suffix part and the part to be completed in the SQL context. The device also includes a benchmark fragment generation model, which is configured to generate a benchmark completion fragment based on the prompt word using a SQL completion model based on a language model. In addition, the device also includes a completion fragment generation module, which is configured to generate a target completion fragment based on the SQL context and the benchmark completion fragment.

[0007] According to a third aspect of the present disclosure, an electronic device is provided, comprising a processor and a memory coupled to the processor, wherein the memory has instructions stored therein, and when the instructions are executed by the processor, the electronic device executes the method according to the first aspect.

[0008] In a fourth aspect of the present disclosure, a computer program product is provided. The computer program product is tangibly stored on a non-transitory computer readable medium and comprises computer executable instructions, which when executed cause a computer to perform the steps of the method of the first aspect of the present disclosure.

[0009] The purpose of this Summary is to introduce a selection of concepts in a simplified form that are further described in the Detailed Description below. This Summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to limit the scope of the claimed subject matter. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, wherein:

[0011] Figure 1 A schematic diagram showing an example environment in which devices and / or methods according to embodiments of the present disclosure may be implemented;

[0012] Figure 2A flowchart of a method for SQL completion according to an embodiment of the present disclosure is shown;

[0013] Figure 3 A flowchart of another method for SQL completion according to an embodiment of the present disclosure is shown;

[0014] Figure 4 A flowchart of a process for generating a SQL completion model according to an embodiment of the present disclosure is shown;

[0015] Figure 5 A block diagram of a SQL completion device according to an embodiment of the present disclosure is shown; and

[0016] Figure 6 A block diagram of an electronic device according to an embodiment of the present disclosure is shown.

[0017] Throughout the drawings, the same or similar reference numbers denote the same or similar elements. DETAILED DESCRIPTION

[0018] It is understandable that before using the technical solutions disclosed in the embodiments of the present disclosure, the type, scope of use, usage scenarios, etc. of the personal information (such as voice) involved in the present disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.

[0019] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.

[0020] In the description of the embodiments of the present disclosure, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "based at least in part on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The terms "first", "second", etc. may refer to different or the same objects, unless explicitly stated. Other explicit and implicit definitions may also be included below.

[0021] As mentioned above, with the explosive growth of data volume, SQL has become a core tool in the data platform. However, SQL writing requires users to have certain professional knowledge, and it is difficult to write and optimize complex queries, which places high demands on the user's technical level. Although there are some SQL completion tools in related technologies, most of them are based on simple pattern matching or syntax parsing rules, and can only provide common scenarios such as keywords, table names, column names, and function names, which are difficult to cope with complex and changing SQL syntax and business needs.

[0022] To this end, an embodiment of the present disclosure proposes a solution for SQL completion. The solution determines SQL fragments similar to the SQL context by analyzing the SQL context, and the SQL context is the SQL code to be completed. Then, the data table and the table creation statement related to the context are determined, and the table creation statement includes table comments, field information, field comments and other contents. Then, the associated SQL fragments related to the SQL context are determined. In combination with the SQL context, the table creation statement, the associated SQL fragments and similar SQL fragments, prompt words containing predetermined indicators are generated, and the predetermined indicators indicate the prefix, suffix and part to be completed in the SQL context. Through these prompt words, the SQL completion model generates a benchmark completion fragment. Finally, according to the SQL context and the benchmark completion fragment, a target completion fragment is generated.

[0023] Therefore, according to the embodiments of the present disclosure, the capabilities of the language model are fully utilized, and the language model is fine-tuned specifically for the SQL completion task, while optimizing the generation of prompt words, ensuring that the prompt words contain the key information required for SQL completion, and can effectively improve the generated completion fragments, ensuring that the final SQL fragments are accurate and easy to execute. In this way, high-quality SQL completion fragments can be generated, effectively reducing the burden of users manually writing SQL, and significantly improving writing efficiency and accuracy.

[0024] Figure 1 Schematic diagram of an example environment in which the device and / or method according to an embodiment of the present disclosure may be implemented. Figure 1 As shown, the example environment 100 may include a computing device 110, which may be a user terminal, a mobile device, a computer, etc., or a computing system, a single server, a distributed server, or a cloud-based server. The computing device 110 may receive an SQL context 112, which is the SQL code to be completed. For example, according to the position of the user cursor, the SQL fragment before the cursor and the SQL fragment after the cursor may be obtained as the SQL context 112.

[0025] The computing device 110 may determine a similar SQL snippet 114 that is contextually similar to the SQL context 112 based on the SQL context 112. For example, one or more SQL code snippets that are similar to the SQL context 112 may be retrieved from a SQL snippet library. The computing device 110 may determine a data table 116 associated with the SQL context based on the SQL context 112, and obtain a table creation statement 118 for the data table 116, which at least indicates a table comment, fields, and field comments of the data table 116. In the SQL language, a table creation statement for a data table is used to define and create a structure of a database table, such as a CREATE TABLE statement, which may include a table name, a table comment, names of each field, and field comments. In addition, the table creation statement may also include data types of each field, primary keys, foreign keys, indexes, and the like of the data table.

[0026] The computing device 110 may determine an associated SQL fragment 120 associated with the SQL context 112 based on the data table 116. For example, the associated SQL fragment 120 may be a SQL fragment that generates the data table 116 or a SQL fragment that uses the data table 116. The computing device 110 may generate a prompt word including a predetermined indicator based on the SQL context 112, the similar SQL fragment 114, the table creation statement 118, and the associated SQL fragment 120, and the predetermined indicator indicates a prefix part, a suffix part, and a part to be completed in the SQL context. For example, the predetermined indicator may include a prefix indicator, a suffix indicator, and a to-be-completed indicator, and the prefix indicator, the suffix indicator, and the to-be-completed indicator may be added before the prefix part, the suffix part, and the to-be-completed part in the SQL context 112, respectively.

[0027] The computing device 110 may generate a reference completion segment 126 based on the prompt word 122 using a language model-based SQL completion model 124. The SQL completion model 124 may be a language model that is fine-tuned and trained specifically for the SQL completion task. The computing device 110 generates a target completion segment 128 based on the SQL context 112 and the reference completion segment 126. For example, undefined fields or functions in the reference completion segment 126 may be removed, or portions of the reference completion segment 126 that are repeated with the SQL context 112 may be removed.

[0028] Therefore, according to the embodiments of the present disclosure, the capabilities of the language model are fully utilized, and the language model is fine-tuned specifically for the SQL completion task, while optimizing the generation of prompt words to ensure that the prompt words contain the key information required for SQL completion, and can effectively improve the generated completion fragments, ensuring that the final SQL fragments are accurate and easy to execute. In this way, high-quality SQL completion fragments can be generated, effectively reducing the burden of users manually writing SQL, and significantly improving writing efficiency and accuracy.

[0029] It should be understood that the architecture and functions in the example environment 100 are described for exemplary purposes only and do not imply any limitation on the scope of the present disclosure. Embodiments of the present disclosure may also be applied to other environments with different structures and / or functions.

[0030] The following will combine Figures 2 to 6 The process according to the embodiment of the present disclosure is described in detail. For ease of understanding, the specific data mentioned in the following description are exemplary and are not intended to limit the scope of protection of the present disclosure. It is understood that the embodiments described below may also include additional actions not shown and / or the actions shown may be omitted, and the scope of the present disclosure is not limited in this respect.

[0031] Figure 2 A flowchart of a method 200 for SQL completion according to an embodiment of the present disclosure is shown. The method can be executed by a computing device, which can be a user terminal, a mobile device, a computer, etc. It can also be a computing system, a single server, a distributed server, or a cloud-based server. At block 202, a similar SQL fragment similar to the SQL context can be determined based on the SQL context, where the SQL context is the SQL code to be completed. For example, referring to Figure 1 The computing device 110 may determine a similar SQL fragment 114 that is similar to the SQL context 112 based on the SQL context 112 , where the SQL context 112 is the SQL code to be completed.

[0032] At block 204, a data table and a table creation statement associated with the SQL context may be determined based on the SQL context, wherein the table creation statement at least indicates a table comment, a field, and a field comment of the data table. Figure 1 The computing device 110 may determine a data table 116 and a table creation statement 118 of the data table 116 associated with the SQL context 112 based on the SQL context 112, wherein the table creation statement 118 indicates at least a table comment, a field, and a field comment of the data table 116. At block 206, an associated SQL fragment associated with the SQL context may be determined based on the data table. For example, referring to Figure 1The computing device 110 may determine the associated SQL fragment 120 associated with the SQL context 112 based on the data table 116 .

[0033] At block 208, a prompt word including a predetermined indicator may be generated based on the SQL context, similar SQL fragments, table creation statements, and associated SQL fragments. The predetermined indicator indicates the prefix part, the suffix part, and the part to be completed in the SQL context. Figure 1 The computing device 110 may generate a prompt word 122 including a predetermined indicator based on the SQL context 112, the similar SQL fragment 114, the table creation statement 118, and the associated SQL fragment 120, wherein the predetermined indicator indicates the prefix part, the suffix part, and the part to be completed in the SQL context 112. At block 210, a reference completion fragment may be generated based on the prompt word using a SQL completion model based on a language model. For example, referring to Figure 1 , the computing device 110 may generate a reference completion segment 126 based on the prompt word 122 using the language model-based SQL completion model 124. At block 212, a target completion segment may be generated based on the SQL context and the reference completion segment. Figure 1 The computing device 110 may generate a target completion segment 128 based on the SQL context 112 and the reference completion segment 126 .

[0034] Therefore, the method 200 according to the embodiment of the present disclosure fully utilizes the capabilities of the language model, and by fine-tuning the language model specifically for the SQL completion task, optimizes the generation of prompt words, ensures that the prompt words contain the key information required for SQL completion, and can effectively improve the generated completion fragments, ensuring that the final SQL fragments are accurate and easy to execute. In this way, high-quality SQL completion fragments can be generated, effectively reducing the burden of users manually writing SQL, and significantly improving writing efficiency and accuracy.

[0035] Figure 3 FIG. 3 is a flow chart showing another method 300 for SQL completion according to an embodiment of the present disclosure. Figure 3As shown, at box 302, a SQL fragment similar to the SQL context can be determined. In some embodiments, a tag set can be generated based on the SQL context, and the tag set includes at least keywords, functions, table names, field names, and operators in the SQL context. According to the position of the user cursor, the SQL fragment before the cursor and the SQL fragment after the cursor can be obtained as the SQL context, that is, the SQL code to be completed. For example, the SQL context can be "SELECT name, age FROM employeesWHERE [to be completed] ORDER BY hire_date", and the SQL context can be decomposed to generate a tag set, which can include keywords, table names, field names, operators, and function names in the SQL context. It should be understood that the SQL code snippets listed in this article are for illustrative purposes only.

[0036] In some embodiments, the similarity score between the SQL context and each SQL fragment in the SQL fragment library can be determined based on the intersection and union of the tag set and the tag set of each SQL fragment in the SQL fragment library. The SQL fragment library can be a database containing multiple historical SQL queries, which is used to store and manage SQL fragments generated by users or programs in the system. For example, for each SQL fragment in the SQL fragment library, its tag set can be compared with the tag set of the current SQL context, and the intersection (i.e., the tags shared by the two sets) and the union (i.e., all the tags of the two sets) can be calculated. Then, the number of tags in the intersection can be divided by the number of tags in the union to obtain the similarity score.

[0037] In some embodiments, similar SQL fragments may be determined based on similarity scores. For example, similar SQL fragments may be determined according to a similarity score threshold. If the similarity score of a certain SQL fragment is greater than a predetermined threshold, it is considered to be sufficiently similar to the current SQL context, and the SQL fragment is thus determined as a similar SQL fragment. In addition, similar SQL fragments may be determined according to a predetermined number, that is, the SQL fragments are sorted according to the calculated similarity scores, and then several SQL fragments (e.g., the first N) with the highest similarity scores are selected as similar SQL fragments.

[0038] At box 304, the data table related to the SQL context can be determined. In some embodiments, the SQL context can be parsed by a syntax analyzer to determine the data table used by the SQL context. For example, the current SQL context can be parsed by an LR syntax analyzer that supports error recovery to extract the data table involved in the SQL fragment input by the user. Since the SQL context may not be a complete SQL code, an LR syntax analyzer that supports error recovery is required. The LR in the LR syntax analyzer stands for Left-to-right. During the parsing process, a syntax tree is generated based on the input SQL fragment, and the table name of the data table involved is determined from the syntax tree.

[0039] In some embodiments, a table creation statement of a data table can be obtained from a metadata database based on the data table. The metadata database stores metadata of all data tables in the database, including detailed information of each table. The table creation statement of a data table is used to define and create the structure of a database table, such as a CREATE TABLE statement, which includes a table name, a table comment, the name of each field, and a field comment. In addition, the table creation statement may also include the data type, primary key, foreign key, index, etc. of the field.

[0040] At block 306, an associated SQL fragment associated with the SQL context may be determined. In some embodiments, a first SQL fragment that generates a data table may be retrieved from a SQL fragment library based on a data table. For example, an SQL fragment that generates a field of a data table may be retrieved through a CREATE statement, an INSERT INTO statement, or an UPDATE statement. It should be understood that the SQL fragment that generates the data table may be one or more. In some embodiments, a second SQL fragment that uses a data table may be matched from a SQL fragment library based on a data table. For example, other SQL fragments that use the same data table may be retrieved from a SQL fragment library based on the data table involved in the SQL context as the second SQL fragment. For example, the SQL fragment involves the current data table in a query or operation, such as a direct reference to the data table, or interacts with the data table in a query, insert, update, or delete operation, and the like. In some embodiments, an associated SQL fragment may be determined based on the first SQL fragment and the second SQL fragment. For example, the first SQL fragment and the second SQL fragment may be combined and spliced ​​as an associated SQL fragment of the current SQL context.

[0041] At block 308, a prompt word for the SQL completion model may be determined. In some embodiments, the predetermined indicator may include a prefix indicator, a suffix indicator, and a to-be-completed indicator, and the prefix indicator, the suffix indicator, and the to-be-completed indicator may be added before the prefix part, the suffix part, and the to-be-completed part in the SQL context, respectively. For example, the SQL context may be "SELECT name, age FROM employees WHERE ORDERBY hire_date", and the prefix indicator may be <pre>, the suffix indicator can be <suf>, the to-be-completed indicator can be <mid>By adding the predefined indicator, the completed SQL context can be " <pre>SELECT name, age FROM employees WHERE <suf>ORDER BY hire_date <mid>”.

[0042] The prefix indicator can mark the prefix part in the SQL context, that is, the part that the user has entered before the content to be completed. The suffix indicator can mark the suffix part in the SQL context, that is, the content after the user cursor. The to-be-completed indicator can also be called the middle part indicator, which is used to mark the part that currently needs to be completed by the model. Through these indicators, the SQL completion model can better understand the structure of the SQL query, locate the fragment to be completed, and generate completion content that is consistent with the context, thereby improving the accuracy of completion and the coherence of the context.

[0043] At block 310, a SQL completion model may be used to generate a baseline completion fragment. The SQL completion model may be obtained by fine-tuning and training a language model. Figure 4 The process is described in detail. In some embodiments, the prompt word can be input into the SQL completion model, and the SQL completion model can generate corresponding completion code. For example, the SQL code to be completed is "SELECT name, age FROM employees WHERE ORDERBY hire_date", and the SQL completion model can generate a base completion fragment "department = 'IT'", that is, the completed SQL code is "SELECT name, age FROMemployees WHERE department = 'IT' ORDER BY hire_date".

[0044] In box 312, invalid objects in the benchmark completion fragment can be removed. In some embodiments, a combined SQL code can be generated based on the SQL context and the benchmark completion fragment. For example, the benchmark completion fragment can be added to the SQL context to generate a combined SQL code. In some embodiments, the combined SQL code can be parsed by a syntax analyzer to determine whether invalid objects exist in the benchmark completion fragment. Although the SQL completion model can generate accurate completion code in most cases, in complex or context-deficient situations, due to the "illusion" of the language model, invalid objects such as undefined fields or functions may appear in the completion code. For example, it can be determined whether the field or function referenced in the benchmark completion fragment exists in the table, view, alias originally defined in SQL, or exists in the metadata database of the data table, etc. If not, the field or function is determined to be an invalid object.

[0045] In some embodiments, if it is determined that an invalid object exists in the baseline completion segment, the invalid object and the portion after the invalid object are removed from the baseline completion segment. It should be understood that even if the invalid portion is removed, the user can still perform subsequent editing and expansion based on the remaining completion code. By removing the invalid object, it is possible to effectively avoid interference from these inaccurate contents to the user, and ensure that the generated SQL segment conforms to the actual data structure and business logic. This can improve the accuracy and executability of the completion code and reduce the user's manual modification of invalid parts.

[0046] At block 314, the repeated parts in the reference completion segment may be removed. For example, in some cases, the result generated by the language model may have a "repeat" or "duplicate" phenomenon, resulting in the generated SQL segment partially overlapping with the content already input by the user. For example, if the prefix of the generated completion segment and the suffix of the SQL segment before the user cursor have a long continuous repetition, the repeated prefix may be removed. Similarly, if the suffix of the generated completion segment and the prefix of the SQL segment after the user cursor have a long continuous repetition, the repeated suffix may also be removed.

[0047] In some embodiments, the reference completion fragment can be range-truncated. In order to allow users to concentrate and reduce interference when writing SQL, the SQL completion fragment should not be too long, especially should not exceed the user's current attention range. Therefore, a syntax parser can be used to generate a parsing result of the SQL code containing the completion fragment, and according to the position of the first word of the completion fragment, the user's current expected completion range is delineated, and the part exceeding the range is truncated. For example, the range can be "a complete SQL statement" (such as a subquery) or "a complete SQL clause" (such as SELECT, WHERE, GROUP BY, etc.). In this way, it can be ensured that the generated SQL completion fragment not only meets the user's needs, but also does not interfere with the user's thinking due to the completion fragment being too long.

[0048] Figure 4 A flow chart of a fine-tuning process 400 of a SQL completion model according to an embodiment of the present disclosure is shown. At box 402, the pre-trained language model is fine-tuned based on a SQL language data set. For example, the SQL language data set may be a corpus containing large-scale SQL statements, and the pre-trained language model is used to process general programming languages ​​(such as Python and Java). Since the SQL language differs from general programming languages ​​in grammatical structure and usage scenarios, it is necessary to fine-tune the pre-trained model through the SQL corpus so that it can better understand and generate query statements that comply with SQL grammar rules. Through this fine-tuning process, the model can learn the key structures of queries from SQL-specific corpus, such as common syntax such as SELECT, WHERE, JOIN, GROUP BY, etc., thereby improving the accuracy of SQL completion and the ability to understand the context.

[0049] At block 404, a training dataset for the SQL completion task may be constructed. For example, the SQL code in the SQL language dataset may be first divided into a prefix part, a middle part, and a suffix part, that is, SQL=(prefix, middle, suffix), and then the middle part is moved to the end of the SQL code to obtain SQL=(prefix, suffix, middle). In order to distinguish the prefix, the middle part, and the suffix, an indicator may be used. <pre>、 <mid>and <suf>Respectively represent the beginning of the prefix, middle part and suffix. The converted SQL code can be represented during training" <pre>encode(prefix) <suf>encode(suffix) <mid>encode(middle)". In some embodiments, the encode method may use Byte-Pair Encoding (BPE).

[0050] At block 404, training data for the SQL completion task may be constructed. For example, the SQL code in the SQL language dataset may be first divided into a prefix part, a middle part, and a suffix part, that is, SQL=(prefix, middle, suffix). Then the middle part is moved to the end of the SQL code, resulting in SQL=(prefix, suffix, middle). In order to distinguish the prefix, the middle part, and the suffix, an indicator may be used. <pre>、 <mid>and <suf>Respectively represent the beginning of the prefix, middle part and suffix. In addition, each part can be encoded using Byte-Pair Encoding (BPE). The converted SQL code data can be represented as " <pre>encode(prefix) <suf>encode(suffix) <mid>encode(middle)". In this way, the structure in the original SQL statement can be effectively decomposed into different parts, helping the model better understand the relationship between SQL fragments and help the model generate more accurate completion results.

[0051] At box 406, the SQL fine-tuning model can be trained based on the completion training data to generate a SQL completion model. For example, during the training process, the model can perform self-supervised learning based on the constructed completion training data, and gradually optimize the understanding and generation capabilities of the SQL statement completion task. Specifically, each SQL fragment in the training data will provide a SQL context and a corresponding completion fragment. Through continuous training, the model can learn how to accurately predict and generate subsequent completion fragments based on the SQL context. In some embodiments, the training process can also be combined with specific optimization goals, such as improving the accuracy of completion and improving the processing capabilities of complex SQL structures (such as nested queries, subqueries, etc.). As the training progresses, the model can improve the completion capabilities of various SQL grammatical structures and generate a high-quality SQL completion model.

[0052] Figure 5 FIG. 5 shows a block diagram of a SQL completion device 500 according to some embodiments of the present disclosure. Figure 5 As shown, the apparatus 500 includes a similar fragment determination module 502, which is configured to determine similar SQL fragments similar to the SQL context based on the SQL context, where the SQL context is the SQL code to be completed. The apparatus 500 also includes a data information determination module 504, which is configured to determine a data table and a table creation statement of the data table associated with the SQL context based on the SQL context, where the table creation statement at least indicates a table comment, a field, and a field comment of the data table. The apparatus 500 also includes an associated fragment determination module 506, which is configured to determine an associated SQL fragment associated with the SQL context based on the data table.

[0053] The device 500 further includes a prompt content generation module 508, which is configured to generate a prompt word including a predetermined indicator based on the SQL context, similar SQL fragments, table creation statements, and associated SQL fragments, wherein the predetermined indicator indicates a prefix part, a suffix part, and a part to be completed in the SQL context. The device 500 further includes a reference fragment generation model 510, which is configured to generate a reference completion fragment based on the prompt word using a SQL completion model based on a language model. In addition, the device 500 further includes a completion fragment generation module 512, which is configured to generate a target completion fragment based on the SQL context and the reference completion fragment.

[0054] Figure 6 A block diagram of an electronic device 600 is shown in accordance with certain embodiments of the present disclosure. Figure 6 1 shows a block diagram of an electronic device 600 according to some embodiments of the present disclosure. The device 600 may be a device or apparatus described in an embodiment of the present disclosure. Figure 6 As shown, the device 600 includes a central processing unit (CPU) and / or a graphics processing unit (GPU) 601, which can perform various appropriate actions and processes according to computer program instructions stored in a read-only memory (ROM) 602 or loaded from a storage unit 608 to a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the device 600 can also be stored. The CPU / GPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604. Although not shown in FIG. Figure 6 As shown in FIG. 6 , device 600 may further include a co-processor.

[0055] A number of components in the device 600 are connected to the I / O interface 605, including: an input unit 606, such as a keyboard, a mouse, etc.; an output unit 607, such as various types of displays, speakers, etc.; a storage unit 608, such as a disk, an optical disk, etc.; and a communication unit 609, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 609 allows the device 600 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0056] The various methods or processes described above may be performed by the CPU / GPU 601. For example, in some embodiments, the methods may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 608. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 600 via the ROM 602 and / or the communication unit 609. When the computer program is loaded into the RAM 603 and executed by the CPU / GPU 601, one or more steps or actions in the methods or processes described above may be performed.

[0057] In some embodiments, the methods and processes described above may be implemented as a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for executing various aspects of the present disclosure.

[0058] Computer readable storage medium can be a tangible device that can hold and store instructions used by an instruction execution device. Computer readable storage medium can be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination thereof. More specific examples (non-exhaustive list) of computer readable storage medium include: 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), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, for example, a punch card or a convex structure in a groove on which instructions are stored, and any suitable combination thereof. The computer readable storage medium used here is not interpreted as a transient signal itself, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagated by a waveguide or other transmission medium (for example, a light pulse by an optical fiber cable), or an electrical signal transmitted by a wire.

[0059] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.

[0060] The computer program instructions for performing the operations of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, and conventional procedural programming languages. Computer-readable program instructions may be executed entirely on a user's computer, partially on a user's computer, as a separate software package, partially on a user's computer, 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 via 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., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby implementing various aspects of the present disclosure.

[0061] These computer-readable program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processing unit of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0062] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0063] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the equipment, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each frame in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the frame can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous frames can actually be executed substantially in parallel, and they can also be executed in the opposite order sometimes, depending on the functions involved. It should also be noted that each frame in the block diagram and / or flow chart, and the combination of frames in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0064] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The choice of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

[0065] Some example implementations of the present disclosure are listed below.

[0066] Example 1. A SQL completion method includes:

[0067] Based on the SQL context, determining a similar SQL fragment similar to the SQL context, wherein the SQL context is the SQL code to be completed;

[0068] Based on the SQL context, determining a data table associated with the SQL context and a table creation statement of the data table, wherein the table creation statement at least indicates a table comment, a field, and a field comment of the data table;

[0069] Based on the data table, determining an associated SQL fragment associated with the SQL context;

[0070] Based on the SQL context, similar SQL fragments, the table creation statement and the associated SQL fragments, a prompt word including a predetermined indicator is generated, where the predetermined indicator indicates a prefix part, a suffix part and a part to be completed in the SQL context;

[0071] Based on the prompt word, using a language model-based SQL completion model to generate a benchmark completion fragment; and

[0072] A target completion fragment is generated based on the SQL context and the reference completion fragment.

[0073] Example 2. The method according to Example 1, wherein determining the similar SQL fragment similar to the SQL context comprises:

[0074] Based on the SQL context, generate a tag set, the tag set including at least keywords, table names, field names, and operators in the SQL context;

[0075] Determine a similarity score between the SQL context and each SQL fragment in the SQL fragment library based on an intersection and a union of the tag set of the SQL context and the tag set of each SQL fragment in the SQL fragment library;

[0076] Based on the similarity scores, the similar SQL fragments are determined.

[0077] Example 3. According to any one of Examples 1-2, the method, wherein determining the data table and the table creation statement associated with the SQL context comprises:

[0078] Parsing the SQL context by a syntax analyzer to determine a data table used by the SQL context; and

[0079] Based on the data table, the table creation statement of the data table is obtained from a metadata repository.

[0080] Example 4. The method according to any one of Examples 1-3, wherein determining the associated SQL fragment associated with the SQL context comprises:

[0081] Based on the data table, a first SQL fragment for generating the data table is retrieved from a SQL fragment library;

[0082] Based on the data table, retrieving a second SQL fragment using the data table from the SQL fragment library; and

[0083] The associated SQL fragment is determined based on the first SQL fragment and the second SQL fragment.

[0084] Example 5. The method according to any one of Examples 1-4, wherein the predetermined indicator includes a prefix indicator, a suffix indicator, and a to-be-completed indicator, and generating the prompt word includes:

[0085] Based on the SQL context, similar SQL fragments, the table creation statement and the associated SQL fragments, a prompt word including a predetermined indicator is generated, where the predetermined indicator indicates a prefix part, a suffix part and a part to be completed in the SQL context;

[0086] Adding the prefix indicator, the suffix indicator and the to-be-completed indicator before the prefix part, the suffix part and the to-be-completed part in the SQL context respectively; and

[0087] The prompt word is generated by splicing the table creation statement, the associated SQL fragment, the similar SQL fragment and the SQL context.

[0088] Example 6. The method according to any one of Examples 1-5, wherein generating the target completion fragment further comprises:

[0089] Generate a combined SQL code based on the SQL context and the benchmark completion fragment;

[0090] Parsing the combined SQL code by a syntax analyzer to determine whether there are invalid objects in the benchmark completion segment; and

[0091] In response to determining that an invalid object exists in the reference completion segment, a portion from and after the invalid object is removed from the reference completion segment.

[0092] Example 7. The method according to any one of Examples 1-6, further comprising:

[0093] Determine whether the reference completion segment has a repeated segment that repeats the prefix portion and the suffix portion in the SQL context; and

[0094] In response to determining that the duplicate segment exists, the duplicate segment is removed from the reference completion segment.

[0095] Example 8. The method according to any one of Examples 1-7, further comprising:

[0096] Generate a SQL fine-tuning model by fine-tuning a pre-trained language model using a SQL code dataset, wherein the pre-trained language model is a general code model;

[0097] Based on the SQL language dataset, construct completion training data for the SQL completion task; and

[0098] The SQL completion model is generated by training a SQL fine-tuning model based on the completion training data.

[0099] Example 9. A device for SQL completion, comprising:

[0100] A similar fragment determination module is configured to determine, based on an SQL context, a similar SQL fragment that is similar to the SQL context, wherein the SQL context is an SQL code to be completed;

[0101] A data information determination module is configured to determine, based on an SQL context, a data table and a table creation statement of the data table associated with the SQL context, wherein the table creation statement at least indicates a table comment, a field, and a field comment of the data table;

[0102] an associated fragment determination module, configured to determine an associated SQL fragment associated with the SQL context based on the data table;

[0103] A prompt content generating module is configured to generate a prompt word including a predetermined indicator based on the SQL context, similar SQL fragments, the table creation statement and the associated SQL fragments, wherein the predetermined indicator indicates a prefix part, a suffix part and a part to be completed in the SQL context;

[0104] A reference segment generation module is configured to generate a reference completion segment based on the prompt word by using a SQL completion model based on a language model; and

[0105] The completion segment generating module is configured to generate a target completion segment based on the SQL context and the reference completion segment.

[0106] Example 10. The apparatus according to Example 9, wherein the similar segment determination module comprises:

[0107] A tag set generating module, configured to generate a tag set based on the SQL context, wherein the tag set at least includes keywords, table names, field names, and operators in the SQL context;

[0108] a similarity score determination module, configured to determine a similarity score between the SQL context and each SQL fragment in the SQL fragment library based on an intersection and a union of the tag set of the SQL context and the tag set of each SQL fragment in the SQL fragment library;

[0109] The similar segment second determination module is configured to determine the similar SQL segment based on the similarity score.

[0110] Example 11. The apparatus according to any one of Examples 9-10, wherein the data information determination module comprises:

[0111] a data table determination module, configured to parse the SQL context through a syntax analyzer to determine a data table used by the SQL context; and

[0112] The table creation statement determination module is configured to obtain the table creation statement of the data table from a metadata repository based on the data table.

[0113] Example 12. The apparatus according to any one of Examples 9-11, wherein the associated segment determination module comprises:

[0114] A first fragment determination module is configured to retrieve and generate a first SQL fragment of the data table from an SQL fragment library based on the data table;

[0115] A second fragment determination module is configured to retrieve a second SQL fragment using the data table from the SQL fragment library based on the data table; and

[0116] The associated fragment second determination module is configured to determine the associated SQL fragment based on the first SQL fragment and the second SQL fragment.

[0117] Example 13. The apparatus according to any one of Examples 9-12, wherein the predetermined indicator includes a prefix indicator, a suffix indicator, and a to-be-completed indicator, and the prompt content generation module includes:

[0118] an indicator adding module, configured to add the prefix indicator, the suffix indicator and the to-be-completed indicator before the prefix part, the suffix part and the to-be-completed part in the SQL context, respectively; and

[0119] The prompt word generation module is configured to generate the prompt word by splicing the table creation statement, the associated SQL fragment, the similar SQL fragment and the SQL context.

[0120] Example 14. The apparatus according to any one of Examples 9-13, wherein the completion segment generation module comprises:

[0121] A combined code generation module is configured to generate a combined SQL code based on the SQL context and the benchmark completion fragment;

[0122] an invalid object determination module, configured to parse the combined SQL code through a syntax analyzer to determine whether there are invalid objects in the benchmark completion segment; and

[0123] The invalid content removal module is configured to remove a portion from and after the invalid object from the reference completion segment in response to determining that the invalid object exists in the reference completion segment.

[0124] Example 15. The apparatus of any one of Examples 9-14, further comprising:

[0125] a repeated content determination module configured to determine whether the reference completion segment has a repeated segment that is repeated with the prefix part and the suffix part in the SQL context; and

[0126] The duplicate content removal module is configured to remove the duplicate segment from the reference completion segment in response to determining that the duplicate segment exists.

[0127] Example 16. The apparatus according to any one of Examples 9-15, further comprising:

[0128] A fine-tuning model generation module is configured to generate a SQL fine-tuning model by fine-tuning a pre-trained language model using a SQL code dataset, wherein the pre-trained language model is a general code model;

[0129] A training data construction module is configured to construct completion training data for the SQL completion task based on the SQL language data set; and

[0130] The completion model generation module is configured to generate the SQL completion model by training the SQL fine-tuning model based on the completion training data.

[0131] Example 17. An electronic device comprising:

[0132] Processor; and

[0133] A memory coupled to the processor, the memory having instructions stored therein, wherein when the instructions are executed by the processor, the electronic device performs actions, the actions comprising:

[0134] Based on the SQL context, determining a similar SQL fragment similar to the SQL context, wherein the SQL context is the SQL code to be completed;

[0135] Based on the SQL context, determining a data table associated with the SQL context and a table creation statement of the data table, wherein the table creation statement at least indicates a table comment, a field, and a field comment of the data table;

[0136] Based on the data table, determining an associated SQL fragment associated with the SQL context;

[0137] Based on the SQL context, similar SQL fragments, the table creation statement and the associated SQL fragments, a prompt word including a predetermined indicator is generated, where the predetermined indicator indicates a prefix part, a suffix part and a part to be completed in the SQL context;

[0138] Based on the prompt word, using a language model-based SQL completion model to generate a benchmark completion fragment; and

[0139] A target completion fragment is generated based on the SQL context and the reference completion fragment.

[0140] Example 18. The electronic device according to claim 17, wherein determining the similar SQL fragment similar to the SQL context comprises:

[0141] Based on the SQL context, generate a tag set, the tag set including at least keywords, table names, field names, and operators in the SQL context;

[0142] Determine a similarity score between the SQL context and each SQL fragment in the SQL fragment library based on an intersection and a union of the tag set of the SQL context and the tag set of each SQL fragment in the SQL fragment library;

[0143] Based on the similarity scores, the similar SQL fragments are determined.

[0144] Example 19. The electronic device according to any one of claims 17-18, wherein determining the data table and the table creation statement associated with the SQL context comprises:

[0145] Parsing the SQL context by a syntax analyzer to determine a data table used by the SQL context; and

[0146] Based on the data table, the table creation statement of the data table is obtained from a metadata repository.

[0147] Example 20. The electronic device according to any one of claims 17-18, wherein determining the associated SQL fragment associated with the SQL context comprises:

[0148] Based on the data table, a first SQL fragment for generating the data table is retrieved from a SQL fragment library;

[0149] Based on the data table, retrieving a second SQL fragment using the data table from the SQL fragment library; and

[0150] The associated SQL fragment is determined based on the first SQL fragment and the second SQL fragment.

[0151] Example 21. The electronic device according to any one of claims 17-18, wherein the predetermined indicator comprises a prefix indicator, a suffix indicator, and a to-be-completed indicator, and generating the prompt word comprises:

[0152] Adding the prefix indicator, the suffix indicator and the to-be-completed indicator before the prefix part, the suffix part and the to-be-completed part in the SQL context respectively; and

[0153] The prompt word is generated by splicing the table creation statement, the associated SQL fragment, the similar SQL fragment and the SQL context.

[0154] Example 22. The electronic device according to any one of claims 17-18, wherein generating the target completion segment comprises:

[0155] Generate a combined SQL code based on the SQL context and the benchmark completion fragment;

[0156] Parsing the combined SQL code by a syntax analyzer to determine whether there are invalid objects in the benchmark completion segment; and

[0157] In response to determining that an invalid object exists in the reference completion segment, a portion from and after the invalid object is removed from the reference completion segment.

[0158] Example 23. The electronic device according to any one of claims 17-18, wherein the actions further include:

[0159] Determine whether the reference completion segment has a repeated segment that repeats the prefix portion and the suffix portion in the SQL context; and

[0160] In response to determining that the duplicate segment exists, the duplicate segment is removed from the reference completion segment.

[0161] Example 24. The electronic device according to any one of claims 17-18, wherein the actions further include:

[0162] Generate a SQL fine-tuning model by fine-tuning a pre-trained language model using a SQL code dataset, wherein the pre-trained language model is a general code model;

[0163] Based on the SQL language dataset, construct completion training data for the SQL completion task; and

[0164] The SQL completion model is generated by training a SQL fine-tuning model based on the completion training data.

[0165] Example 25. A computer-readable storage medium having one or more computer instructions stored thereon, wherein the one or more computer instructions are executed by a processor to implement the method according to any one of Examples 1 to 8.

[0166] Example 26. A computer program product tangibly stored on a computer-readable medium and comprising computer-executable instructions that, when executed by a device, cause the device to perform the method according to any one of Examples 1 to 8.

[0167] Although the disclosure has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Instead, the specific features and actions described above are merely example forms of implementing the claims.< / mid> < / suf> < / pre> < / suf> < / mid> < / pre> < / mid> < / suf> < / pre> < / suf> < / mid> < / pre> < / mid> < / suf> < / pre> < / mid> < / suf> < / pre>

Claims

1. A method for completing a structured query language SQL, comprising: Based on the SQL context, determining a similar SQL fragment similar to the SQL context, wherein the SQL context is the SQL code to be completed; Based on the SQL context, determining a data table associated with the SQL context and a table creation statement of the data table, wherein the table creation statement at least indicates a table comment, a field, and a field comment of the data table; Based on the data table, determining an associated SQL fragment associated with the SQL context; Based on the SQL context, the similar SQL fragments, the table creation statement, and the associated SQL fragments, a prompt word including a predetermined indicator is generated, where the predetermined indicator indicates a prefix part, a suffix part, and a part to be completed in the SQL context; Based on the prompt word, a SQL completion model based on a language model is used to generate a benchmark completion fragment; as well as A target completion fragment is generated based on the SQL context and the reference completion fragment.

2. The method according to claim 1, wherein determining the similar SQL fragment similar to the SQL context comprises: Based on the SQL context, generate a tag set, the tag set including at least keywords, table names, field names, and operators in the SQL context; Determine a similarity score between the SQL context and each SQL fragment in the SQL fragment library based on an intersection and a union of the tag set of the SQL context and the tag set of each SQL fragment in the SQL fragment library; Based on the similarity scores, the similar SQL fragments are determined.

3. The method according to claim 1, wherein determining the data table and the table creation statement associated with the SQL context comprises: Parsing the SQL context by a syntax analyzer to determine a data table used by the SQL context; as well as Based on the data table, the table creation statement of the data table is obtained from a metadata repository.

4. The method of claim 3, wherein determining the associated SQL fragment associated with the SQL context comprises: Based on the data table, a first SQL fragment for generating the data table is retrieved from a SQL fragment library; Based on the data table, retrieving a second SQL fragment using the data table from the SQL fragment library; and The associated SQL fragment is determined based on the first SQL fragment and the second SQL fragment.

5. The method according to claim 1, wherein the predetermined indicator comprises a prefix indicator, a suffix indicator, and a to-be-completed indicator, and generating the prompt word comprises: Add the prefix indicator, the suffix indicator and the to-be-completed indicator before the prefix part, the suffix part and the to-be-completed part in the SQL context respectively; as well as The prompt word is generated by splicing the table creation statement, the associated SQL fragment, the similar SQL fragment and the SQL context.

6. The method according to claim 1, wherein generating the target completion segment comprises: Generate a combined SQL code based on the SQL context and the benchmark completion fragment; Parsing the combined SQL code by a syntax analyzer to determine whether there are invalid objects in the benchmark completion segment; as well as In response to determining that an invalid object exists in the reference completion segment, a portion from and after the invalid object is removed from the reference completion segment.

7. The method according to claim 6, further comprising: Determine whether the reference completion segment has a repeated segment that repeats the prefix part and the suffix part in the SQL context; as well as In response to determining that the duplicate segment exists, the duplicate segment is removed from the reference completion segment.

8. The method according to claim 1, further comprising: Generate a SQL fine-tuning model by fine-tuning a pre-trained language model using a SQL code dataset, wherein the pre-trained language model is a general code model; Based on the SQL language dataset, construct completion training data for the SQL completion task; as well as The SQL completion model is generated by training a SQL fine-tuning model based on the completion training data.

9. A device for SQL completion, comprising: A similar fragment determination module is configured to determine, based on an SQL context, a similar SQL fragment that is similar to the SQL context, wherein the SQL context is an SQL code to be completed; A data information determination module is configured to determine, based on the SQL context, a data table associated with the SQL context and a table creation statement of the data table, wherein the table creation statement at least indicates a table comment, a field, and a field comment of the data table; an associated fragment determination module, configured to determine an associated SQL fragment associated with the SQL context based on the data table; a prompt content generating module configured to generate a prompt word including a predetermined indicator based on the SQL context, the similar SQL fragment, the table creation statement and the associated SQL fragment, wherein the predetermined indicator indicates a prefix part, a suffix part and a part to be completed in the SQL context; A reference segment generation module is configured to generate a reference completion segment based on the prompt word by using a SQL completion model based on a language model; as well as The completion segment generating module is configured to generate a target completion segment based on the SQL context and the reference completion segment.

10. An electronic device comprising: processor; as well as A memory coupled to the processor, the memory having instructions stored therein, wherein when the instructions are executed by the processor, the electronic device executes the method according to any one of claims 1 to 8.

11. A computer program product tangibly stored on a non-transitory computer readable medium and comprising computer executable instructions for performing the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Code completion method and device

    CN113867710A

  • Database query instruction generation method and device, computer equipment and storage medium

    CN117909355A