Code processing method and device, medium, equipment and product

By obtaining SQL code and location information, determining the database table and the code snippet submitted by the recall history, the problem of inaccurate SQL code completion in the existing technology is solved and the encoding efficiency is improved.

CN119988413APending Publication Date: 2025-05-13BEIJING VOLCANO ENGINE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510170710.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-14
Publication Date
2025-05-13

AI Technical Summary

Technical Problem

When performing data query in database tables in prior art, users need to write a large amount of SQL code, resulting in a large amount of encoding workload and inaccurate code completion, which affects coding efficiency.

Method used

By obtaining SQL code and location information, determine the database table referenced at the location that needs to be completed by code, and recall relevant code snippets in the historically submitted SQL code, including field names and parameters, to accurately complete the code.

Benefits of technology

It improves the accuracy of code completion, reduces the workload of users to write code, and improves coding efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119988413A_ABST
    Figure CN119988413A_ABST
Patent Text Reader

Abstract

The invention provides a code processing method and device, a medium, equipment and a product, and the method comprises the steps that a first SQL code and position information are obtained, and the position information is used for indicating the position, needing code completion, in the first SQL code; according to the first SQL code and the position information, determining a first database table referenced by the position needing to be subjected to code completion; a first code snippet is determined, the first code snippet is obtained according to a second SQL code, the second SQL code comprises a historically submitted SQL code quoting the first database table, and the first code snippet comprises names of fields in the first database table and parameters corresponding to the fields; and according to the first code snippet, determining a code for code completion at the position. Through the scheme, the problem that the field name and the parameter corresponding to the field in the code for completion are inaccurate can be avoided, and the accuracy of code completion is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of data processing technology, and in particular, to a code processing method, device, medium, equipment and product. Background Art

[0002] SQL (Structured Query Language) is a programming language for data query. In order to query data in a database table, users usually need to write SQL code to implement data query. At present, with the increase in data volume and the increase in database size, users need to write a large amount of SQL code to implement more complex data query operations. In the process of users writing SQL code, code completion can be automatically performed, that is, to complete part of the code that the user may continue to write later. Code completion can reduce the workload of users in writing code, thereby improving coding efficiency. Summary of the invention

[0003] This summary is provided to introduce concepts in a brief form that will be described in detail in the detailed description below. This summary is not intended to identify key features or essential features of the claimed technical solution, nor is it intended to limit the scope of the claimed technical solution.

[0004] In a first aspect, the present disclosure provides a code processing method, the method comprising: Acquire a first SQL code and position information, where the position information is used to indicate a position in the first SQL code where code completion is required; Determine, according to the first SQL code and the position information, a first database table referenced by the position where code completion is required; Determine a first code snippet, wherein the first code snippet is obtained according to a second SQL code, the second SQL code includes a historically submitted SQL code that references the first database table, and the first code snippet includes a name of a field in the first database table and a parameter corresponding to the field; According to the first code fragment, a code for performing code completion at the position is determined.

[0005] In a second aspect, the present disclosure provides a code processing device, the device comprising: An acquisition module, used for acquiring a first SQL code and position information, wherein the position information is used for indicating a position in the first SQL code where code completion is required; A first determination module, configured to determine, according to the first SQL code and the position information, a first database table referenced by a position where code completion is required; A second determination module is used to determine a first code fragment, wherein the first code fragment is obtained according to a second SQL code, the second SQL code includes a historically submitted SQL code that references the first database table, and the first code fragment includes a name of a field in the first database table and a parameter corresponding to the field; The third determining module is used to determine, according to the first code fragment, a code for performing code completion at the position.

[0006] In a third aspect, the present disclosure provides a computer-readable medium having a computer program stored thereon, which, when executed by a processing device, implements the steps of the code processing method provided in the first aspect of the present disclosure.

[0007] In a fourth aspect, the present disclosure provides an electronic device, including: a storage device having a computer program stored thereon; A processing device is used to execute the computer program in the storage device to implement the steps of the code processing method provided in the first aspect of the present disclosure.

[0008] In a fifth aspect, the present disclosure provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the code processing method provided in the first aspect of the present disclosure.

[0009] Through the above technical solution, the first database table referenced by the position where code completion is required is determined according to the first SQL code and the position information, and which database table is referenced at the position can be determined, so that the first code snippet associated with the first database table can be recalled. The first code snippet includes the name of the field in the first database table and the parameters corresponding to the field. The second SQL code has been submitted historically, so the first code snippet obtained according to the second SQL code can be used to query the first database table. The name of the field in the first code snippet and the parameters corresponding to the field are accurate. Code completion based on the first code snippet can avoid the problem of inaccurate field names and parameters corresponding to the fields in the code used for completion, thereby improving the accuracy of code completion.

[0010] Other features and advantages of the present disclosure will be described in detail in the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] 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. Throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale. In the drawings: Figure 1 The figure is a flowchart of a code processing method according to an exemplary embodiment.

[0012] Figure 2 The figure is a flowchart of a method for determining first code record information according to an exemplary embodiment.

[0013] Figure 3 The invention is a block diagram of a code processing device according to an exemplary embodiment.

[0014] Figure 4 A schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present disclosure is shown. DETAILED DESCRIPTION

[0015] 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.

[0016] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.

[0017] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.

[0018] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0019] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".

[0020] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.

[0021] It is understandable that before using the technical solutions disclosed in the embodiments of the present disclosure, the types, scope of use, usage scenarios, etc. of the personal information 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.

[0022] For example, in response to receiving an active request from a user, a prompt message is sent to the user to clearly prompt the user that the operation requested to be performed will require obtaining and using the user's personal information. Thus, the user can autonomously choose whether to provide personal information to software or hardware such as an electronic device, application, server, or storage medium that performs the operation of the technical solution of the present disclosure according to the prompt message.

[0023] As an optional but non-limiting implementation, in response to receiving an active request from the user, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. In addition, the pop-up window may also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.

[0024] It is understandable that the above notification and the process of obtaining user authorization are merely illustrative and do not constitute a limitation on the implementation of the present disclosure. Other methods that meet the relevant laws and regulations may also be applied to the implementation of the present disclosure.

[0025] At the same time, it is understandable that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) shall comply with the requirements of relevant laws, regulations and relevant provisions.

[0026] As described in the background technology, code completion can improve the efficiency of users writing codes. At present, the code that needs to be completed can be output through the code completion model. For example, the SQL code that the user has written on the code editing page and the metadata information of the database table associated with the SQL code can be input into the code completion model. The code completion model can infer based on the input information and output the code that needs to be completed. However, the code completed by the method in the related technology may not be accurate enough. For example, the enumeration value of the field in the metadata information of the database table is incomplete, the metadata information does not have parameter information and key (KEY) information of complex data types (such as json, struct), and the DDL (Data Definition Language) information of the database table in the metadata information is not updated in time, etc. These problems will lead to insufficient context information provided to the code completion model, and the user's intention cannot be accurately inferred, resulting in model hallucination.

[0027] For example, for function-type codes, take get_json_object(json_txt,path) as an example, get_json_object() is a function in SQL, json_txt is the name of the field in the database table, and path is the parameter of the function. The parameter path provided by the code completion model may be inaccurate. For conditional expressions, take column=value as an example, value is the parameter of the field column, and the parameter provided by the model may be inaccurate. Take gender as an example, the database table stores 0 and 1, 0 for female and 1 for male. The model may provide gender=female, and the gender value is not the actual value stored in the database table.

