Data processing method and device and other equipment

By converting SQL into a relational algebra tree and combining technical means of template method and large language model, the accuracy and fluency problems of complex SQL code being converted into natural language description are solved, and high-quality natural language interpretation is achieved.

CN119441258AInactive Publication Date: 2025-02-14SHENZHEN HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202510032322.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-09
Publication Date
2025-02-14
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The existing technology is difficult to take into account the accuracy and natural fluency of the conversion of complex SQL code into natural language. The description generated by template method is not natural, while the accuracy of the deep learning model decreases when the number of SQL nested layers increases.

Method used

By converting SQL into a relational algebra tree and matching its nodes with natural language templates, after obtaining a preliminary explanation, it is then polished with a large language model to generate the final natural language description.

Benefits of technology

It realizes the accuracy of converting complex SQL code into natural language descriptions while maintaining natural fluency, and avoids inaccuracy when relying solely on large language models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119441258A_ABST
    Figure CN119441258A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a data processing method and device and other equipment, which are used for translating a structured query language (SQL) into natural language description easy to understand by a user so as to assist the user in understanding SQL codes. The method comprises the steps that a structured query language (SQL) is converted into a relational algebraic tree, the relational algebraic tree comprises a plurality of relational algebraic nodes, one relational algebraic node represents an operation performed on data and comprises field information and logic information, the field information is used for indicating an operation object of the relational algebraic node, and the logic information is used for indicating the operation object of the relational algebraic node; the logic information is used for indicating a logic relationship between the operation objects; matching a first natural language template for the relational algebraic node in the relational algebraic tree to obtain a first natural language description of the SQL, the first natural language template being any one natural language template in a template library; the first big language model is adopted to embellish the first natural language description to obtain a second natural language description, and the second natural language description is used for assisting the user in understanding the SQL.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing, and in particular to a data processing method, device and other equipment. Background Art

[0002] Structured query language (SQL) is a standardized programming language for interacting with relational databases. Users can perform data query, data operation and management tasks through structured query language. However, due to the complexity of SQL language, users need to have certain professional skills to effectively write and understand SQL code. In order to overcome this obstacle, natural language interface (NLI) has been proposed. NLI uses artificial intelligence (AI) and machine learning (ML) technology to convert natural language questions (NLQ) into SQL statements. The emergence of NLI allows non-technical users who lack programming knowledge to use NLI to automatically convert natural language questions into SQL code. At the same time, in order to enable users to better understand SQL code, it is particularly important to automatically translate SQL code into natural language descriptions that are easy for users to understand.

[0003] Currently, there are solutions that can use template methods or deep neural network models to interpret SQL codes and automatically convert SQL codes into natural language descriptions. Among them, the template method can convert SQL query statements into abstract syntax trees (ASTs), and then select the corresponding templates according to the nodes in the AST to generate natural language descriptions of SQL statements. Alternatively, SQL statements can be interpreted through deep neural network models to generate natural language text of SQL statements.

[0004] However, the natural language description of SQL statements generated by the template method is mechanical and unnatural, and as the number of nested layers of SQL queries increases, the accuracy of the natural language description inferred by deep learning models or large language models may decrease. Therefore, how to balance the accuracy and natural fluency of converting complex SQL into natural language has become a problem that needs to be solved urgently. Summary of the invention

[0005] The present application provides a data processing method, apparatus and other devices for translating structured query language SQL into natural language descriptions that are easy for users to understand, so as to assist users in understanding SQL codes.

[0006] In a first aspect, the present application provides a data processing method, which includes: first, a structured query language SQL can be converted into a relational algebra tree, the relational algebra tree includes multiple relational algebra nodes, one relational algebra node represents an operation performed on data, and the relational algebra node includes field information and logical information, wherein the field information is used to indicate the operation object of the relational algebra node, and the logical information is used to indicate the logical relationship between the operation objects; after obtaining the relational algebra tree, a first natural language template can be matched to the relational algebra node in the relational algebra tree to obtain a first natural language description of SQL, wherein the first natural language template is any natural language template in a template library, and the natural language template is used to translate SQL into natural language; after the SQL is preliminarily translated into a natural language description by a template method, the first large language model can be used to polish the first natural language description to obtain a second natural language description, and the second natural language description is used to assist users in understanding SQL.

[0007] In the embodiment of the present application, a preliminary interpretation of SQL, i.e., a first natural language description, can be obtained by matching a natural language template to a relational algebraic node in a relational algebraic tree. Subsequently, the preliminary interpretation of SQL can be polished by a large language model to obtain a second natural language description. Parsing SQL based on relational algebra expressions can convert SQL statements of different expressions into the same relational algebra tree, so that after subsequent template matching based on a relational algebra tree, translations of SQL statements of multiple expressions can be obtained, which is different from parsing SQL based on an abstract syntax tree, where only one SQL statement can be translated based on template matching of an abstract syntax tree, and the workload of translating SQL based on the template method can be further reduced. In addition, the embodiment of the present application first uses the template method to obtain a preliminary interpretation of SQL, laying the foundation for the basic interpretation framework of SQL, and then uses a large language model to polish the preliminary interpretation, which can avoid the inaccuracy that may exist when only using a large language model to interpret complex SQL codes. At the same time, using a large language model to polish the preliminary interpretation can optimize the problem of unnatural description when translating by the template method, making the final interpretation result more natural and smooth.

