Structured query language statement processing method and device
By parsing code snippets and target keyword areas in SQL files and generating context information in combination with the big model, the problem of low code completion efficiency in SQL statement writing is solved, and efficient and accurate code completion is achieved.
Patent Information
- Application Number
- CN202411281696.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-12
- Publication Date
- 2024-12-27
AI Technical Summary
The existing technology is difficult to achieve efficient and accurate code completion in the process of writing SQL statements, especially since SQL is a process-oriented language, its core logic lies in data table mapping and processing logic, and traditional code completion strategies are difficult to achieve good results. .
By responding to the code completion trigger condition in the SQL file, the current editing location is automatically obtained, the code fragment is parsed to determine the target keyword area, the code to be completed is generated, and the code is completed in combination with the big model to ensure that the complete code and the developer's Write a high match of intent and generate context information by querying similar code snippets and code bases for improved accuracy.
It realizes the flexibility and accuracy of SQL code completion, reduces coding errors, improves the efficiency and accuracy of code completion, and ensures that the complete code meets user needs.
Smart Images

Figure CN119202174A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of data processing, and in particular to a method and device for processing structured query language statements. Background Art
[0002] As the size of databases continues to expand and Structured Query Language (SQL) statements become increasingly complex, developers need a more efficient way to write SQL statements. In order to improve the efficiency of SQL writing, real-time code suggestions and automatic completion can be provided to developers. For example, based on the keywords entered by the user, possible keywords or grammatical structures are automatically prompted, thereby helping users to complete SQL statement writing more quickly. Therefore, in order to improve the efficiency of SQL writing, it is very important to accurately complete SQL statements. Summary of the invention
[0003] The present disclosure provides a method and device for processing structured query language statements to at least solve one of the technical problems in the related art to a certain extent. The technical solution of the present disclosure is as follows:
[0004] According to a first aspect of an embodiment of the present disclosure, a method for processing a structured query language statement is provided, comprising: in a process of code editing a target structured query language file, in response to satisfying a set code completion trigger condition, obtaining a current editing position from the target structured query language file; parsing a code fragment between a code start position and the current editing position in the target structured query language file to obtain a current code sub-fragment to which the current editing position belongs; parsing the current code sub-fragment to determine a target keyword region to which the current editing position belongs; generating a code to be completed based on the target keyword region and the current code sub-fragment; and in response to a confirmation operation on the code to be completed, using the code to be completed to complete the current editing position in the target structured query language file.
[0005] According to a second aspect of an embodiment of the present disclosure, a device for processing a structured query language statement is provided, comprising: an acquisition module, used to acquire a current editing position from the target structured query language file in response to satisfying a set code completion trigger condition during code editing of the target structured query language file; a first parsing module, used to parse a code fragment between a code start position and the current editing position in the target structured query language file to obtain a current code sub-fragment to which the current editing position belongs; a second parsing module, used to parse the current code sub-fragment to determine a target keyword region to which the current editing position belongs; a generation module, used to generate a code to be completed based on the target keyword region and the current code sub-fragment; and a processing module, used to complete the code at the current editing position in the target structured query language file using the code to be completed in response to a confirmation operation on the code to be completed.
[0006] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement a method for processing structured query language statements as described in an embodiment of the first aspect of the present disclosure.
[0007] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the method for processing structured query language statements as described in the embodiment of the first aspect of the present disclosure.
[0008] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, including: a computer program, which, when executed by a processor, implements the method for processing a structured query language statement as described in the embodiment of the first aspect of the present disclosure.
[0009] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects:
[0010] In the technical scheme, by responding to the set code completion trigger condition, the current editing position is automatically obtained without the need for the user to manually locate the current editing position. Then, the code fragment from the code start position to the current editing position is parsed to determine the current code sub-fragment, and the current code sub-fragment is parsed to determine the target keyword area to which the current editing position belongs, thereby accurately identifying the target keyword area to which the current editing position in the code belongs, and generating the code to be completed based on the target keyword area and the current code sub-fragment, thereby ensuring that the code to be completed is highly matched with the developer's writing intention, thereby improving the accuracy of the code to be completed, and finally, in response to the user's confirmation operation on the code to be completed, completing the code completion, thereby improving the flexibility and accuracy of SQL code completion; wherein, when the target keyword area is the first specified keyword area, by querying multiple first similar code sub-fragments similar to the first code sub-fragment, and querying multiple second similar code sub-fragments similar to the second code sub-fragment, based on multiple A first similar code sub-segment and a plurality of second similar code sub-segments are combined to generate a code to be completed, thereby realizing rapid generation of the code to be completed by automatically analyzing and integrating similar code fragments, and improving the accuracy and generation efficiency of the code to be completed; in addition, when the target keyword area to which the current editing position belongs is the second designated keyword area, based on the current code sub-segment, a plurality of similar third similar code sub-segments are quickly retrieved from the second keyword code library; then, the second remaining code sub-segments except the current code sub-segment are obtained from the code fragment, and the second remaining code sub-segments are sequentially spliced with the retrieved third similar code sub-segments and the current code sub-segment to generate second context information associated with the current code sub-segment, thereby improving the richness of the second context information; finally, the richer second context information is input into the large model, and a more accurate code to be completed that meets user needs is efficiently generated, thereby performing code completion based on the code to be completed, and effectively reducing coding errors.
[0011] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.
[0013] Figure 1 It is a flowchart of a method for processing a structured query language statement shown in the first embodiment of the present disclosure;
[0014] Figure 2 is a flow chart of a method for processing a structured query language statement shown in the second embodiment of the present disclosure;
[0015] Figure 3 is a flowchart of a method for processing a structured query language statement shown in the third embodiment of the present disclosure;
[0016] Figure 4 is a flowchart of a method for processing a structured query language statement shown in the fourth embodiment of the present disclosure;
[0017] Figure 5 is a flowchart of a method for processing a structured query language statement shown in the fifth embodiment of the present disclosure;
[0018] Figure 6 It is a schematic diagram of the principle of the method for processing structured query language statements shown in the embodiment of the present disclosure;
[0019] Figure 7 is a schematic diagram of the structure of a device for processing structured query language statements shown in the sixth embodiment of the present disclosure;
[0020] Figure 8 It is a schematic structural diagram of an electronic device shown in an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION
[0021] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.
[0022] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0023] It should be noted that in the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information are all carried out with the user's consent, and are in compliance with the relevant laws and regulations and do not violate public order and good morals.
[0024] In the field of software development, using big models for real-time code completion has become a widely used technical means. These big models can support mainstream programming languages including C, C++, Python and Java, and have shown significant performance improvements. However, when processing SQL statements, directly applying big model technology for code completion often fails to achieve the expected results. The reason for this phenomenon is that, unlike programming languages such as Python and Java that are mainly based on structure and function calls, SQL is a process-oriented language. Its core logic is to process the original data table through mapping and calculation, and finally generate a new data table or extract the required information. The traditional code completion strategy is to use the first few lines of the written code as "context" and input them into the big model, so that the big model can generate the next possible code statements. However, in the process of writing SQL statements, the first few lines often do not contain information about data field mapping and processing logic, making it difficult for big model completion to achieve good results.
[0025] Therefore, in order to solve the above problems, the present disclosure proposes a method and device for processing structured query language statements.
[0026] The following describes a method and apparatus for processing structured query language statements according to an embodiment of the present disclosure with reference to the accompanying drawings.
[0027] Figure 1 It is a flowchart of a method for processing a structured query language statement shown in the first embodiment of the present disclosure.
[0028] like Figure 1 As shown, the method for processing the structured query language statement includes the following steps:
[0029] Step 101 : in the process of editing the code of a target structured query language file, in response to satisfying a set code completion trigger condition, obtaining a current editing position from the target structured query language file.
[0030] In order to improve the efficiency and accuracy of code completion, as a possible implementation method, during the code editing process of the target structured query language file, and when the set code completion triggering condition is met, the current editing position is automatically identified.
[0031] As an example, writing a part of a keyword or a table name is used as a trigger condition for setting code completion. When a user enters a part of a keyword or a table name, the current editing position is automatically obtained from the target structured query language file.
[0032] As another example, pressing a set shortcut key is used as a set code completion trigger condition, and when the user presses the set shortcut key (eg, Ctrl+Space), the current editing position is automatically obtained from the target structured query language file.
[0033] Step 102: parse the code segment between the code start position and the current editing position in the target structured query language file to obtain the current code sub-segment to which the current editing position belongs.
[0034] In order to improve the accuracy of code completion, as a possible implementation method, first determine the current code sub-segment to which the current editing position belongs, and then determine the context information of code completion based on the current code sub-segment, and generate the code to be completed based on the context information of code completion.
[0035] As an example, by parsing the code segment between the code start position and the current editing position in the target structured query language file, the current code sub-segment to which the current editing position belongs can be determined.
[0036] For example, the code segment between the code start position and the current editing position includes code sub-segment 1, code sub-segment 2, and code sub-segment 3, and the current editing position belongs to code sub-segment 3.
[0037] Step 103: parse the current code sub-segment to determine the target keyword region to which the current editing position belongs.
[0038] It should be understood that the target keyword area is the first specified keyword area or the second specified keyword area, wherein the first specified keyword area is the code area associated with the first specified keyword, the first specified keyword is, for example, "FORM", the first specified keyword area is the code area containing "FROM", and the second specified keyword area is the code area associated with the second specified keyword, the second specified keyword is, for example, "SELECT", the second specified keyword area is the code area containing "SELECT".
[0039] Step 104: Generate code to be completed according to the target keyword region and the current code sub-segment.
[0040] It is important to understand that by analyzing the target keyword area and the current code sub-fragment, a rich context can be provided for the code to be completed. The context includes information about data field mapping and processing logic. Therefore, the code to be completed is generated based on the target keyword area and the current code sub-fragment, that is, through the rich context of the code to be completed, so that the code to be completed is highly matched with the developer's writing intention, thereby improving the accuracy of the code to be completed.
[0041] Step 105 , in response to the confirmation operation on the code to be completed, the code to be completed is used to complete the code at the current editing position in the target structured query language file.
[0042] In order to improve the flexibility of code completion, as an example, when the user confirms the code to be completed, the code to be completed is automatically used to complete the current editing position in the target structured query language file.
[0043] In summary, by responding to the set code completion trigger conditions, the current editing position is automatically obtained without the need for the user to manually locate the current editing position. Next, the code fragment from the code start position to the current editing position is parsed to determine the current code sub-fragment, and the current code sub-fragment is parsed to determine the target keyword area to which the current editing position belongs, thereby accurately identifying the target keyword area to which the current editing position in the code belongs. According to the target keyword area and the current code sub-fragment, the code to be completed is generated, ensuring that the code to be completed is highly matched with the developer's writing intention, and improving the accuracy of the code to be completed. Finally, in response to the user's confirmation operation on the code to be completed, the code completion is completed, thereby improving the flexibility and accuracy of SQL code completion.
[0044] In order to clearly explain how to generate the code to be completed according to the target keyword region and the current code sub-segment in the above embodiment, the present disclosure proposes another method for processing a structured query language statement.
[0045] Figure 2 It is a flowchart of a method for processing a structured query language statement shown in the second embodiment of the present disclosure.
[0046] like Figure 2 As shown, the method for processing the structured query language statement includes the following steps:
[0047] Step 201 : in the process of editing the code of the target structured query language file, in response to satisfying a set code completion trigger condition, obtaining a current editing position from the target structured query language file.
[0048] Step 202: parse the code segment between the code start position and the current editing position in the target structured query language file to obtain the current code sub-segment to which the current editing position belongs.
[0049] Step 203: parse the current code sub-segment to determine the target keyword region to which the current editing position belongs.
[0050] Step 204 : in response to the target keyword region being the first designated keyword region, obtaining a first code sub-segment and a second code sub-segment associated with the current code sub-segment from the code segment.
[0051] The first code sub-segment includes a first specified keyword, and the second code sub-segment includes a second specified keyword.
[0052] For example, taking the case where the first designated keyword is "FROM", the second designated keyword is "SELECT", the first designated keyword area is the code area including "FROM", and the second designated keyword area is the code area including "SELECT", since "SELECT" usually appears before "FROM" in the writing order of SQL statements, in order to accurately determine the context of code completion, the target keyword area to which the current editing position belongs is the code area including "FROM", the code of the "FROM" area is obtained from the code fragment, that is, the first code sub-segment, and the code of the "SELECT" area is obtained from the code fragment, that is, the second code sub-segment, thereby determining the code to be completed based on the first code sub-segment and the second code sub-segment.
[0053] Step 205: According to the first code sub-segment, query a first code vector library associated with the first specified keyword to obtain a plurality of first similar code sub-segments that are similar to the first code sub-segment.
[0054] In order to improve the accuracy of the code to be completed, as a possible implementation method, multiple first similar code sub-segments similar to the first code sub-segment are determined from the first code vector library, and multiple second similar code sub-segments similar to the second code sub-segment are determined from the second code vector library, and the code to be completed is generated based on the multiple first similar code sub-segments and the multiple second similar code sub-segments.
[0055] As an example, based on the first code sub-segment, a first code vector library associated with a first specified keyword is queried to obtain multiple first code vectors similar to the first code sub-segment, and the multiple first code vectors are devectorized to obtain multiple first similar code sub-segments.
[0056] For example, the first code sub-segment is the code of the "FROM" area, and the first code vector library is queried according to the code of the "FROM" area to obtain multiple "FROM" code segments similar to the code of the "FROM" area.
[0057] Step 206: According to the second code sub-segment, query a second code vector library associated with the second specified keyword to obtain a plurality of second similar code sub-segments that are similar to the second code sub-segment.
[0058] As an example, based on the second code sub-segment, a second code vector library associated with a second specified keyword is queried to obtain multiple second code vectors similar to the second code sub-segment, and the multiple second code vectors are devectorized to obtain multiple second similar code sub-segments.
[0059] For example, the first code sub-segment is the code in the "SELECT" area, and the second code vector library is queried according to the code in the "SELECT" area to obtain multiple "SELECT" code segments similar to the code in the "SELECT" area.
[0060] Step 207: Generate a code to be completed according to the plurality of first similar code sub-segments and the plurality of second similar code sub-segments.
[0061] In order to further improve the accuracy of code completion, as a possible implementation manner, a context of the code to be completed is generated based on multiple first similar code sub-segments and multiple second similar code sub-segments, and the code to be completed is generated based on the context.
[0062] As an example, according to any second similar code sub-segment, the first code vector library is queried to obtain a first associated code sub-segment having a mapping relationship with any second similar code sub-segment; the first remaining code sub-segments other than the current code sub-segment are obtained from the code fragments; the first remaining code sub-segments, multiple first similar code sub-segments, each first associated code sub-segment and the current code sub-segment are sequentially spliced to obtain first context information associated with the current code sub-segment; and the code to be completed is generated according to the first context information.
[0063] For example, taking any second similar code sub-segment as a code segment similar to the code in the "SELECT" area as an example, obtain a first associated code sub-segment having a mapping relationship with any second similar code sub-segment from the first code vector library, that is, the "FROM" code where any second similar code sub-segment is located; then, obtain the first remaining code sub-segments except the current code sub-segment from the code segment between the code start position and the current editing position, splice the first remaining code sub-segment with multiple first similar code sub-segments, continue to splice the spliced result with multiple first associated code sub-segments, and splice the spliced result with the current code sub-segment to obtain first context information, and use a large model to generate the code to be completed according to the first context information.
[0064] The steps of generating the code to be completed according to the first context information are as follows:
[0065] 1. Obtain a prompt template, where the prompt template is used to indicate the task information to be performed by the large model;
[0066] 2. Fill the prompt template with the first context information to obtain model prompt information;
[0067] 3. Input the model prompt information into the large model for processing to obtain the code to be completed.
[0068] Step 208 , in response to the confirmation operation on the code to be completed, the code to be completed is used to complete the code at the current editing position in the target structured query language file.
[0069] It should be noted that the execution process of steps 201 to 203 and step 208 can be implemented in any manner in the embodiments of the present disclosure, and the embodiments of the present disclosure do not limit this and will not be described in detail.
[0070] In summary, in response to the target keyword area being the first specified keyword area, a first code sub-segment and a second code sub-segment associated with the current code sub-segment are obtained from the code fragment; wherein the first code sub-segment includes the first specified keyword, and the second code sub-segment includes the second specified keyword; according to the first code sub-segment, a first code vector library associated with the first specified keyword is queried to obtain a plurality of first similar code sub-segments similar to the first code sub-segment; according to the second code sub-segment, a second code vector library associated with the second specified keyword is queried to obtain a plurality of second similar code sub-segments similar to the second code sub-segment; based on the plurality of first similar code sub-segments and the plurality of second similar code sub-segments, a code to be completed is generated, thereby, by querying a plurality of first similar code sub-segments similar to the first code sub-segment, and querying a plurality of second similar code sub-segments similar to the second code sub-segment, a code to be completed is generated based on the plurality of first similar code sub-segments and the plurality of second similar code sub-segments, so that the code to be completed is quickly generated by automatically analyzing and integrating similar code fragments, thereby improving the accuracy and generation efficiency of the code to be completed.
[0071] In order to clearly illustrate how the above embodiment generates the code to be completed according to the target keyword region and the current code sub-segment, the present disclosure proposes another method for processing a structured query language statement.
[0072] Figure 3 It is a flowchart of a method for processing a structured query language statement shown in the third embodiment of the present disclosure.
[0073] like Figure 3 As shown, the method for processing the structured query language statement includes the following steps:
[0074] Step 301 : in the process of editing the code of the target structured query language file, in response to satisfying a set code completion trigger condition, obtaining a current editing position from the target structured query language file.
[0075] Step 302: parse the code segment between the code start position and the current editing position in the target structured query language file to obtain the current code sub-segment to which the current editing position belongs.
[0076] Step 303: parse the current code sub-segment to determine the target keyword region to which the current editing position belongs.
[0077] Step 304 : In response to the target keyword region being the second designated keyword region, query the second keyword code library according to the current code sub-segment to obtain a plurality of third similar code sub-segments that are similar to the current code sub-segment.
[0078] For example, continuing with the example of the first designated keyword being "FROM", the second designated keyword being "SELECT", the first designated keyword area being the code area including "FROM", and the second designated keyword area being the code area including "SELECT", in order to accurately determine the context of code completion, the target keyword area to which the current editing position belongs is the code area including "SELECT", then based on the current code sub-segment, the second keyword code library is queried to obtain multiple third similar code sub-segments that are similar to the "SELECT" area code.
[0079] Step 305: Obtain the second remaining code sub-segments except the current code sub-segment from the code segment.
[0080] Furthermore, a second remaining code sub-segment except the current code sub-segment is obtained from the code segment between the code start position and the current editing position.
[0081] Step 306: sequentially concatenate the second remaining code sub-segments, the plurality of third similar code sub-segments, and the current code sub-segment to obtain second context information associated with the current code sub-segment.
[0082] In order to improve the richness of the context of the code to be completed, as an example, the second remaining code sub-fragment is first spliced with multiple third similar code sub-fragments, then the spliced result is spliced with the current code sub-fragment, and finally, the result spliced with the current code sub-fragment is spliced with the current code sub-fragment to obtain the second context information associated with the current code sub-fragment.
[0083] Step 307: input the second context information into the large model to obtain the code to be completed.
[0084] In order to improve the accuracy and generation efficiency of the code to be completed, as an example, the second context information is input into the large model to process the second context information and output the code to be completed.
[0085] Step 308: In response to the confirmation operation on the code to be completed, the code to be completed is used to complete the code at the current editing position in the target structured query language file.
[0086] It should be noted that the execution process of steps 301 to 303 and step 308 can be implemented in any way in the embodiments of the present disclosure, and the embodiments of the present disclosure do not limit this and will not be described in detail.
[0087] In summary, in response to the target keyword area to which the current editing position belongs being the second designated keyword area, multiple similar third similar code sub-segments are quickly retrieved from the second keyword code library based on the current code sub-segment; then, the second remaining code sub-segments except the current code sub-segment are obtained from the code fragments, and the second remaining code sub-segments are sequentially spliced with the retrieved third similar code sub-segments and the current code sub-segment to generate second context information associated with the current code sub-segment, thereby improving the richness of the second context information; finally, the richer second context information is input into the large model, thereby achieving efficient generation of more accurate code to be completed that meets user needs, thereby performing code completion based on the code to be completed, and effectively reducing coding errors.
[0088] In order to clearly explain how the current code sub-segment is parsed in the above embodiment to determine the target keyword region to which the current editing position belongs, the present disclosure proposes another method for processing a structured query language statement.
[0089] Figure 4 It is a flowchart of a method for processing a structured query language statement shown in the fourth embodiment of the present disclosure.
[0090] like Figure 4 As shown, the method for processing the structured query language statement includes the following steps:
[0091] Step 401 : in the process of editing the code of the target structured query language file, in response to satisfying a set code completion trigger condition, obtaining a current editing position from the target structured query language file.
[0092] Step 402: parse the code segment between the code start position and the current editing position in the target structured query language file to obtain the current code sub-segment to which the current editing position belongs.
[0093] Step 403: parse the current code sub-segment to obtain a parsing result.
[0094] As an example, the current code sub-segment is parsed, keywords in the current code sub-segment are identified, and a parsing result is generated according to the recognition result of the keyword.
[0095] Step 404: in response to the parsing result indicating that the current code sub-segment includes the first designated keyword, determining that the target keyword region to which the current editing position belongs is the first designated keyword region.
[0096] As an example, when the parsing result indicates that the current code sub-segment includes the first specified keyword, the target keyword area to which the current editing position belongs is determined to be the first specified keyword area. For example, the current code sub-segment includes the "FROM" keyword, and the target keyword area to which the current editing position belongs is determined to be the "FROM" code area.
[0097] Step 405: In response to the parsing result indicating that the current code sub-segment includes the second designated keyword, determining that the target keyword region to which the current editing position belongs is the second designated keyword region.
[0098] As another example, when the parsing result indicates that the current code sub-fragment includes the second specified keyword, the target keyword area to which the current editing position belongs is determined to be the second specified keyword area. For example, the current code sub-fragment includes the "SELECT" keyword, and the target keyword area to which the current editing position belongs is determined to be the "SELECT" code area.
[0099] Step 406: Generate code to be completed according to the target keyword region and the current code sub-segment.
[0100] Step 407 , in response to the confirmation operation on the code to be completed, the code to be completed is used to complete the code at the current editing position in the target structured query language file.
[0101] It should be noted that the execution process of steps 401 to 402 and steps 406 to 407 can be implemented in any way in the embodiments of the present disclosure, and the embodiments of the present disclosure do not limit this and will not be described in detail.
[0102] In summary, the current code sub-fragment is parsed to obtain a parsing result; in response to the parsing result indicating that the current code sub-fragment includes the first specified keyword, the target keyword area to which the current editing position belongs is determined to be the first specified keyword area; in response to the parsing result indicating that the current code sub-fragment includes the second specified keyword, the target keyword area to which the current editing position belongs is determined to be the second specified keyword area. Thus, the parsing result obtained by parsing the current code sub-fragment can accurately determine the target keyword area to which the current editing position belongs.
[0103] In order to accurately and quickly obtain multiple first similar code sub-segments similar to the first code sub-segment from the first code vector library, and obtain multiple second similar code sub-segments similar to the second code sub-segment from the second code vector library, in the embodiment of the present disclosure, according to the first code sub-segment, before querying the first code vector library associated with the first specified keyword to obtain multiple first similar code sub-segments similar to the first code sub-segment, it is necessary to generate the first code vector library and the second code vector library according to multiple reference structured query language files. Figure 5 Provide detailed explanation.
[0104] Figure 5 It is a flowchart of a method for processing a structured query language statement shown in the fifth embodiment of the present disclosure.
[0105] like Figure 5 As shown, the method for processing the structured query language statement includes the following steps:
[0106] Step 501: Acquire multiple reference structured query language files.
[0107] As an example, multiple reference structured query language files are obtained from a database; or multiple reference structured query language files are obtained from pre-written structured query language files.
[0108] Step 502 : for any reference structured query language file, segment the reference code in any reference structured query language file to obtain a plurality of reference code segments.
[0109] The reference code snippet is used to indicate a reference structured query language statement.
[0110] To facilitate code management and maintenance, as a possible implementation method, the reference code in any reference structured query language file is divided into multiple SQL statement code fragments, and each SQL statement code fragment is managed separately.
[0111] As an example, the reference code in any reference structured query language file is segmented according to SQL statements to obtain a plurality of reference code segments, wherein the reference code segment is used to indicate a reference SQL statement.
[0112] Step 503: Generate a first code vector library and a second code vector library according to a plurality of reference code fragments.
[0113] To facilitate code retrieval and management, as an example, for any reference code fragment, in response to any reference code fragment including a first specified keyword and a second specified keyword, any reference code fragment is segmented to obtain a first reference code sub-segment and a second reference code sub-segment of any reference code fragment; wherein the first reference sub-segment includes the first specified keyword and the second reference code sub-segment includes the second specified keyword; a mapping relationship between the first reference code sub-segment and the second reference code sub-segment of any reference code fragment is created; and a first code vector library and a second code vector library are generated according to the first reference code sub-segment and the second reference code sub-segment of each reference code fragment.
[0114] For example, taking the first designated keyword as "FORM" and the second designated keyword as "SELECT" as an example, for the reference code fragment corresponding to each reference SQL statement in the reference SQL file, when any reference code fragment includes the "FORM" keyword and the "SELECT" keyword, any reference code fragment is segmented to obtain a first reference code sub-segment containing the "FORM" keyword and a second reference code sub-segment containing the "SELECT" keyword. To facilitate subsequent retrieval, a mapping relationship needs to be established between the first reference code sub-segment containing the "FORM" keyword and the second reference code sub-segment containing the "SELECT" keyword in the same reference code fragment. Furthermore, a first code vector library and a second code vector library are generated based on the first reference code sub-segment and the second reference code sub-segment of each reference code fragment.
[0115] In order to facilitate code fuzzy identification and improve the subsequent code retrieval speed, the specific steps of generating the first code vector library and the second code vector library according to the first reference code sub-segment and the second reference code sub-segment of each reference code segment are as follows:
[0116] 1. For any reference code segment, respectively vectorize a first reference code sub-segment and a second reference code sub-segment of any reference code segment to obtain a first code vector and a second code vector corresponding to any reference code segment;
[0117] 2. The first code vector corresponding to each reference code segment is stored in a first code vector library, and the second code vector corresponding to each reference code segment is stored in a second code vector library.
[0118] In summary, by conducting in-depth analysis of multiple reference SQL files and segmenting the code in each file, multiple reference code fragments are obtained, and a first code vector library and a second code vector library are generated based on the multiple reference code fragments. This not only improves the accuracy of the code vector library, but also improves the code retrieval and management efficiency.
[0119] Based on any embodiment of the present disclosure, Figure 6 As shown, the method for processing the structured query language statement of the embodiment of the present disclosure can also be implemented based on the following steps:
[0120] A01. Split SQL fragments
[0121] As an example, the current database processing SQL file (reference SQL file) is preprocessed, all SQL files are segmented to obtain independent SQL fragments (reference code fragments), and each SQL fragment is further segmented into a "SELECT" part and a "FROM" part;
[0122] A02. These SQL fragments are vectorized respectively and stored in a vector database, which is divided into a "FROM" library (first code vector library) and a "SELECT" library (second code vector library). This part of the vector database will serve subsequent retrieval;
[0123] S01: When code completion is triggered, first obtain all the codes before the current trigger position of the current file (target SQL file), parse the code, and obtain the code fragment from the current code fragment to the current trigger position;
[0124] S02, syntax analysis, determining whether the trigger position is in the "SELECT" part or the "FROM" part, that is, determining the target keyword area to which the current editing position belongs;
[0125] S03. If it is in the "FROM" part (the first specified keyword area), then respectively obtain the "FROM" part (the first code sub-segment) and the "SELECT" part (the second code sub-segment) of the code fragment;
[0126] S04, using the “FROM” part, searching the “FROM” code base in the vector database, and recalling the top 3 “FROM” code fragments (multiple first similar code sub-fragments) similar to it from other code files;
[0127] S05, using the "SELECT" part, searching the "SELECT" code base in the vector database, and recalling the top 3 "SELECT" code fragments (multiple second similar code sub-fragments) similar to it from other code files;
[0128] S06. Since the FROM code needs to be completed now, the "SELECT" code fragment recalled in S05 is used to find the FROM code fragment where the fragment is located as the input for the next step;
[0129] S08. If the current trigger position is in the "SELECT" part, the SQL fragment is obtained, and the code content from the beginning of the fragment to the current completion position is obtained.
[0130] S09. Use the content of S08 to search the "SELECT" code base in the vector database, and recall the TOP3 "SELECT" code fragments (multiple third similar code sub-fragments) similar to it from other code files.
[0131] S07. Assembly context
[0132] For completions in the "FROM" part, the context consists of four parts, assembled in the following order:
[0133] (1) All code from the beginning of the file to the current code snippet
[0134] (2) S04 recalled “FROM” code snippet
[0135] (3) S06 recalled “FROM” code snippet
[0136] (4) Code from the current code snippet to the completion trigger position
[0137] For completions in the "SELECT" part, the context consists of three parts, assembled in the following order:
[0138] (1) All code from the beginning of the file to the current code snippet
[0139] (2) S09 recalled “SELECT” code snippet
[0140] (3) Code from the current code snippet to the completion trigger position
[0141] S10. Send the assembled context to the big model, which generates the following code to complete the code completion.
[0142] Corresponding to the method for processing structured query language statements provided in the above-mentioned embodiment, the present disclosure further provides a device for processing structured query language statements. Since the device for processing structured query language statements provided in the embodiment of the present disclosure corresponds to the method for processing structured query language statements provided in the above-mentioned embodiment, the implementation method of the method for processing structured query language statements is also applicable to the device for processing structured query language statements provided in the embodiment of the present disclosure, and will not be described in detail in the embodiment of the present disclosure.
[0143] Figure 7 It is a schematic diagram of the structure of a device for processing structured query language statements shown in the sixth embodiment of the present disclosure.
[0144] like Figure 7As shown, the structured query language statement processing device 700 includes: an acquisition module 710 , a first parsing module 720 , a second parsing module 730 , a generation module 740 and a processing module 750 .
[0145] Among them, the acquisition module 710 is used to obtain the current editing position from the target structured query language file in response to meeting the set code completion trigger condition during the code editing process of the target structured query language file; the first parsing module 720 is used to parse the code fragment between the code start position and the current editing position in the target structured query language file to obtain the current code sub-fragment to which the current editing position belongs; the second parsing module 730 is used to parse the current code sub-fragment to determine the target keyword area to which the current editing position belongs; the generation module 740 is used to generate the code to be completed according to the target keyword area and the current code sub-fragment; the processing module 750 is used to respond to the confirmation operation of the code to be completed, and use the code to be completed to complete the current editing position in the target structured query language file.
[0146] As a possible implementation manner of an embodiment of the present disclosure, a generation module 740 is used to obtain, in response to the target keyword area being a first specified keyword area, a first code sub-segment and a second code sub-segment associated with the current code sub-segment from the code fragment; wherein the first code sub-segment includes a first specified keyword, and the second code sub-segment includes a second specified keyword; based on the first code sub-segment, query a first code vector library associated with the first specified keyword to obtain a plurality of first similar code sub-segments similar to the first code sub-segment; based on the second code sub-segment, query a second code vector library associated with the second specified keyword to obtain a plurality of second similar code sub-segments similar to the second code sub-segment; and generate a code to be completed based on the plurality of first similar code sub-segments and the plurality of second similar code sub-segments.
[0147] As a possible implementation method of the embodiment of the present disclosure, the generation module 740 is used to query the first code vector library according to any second similar code sub-segment to obtain a first associated code sub-segment having a mapping relationship with any second similar code sub-segment; obtain the first remaining code sub-segment except the current code sub-segment from the code fragment; sequentially splice the first remaining code sub-segment, multiple first similar code sub-segments, each first associated code sub-segment and the current code sub-segment to obtain the first context information associated with the current code sub-segment; and generate the code to be completed according to the first context information.
[0148] As a possible implementation method of the embodiment of the present disclosure, a generation module 740 is used to obtain a prompt template, wherein the prompt template is used to indicate the task information to be executed by the large model; the prompt template is filled with the first context information to obtain the model prompt information; the model prompt information is input into the large model for processing to obtain the code to be completed.
[0149] As a possible implementation method of the embodiment of the present disclosure, a generation module 740 is used to query a second keyword code library in response to the target keyword area being a second designated keyword area, based on the current code sub-fragment, to obtain multiple third similar code sub-fragments similar to the current code sub-fragment; obtain second remaining code sub-fragments other than the current code sub-fragment from the code fragment; sequentially splice the second remaining code sub-fragment, multiple third similar code sub-fragments and the current code sub-fragment to obtain second context information associated with the current code sub-fragment; and input the second context information into the large model to obtain the code to be completed.
[0150] As a possible implementation method of the embodiment of the present disclosure, the second parsing module 730 is used to parse the current code sub-fragment to obtain a parsing result; in response to the parsing result indicating that the current code sub-fragment includes a first specified keyword, determine that the target keyword area to which the current editing position belongs is the first specified keyword area; in response to the parsing result indicating that the current code sub-fragment includes a second specified keyword, determine that the target keyword area to which the current editing position belongs is the second specified keyword area.
[0151] As a possible implementation of the embodiment of the present disclosure, the structured query language statement processing device 700 further includes: a segmentation module.
[0152] Among them, the acquisition module 710 is also used to obtain multiple reference structured query language files; the segmentation module is used to segment the reference code in any reference structured query language file to obtain multiple reference code fragments; wherein the reference code fragment is used to indicate a reference structured query language statement; the generation module 740 is used to generate a first code vector library and a second code vector library based on the multiple reference code fragments.
[0153] As a possible implementation method of an embodiment of the present disclosure, a generation module 740 is used to, for any reference code fragment, in response to any reference code fragment including a first specified keyword and a second specified keyword, segment any reference code fragment to obtain a first reference code sub-segment and a second reference code sub-segment of any reference code fragment; wherein the first reference sub-segment includes the first specified keyword and the second reference code sub-segment includes the second specified keyword; create a mapping relationship between the first reference code sub-segment and the second reference code sub-segment of any reference code fragment; and generate a first code vector library and a second code vector library according to the first reference code sub-segment and the second reference code sub-segment of each reference code fragment.
[0154] As a possible implementation method of the embodiment of the present disclosure, a generation module 740 is used to vectorize the first reference code sub-segment and the second reference code sub-segment of any reference code fragment, respectively, to obtain a first code vector and a second code vector corresponding to any reference code fragment; store the first code vector corresponding to each reference code fragment in a first code vector library, and store the second code vector corresponding to each reference code fragment in a second code vector library.
[0155] The structured query language statement processing device of the disclosed embodiment automatically obtains the current editing position by responding to the set code completion trigger condition, without the need for the user to manually locate the current editing position, and then parses the code fragment from the code start position to the current editing position to determine the current code sub-fragment, and parses the current code sub-fragment to determine the target keyword area to which the current editing position belongs, thereby accurately identifying the target keyword area to which the current editing position in the code belongs, and generating the code to be completed based on the target keyword area and the current code sub-fragment, thereby ensuring that the code to be completed is highly matched with the developer's writing intention, and improving the accuracy of the code to be completed. Finally, in response to the user's confirmation operation on the code to be completed, the code completion is completed, thereby improving the flexibility and accuracy of SQL code completion.
[0156] In an exemplary embodiment, an electronic device is also provided.
[0157] Among them, electronic equipment includes:
[0158] processor;
[0159] a memory for storing processor-executable instructions;
[0160] The processor is configured to execute instructions to implement the method for processing the structured query language statement proposed in any of the aforementioned embodiments.
[0161] As an example, Figure 8is a schematic diagram of the structure of an electronic device 800 shown in an exemplary embodiment of the present disclosure, such as Figure 8 As shown, the electronic device 800 may further include:
[0162] The memory 810 and the processor 820, a bus 830 connecting different components (including the memory 810 and the processor 820), the memory 810 stores a computer program, and when the processor 820 executes the program, the method for processing the structured query language statement described in the embodiment of the present disclosure is implemented.
[0163] Bus 830 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. For example, these architectures include but are not limited to Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus and Peripheral Component Interconnect (PCI) bus.
[0164] The electronic device 800 typically includes a variety of electronic device readable media. These media can be any available media that can be accessed by the electronic device 800, including volatile and non-volatile media, removable and non-removable media.
[0165] The memory 810 may also include computer system readable media in the form of volatile memory, such as random access memory (RAM) 840 and / or cache memory 850. The server 800 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 860 may be used to read and write non-removable, non-volatile magnetic media ( Figure 8 not shown, usually called a "hard drive"). Although Figure 8 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 830 via one or more data medium interfaces. The memory 810 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present disclosure.
[0166] A program / utility 880 having a set (at least one) of program modules 870 may be stored, for example, in the memory 810, such program modules 870 including but not limited to an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules 870 generally perform the functions and / or methods of the embodiments described in the present disclosure.
[0167] The electronic device 800 may also communicate with one or more external devices 890 (e.g., keyboard, pointing device, display 891, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 800, and / or may communicate with any device that enables the electronic device 800 to communicate with one or more other computing devices (e.g., network card, modem, etc.). Such communication may be performed via an input / output (I / O) interface 892. Furthermore, the electronic device 800 may also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN) and / or public network, such as the Internet) via a network adapter 893. As shown, the network adapter 893 communicates with other modules of the electronic device 800 via a bus 830. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 800, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0168] The processor 820 executes various functional applications and data processing by running the programs stored in the memory 810 .
[0169] It should be noted that the implementation process and technical principles of the electronic device of this embodiment refer to the aforementioned explanation of the method for processing the structured query language statement of the embodiment of the present disclosure, and will not be repeated here.
[0170] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory including instructions, and the above instructions can be executed by a processor of an electronic device to complete the method for processing a structured query language statement proposed in any of the above embodiments. Optionally, the computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0171] In an exemplary embodiment, a computer program product is also provided, including a computer program / instruction, characterized in that when the computer program / instruction is executed by a processor, the method for processing a structured query language statement proposed in any of the above embodiments is implemented.
[0172] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0173] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A method for processing a structured query language statement, characterized in that: include: In a process of code editing a target structured query language file, in response to satisfying a set code completion trigger condition, obtaining a current editing position from the target structured query language file; Parsing the code segment between the code start position and the current editing position in the target structured query language file to obtain the current code sub-segment to which the current editing position belongs; Parsing the current code sub-segment to determine the target keyword region to which the current editing position belongs; Generate a code to be completed according to the target keyword region and the current code sub-segment; In response to a confirmation operation on the code to be completed, the code to be completed is used to complete the current editing position in the target structured query language file.
2. The method according to claim 1, characterized in that The step of generating the code to be completed according to the target keyword region and the current code sub-segment includes: In response to the target keyword region being a first designated keyword region, acquiring a first code sub-segment and a second code sub-segment associated with the current code sub-segment from the code segment; wherein the first code sub-segment includes a first designated keyword, and the second code sub-segment includes a second designated keyword; According to the first code sub-segment, querying a first code vector library associated with the first designated keyword to obtain a plurality of first similar code sub-segments similar to the first code sub-segment; According to the second code sub-segment, querying a second code vector library associated with the second designated keyword to obtain a plurality of second similar code sub-segments similar to the second code sub-segment; The code to be completed is generated according to the multiple first similar code sub-segments and the multiple second similar code sub-segments.
3. The method according to claim 2, characterized in that The step of generating the code to be completed according to the plurality of first similar code sub-segments and the plurality of second similar code sub-segments comprises: According to any second similar code sub-segment, query the first code vector library to obtain a first associated code sub-segment having a mapping relationship with the any second similar code sub-segment; Acquire a first remaining code sub-segment except the current code sub-segment from the code segment; sequentially splicing the first remaining code sub-segments, the multiple first similar code sub-segments, each of the first associated code sub-segments, and the current code sub-segment to obtain first context information associated with the current code sub-segment; The code to be completed is generated according to the first context information.
4. The method according to claim 3, characterized in that The step of generating the code to be completed according to the first context information includes: Obtaining a prompt template, wherein the prompt template is used to indicate task information to be performed by the large model; Filling the prompt template with the first context information to obtain model prompt information; The model prompt information is input into the large model for processing to obtain the code to be completed.
5. The method according to claim 1, characterized in that The step of generating the code to be completed according to the target keyword region and the current code sub-segment includes: In response to the target keyword region being a second designated keyword region, querying a second keyword code library according to the current code sub-segment to obtain a plurality of third similar code sub-segments similar to the current code sub-segment; Acquire a second remaining code sub-segment except the current code sub-segment from the code segment; sequentially splicing the second remaining code sub-segments, the plurality of third similar code sub-segments, and the current code sub-segment to obtain second context information associated with the current code sub-segment; The second context information is input into the large model to obtain the code to be completed.
6. The method according to claim 1, characterized in that The parsing of the current code sub-segment to determine the target keyword region to which the current editing position belongs includes: Parsing the current code sub-segment to obtain a parsing result; In response to the parsing result indicating that the current code sub-segment includes a first designated keyword, determining that the target keyword region to which the current editing position belongs is the first designated keyword region; In response to the parsing result indicating that the current code sub-segment includes a second designated keyword, the target keyword region to which the current editing position belongs is determined to be the second designated keyword region.
7. The method according to claim 2, characterized in that Before querying a first code vector library associated with the first specified keyword according to the first code sub-segment to obtain a plurality of first similar code sub-segments similar to the first code sub-segment, the method further includes: obtaining a plurality of reference structured query language files; For any reference structured query language file, segment the reference code in the reference structured query language file to obtain a plurality of reference code segments; wherein the reference code segment is used to indicate a reference structured query language statement; The first code vector library and the second code vector library are generated according to the multiple reference code fragments.
8. The method according to claim 7, characterized in that The step of generating the first code vector library and the second code vector library according to the plurality of reference code fragments comprises: For any reference code segment, in response to the first designated keyword and the second designated keyword being included in the any reference code segment, the any reference code segment is segmented to obtain a first reference code sub-segment and a second reference code sub-segment of the any reference code segment; wherein the first reference sub-segment includes the first designated keyword, and the second reference code sub-segment includes the second designated keyword; Creating a mapping relationship between a first reference code sub-segment and a second reference code sub-segment of any reference code segment; The first code vector library and the second code vector library are generated according to the first reference code sub-segment and the second reference code sub-segment of each of the reference code segments.
9. The method according to claim 8, characterized in that The step of generating the first code vector library and the second code vector library according to the first reference code sub-segment and the second reference code sub-segment of each of the reference code segments comprises: For any reference code segment, respectively vectorize a first reference code sub-segment and a second reference code sub-segment of the any reference code segment to obtain a first code vector and a second code vector corresponding to the any reference code segment; The first code vector corresponding to each of the reference code segments is stored in the first code vector library, and the second code vector corresponding to each of the reference code segments is stored in the second code vector library.
10. A structured query language statement processing device, characterized in that: include: An acquisition module, configured to acquire a current editing position from the target structured query language file in response to satisfying a set code completion trigger condition during code editing of the target structured query language file; A first parsing module, configured to parse a code segment between a code start position and a current editing position in the target structured query language file to obtain a current code sub-segment to which the current editing position belongs; A second parsing module is used to parse the current code sub-segment to determine the target keyword area to which the current editing position belongs; A generating module, used for generating a code to be completed according to the target keyword region and the current code sub-segment; The processing module is used for, in response to a confirmation operation on the code to be completed, using the code to be completed to complete the code at the current editing position in the target structured query language file.