[0028] In view of this, the present disclosure provides a code processing method, apparatus, medium, device and product to improve the accuracy of code completion.

[0029] Figure 1 is a flowchart of a code processing method according to an exemplary embodiment, which can be applied to electronic devices with processing capabilities, such as servers, Figure 1 As shown, the method may include steps 11 to 14.

[0030] In step 11, the first SQL code and location information are obtained.

[0031] The location information is used to indicate the location in the first SQL code where code completion is required. In one embodiment, a user may write SQL code in a SQL code editor through a client, and the first SQL code may be the SQL code currently written by the user in the editor. A cursor may be displayed in the editor, and the location of the cursor is the location where the user continues to write code. The location information may be information about the location of the cursor, which is used to indicate the location where code completion is required. The client may send the first SQL code and the location information to the server, and the server may obtain the first SQL code and the location information.

[0032] In step 12, the first database table referenced by the position where code completion is required is determined according to the first SQL code and the position information.

[0033] In one embodiment, the server may generate an Abstract Syntax Tree (AST) corresponding to the first SQL code, and based on the abstract syntax tree and position information, parse out the first database table referenced by the location where code completion is required. The abstract syntax tree is one of the data structures commonly used by compilers and interpreters. It represents the syntax structure of the program source code and parses the code into a tree structure, in which each node represents a syntax element of the code (such as a statement, expression, function, etc.). Taking the following SQL code 1 as an example, XX represents the cursor position, that is, the location where code completion is required. The location references the database table db.table_a, which can be used as the first database table.

[0034] SELECT * FROM db.table_a AS a WHERE a.AAXX In step 13, a first code segment is determined.

[0035] The first code snippet is obtained based on the second SQL code, and the second SQL code includes the SQL code that references the first database table and was submitted historically. The number of second SQL codes can be multiple, and each second SQL code can be a complete SQL code. If the first database table is referenced in the second SQL code, then there is a code snippet associated with the first database table, so the first code snippet can be parsed based on the second SQL code, and the first code snippet includes the name of the field in the first database table and the parameters corresponding to the field. The second SQL code can be a complete code that was submitted historically and can run normally, so the name of the field obtained from the second SQL code and the parameters corresponding to the field are accurate and can be used to query in the first database table.

[0036] For example, from the second SQL code, the first code fragment parsed is AA>3, AA is the name of the field in the first database table, and 3 is the parameter corresponding to the field. According to AA>3, the data of the field AA can be queried, so the parameter corresponding to the field is accurate. For example, from the second SQL code, the first code fragment parsed is BB=10, BB is the name of the field in the first database table, and 10 is the parameter corresponding to the field BB. Since the second SQL code has been submitted historically, the parameter 10 exists under the field BB.

[0037] It should be noted that the SQL code examples, the first code snippet examples, and the parameter examples provided in the present disclosure are only for explanation and do not constitute a limitation on the implementation methods. For example, in actual applications, the form of parameters is not limited to the digital type.

[0038] In step 14, a code for performing code completion at the position is determined according to the first code fragment.

[0039] In one embodiment, the first code snippet and the first SQL code can be input into a pre-trained code completion model to obtain the code that needs to be completed output by the model. The first code snippet can be used as context information and reasoning basis for the code completion model, thereby providing accurate context information for the code completion model, avoiding model hallucinations, and improving the accuracy of code completion.

[0040] In one embodiment, the position that needs to be completed, relative to the incomplete part of the first code snippet, can be used as the code that needs to be completed. Taking the position that needs to be completed in the above SQL code 1 as an example, for example, the first code snippet is AA>3, then the code that needs to be completed is: >3.

[0041] After determining the code for completion, the server may send the code to the client. In one embodiment, the client may directly complete the code, that is, display it at the location where the code completion is required. In another embodiment, the client may display the code as recommendation information in the code recommendation area, and complete the code in response to the user selecting the code.

[0042] Through the above technical solution, the first database table referenced by the position where code completion is required is determined according to the first SQL code and the position information, and which database table is referenced at the position can be determined, so that the first code snippet associated with the first database table can be recalled. The first code snippet includes the name of the field in the first database table and the parameters corresponding to the field. The second SQL code has been submitted historically, so the first code snippet obtained according to the second SQL code can be used to query the first database table. The name of the field in the first code snippet and the parameters corresponding to the field are accurate. Code completion based on the first code snippet can avoid the problem of inaccurate field names and parameters corresponding to the fields in the code used for completion, thereby improving the accuracy of code completion.

[0043] The code processing method provided by the present disclosure may also include: According to the first SQL code and the position information, first type information is determined, where the first type information is used to indicate that the position where code completion is required corresponds to a conditional clause or a selection clause.

[0044] Among them, the selection clause includes the SELECT clause, and the conditional clause includes the WHERE clause, WHEN clause, HAVING clause and other clauses used to limit data screening conditions and filtering conditions.

[0045] For example, the server may parse the first type of information according to the position information and the abstract syntax tree corresponding to the first SQL code. For example, if the position to be completed is in the SELECT clause, it may be determined that the first type of information is used to indicate the selection clause, and if the position to be completed is in the WHERE clause, the CASE WHEN clause, or the HAVING clause, it may be determined that the first type of information is used to indicate the conditional clause.

[0046] Taking the above SQL code 1 as an example, the position where code completion is required corresponds to the WHERE clause, that is, the conditional clause, and it can be determined that the first type of information is information used to indicate the conditional clause.

[0047] Taking the following SQL code 2 as an example, XX indicates the cursor position, that is, the position where code completion is required. The position references the database table db.table_b, which can be used as the first database table. The position corresponds to the SELECT clause, that is, the selection clause. It can be determined that the first type of information is used to indicate the selection clause.

[0048] SELECT get_json_object(json_txt,XX) FROM db.table_b In one embodiment, the step of determining the first type of information according to the first SQL code and the location information may be performed before step 12, after step 12 and before step 13, or simultaneously with step 12 without limitation.

[0049] In step 13, determining the first code segment may include: A candidate code fragment corresponding to a field in the first database table is obtained, wherein the candidate code fragment corresponding to the field includes a code fragment that references the field and has type information that is the same as the first type information, and the candidate code fragment is obtained according to the second SQL code.

[0050] Among them, the type information of the code snippet is used to indicate that the code snippet corresponds to a conditional clause or a selection clause. For example, the first type information indicates a conditional clause, and the first database table includes fields AA and BB. The candidate code snippets corresponding to field AA include, for example, AA>3, AA>5, and AA<2, and the candidate code snippets corresponding to field BB include, for example, BB=10, BB>9, and BB>8. For example, the first type information indicates a selection clause, and the first database table includes fields json_txt and map. The candidate code snippets corresponding to field json_txt include, for example, get_json_object(json_txt,path1) and get_json_object(json_txt,path2), and the candidate code snippets corresponding to field map include, for example, map[params1] and map[params2].

[0051] Afterwards, a first code segment is determined from candidate code segments corresponding to the field. The first code segment may be determined from candidate code segments corresponding to a plurality of fields.