[0008] In a possible implementation, when there is no matching first natural language template for the relational algebra node, the method may further include: rewriting the first SQL statement of the relational algebra node into a second SQL statement, the second SQL statement has a matching second natural language template, and the second natural language template is any natural language template in the template library.

[0009] In an embodiment of the present application, when matching a template with a relational algebra node, if a template matching the first SQL statement of the relational algebra node does not exist in the template library, the first SQL statement can be rewritten so that it can be adapted to the existing template, thereby reducing the development and customization costs of the template and improving the generalization of the template.

[0010] In a possible implementation, before matching the natural language template for the relational algebraic nodes in the relational algebraic tree to obtain the first natural language description of SQL, the method may further include: dividing the relational algebraic tree into multiple segments according to preset segmentation points, the segments including multiple target relational algebraic nodes, and the target relational algebraic nodes including target field information and target logical information.

[0011] In the embodiment of the present application, since the constructed template is usually for a SQL fragment or a specific SQL statement, it is usually necessary to call multiple templates to translate a complex SQL code. Therefore, when performing template matching on a relational algebraic tree, the relational algebraic tree can be divided into multiple fragments, so that when the template method is subsequently used to perform a preliminary interpretation of the relational algebraic tree, multiple fragments can be translated in batches at the same time to finally obtain a natural language description of the entire SQL code.

[0012] In a possible implementation, the aforementioned matching of natural language templates for relational algebraic nodes in the relational algebraic tree to obtain the first natural language description of SQL may include: matching the natural language templates for the target relational algebraic nodes in each segment to obtain the first natural language description of SQL.

[0013] In a possible implementation, matching a natural language template for a target relational algebra node in each segment to obtain a first natural language description of SQL may include: determining a target natural language template for the target relational algebra node in each segment according to the type of the keyword in the target relational algebra node; and filling the target natural language template with the target field information of the target relational algebra node to obtain a first natural language description.

[0014] In a possible implementation, the target field information includes a name of the target field, and the method may further include: translating the target field using a second language model to obtain a translated target field.

[0015] In an embodiment of the present application, a large language model can be used to translate the target field in the relational algebra node, which can avoid the interpretation of field information such as abbreviations, English and pinyin mixtures, and improve the accuracy of translating fields such as abbreviations, English and pinyin mixtures.

[0016] In a possible implementation, the aforementioned filling the target field information of the target relational algebra node into the target natural language template to obtain the first natural language description may include: filling the translated target field into the target natural language template to obtain the first natural language description.

[0017] In the embodiment of the present application, the translated field information can be filled into the template to improve the accuracy of translating SQL into natural language description.

[0018] In a second aspect, the present application provides a data processing device, including: a conversion module, used to convert a structured query language SQL into a relational algebra tree, the relational algebra tree including multiple relational algebra nodes, one relational algebra node represents an operation performed on data, the relational algebra node includes field information and logical information, the field information is used to indicate the operation object of the relational algebra node, and the logical information is used to indicate the logical relationship between the operation objects; a matching module, used to match a first natural language template for the relational algebra node in the relational algebra tree to obtain a first natural language description of SQL, the first natural language template is any natural language template in a template library, and the natural language template is used to translate SQL into natural language; an inference module, used to polish the first natural language description using a first large language model to obtain a second natural language description, and the second natural language description is used to assist users in understanding SQL.

[0019] In a possible implementation, when there is no matching first natural language template for a relational algebra node, the device may further include: a rewriting module, used to rewrite the first SQL statement of the relational algebra node into a second SQL statement, the second SQL statement has a matching second natural language template, and the second natural language template is any natural language template in the template library.

[0020] In a possible implementation, before the aforementioned matching of the relational algebraic nodes in the relational algebraic tree with the natural language template to obtain the first natural language description of SQL, the device may also include: a segmentation module, used to segment the relational algebraic tree into multiple segments according to preset segmentation points, the segments including multiple target relational algebraic nodes, and the target relational algebraic nodes including target field information and target logical information.

[0021] In a possible implementation, the aforementioned matching module is specifically used to: match a natural language template for a target relational algebra node in each segment to obtain a first natural language description of SQL.

[0022] In a possible implementation, the aforementioned matching module is specifically used to: determine the target natural language template of the target relational algebra node in each fragment according to the type of the keyword in the target relational algebra node; fill the target field information of the target relational algebra node into the target natural language template to obtain a first natural language description.

[0023] In a possible implementation, the target field information includes the name of the target field, and the aforementioned reasoning module is further used to translate the target field using the second largest language model to obtain a translated target field.

[0024] In a possible implementation manner, the aforementioned matching module is specifically used to fill the translated target field into the target natural language template to obtain a first natural language description.

[0025] In a third aspect, an embodiment of the present application provides a computing device, comprising a processor and a memory; the processor of at least one computing device is used to execute instructions stored in the memory of at least one computing device, so that the computing device executes a method such as the first aspect or any possible implementation of the first aspect.

[0026] In a fourth aspect, an embodiment of the present application provides a computing device cluster, comprising at least one computing device, each computing device comprising a processor and a memory; the processor of at least one computing device is used to execute instructions stored in the memory of at least one computing device, so that the computing device cluster executes a method such as the first aspect or any possible implementation of the first aspect.