[0052] In the case where the first type of information indicates a conditional clause, the first code snippet also includes an SQL operator, and the SQL operation refers to a predicate operator used to limit the query condition, such as >, >=, <, <=, !=, IN, etc. In this case, the first code snippet can be a predicate expression. If the first code snippet does not make a function call, the first code snippet may include an SQL operator, the name of a field in the first database table, and the parameters corresponding to the field. If the first code snippet has a function call, the first code snippet may include the function name, the SQL operator, the name of a field in the first database table, and the parameters corresponding to the field. For example, the first code snippet is COALESCE(condition_name1,")!=", the function name is COALESCE, the operator is !=, the name of the field is condition_name1, and the parameter corresponding to the field can be an empty string.

[0053] In the case where the first type information indicates a selection clause and there is a function call in the first code snippet, the first code snippet also includes the function name. For example, get_json_object(json_txt,path2) has the function name get_json_object, the field name is json_txt, and the parameter corresponding to the field is path2. If the first type information indicates a selection clause and there is no function call in the first code snippet, the first code snippet may include the name of the field and the parameter corresponding to the field. For example, the first code snippet is map[params1], where map is the name of the field, the field stores data of the data type map, and params1 is the parameter corresponding to the field.

[0054] The first code snippet in the present disclosure can be a complete expression, such as a function expression, including a function name, a field name and parameters, such as a predicate expression, including an operator, a field name and parameters, and taking into account the reference relationship between the first code snippet and the database table, the determined first code snippet is compatible with the referenced first database table, and the first code snippet can represent complete SQL semantics. The code used for completion is determined based on the first code snippet to improve the accuracy of code completion.

[0055] The following describes the process of generating code record information in the present disclosure. Figure 2 is a flow chart showing a method for determining first code record information according to an exemplary embodiment. Figure 2 As shown, it includes steps 21 to 23.

[0056] In step 21, a third SQL code is obtained.

[0057] The third SQL code may be a historically submitted SQL code, and the number of the third SQL code is multiple, and the multiple third SQL codes may include the second SQL code. Each third SQL code may be a complete code that is historically submitted and can run normally.

[0058] In step 22, the second code record information corresponding to each third SQL code is determined respectively.

[0059] The implementation method of step 22 may be: for each third SQL code, generate an abstract syntax tree corresponding to the third SQL code, parse the abstract syntax tree, and obtain the second code record information corresponding to the third SQL code.

[0060] The method of generating the abstract syntax tree corresponding to the third SQL code may refer to the relevant technology, the abstract syntax tree may represent the structured data in the third SQL code, and the second code record information corresponding to the third SQL code may be parsed according to the data of each node in the abstract syntax tree. In the present disclosure, the code record information may include a code snippet, type information of the code snippet, and the name of a database table referenced by the code snippet.

[0061] As shown in the following Table 1, the second code record information corresponding to the third SQL code 1 is parsed according to the third SQL code 1 submitted by the user 1 in the past.

[0062] Table 1

[0063] The first column is the row number. The second column is the name of the database table referenced by the code snippet. The third column is the code snippet. The fourth column is the type information of the code snippet, where pre indicates that the type information indicates a conditional clause, and exp indicates that the type information indicates a selection clause. The fifth column is the name of the field referenced by the code snippet. The sixth column is the information of user 1 who submitted the third SQL code 1, for example, it may be the identification information of user 1 (such as user ID). The seventh column is the information of the business department to which user 1 belongs, for example, it may be the identification information of the business department (such as department name, department ID). The eighth column is the information of the project to which the third SQL code 1 belongs, for example, it may be the identification information of the project (such as project name, project ID). The ninth column is the time when user 1 submitted the third SQL code 1, where the submission time is a date as an example, and may also be represented by specific hours, minutes, etc.

[0064] It should be noted that the examples of code record information provided in the present disclosure are only for subsequent explanations, in which line number, field name, user information, department information, project information, submission time, and other information are optional and are not used to limit the code record information to include such information.

[0065] As shown in the following Table 2, the second code record information corresponding to the third SQL code 2 is parsed according to the third SQL code 2 submitted by the user 1 in the past.

[0066] Table 2

[0067] As shown in the following Table 3, the second code record information corresponding to the third SQL code 3 is parsed according to the third SQL code 3 submitted by the user 2 in the past.

[0068] Table 3

[0069] In step 23, according to the second code record information corresponding to each third SQL code, an aggregation operation is performed on the second code record information according to a preset dimension to obtain first code record information corresponding to the preset dimension.

[0070] The aggregation operation includes: aggregating the second code record information corresponding to different third SQL codes and having the same preset dimension into one piece of code record information. The preset dimension includes a first preset dimension and / or at least one second preset dimension.

[0071] An implementation method of performing aggregation operation according to a first preset dimension is introduced. The first preset dimension includes a code snippet and a database table name, and the aggregation operation includes aggregating the second code record information in which the code snippet and the database table name are the same into one code record information.

[0072] As shown in Table 1, Table 2 and Table 3, the first second code record information corresponding to the third SQL code 1 (the first row in Table 1), the first second code record information corresponding to the third SQL code 2 (the first row in Table 2), and the first second code record information corresponding to the third SQL code 3 (the first row in Table 3) all have code snippets of AA>3, and the names of the database tables are all db.table_a, that is, the first preset dimensions of the three second code record information are the same, and the three second code record information can be aggregated into one code record information. Table 4 below is the result of aggregation according to the first preset dimension. Table 4 shows the first code record information corresponding to the first preset dimension. For example, the first first code record information in Table 4 has a usage count of 3 for the code snippet AA>3, which is the number of aggregated second code record information. The usage count can also represent the number of times the code snippet AA>3 is used globally without distinguishing between users, departments and projects. The submission time corresponding to the code snippet AA>3 is the latest time among the three aggregated second code record information, that is, the submission time of the third SQL code 3.

[0073] Table 4

[0074] The second second code record information corresponding to the third SQL code 1 (the second row in Table 1) and the second second code record information corresponding to the third SQL code 3 (the second row in Table 3) have code snippets of AA>5, and the names of the database tables are both db.table_a. The first preset dimensions of these two second code record information are the same, and they are aggregated into one code record information, as shown in the second first code record information in Table 4, wherein the number of uses and submission time in this first code record information can refer to the above explanation.

[0075] The other first code record information in Table 4 is not obtained through the aggregation operation, the number of times used is 1, and the submission time is the submission time of the corresponding third SQL code.

[0076] An implementation method of performing aggregation operations according to a second preset dimension is introduced. The second preset dimension includes first code association information, a code snippet, and a name of a database table, and the first code association information is one of the following: information of a first user who submits a third SQL code, information of a business department to which the first user belongs, and information of a project to which the third SQL code belongs.

[0077] Taking the information of the first user who submitted the third SQL code as the first code association information as an example, as shown in Table 1 and Table 2, the first second code record information corresponding to the third SQL code 1 (the first row in Table 1) and the first second code record information corresponding to the third SQL code 2 (the first row in Table 2), the code fragments are all AA>3, the names of the database tables are all db.table_a, and the user information is all user 1, that is, the second preset dimension of these two second code record information is the same, and these two second code record information can be aggregated into one code record information. Table 5 below is the result of aggregation according to the second preset dimension, which is the first code record information corresponding to the second preset dimension. For example, the first first code record information in Table 5 has a usage count of 2 for the code fragment AA>3, which can represent the number of times user 1 has used the code fragment AA>3. The method for determining the submission time can refer to the above description. In addition, since only the embodiment of the second code record information corresponding to the third SQL code 3 submitted by user 2 in history is given, the code record information corresponding to user 2 is not aggregated in the results shown in Table 5.

[0078] Table 5

[0079] In the present disclosure, there is no limit on the number of second preset dimensions. For example, if the first code-related information is information about a business department, an aggregation operation can be performed based on the information about the business department to obtain the first code record information corresponding to the second preset dimension. For example, if the first code-related information is information about a project, an aggregation operation can be performed based on the information about the project to obtain the first code record information corresponding to the second preset dimension. For example, the code record information in Table 2 and Table 3 with the same code snippet, database table name, and project information can be aggregated.

[0080] Through the above technical solution, the second code record information with the same preset dimension can be aggregated into one code record information, which can avoid the existence of repeated second code record information with the same preset dimension. In addition, the number of times the code snippet is used in different dimensions and the latest submission time of the code snippet can be counted, which can reflect the utilization rate of the code snippet, thereby providing a basis for completing the code.

[0081] In this disclosure, the candidate code snippets corresponding to the fields are obtained in the following manner: Acquire first code record information, wherein the first code record information is obtained according to third SQL codes submitted historically, the number of third SQL codes is multiple, the multiple third SQL codes include the second SQL code, and the code record information includes a code snippet, type information of the code snippet, and a name of a database table referenced by the code snippet; According to the first code record information, a candidate code segment corresponding to the field is determined.

[0082] For example, if the first database table is db.table_a, the third SQL code 1, the third SQL code 2 and the third SQL code 3 mentioned above can also be used as the second SQL code. For example, if the first database table is db.table_b, the third SQL code 1 can be used as the second SQL code.

[0083] The first code record information stores a code snippet, i.e., a complete SQL expression, and stores type information of the code snippet and the name of the referenced database table, so that a code snippet matching the type information of the code currently to be completed and the referenced first database table can be recalled from the first code record information, thereby providing a basis for code completion.

[0084] In one implementation, determining the candidate code segment corresponding to the field according to the first code record information may include: If the preset dimensions include a first preset dimension, the first code recording information corresponding to the first preset dimension that satisfies a first condition is used as the third code recording information corresponding to the first preset dimension, and the first condition includes: the name of the database table is the name of the first database table, and the type information of the code snippet is the same as the first type information.

[0085] Taking the first code record information corresponding to the first preset dimension shown in Table 4 as an example, for example, the first database table is db.table_a, and the first type information indicates a conditional clause, then the first 5 rows of first code record information in Table 4 can be used as the third code record information corresponding to the first preset dimension.

[0086] In this way, the code snippet in the third code record information is matched with the first database table and the first type of information, so that the candidate code snippet corresponding to the field is determined according to the third code record information, ensuring that the candidate code snippet is consistent with the user's code writing intention.

[0087] If the preset dimension includes a second preset dimension, the first code record information corresponding to the second preset dimension that satisfies the second condition is used as the third code record information corresponding to the second preset dimension, and the second condition includes: the name of the database table is the name of the first database table, the type information of the code snippet is the same as the first type information, and the first code association information is the same as the corresponding second code association information.

[0088] The second code association information is one of the following: information of the second user who wrote the first SQL code, information of the business department to which the second user belongs, and information of the project to which the first SQL code belongs. The second code association information can be obtained in advance based on the information input by the user. Taking the first code record information corresponding to the second preset dimension shown in Table 5 as an example, the first code association information in the second preset dimension is the information of the first user who submitted the third SQL code, and the corresponding second code association information is the information of the second user who submitted the first SQL code. For example, if the second user is user 1, the first three rows of the first code record information in Table 5 can be used as the third code record information corresponding to the second preset dimension.

[0089] In addition, if an aggregation operation is performed in advance based on the information of the business department to obtain the first code record information corresponding to the second preset dimension, the third code record information corresponding to the second preset dimension can be determined through the information of the business department to which the second user belongs. If an aggregation operation is performed in advance based on the information of the project to obtain the first code record information corresponding to the second preset dimension, the third code record information corresponding to the second preset dimension can be determined through the information of the project to which the first SQL code belongs.

[0090] In this way, for example, based on the information of the second user, the third code record information that meets the conditions is determined, and the code snippets that the second user has submitted historically can be recalled. The third code record information is determined based on the information of the second user's business department, and the code snippets that the business department has submitted historically can be recalled. The third code record information is determined based on the information of the project to which the first SQL code belongs, and the code snippets that the project has submitted historically can be recalled. Since these historically submitted code snippets are likely to be reused by the second user at present, and the code snippets match the first database table and the first type of information, the candidate code snippets can be made consistent with the user's code writing intention.

[0091] Afterwards, the candidate code snippet corresponding to the field is determined according to the third code record information. The third code record information also includes the number of times the code snippet is used and / or the submission time of the corresponding third SQL code, wherein the method for determining the number of times used and the submission time has been described above. If sorting is performed only according to the number of times used, it can be sorted in descending order from most to least, and those with the same number of times used can be sorted randomly. If sorting is performed only according to the submission time, it can be sorted in descending order from late to early submission time, and those with the same submission time can be sorted randomly. If sorting is performed according to both the number of times used and the submission time, it can be sorted in descending order from most to least first, and those with the same number of times used can be sorted in descending order from late to early submission time.

[0092] In the case where the third code record information corresponds to a preset dimension, the code snippets that reference the field in the third code record information corresponding to the preset dimension are sorted according to the number of uses and / or submission time; if the number of code snippets that reference the field is greater than a first preset number, the first preset number of code snippets sorted in front are used as candidate code snippets corresponding to the field.

[0093] Among them, taking the third code record information corresponding to the first preset dimension as an example, referring to the code record information of the first 5 rows in Table 4, taking field AA as an example, the code snippets referencing the field AA include the code snippets in the first 3 rows. If the first preset number threshold is 2, the code snippets AA>3 and AA>5 can be used as candidate code snippets corresponding to field AA according to the number of uses. If the first preset number is 4, the code snippets AA>3, AA>5 and AA>9 can all be used as candidate code snippets corresponding to field AA. The determination method of candidate code snippets for other fields is similar.

[0094] In the case where the third code recording information corresponds to N preset dimensions, if there are repeated code fragments, a deduplication operation is performed. The repeated code fragments are code fragments that exist in the third code recording information corresponding to the n preset dimensions respectively. The deduplication operation includes deleting the third code recording information of the repeated code fragments corresponding to n-1 preset dimensions, N≥2, 2≤n≤N.

[0095] N preset dimensions are set with different priorities, and n-1 preset dimensions are preset dimensions with low priorities among the n preset dimensions. For example, the first preset dimension is the global dimension, and the second preset dimension includes the user dimension, the business department dimension, and the project dimension. The priorities can be preset from high to low as follows: user dimension>business department dimension>project dimension>global dimension.

[0096] If the third code record information corresponds to multiple preset dimensions, there may be repeated code fragments. Referring to Table 4 and Table 5, including the third code record information corresponding to two preset dimensions, wherein the code fragments AA>3, AA>5 and BB=7 are repeated code fragments. Taking AA>3 as an example, the priority of the preset dimension corresponding to Table 4 is low, and the third code record information of the first row in Table 4 can be deleted. For example, the code fragment AA>3 exists in the third code record information corresponding to the user dimension, business department dimension, project dimension and global dimension respectively, and the user dimension has the highest priority. Then delete the third code record information of the code fragment AA>3 corresponding to the business department dimension, project dimension and global dimension respectively, and only retain the code fragment corresponding to the user dimension.

[0097] According to the third code record information after the deduplication operation, the candidate code fragment corresponding to the field is determined, so that it can be ensured that after the deduplication operation, there are no repeated code fragments in the third code record information corresponding to different preset dimensions.

[0098] For example, determining the candidate code snippet corresponding to the field according to the third code record information after the deduplication operation includes: For each preset dimension of the N preset dimensions, in the third code record information after the deduplication operation corresponding to the preset dimension, the code snippets referencing the field are sorted according to the number of uses and / or submission time; The third code record information after the deduplication operation corresponding to each of the N preset dimensions is traversed in order from high to low priority, and from the third code record information corresponding to the currently traversed preset dimension, according to the sorting result of the code snippets, the code snippet referencing the field is extracted as the candidate code snippet corresponding to the field, until the number of candidate code snippets reaches a first preset number, or the third code record information corresponding to each of the N preset dimensions has been traversed.

[0099] Taking field AA as an example, referring to Table 4, after the deduplication operation, the code snippet referencing field AA is AA>9. Referring to Table 5, the code snippets referencing field AA include AA>3 and AA>5, and the sorting result is AA>3 first and AA>5 last. The second preset dimension has a high priority. First, for Table 5, if the first preset number is 1, the candidate code snippet corresponding to field AA is AA>3, and the traversal stops. If the first preset number is 3, after extracting two candidate code snippets from Table 5, then for Table 4, the candidate code snippet AA>9 is extracted. Taking field SS as an example, the third code record information in Table 5 does not include the code snippet referencing field SS. The code snippet SS<9 can be extracted from Table 4 as the candidate code snippet for field SS.

[0100] Through the above technical scheme, the candidate code snippets corresponding to each field can be determined, and the candidate code snippets can be determined based on the number of times used and / or the submission time. Code snippets with a large number of uses and code snippets with a late submission time are more likely to be reused by users, which can make the determined candidate code snippets more in line with user needs and improve the accuracy of code completion.

[0101] The following describes an implementation method of determining a first code snippet from candidate code snippets corresponding to a field in the present disclosure.

[0102] In one embodiment, if there is a written second code snippet in the first SQL code, and there is field information at the location where code completion is required, the first code snippet is determined based on other code snippets except the second code snippet among the candidate code snippets corresponding to the field matching the field information.

[0103] For example, the field information includes all or part of the name of the field in the referenced first database table, and the type information of the second code snippet is the same as the first type information and the referenced database table is the first database table. That is, the second code snippet includes a code snippet that has been written in the first SQL code, references the first database table, and has the type information of the first type information, and there can be one or more. The server can parse whether there is a written second code snippet in the first SQL code and whether there is field information at the location where code completion is required based on the location information and the abstract syntax tree of the first SQL code. Taking the following SQL code as an example, XX in the SQL code indicates the position of the cursor, that is, the position where code completion is required.

[0104] WHERE a.condition_naXX AND a.condition_name2<100 Wherein, there is field information "condition_na" at the position where code completion is required, and the field information is part of the name of the field in the first database table. There is a written second code snippet condition_name2<100 in the first SQL code. For example, the field that matches the field information may be a field that includes the field information, for example, the field that matches the field information "condition_na" may include condition_name1 and condition_name2. The first code snippet can be determined from the candidate code snippets corresponding to condition_name2, other code snippets except condition_name2<100, and the candidate code snippets corresponding to condition_name1, for example, all of these candidate code snippets are used as the first code snippet, or part of these candidate code snippets can be used as the first code snippet. For example, the above introduces a method for sorting code snippets, and the sorting result can be maintained when extracting candidate code snippets, for example, the code snippet that is ranked in the front preset number of other code snippets corresponding to condition_name2 is used as the first code snippet, and the code snippet that is ranked in the front preset number of candidate code snippets corresponding to condition_name1 is used as the first code snippet. There is no restriction on the method of determining the first code snippet.

[0105] It is worth noting that, taking the SQL code as an example, when the user writes a.condition_name2<100, the server can determine the candidate code snippets corresponding to the fields in the database table db.table_a, such as the candidate code snippets corresponding to the field condition_name1, the candidate code snippets corresponding to the field condition_name2, and the candidate code snippets corresponding to other fields. The server can cache these candidate code snippets. When code completion is currently required, the candidate code snippets corresponding to the fields of the database table db.table_a can be obtained from the cache without re-executing the step of determining the candidate code snippets corresponding to each field. If the second code snippet condition_name2<100 does not exist in the SQL code, the server can execute the step of determining the candidate code snippet corresponding to the field in real time. That is, the candidate code snippet corresponding to the field can be determined in real time or obtained from the cache.

[0106] In one embodiment, if there is field information at the location where code completion is required and there is no written second code snippet in the first SQL code, the first code snippet is determined based on the candidate code snippet corresponding to the field matching the field information.

[0107] Take the following SQL code as an example. The XX in the SQL code indicates the location where code completion is required.

[0108] SELECT get_json_object(json_txt,XX) FROM db.table_a AS a Among them, there is field information "json_txt" at the position where code completion is required, and the written second code snippet does not exist in the first SQL code. For the code snippet with a function name, for example, there is a function name get_json_object here, all or part of the candidate code snippet with the function name in the candidate code snippet corresponding to the field json_txt can be used as the first code snippet.

[0109] In one embodiment, if there is a written second code snippet in the first SQL code and there is no field information at the location where code completion is required, the first code snippet is determined from other code snippets in the candidate code snippets except the second code snippet.

[0110] Take the following SQL code as an example, where XX indicates the location where code completion is required.

[0111] WHERE XX AND a.condition_name2<100 Among them, there is no field information at the position where code completion is required, and there is a written second code fragment condition_name2<100 in the first SQL code. The first code fragment can be determined from the candidate code fragments corresponding to multiple fields of the database table db.table_a, except for condition_name2<100. For example, all or part of the other code fragments can be used as the first code fragment.

[0112] Through the above technical solution, since the user has already written the second code snippet, it is generally not necessary to write it again. In order to avoid invalid recommendations and completion, the second code snippet may not be used as the first code snippet. If the user has already written field information at the location that needs to be completed, the first code snippet can be determined based on the candidate code snippet corresponding to the field that matches the field information, which is more in line with the user's code writing intention and has higher accuracy in code completion.

[0113] Based on the same inventive concept, the present disclosure also provides a code processing device, Figure 3 is a block diagram of a code processing device according to an exemplary embodiment. Figure 3As shown, the code processing device 30 may include: An acquisition module 31 is used to acquire a first SQL code and position information, where the position information is used to indicate a position in the first SQL code where code completion is required; A first determination module 32, configured to determine, according to the first SQL code and the position information, a first database table referenced by a position requiring code completion; A second determining module 33 is used to determine a first code fragment, wherein the first code fragment is obtained according to a second SQL code, the second SQL code includes a historically submitted SQL code that references the first database table, and the first code fragment includes a name of a field in the first database table and a parameter corresponding to the field; The third determining module 34 is used to determine, according to the first code fragment, a code for performing code completion at the position.

[0114] Optionally, the device 30 further includes: A fourth determination module, configured to determine first type information according to the first SQL code and the position information, wherein the first type information is used to indicate that the position requiring code completion corresponds to a conditional clause or a selection clause; The second determining module 33 includes: A first acquisition submodule is used to acquire candidate code snippets corresponding to fields in the first database table, wherein the candidate code snippets corresponding to the fields include code snippets that reference the fields and whose type information is the same as the first type information, and the candidate code snippets are obtained according to the second SQL code; A first determination submodule is used to determine the first code snippet from the candidate code snippets corresponding to the field, wherein, when the first type information indicates the conditional clause, the first code snippet also includes a SQL operator, and when the first type information indicates the selection clause and there is a function call in the first code snippet, the first code snippet also includes a function name.

[0115] Optionally, the candidate code snippet corresponding to the field is obtained through the following module: A first acquisition module is used to acquire first code record information, wherein the first code record information is obtained according to third SQL codes submitted historically, the number of the third SQL codes is multiple, the multiple third SQL codes include the second SQL code, and the code record information includes a code snippet, type information of the code snippet, and a name of a database table referenced by the code snippet; A fragment determination module is used to determine the candidate code fragment corresponding to the field according to the first code record information.

[0116] Optionally, the first code record information is obtained through the following module: A second acquisition module, used to acquire the third SQL code; An information determination module, used to respectively determine the second code record information corresponding to each of the third SQL codes; an aggregation module, configured to perform an aggregation operation on the second code record information according to a preset dimension according to the second code record information respectively corresponding to each of the third SQL codes, so as to obtain the first code record information corresponding to the preset dimension; The aggregation operation includes: aggregating the second code record information corresponding to different third SQL codes and having the same preset dimension into one piece of code record information; The preset dimension includes a first preset dimension and / or at least one second preset dimension, the first preset dimension includes the code snippet and the name of the database table, the second preset dimension includes first code association information, the code snippet and the name of the database table, the first code association information is one of the following: information of the first user who submits the third SQL code, information of the business department to which the first user belongs, and information of the project to which the third SQL code belongs.

[0117] Optionally, the fragment determination module includes: a second determining submodule, configured to, if the preset dimension includes the first preset dimension, use the first code record information that satisfies a first condition in the first code record information corresponding to the first preset dimension as the third code record information corresponding to the first preset dimension, wherein the first condition includes: the name of the database table is the name of the first database table, and the type information of the code snippet is the same as the first type information; a third determining submodule, configured to, if the preset dimension includes the second preset dimension, use the first code record information that satisfies a second condition in the first code record information corresponding to the second preset dimension as the third code record information corresponding to the second preset dimension, wherein the second condition includes: the name of the database table is the name of the first database table, the type information of the code snippet is the same as the first type information, and the first code association information is the same as the corresponding second code association information, and the second code association information is one of the following: information of a second user who writes the first SQL code, information of a business department to which the second user belongs, and information of a project to which the first SQL code belongs; The fourth determining submodule is used to determine the candidate code segment corresponding to the field according to the third code record information.

[0118] Optionally, the third code record information further includes the number of times the code snippet is used and / or the submission time of the corresponding third SQL code; The fourth determining submodule includes: The fifth determination submodule is used to sort the code snippets that reference the field in the third code record information corresponding to the preset dimension according to the number of uses and / or the submission time, when the third code record information corresponds to one of the preset dimensions; if the number of the code snippets that reference the field is greater than a first preset number, then the first preset number of the code snippets that are sorted in front are used as the candidate code snippets corresponding to the field.

[0119] Optionally, the fourth determining submodule includes: a processing submodule, configured to perform a deduplication operation if there are repeated code snippets when the third code record information corresponds to N preset dimensions, wherein the repeated code snippets are code snippets that exist simultaneously in the third code record information corresponding to the n preset dimensions respectively, and the deduplication operation includes deleting the third code record information of the repeated code snippets corresponding to n-1 preset dimensions, N≥2, 2≤n≤N, the N preset dimensions are set with different priorities, and the n-1 preset dimensions are preset dimensions with low priorities among the n preset dimensions; The sixth determination submodule is used to determine the candidate code segment corresponding to the field according to the third code record information after the deduplication operation.

[0120] Optionally, the third code record information further includes the number of times the code snippet is used and / or the submission time of the corresponding third SQL code; The sixth determining submodule comprises: a sorting submodule, configured to sort, for each of the N preset dimensions, the code snippets referencing the field in the third code record information after the deduplication operation corresponding to the preset dimension according to the number of uses and / or the submission time; An extraction submodule is used to traverse the third code record information after the deduplication operation corresponding to the N preset dimensions respectively in order of priority from high to low, and from the third code record information corresponding to the preset dimension currently traversed, according to the sorting result of the code snippets, extract the code snippet that references the field as the candidate code snippet corresponding to the field, until the number of the candidate code snippets reaches a first preset number, or the third code record information corresponding to the N preset dimensions has been traversed.

[0121] Optionally, the information determination module is used to: For each of the third SQL codes, an abstract syntax tree corresponding to the third SQL code is generated, and the abstract syntax tree is parsed to obtain the second code record information corresponding to the third SQL code.

[0122] Optionally, the first determining submodule includes: a seventh determination submodule, for determining, if there is a written second code snippet in the first SQL code and there is field information at a position where code completion is required, the first code snippet based on other code snippets other than the second code snippet in the candidate code snippets corresponding to the field matching the field information, the field information including all or part of the name of the field in the referenced first database table, the type information of the second code snippet being the same as the first type information and the referenced database table being the first database table.

[0123] Optionally, the first determining submodule includes: an eighth determination submodule, for determining, if there is a written second code snippet in the first SQL code and there is no field information at the position where code completion is required, the first code snippet from other code snippets in the candidate code snippets except the second code snippet, the field information including all or part of the name of the field in the referenced first database table, the type information of the second code snippet being the same as the first type information and the referenced database table being the first database table.

[0124] Optionally, the first determining submodule includes: a ninth determination submodule, for determining the first code snippet according to the candidate code snippet corresponding to the field matching the field information if there is field information at the position where code completion is required and there is no written second code snippet in the first SQL code, the field information including all or part of the name of the field in the referenced first database table, the type information of the second code snippet being the same as the first type information and the referenced database table being the first database table.

[0125] Reference below Figure 4 , which shows a structural schematic diagram of an electronic device 600 suitable for implementing an embodiment of the present disclosure. Figure 4 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0126] like Figure 4 As shown, the electronic device 600 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 600 are also stored. The processing device 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.

[0127] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 4 The electronic device 600 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0128] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 609, or installed from a storage device 608, or installed from a ROM 602. When the computer program is executed by the processing device 601, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.

[0129] It should be noted that the computer-readable medium mentioned above in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. Computer readable signal media may also be any computer readable medium other than computer readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0130] In some embodiments, the servers may communicate using any currently known or future developed network protocol, such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.

[0131] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0132] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: obtains a first SQL code and position information, where the position information is used to indicate a position in the first SQL code where code completion is required; Determine, according to the first SQL code and the position information, a first database table referenced by the position where code completion is required; Determine a first code snippet, wherein the first code snippet is obtained according to a second SQL code, the second SQL code includes a historically submitted SQL code that references the first database table, and the first code snippet includes a name of a field in the first database table and a parameter corresponding to the field; According to the first code fragment, a code for performing code completion at the position is determined.

[0133] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages ​​or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0134] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0135] The modules involved in the embodiments described in the present disclosure may be implemented by software or hardware. The name of a module does not limit the module itself in some cases. For example, the acquisition module may also be described as a "module for acquiring the first SQL code and location information".

[0136] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.

[0137] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0138] According to one or more embodiments of the present disclosure, Example 1 provides a code processing method, the method comprising: Acquire a first SQL code and position information, where the position information is used to indicate a position in the first SQL code where code completion is required; Determine, according to the first SQL code and the position information, a first database table referenced by the position where code completion is required; Determine a first code snippet, wherein the first code snippet is obtained according to a second SQL code, the second SQL code includes a historically submitted SQL code that references the first database table, and the first code snippet includes a name of a field in the first database table and a parameter corresponding to the field; According to the first code fragment, a code for performing code completion at the position is determined.