[0027] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium, including computer program instructions. When the computer program instructions are executed by a computing device cluster, the computing device cluster executes a method such as the first aspect or any possible implementation of the first aspect.

[0028] In a sixth aspect, an embodiment of the present application provides a computer program product comprising instructions, which, when executed by a computing device cluster, enables the computing device cluster to execute a method such as the first aspect or any possible implementation manner of the first aspect.

[0029] Among them, the technical effects brought about by the second to sixth aspects or any possible implementation methods thereof can refer to the technical effects brought about by the first aspect or the relevant possible implementation methods of the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 A schematic diagram of a system framework provided for an embodiment of the present application; Figure 2 A flowchart of a data processing method provided in this application; Figure 3 It is a schematic diagram of SQL parsing based on relational algebra expressions; Figure 4 A flowchart for matching templates to relational algebra nodes and filling them in to obtain natural language descriptions; Figure 5 An example diagram of rewriting an SQL statement when there is no matching template for the SQL statement; Figure 6 A schematic diagram for splitting a relational algebra tree; Figure 7 A schematic diagram of the process of performing template matching on the relational algebra nodes in each fragment; Figure 8 A flowchart for translating SQL by combining the template method and the big model; Fig. 9 A schematic diagram of the structure of a data processing device provided in this application; Fig.10 A schematic diagram of the structure of a computing device in an embodiment of the present application; Fig.11 A schematic diagram of the structure of a computing device cluster in an embodiment of the present application; Fig.12 Another structural diagram of a computing device cluster in an embodiment of the present application. DETAILED DESCRIPTION

[0031] The following will describe the technical solutions in the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.

[0032] To facilitate understanding, some concepts involved in this application are first introduced.

[0033] 1. Field In SQL, a field (also called a column) is the basic building block of a table and is used to store a specific type of data.

[0034] 2. Relational Algebra Tree A relational algebra tree is a tree structure used to represent and operate query statements in relational databases. It clearly represents the query process by splitting the query statement into a series of relational algebra operators and organizing these operators and related operands (usually relations or attributes) in the form of a tree.

[0035] 3. Large Language Model (LLM) LLM refers to a language model containing hundreds of millions (or more) parameters, which are trained on a large amount of text data. It is a natural language processing model based on deep learning. These models can process a large amount of text data to learn the grammatical and semantic rules of natural language. LLM can be specifically applied to text generation, machine translation, question-answering systems, text summarization, or sentiment analysis, etc. It has the advantages of strong generation ability, strong adaptability, accurate prediction, and strong scalability. For example, in the movie recommendation scenario, the large language model can generate a description of the movie scene, including the movie type, starring actors, storyline, etc., so that the system can better recommend similar movies. The large language model can also generate reasons for recommendations. For example, e-commerce websites can use large language models to generate reasons for recommending products, such as product quality, price, function, etc., so that users can better understand the value of the product.

[0036] In order to make the technical solution of the present application clearer and easier to understand, the system architecture of the present application is introduced below with reference to the accompanying drawings.

[0037] See also Figure 1 , is a system architecture 100 provided by this application. Figure 1 As shown, the system architecture 100 may include a computing device cluster 110, and the computing device cluster 110 includes at least one computing device. The computing device may be a server, such as a cloud server, a central server, an edge server, or a local server in a local data center. In some possible embodiments, the computing device may also be a desktop computer, a laptop computer, or other terminal devices.

[0038] Exemplarily, the computing device cluster may include one or more servers, which convert SQL code into natural language description by calling relevant microservices deployed on the servers; alternatively, the computing device cluster may also be a client device, and implement the data processing method of the embodiment of the present application through installed applications or plug-ins, that is, complete the conversion of SQL code into natural language description.

[0039] It is worth noting that Figure 1 The system architecture shown is only an example and is not intended to limit its specific implementation to this example. For example, in other possible system architectures, the system architecture 100 also includes a template library for natural language templates, and the SQL code can be initially converted into a natural language description in combination with the natural language templates in the template library.

[0040] The embodiments of the present application can be applied to the data development process, providing an SQL explanation interaction scenario, where users can obtain explanation results of different levels such as the full text fragment or field of the SQL code. For example, the user can select the SQL explanation function to obtain the explanation of the selected SQL statement, which can help the user understand the SQL code.

[0041] Due to the complexity of structured query language (SQL), users usually need to have certain professional knowledge to understand and write SQL code. In order to make it easier for non-technical users who lack professional knowledge to understand SQL code, template method or deep neural network model can be used to convert SQL code into natural language description. However, the natural language description of SQL code generated by template method is mechanical and unnatural, and the template method needs to set specific templates for different functions and logical expressions in SQL, resulting in poor generalization; and the number of nested layers of SQL processed by deep learning model is limited. As the complexity of SQL code increases, the accuracy of natural language description of SQL code obtained by reasoning with deep learning model or large model will decrease.

[0042] Based on this, in order to take into account the accuracy and fluency of converting complex SQL code into natural language, this application proposes a data processing method. First, SQL can be converted into a relational algebraic tree. Then, the relational algebraic nodes in the relational algebraic tree are matched with templates to obtain a first natural language description of SQL. Then, the language model is used to polish the first natural language description to obtain a second natural language description. Combining the advantages of the template method and the language model, the template method is first used to obtain the basic interpretation framework of SQL, and then the language model is used for polishing, thereby taking into account the accuracy and fluency of the conversion of complex nested SQL.