[0139] According to one or more embodiments of the present disclosure, Example 2 provides the method of Example 1, wherein the method further includes: Determine first type information according to the first SQL code and the position information, where the first type information is used to indicate that the position where code completion is required corresponds to a conditional clause or a selection clause; The determining of the first code snippet comprises: Acquire candidate code snippets corresponding to fields in the first database table, wherein the candidate code snippets corresponding to the fields include code snippets that reference the fields and whose type information is the same as the first type information, and the candidate code snippets are obtained according to the second SQL code; The first code snippet is determined from the candidate code snippets corresponding to the field, wherein, when the first type information indicates the conditional clause, the first code snippet also includes a SQL operator, and when the first type information indicates the selection clause and there is a function call in the first code snippet, the first code snippet also includes a function name.

[0140] According to one or more embodiments of the present disclosure, Example 3 provides the method of Example 2, and the candidate code snippet corresponding to the field is obtained in the following manner: Acquire first code record information, wherein the first code record information is obtained according to third SQL codes submitted historically, the number of the third SQL codes is multiple, the multiple third SQL codes include the second SQL code, and the code record information includes a code snippet, type information of the code snippet, and a name of a database table referenced by the code snippet; The candidate code segment corresponding to the field is determined according to the first code record information.

[0141] According to one or more embodiments of the present disclosure, Example 4 provides the method of Example 3, wherein the first code record information is obtained in the following manner: Obtain the third SQL code; Respectively determine the second code record information corresponding to each of the third SQL codes; According to the second code record information respectively corresponding to each of the third SQL codes, an aggregation operation is performed on the second code record information according to a preset dimension to obtain the first code record information corresponding to the preset dimension; The aggregation operation includes: aggregating the second code record information corresponding to different third SQL codes and having the same preset dimension into one piece of code record information; The preset dimension includes a first preset dimension and / or at least one second preset dimension, the first preset dimension includes the code snippet and the name of the database table, the second preset dimension includes first code association information, the code snippet and the name of the database table, the first code association information is one of the following: information of the first user who submits the third SQL code, information of the business department to which the first user belongs, and information of the project to which the third SQL code belongs.

[0142] According to one or more embodiments of the present disclosure, Example 5 provides the method of Example 4, wherein determining the candidate code snippet corresponding to the field according to the first code record information includes: If the preset dimensions include the first preset dimension, the first code record information that satisfies a first condition in the first code record information corresponding to the first preset dimension is used as the third code record information corresponding to the first preset dimension, wherein the first condition includes: the name of the database table is the name of the first database table, and the type information of the code snippet is the same as the first type information; If the preset dimension includes the second preset dimension, the first code record information that satisfies a second condition in the first code record information corresponding to the second preset dimension is used as the third code record information corresponding to the second preset dimension, wherein the second condition includes: the name of the database table is the name of the first database table, the type information of the code snippet is the same as the first type information, and the first code association information is the same as the corresponding second code association information, and the second code association information is one of the following: information of a second user who writes the first SQL code, information of a business department to which the second user belongs, and information of a project to which the first SQL code belongs; The candidate code segment corresponding to the field is determined according to the third code record information.

[0143] According to one or more embodiments of the present disclosure, Example 6 provides the method of Example 5, wherein the third code record information further includes the number of times the code snippet is used and / or the submission time of the corresponding third SQL code; The determining, according to the third code record information, the candidate code segment corresponding to the field includes: In the case where the third code record information corresponds to one of the preset dimensions, the code snippets that reference the field in the third code record information corresponding to the preset dimension are sorted according to the number of uses and / or the submission time; if the number of the code snippets that reference the field is greater than a first preset number, the first preset number of code snippets that are sorted in front are used as the candidate code snippets corresponding to the field.