[0043] The following is an introduction to the method flow provided by this application in conjunction with the aforementioned system architecture.

[0044] See also Figure 2 , a flow chart of a data processing method provided in this application is as follows.

[0045] Step 201: converting structured query language SQL into a relational algebra tree; Generally, when using the template method to convert SQL into a natural language description that is easy for users to understand, it is necessary to understand the structure and semantics of SQL, such as the SELECT, FROM, WHERE clauses and their interrelated logical relationships. Then, based on the structure and semantics of SQL, the corresponding template can be matched to SQL to obtain a natural language description of SQL.

[0046] Therefore, in the embodiment of the present application, SQL can be parsed first to understand the structure and semantics of SQL. Usually, before converting SQL into a natural language description using the template method, SQL is first parsed into an abstract syntax tree, and a SQL statement is usually converted into an abstract syntax tree. Since the same operation can be represented by different SQL statements, each SQL statement in a certain form needs to be converted into an abstract syntax tree. When template matching is subsequently performed based on the abstract syntax tree, each newly added SQL statement needs to be template matched based on the new abstract syntax tree, which will bring a large amount of calculation.

[0047] Since the relational algebra tree is a tree structure with database operations as the core, the relational algebra nodes in the relational algebra tree represent the operations performed on the data in the database. Different SQL expressions of the same operation can be converted into the same relational algebra tree. It is only necessary to perform template matching on the relational algebra tree to obtain the translation of SQL statements in various different expressions, thereby reducing the amount of calculation for SQL interpretation using the template method, and allowing the template method to translate SQL parsed based on the relational algebra tree and eventually reach convergence.

[0048] The relational algebra nodes in the relational algebra tree include field information and logic information. The field information is used to indicate the operation object of the relational algebra node, and the logic information is used to indicate the logical relationship between the operation objects. The relational algebra tree can not only represent the structure of SQL, but also the relational algebra nodes in the relational algebra tree include the operation objects and the logical relationship between the operation objects.

[0049] Optionally, SQL can be parsed based on relational algebra expressions to convert SQL into a relational algebra tree. Figure 3 shown. Figure 3In the relational algebra tree, according to the SQL code, the SQL code can be converted into a relational algebra tree. Taking the relational algebra node logicalproject as an example, it can be known that the fields in the logicalproject node include city, install_city, total and install_city_name. Through the logical judgment of the IF function "IF (= ('$install_city', 'total', $install_city_name))", it can be known that the logical relationship between city, install_city, total and install_city_name is that when install_city = total, city is total, otherwise city is install_city_name. Among them, the logicalproject in the relational algebra tree represents the projection operation on the data. The projection operation will select certain columns in the table and generate a new table. This new table only contains the selected columns. For example, if there is a table containing name, age and address information, you can choose to display only the name and age columns through the projection operation. Figure 3 In the example, it means selecting the column whose field is city; logicalfilter means filtering the data. The filtering operation will select the records that meet the conditions according to certain conditions. Figure 3 The filter conditions that can be extracted are create_day<='$start_date' and create_day>='$start_date'; logicaljoin represents the join operation of two or more tables, which can merge data from different tables together according to certain conditions; logicaltablescan represents a full table scan operation on the table. In SQL queries, a full table scan reads every row of data in the table, and is usually used when there is no index or the index cannot be used.

[0050] After converting the SQL into a relational algebra tree, template matching can be performed based on the relational algebra nodes, and the field information in the relational algebra nodes can be directly filled into the template.

[0051] Step 202: Match a first natural language template to a relational algebra node in the relational algebra tree to obtain a first natural language description of SQL; In the embodiment of the present application, the template method can be used to preliminarily interpret SQL. First, it can be determined whether there is a first natural language template matching the relational algebra node in the template library. If so, the first natural language template can be matched for the relational algebra node. Subsequently, the field information in the relational algebra node can be filled into the first natural language template to obtain the first natural language description of SQL.

[0052] For example, Figure 4 As shown, Figure 4 In order to match the templates of the relational algebra nodes and fill in the process diagram described in natural language, the template library may include multiple templates, such as SQL structure templates, IF judgment logic templates, etc. After extracting the keywords in the relational algebra nodes and matching the templates according to the types of keywords, the field information can be filled into the templates. Taking IF (=('$install_city', 'Total', $install_city_name)) as an example, combined with the IF judgment logic template, the natural language description of the if statement can be obtained: if install_city is a total, return the total, otherwise, return city_name. Among them, the keywords are determined in the SQL standard and are used to perform specific database operations, such as query, update, delete, create table, etc.

[0053] Optionally, when there is no first natural language template matching the relational algebra node in the template library, that is, when there is no template matching the keyword in the relational algebra node in the template library, the first SQL statement of the relational algebra node can be rewritten into a second SQL statement, wherein there is a matching second natural language template for the second SQL statement.

[0054] Specifically, the first SQL statement can be converted into a relational algebraic expression, and then based on the relational algebraic expression, the template library is searched for a second SQL statement that is the same as the relational algebraic expression, and then the first SQL statement is converted into the second SQL statement, so that the corresponding template can be matched for the first SQL statement.