[0144] According to one or more embodiments of the present disclosure, Example 7 provides the method of Example 5, wherein determining the candidate code fragment corresponding to the field according to the third code record information includes: In the case where the third code record information corresponds to N preset dimensions, if there are repeated code snippets, a deduplication operation is performed, wherein the repeated code snippets are code snippets that exist simultaneously in the third code record information corresponding to the n preset dimensions respectively, and the deduplication operation includes deleting the third code record information of the repeated code snippets corresponding to n-1 preset dimensions, N≥2, 2≤n≤N, the N preset dimensions are set with different priorities, and the n-1 preset dimensions are preset dimensions with low priorities among the n preset dimensions; The candidate code segment corresponding to the field is determined according to the third code record information after the deduplication operation.

[0145] According to one or more embodiments of the present disclosure, Example 8 provides the method of Example 7, wherein the third code record information further includes the number of times the code snippet is used and / or the submission time of the corresponding third SQL code; The determining, according to the third code record information after the deduplication operation, the candidate code segment corresponding to the field includes: For each of the N preset dimensions, sorting the code snippets that reference the field in the third code record information after the deduplication operation corresponding to the preset dimension according to the number of uses and / or the submission time; The third code record information after the deduplication operation corresponding to the N preset dimensions is traversed in order from high to low priority, and from the third code record information corresponding to the currently traversed preset dimension, according to the sorting result of the code snippets, the code snippet that references the field is extracted as the candidate code snippet corresponding to the field, until the number of the candidate code snippets reaches a first preset number, or the third code record information corresponding to the N preset dimensions has been traversed.

[0146] According to one or more embodiments of the present disclosure, Example 9 provides the method of Example 4, wherein the step of respectively determining the second code record information corresponding to each of the third SQL codes includes: For each of the third SQL codes, an abstract syntax tree corresponding to the third SQL code is generated, and the abstract syntax tree is parsed to obtain the second code record information corresponding to the third SQL code.

[0147] According to one or more embodiments of the present disclosure, Example 10 provides the method of Example 2, wherein determining the first code snippet from the candidate code snippets corresponding to the field includes: If there is a written second code snippet in the first SQL code, and there is field information at the position where code completion is required, the first code snippet is determined according to other code snippets except the second code snippet in the candidate code snippets corresponding to the field matching the field information, the field information includes all or part of the name of the field in the referenced first database table, the type information of the second code snippet is the same as the first type information, and the referenced database table is the first database table.

[0148] According to one or more embodiments of the present disclosure, Example 11 provides the method of Example 2, wherein determining the first code snippet from the candidate code snippets corresponding to the field includes: If there is a written second code snippet in the first SQL code, and there is no field information at the position where code completion is required, the first code snippet is determined from other code snippets in the candidate code snippets except the second code snippet, the field information includes all or part of the name of the field in the referenced first database table, the type information of the second code snippet is the same as the first type information, and the referenced database table is the first database table.

[0149] According to one or more embodiments of the present disclosure, Example 12 provides the method of Example 2, wherein determining the first code snippet from the candidate code snippets corresponding to the field includes: If there is field information at the location where code completion is required and there is no written second code snippet in the first SQL code, the first code snippet is determined according to the candidate code snippet corresponding to the field matching the field information, the field information includes all or part of the name of the field in the referenced first database table, the type information of the second code snippet is the same as the first type information and the referenced database table is the first database table.

[0150] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.

[0151] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.

[0152] Although the subject matter has been described in language specific to structural features and / or method logic 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. On the contrary, the specific features and actions described above are merely example forms of implementing the claims. Regarding the device in the above embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.

Claims

1. A code processing method, characterized in that: The method comprises: Acquire a first SQL code and position information, where the position information is used to indicate a position in the first SQL code where code completion is required; Determine, according to the first SQL code and the position information, a first database table referenced by the position where code completion is required; Determine a first code snippet, wherein the first code snippet is obtained according to a second SQL code, the second SQL code includes a historically submitted SQL code that references the first database table, and the first code snippet includes a name of a field in the first database table and a parameter corresponding to the field; According to the first code fragment, a code for performing code completion at the position is determined.