[0055] For example, Figure 5 As shown, Figure 5 This is an example of rewriting an SQL statement when there is no matching template for the SQL statement. Figure 5 It can be seen that if there is a corresponding template for the if statement and there is no corresponding natural language template for the case statement, the case statement can be converted into a relational algebra expression, and based on the relational algebra expression, the case statement can be converted into a statement with a matching template. For example, the relational algebra expression of the if statement is the same as that of the case statement, and the if statement has a matching template, then the case statement can be converted into an if statement.

[0056] In the embodiment of the present application, by rewriting SQL statements for which no matching model exists, the cost of customizing templates for different SQL statements can be reduced, and the generalization of the template can be improved.

[0057] Since there are usually multiple layers of nesting in SQL code, the relational algebraic tree after SQL conversion can be segmented, and template matching can be performed on multiple segments obtained after segmentation.

[0058] Optionally, the relational algebra tree can be divided into multiple fragments according to preset splitting points. A fragment includes multiple target relational algebra nodes, and the target relational algebra node includes target field information and target logical information. Among them, the preset splitting point is determined according to the function of the relational algebra node. Usually, the operation used for connection or merging can be used as the preset splitting point, or the preset splitting point can be determined according to the nesting of the SQL code. The selection of the preset splitting point can also be based on the number of occurrences of the relational algebra node in the relational algebra tree. By counting the number of occurrences of each relational algebra node in the relational algebra tree, the relational algebra nodes with a number of occurrences higher than the preset value are used as preset splitting points, wherein the preset value is set by the technician based on experience. Each fragment obtained by splitting the relational algebra tree according to the preset splitting point includes all the relational algebra nodes of this layer and the information of the sub-query of the next layer, ensuring the integrity of each fragment structure. For example, the preset splitting point can be a node such as project, join or union. For example, Figure 6 As shown, Figure 6 This is a schematic diagram of splitting the relational algebra tree. Figure 6 It can be seen that after converting SQL into a relational algebra tree, the relational algebra tree can be traversed to find preset split points (such as project, join, or union), and then the relational algebra tree can be split into multiple fragments.

[0059] Optionally, after the relational algebra tree is divided into multiple segments, a natural language template may be matched to a target relational algebra node in each segment to obtain a first natural language description of SQL.

[0060] Optionally, when matching the template for the target relational algebra node in each segment, each relational algebra node (relnode node) in each segment is traversed, and the keywords and target field information in each relational algebra node are extracted, and the target natural language template of the target relational algebra node in each segment is determined according to the type of the keyword in the target relational algebra node. The template library stores natural language templates based on different types of keywords, which are usually customized based on the structure and semantics of SQL statements; then the target field information of the target relational algebra node is filled into the target natural language template to obtain the first natural language description. The keywords are determined in the SQL standard and are used to perform specific database operations, such as query, update, delete, create table, etc.

[0061] Optionally, the target field information includes the name of the target field in the target relational algebra node. After extracting the target field information of each relational algebra node, the target field can be translated using the second largest language model to obtain the translated template field. When extracting the target field information in the relational algebra node, the target field can be marked so that the translated target field can be filled into the target natural language template according to the mark of the target field. Specifically, field translation can also be performed based on the user's comments on the SQL code. For example, the historical SQL data entered by the query user is: SELECT user_id ,——sales id user name,——Current sales name Count(distinct cust_id) as sh_cnt——Number of users entering the private sea From ods.crmsea_cs_sea_relation_common_hc——sales customer relationship table Among them, the annotation of sh_cnt is the number of users entering the private sea, and the field sh_cnt can be translated according to the annotation of sh_cnt.

[0062] In an embodiment of the present application, when obtaining field information in a relational algebra node, it can be marked and translated through a large language model to avoid the loss of field information due to fields that cannot be translated due to abbreviations, mixed English and pinyin, etc., and it can be translated into accurate meaning to improve the accuracy of SQL interpretation.

[0063] Exemplarily, the flow chart of performing template matching on the relational algebra nodes in each segment is as follows: Figure 7 As shown by Figure 7 It can be seen that when the keyword in the relational algebra node is identified as a function, the function operation object can be extracted, and the function template can be matched for the node, and then the operation object (field) can be filled into the function template. In addition, when there are other function expressions in the operation object, the templates corresponding to the two function expressions can be combined to obtain the final translation result. For example, there is if A then B else C in the project node, where C is if D then E else F. Combined with the template corresponding to the first if statement, the first if statement can be translated into "Specifically, when A, return B, otherwise, return C"; combined with the template corresponding to the second if statement, the second if statement can be translated into "Specifically, when D, return E, otherwise, return F", and the final translation result can be "Specifically, when A, return B, otherwise, return "Specifically, when D, return E, otherwise, return F"".

[0064] Among them, Figure 7 Take a SQL statement fragment in as an example to describe the process of template matching. For example, SQL can be expressed as SELECT IF(age>=18,'Adult','Minor')AS age_status, which can first be converted into a relational algebra node as LogicalProject(age_status=[IF(>($0,18),'Adult','Minor')]). Then, the operation object and keyword in the relational algebra node can be extracted, and the keyword is IF, the operation object is >($0,18), adult and minor; the keyword is >, and the operation object is age and 18. According to the extracted keywords, IF can be identified as a conditional judgment function by matching the function dictionary, and then the IF template can be matched for it, where the IF template is "Specifically: when..., return... Otherwise, return..."; finally, the operation object is filled into the function template, and the filling result is obtained as Specifically: when age is greater than 18, return adult otherwise, return minor.

[0065] Step 203: Use the first language model to polish the first natural language model to obtain a second natural language description.

[0066] After obtaining a preliminary interpretation of SQL through the template method, the first natural language description can be polished using a first large language model or a deep learning model to obtain a second natural language description, so that the final natural description language is more natural and fluent.

[0067] Optionally, after completing template matching for the relational algebra nodes of each segment, the segments can be connected according to the inter-layer connection template to make the language description between each segment more natural and smooth. The inter-layer connection template is used to connect different segments and can be a transition segment description.

[0068] The following takes adding an inter-layer connection template as an example to describe a possible implementation method in the present application embodiment. Figure 8 As shown, Figure 8 This is a flow chart of translating SQL by combining template method and big model. Figure 8 It can be seen that, firstly, for each fragment, the template method is used to convert each layer of SQL code into a natural description language, and because the SQL code is nested in multiple layers, the fragment and its subquery content can be connected based on the inter-layer connection template. Then, combined with field translation, the translated field information can be filled into the template to obtain a preliminary interpretation, and then a large language model (such as the Pangu model) is used to polish the preliminary interpretation to obtain the final interpretation.

[0069] In the embodiment of the present application, by combining the advantages of the template method and the large language model, SQL can first be converted into a relational algebra tree, wherein the relational algebra tree includes multiple relational algebra nodes, and since each relational algebra node includes field information and logic information, it can avoid information omission when performing template matching according to the relational algebra node later, because the relational algebra tree retains the structural information of SQL, and when performing template matching according to the relational algebra node, the field information in the relational algebra node can be directly filled into the template. After the SQL is preliminarily interpreted by the template method, the preliminary interpretation is polished by the large language model to obtain the final interpretation result, which can both ensure the accuracy of the result and improve the natural fluency of the result.

[0070] The above is an introduction to the method flow provided by the present application. Based on the above method flow, the following is an introduction to the device provided by the present application.

[0071] See also Fig. 9 , a structural diagram of a data processing device provided by the present application, comprising: The conversion module 901 is used to convert the structured query language SQL into a relational algebra tree, where the relational algebra tree includes a plurality of relational algebra nodes, where one relational algebra node represents an operation performed on data, and the relational algebra node includes field information and logic information, where the field information is used to indicate an operation object of the relational algebra node, and the logic information is used to indicate a logical relationship between the operation objects; A matching module 902 is used to match a first natural language template for a relational algebra node in a relational algebra tree to obtain a first natural language description of SQL, wherein the first natural language template is any natural language template in a template library, and the natural language template is used to translate SQL into a natural language; The reasoning module 903 is used to polish the first natural language description using the first large language model to obtain a second natural language description, and the second natural language description is used to assist the user in understanding SQL.

[0072] In a possible implementation, when there is no matching first natural language template for a relational algebra node, the device may further include: a rewriting module 904, used to rewrite the first SQL statement of the relational algebra node into a second SQL statement, where there is a matching second natural language template for the second SQL statement, and the second natural language template is any natural language template in the template library.

[0073] In a possible implementation, before the aforementioned matching of the relational algebraic nodes in the relational algebraic tree with the natural language template to obtain the first natural language description of SQL, the device may also include: a segmentation module 905, which is used to segment the relational algebraic tree into multiple segments according to preset segmentation points, and the segments include multiple target relational algebraic nodes, and the target relational algebraic nodes include target field information and target logical information.

[0074] In a possible implementation, the aforementioned matching module 902 is specifically configured to: match a natural language template for a target relational algebra node in each segment to obtain a first natural language description of SQL.

[0075] In a possible implementation, the aforementioned matching module 902 is specifically used to: determine the target natural language template of the target relational algebra node in each fragment according to the type of the keyword in the target relational algebra node; fill the target field information of the target relational algebra node into the target natural language template to obtain a first natural language description.

[0076] In a possible implementation, the target field information includes the name of the target field, and the aforementioned reasoning module 903 is further configured to translate the target field using the second largest language model to obtain a translated target field.

[0077] In a possible implementation, the aforementioned matching module 902 is specifically configured to fill the translated target field into the target natural language template to obtain a first natural language description.

[0078] Among them, the conversion module, matching module, reasoning module, rewriting module and segmentation module can be implemented by software, or can be implemented by hardware. Exemplarily, the implementation of the conversion module is introduced below by taking the conversion module as an example. Similarly, the implementation of the matching module, reasoning module, rewriting module and segmentation module can refer to the implementation of the conversion module.

[0079] As an example of a software functional unit, a conversion module may include code running on a computing instance. The computing instance may include at least one of a physical host (computing device), a virtual machine, and a container. Furthermore, the computing instance may be one or more. For example, the conversion module may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code may be distributed in the same region or in different regions. Furthermore, the multiple hosts / virtual machines / containers used to run the code may be distributed in the same availability zone (AZ) or in different AZs, each AZ including one data center or multiple data centers with close geographical locations. Generally, a region may include multiple AZs.

[0080] Similarly, multiple hosts / virtual machines / containers used to run the code can be distributed in the same virtual private cloud (VPC) or in multiple VPCs. Usually, a VPC is set up in a region. For cross-region communication between two VPCs in the same region and between VPCs in different regions, a communication gateway needs to be set up in each VPC to achieve interconnection between VPCs through the communication gateway.