2. The method according to claim 1, characterized in that The method further comprises: Determine first type information according to the first SQL code and the position information, where the first type information is used to indicate that the position where code completion is required corresponds to a conditional clause or a selection clause; The determining of the first code snippet comprises: Acquire candidate code snippets corresponding to fields in the first database table, wherein the candidate code snippets corresponding to the fields include code snippets that reference the fields and whose type information is the same as the first type information, and the candidate code snippets are obtained according to the second SQL code; The first code snippet is determined from the candidate code snippets corresponding to the field, wherein, when the first type information indicates the conditional clause, the first code snippet also includes a SQL operator, and when the first type information indicates the selection clause and there is a function call in the first code snippet, the first code snippet also includes a function name.

3. The method according to claim 2, characterized in that The candidate code snippet corresponding to the field is obtained in the following manner: Acquire first code record information, wherein the first code record information is obtained according to third SQL codes submitted historically, the number of the third SQL codes is multiple, the multiple third SQL codes include the second SQL code, and the code record information includes a code snippet, type information of the code snippet, and a name of a database table referenced by the code snippet; The candidate code segment corresponding to the field is determined according to the first code record information.

4. The method according to claim 3, characterized in that The first code record information is obtained in the following manner: Obtain the third SQL code; Respectively determine the second code record information corresponding to each of the third SQL codes; According to the second code record information respectively corresponding to each of the third SQL codes, an aggregation operation is performed on the second code record information according to a preset dimension to obtain the first code record information corresponding to the preset dimension; The aggregation operation includes: aggregating the second code record information corresponding to different third SQL codes and having the same preset dimension into one piece of code record information; The preset dimension includes a first preset dimension and / or at least one second preset dimension, the first preset dimension includes the code snippet and the name of the database table, the second preset dimension includes first code association information, the code snippet and the name of the database table, the first code association information is one of the following: information of the first user who submits the third SQL code, information of the business department to which the first user belongs, and information of the project to which the third SQL code belongs.

5. The method according to claim 4, characterized in that The determining, according to the first code record information, the candidate code segment corresponding to the field includes: If the preset dimensions include the first preset dimension, the first code record information that satisfies a first condition in the first code record information corresponding to the first preset dimension is used as the third code record information corresponding to the first preset dimension, wherein the first condition includes: the name of the database table is the name of the first database table, and the type information of the code snippet is the same as the first type information; If the preset dimension includes the second preset dimension, the first code record information that satisfies a second condition in the first code record information corresponding to the second preset dimension is used as the third code record information corresponding to the second preset dimension, wherein the second condition includes: the name of the database table is the name of the first database table, the type information of the code snippet is the same as the first type information, and the first code association information is the same as the corresponding second code association information, and the second code association information is one of the following: information of a second user who writes the first SQL code, information of a business department to which the second user belongs, and information of a project to which the first SQL code belongs; The candidate code segment corresponding to the field is determined according to the third code record information.

6. The method according to claim 5, characterized in that The third code record information also includes the number of times the code snippet is used and / or the submission time of the corresponding third SQL code; The determining, according to the third code record information, the candidate code segment corresponding to the field includes: In the case where the third code record information corresponds to one of the preset dimensions, the code snippets that reference the field in the third code record information corresponding to the preset dimension are sorted according to the number of uses and / or the submission time; if the number of the code snippets that reference the field is greater than a first preset number, the first preset number of code snippets that are sorted in front are used as the candidate code snippets corresponding to the field.

7. The method according to claim 5, characterized in that The determining, according to the third code record information, the candidate code segment corresponding to the field includes: In the case where the third code record information corresponds to N preset dimensions, if there are repeated code snippets, a deduplication operation is performed, wherein the repeated code snippets are code snippets that exist simultaneously in the third code record information corresponding to the n preset dimensions respectively, and the deduplication operation includes deleting the third code record information of the repeated code snippets corresponding to n-1 preset dimensions, N≥2, 2≤n≤N, the N preset dimensions are set with different priorities, and the n-1 preset dimensions are preset dimensions with low priorities among the n preset dimensions; The candidate code segment corresponding to the field is determined according to the third code record information after the deduplication operation.

8. The method according to claim 7, characterized in that The third code record information also includes the number of times the code snippet is used and / or the submission time of the corresponding third SQL code; The determining, according to the third code record information after the deduplication operation, the candidate code segment corresponding to the field includes: For each of the N preset dimensions, sorting the code snippets that reference the field in the third code record information after the deduplication operation corresponding to the preset dimension according to the number of uses and / or the submission time; The third code record information after the deduplication operation corresponding to the N preset dimensions is traversed in order from high to low priority, and from the third code record information corresponding to the currently traversed preset dimension, according to the sorting result of the code snippets, the code snippet that references the field is extracted as the candidate code snippet corresponding to the field, until the number of the candidate code snippets reaches a first preset number, or the third code record information corresponding to the N preset dimensions has been traversed.

9. The method according to claim 4, characterized in that The respectively determining the second code record information corresponding to each of the third SQL codes includes: For each of the third SQL codes, an abstract syntax tree corresponding to the third SQL code is generated, and the abstract syntax tree is parsed to obtain the second code record information corresponding to the third SQL code.

10. The method according to claim 2, characterized in that The determining the first code fragment from the candidate code fragments corresponding to the field includes: If there is a written second code snippet in the first SQL code, and there is field information at the position where code completion is required, the first code snippet is determined according to other code snippets except the second code snippet in the candidate code snippets corresponding to the field matching the field information, the field information includes all or part of the name of the field in the referenced first database table, the type information of the second code snippet is the same as the first type information, and the referenced database table is the first database table.

11. The method according to claim 2, characterized in that The determining the first code fragment from the candidate code fragments corresponding to the field includes: If there is a written second code snippet in the first SQL code, and there is no field information at the position where code completion is required, the first code snippet is determined from other code snippets in the candidate code snippets except the second code snippet, the field information includes all or part of the name of the field in the referenced first database table, the type information of the second code snippet is the same as the first type information, and the referenced database table is the first database table.

12. The method according to claim 2, characterized in that: The determining the first code fragment from the candidate code fragments corresponding to the field includes: If there is field information at the location where code completion is required and there is no written second code snippet in the first SQL code, the first code snippet is determined according to the candidate code snippet corresponding to the field matching the field information, the field information includes all or part of the name of the field in the referenced first database table, the type information of the second code snippet is the same as the first type information and the referenced database table is the first database table.

13. A code processing device, characterized in that: The device comprises: An acquisition module, used for acquiring a first SQL code and position information, wherein the position information is used for indicating a position in the first SQL code where code completion is required; A first determination module, configured to determine, according to the first SQL code and the position information, a first database table referenced by a position where code completion is required; A second determination module is used to determine a first code fragment, wherein the first code fragment is obtained according to a second SQL code, the second SQL code includes a historically submitted SQL code that references the first database table, and the first code fragment includes a name of a field in the first database table and a parameter corresponding to the field; The third determining module is used to determine, according to the first code fragment, a code for performing code completion at the position.

14. A computer readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processing device, the steps of the method described in any one of claims 1 to 12 are implemented.

15. An electronic device, characterized in that: include: a storage device having a computer program stored thereon; A processing device, configured to execute the computer program in the storage device to implement the steps of the method according to any one of claims 1 to 12.

16. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 12 are implemented.