[0081] As an example of a hardware functional unit, the conversion module may include at least one computing device, such as a server, etc. Alternatively, the conversion module may also be a device implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD may be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0082] The multiple computing devices included in the conversion module can be distributed in the same region or in different regions. The multiple computing devices included in the conversion module can be distributed in the same AZ or in different AZs. Similarly, the multiple computing devices included in the conversion module can be distributed in the same VPC or in multiple VPCs. The multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.

[0083] It should be noted that, in other embodiments, the conversion module can be used to execute any step in the data processing method, the matching module can be used to execute any step in the data processing method, the reasoning module can be used to execute any step in the data processing method, the rewrite module can be used to execute any step in the data processing method, and the segmentation module can be used to execute any step in the data processing method. The steps that the conversion module, matching module, reasoning module, rewrite module and segmentation module are responsible for implementing can be specified as needed. The full functions of the data processing device are realized by respectively implementing different steps in the data processing method through the conversion module, matching module, reasoning module, rewrite module and segmentation module.

[0084] The present application also provides a computing device 1000. Fig.10 As shown, computing device 1000 includes: bus 1002, processor 1004, memory 1006 and communication interface 1008. Processor 1004, memory 1006 and communication interface 1008 communicate through bus 1002. Computing device 1000 can be a server or a terminal device. It should be understood that the present application does not limit the number of processors and memories in computing device 1000.

[0085] The bus 1002 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.10 The bus 1002 may include a path for transmitting information between various components of the computing device 1000 (eg, the memory 1006, the processor 1004, and the communication interface 1008).

[0086] The processor 1004 may include any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).

[0087] The memory 1006 may include a volatile memory, such as a random access memory (RAM). The processor 1004 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD).

[0088] The memory 1006 stores executable program codes, and the processor 1004 executes the executable program codes to respectively implement the functions of the aforementioned conversion module, matching module, reasoning module, rewriting module, and segmentation module, thereby implementing the data processing method. That is, the memory 1006 stores instructions for executing the data processing method.

[0089] The embodiment of the present application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smart phone.

[0090] like Fig.11 As shown, the computing device cluster includes at least one computing device 1000. The memory 1006 in one or more computing devices 1000 in the computing device cluster may store the same instructions for executing the data processing method.

[0091] In some possible implementations, the memory 1006 of one or more computing devices 1000 in the computing device cluster may also store partial instructions for executing the data processing method. In other words, the combination of one or more computing devices 1000 may jointly execute instructions for executing the data processing method.

[0092] It should be noted that the memory 1006 in different computing devices 1000 in the computing device cluster can store different instructions, which are respectively used to execute part of the functions of the data processing device. That is, the instructions stored in the memory 1006 in different computing devices 1000 can implement the functions of one or more modules of the conversion module, the matching module, the reasoning module, the rewriting module and the segmentation module.

[0093] In some possible implementations, one or more computing devices in the computing device cluster may be connected via a network, which may be a wide area network or a local area network. Fig.12 A possible implementation is shown. Fig.12 As shown, two computing devices 1000A and 1000B are connected via a network. Specifically, the network is connected via a communication interface in each computing device. In this type of possible implementation, the memory 1006 in the computing device 1000A stores instructions for executing the functions of the conversion module. At the same time, the memory 1006 in the computing device 1000B stores instructions for executing the functions of the matching module, the reasoning module, the rewriting module, and the segmentation module.

[0094] It should be understood that Fig.12 The functions of the computing device 1000A shown in FIG. 1000A may also be completed by multiple computing devices 1000. Similarly, the functions of the computing device 1000B may also be completed by multiple computing devices 1000.

[0095] The present application embodiment also provides another computing device cluster. The connection relationship between the computing devices in the computing device cluster can be similar to that of Fig.11 and Fig.12 The connection mode of the computing device cluster is different in that the memory 1006 in one or more computing devices 1000 in the computing device cluster may store the same instructions for executing the data processing method.

[0096] In some possible implementations, the memory 1006 of one or more computing devices 1000 in the computing device cluster may also store partial instructions for executing the data processing method. In other words, the combination of one or more computing devices 1000 may jointly execute instructions for executing the data processing method.

[0097] It should be noted that the memory 1006 in different computing devices 1000 in the computing device cluster can store different instructions, which are respectively used to execute part of the functions of the data processing device. That is, the instructions stored in the memory 1006 in different computing devices 1000 can implement the functions of one or more modules of the conversion module, the matching module, the reasoning module, the rewriting module and the segmentation module.

[0098] The embodiment of the present application also provides a computer program product including instructions. The computer program product may be software or a program product including instructions that can be run on a computing device or stored in any available medium. When the computer program product is run on at least one computing device, the at least one computing device executes the data processing method.

[0099] The embodiment of the present application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that can be stored by a computing device or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk). The computer-readable storage medium includes instructions that instruct the computing device to execute the data processing method.

[0100] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0101] Finally, it should be noted that the above is only a specific implementation method of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be covered by the protection scope of the present application.

Claims

1. A data processing method, characterized in that: include: Converting a structured query language SQL into a relational algebra tree, wherein the relational algebra tree includes a plurality of relational algebra nodes, wherein one of the relational algebra nodes represents an operation performed on data, and the relational algebra node includes field information and logic information, wherein the field information is used to indicate an operation object of the relational algebra node, and the logic information is used to indicate a logical relationship between the operation objects; Matching a first natural language template for a relational algebra node in the relational algebra tree to obtain a first natural language description of the SQL, wherein the first natural language template is any natural language template in a template library, and the natural language template is used to translate the SQL into a natural language; The first natural language description is polished using a first large language model to obtain a second natural language description, where the second natural language description is used to assist a user in understanding the SQL.

2. The method according to claim 1, characterized in that When the relational algebra node does not have a matching first natural language template, the method further includes: The first SQL statement of the relational algebra node is rewritten into a second SQL statement, wherein the second SQL statement has a matching second natural language template, and the second natural language template is any natural language template in the template library.

3. The method according to claim 2, characterized in that Before matching the natural language template for the relational algebraic nodes in the relational algebraic tree to obtain the first natural language description of the SQL, the method further includes: According to preset segmentation points, the relational algebra tree is segmented into a plurality of segments, wherein the segments include a plurality of target relational algebra nodes, and the target relational algebra nodes include target field information and target logic information.

4. The method according to claim 3, characterized in that The step of matching a natural language template for a relational algebra node in the relational algebra tree to obtain a first natural language description of the SQL includes: The natural language template is matched for the target relational algebra node in each of the segments to obtain a first natural language description of the SQL.

5. The method according to claim 4, characterized in that The step of matching the natural language template to the target relational algebra node in each of the fragments to obtain the first natural language description of the SQL includes: Determining a target natural language template of the target relational algebra node in each of the segments according to the type of the keyword in the target relational algebra node; Fill the target field information of the target relational algebra node into the target natural language template to obtain the first natural language description.

6. The method according to any one of claims 3 to 5, characterized in that The target field information includes a name of the target field, and the method further includes: The target field is translated using the second largest language model to obtain a translated target field.

7. The method according to claim 6, characterized in that The step of filling the target field information of the target relational algebra node into the target natural language template to obtain the first natural language description includes: Fill the translated target field into the target natural language template to obtain the first natural language description.

8. A data processing device, characterized in that: include: A conversion module, used for converting a structured query language SQL into a relational algebra tree, wherein the relational algebra tree includes a plurality of relational algebra nodes, wherein one of the relational algebra nodes represents an operation performed on data, and the relational algebra node includes field information and logic information, wherein the field information is used for indicating an operation object of the relational algebra node, and the logic information is used for indicating a logical relationship between the operation objects; A matching module, used for matching a first natural language template for a relational algebraic node in the relational algebraic tree to obtain a first natural language description of the SQL, wherein the first natural language template is any natural language template in a template library, and the natural language template is used for translating the SQL into a natural language; The reasoning module is used to polish the first natural language description by using a first large language model to obtain a second natural language description, wherein the second natural language description is used to assist the user in understanding the SQL.

9. The device according to claim 8, characterized in that When the relational algebra node does not have a matching first natural language template, the device further includes: The rewriting module is used to rewrite the first SQL statement of the relational algebra node into a second SQL statement, where the second SQL statement has a matching second natural language template, and the second natural language template is any natural language template in the template library.

10. The device according to claim 9, characterized in that Before matching the natural language template for the relational algebraic nodes in the relational algebraic tree to obtain the first natural language description of the SQL, the device further includes: The segmentation module is used to segment the relational algebra tree into multiple segments according to preset segmentation points, wherein the segments include multiple target relational algebra nodes, and the target relational algebra nodes include target field information and target logic information.

11. The device according to claim 10, characterized in that The matching module is specifically used for: The natural language template is matched for the target relational algebra node in each of the segments to obtain a first natural language description of the SQL.

12. The device according to claim 11, characterized in that The matching module is specifically used for: Determining a target natural language template of the target relational algebra node in each of the segments according to the type of the keyword in the target relational algebra node; Fill the target field information of the target relational algebra node into the target natural language template to obtain the first natural language description.

13. The device according to any one of claims 10 to 12, characterized in that The target field information includes the name of the target field. The reasoning module is further used to translate the target field using a second language model to obtain a translated target field.

14. The device according to claim 13, characterized in that The matching module is specifically used for: Fill the translated target field into the target natural language template to obtain the first natural language description.

15. A computing device, characterized in that: The computing device includes a processor and a memory; The processor is configured to execute instructions stored in the memory, so that the computing device executes the method according to any one of claims 1 to 7.

16. A computing device cluster, characterized in that: comprising at least one computing device, each computing device comprising a processor and a memory; The processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device, so that the computing device cluster executes the method according to any one of claims 1 to 7.

17. A computer program product comprising instructions, characterized in that When the instructions are executed by a computing device cluster, the computing device cluster is caused to perform the method according to any one of claims 1 to 7.

18. A computer-readable storage medium, characterized in that: The method comprises computer program instructions, and when the computer program instructions are executed by a computing device cluster, the computing device cluster performs the method as claimed in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Query rewriting method and system of database system

    CN118445315A

  • Live broadcast text generation method and device based on large language model

    CN119026588A

  • SQL cross-database conversion method and device, equipment and storage medium

    CN119201978A

  • Data processing method and data processing apparatus

    US20230082563A1