A method, apparatus and device for converting SQL statements

By performing row and field matching on the source and target calculation results, generating a difference report and optimizing the SQL statement, the problem of low accuracy in cross-engine SQL statement conversion in existing technologies is solved, and an efficient and reliable SQL statement conversion process is achieved.

CN122152852APending Publication Date: 2026-06-05DUXIAOMAN TECH (BEIJING) CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
DUXIAOMAN TECH (BEIJING) CO LTD
Filing Date
2026-02-27
Publication Date
2026-06-05

AI Technical Summary

Technical Problem

In existing technologies, rule-based SQL syntax conversion tools cannot perceive the semantic equivalence of business logic, resulting in discrepancies between the calculation results of cross-engine SQL statements and the source calculation results. Furthermore, it is difficult to effectively verify and correct errors, leading to low accuracy of the generated target SQL statements.

Method used

By converting the source SQL statement into the initial target SQL statement, and performing row and field matching on the source and target calculation results, a difference report is generated. Based on the difference report, a new target SQL statement is generated, establishing an automated "conversion-verification-optimization" process. The SQL statement is optimized using a large model to improve accuracy.

Benefits of technology

It achieves high reliability and efficiency in cross-engine SQL conversion, reduces the cost of manual intervention, ensures the reliability and accuracy of the target SQL statement, and improves migration efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122152852A_ABST
    Figure CN122152852A_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a SQL statement conversion method, device and equipment, relating to the technical field of big data, to improve the reliability of a target SQL statement and thus improve the accuracy of a target calculation result. The method comprises: converting a source SQL statement into an initial target SQL statement, obtaining a source calculation result obtained by calculating a data source using the source SQL statement on a source calculation engine, and obtaining an initial target calculation result obtained by calculating the data source using the initial target SQL statement on a target calculation engine; performing line matching and field matching on the source calculation result and the initial target calculation result to obtain a target matching value and a difference report between the source calculation result and the initial target calculation result, and determining a detection result of the initial target SQL statement based on the target matching value and a first matching threshold; and when the detection result indicates that the initial target SQL statement fails to pass the detection, generating a new target SQL statement based on the difference report, the source SQL statement and the initial target SQL statement.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of big data technology, and in particular to a method, apparatus and device for converting SQL statements. Background Technology

[0002] With the rapid development of big data technology, enterprise data warehouses generally adopt Structured Query Language (SQL) engines (such as Hive, Spark SQL, and Flink SQL) to meet business needs. In offline data warehouse engine migration (e.g., from Hive to Spark SQL) or hybrid query scenarios, the automated conversion of cross-engine SQL statements has gradually become a core technical means to improve data link efficiency and ensure business consistency.

[0003] In existing technologies, SQL syntax conversion tools based on rule bases are typically used to convert SQL statements to obtain target SQL statements. The rule base includes predefined mapping rules (such as function name replacement and syntax structure rewriting).

[0004] However, the rule base only guarantees syntactic executability and cannot perceive the semantic equivalence of business logic. This leads to a deviation between the target calculation result of the transformed target SQL statement and the source calculation result, and it is difficult to effectively verify and correct errors in the SQL statement, resulting in low accuracy of the generated target SQL statement. Summary of the Invention

[0005] This application provides an SQL statement conversion method, apparatus, and device to improve the reliability of the target SQL statement, thereby improving the accuracy of the target calculation result obtained by executing the target SQL statement.

[0006] In a first aspect, embodiments of this application provide an SQL statement conversion method, the method comprising: The source SQL statement is converted into the initial target SQL statement, and the source calculation result obtained by using the source SQL statement to calculate the data source on the source calculation engine is obtained, as well as the initial target calculation result obtained by using the initial target SQL statement to calculate the data source on the target calculation engine. Row matching and field matching are performed on the source calculation result and the initial target calculation result to obtain the target matching value and difference report between the source calculation result and the initial target calculation result. Based on the target matching value and the first matching threshold, the detection result of the initial target SQL statement is determined. The difference report includes: the difference rows and difference fields that do not match in the source calculation result and the initial target calculation result. When the detection result indicates that the initial target SQL statement fails the detection, a new target SQL statement is generated based on the difference report, the source SQL statement, and the initial target SQL statement.

[0007] In an optional embodiment, after generating a new target SQL statement based on the difference report, the source SQL statement, and the initial target SQL statement, the method further includes: The new target SQL statement is used as the first target SQL statement, and multiple rounds of transformation and optimization operations are performed until the current loop count exceeds the loop count threshold or the current target SQL statement passes the test. One round of transformation and optimization operations includes: Retrieve the current round target calculation result obtained by using the current round target SQL statement to calculate the data source on the target calculation engine; Perform row and field matching on the source calculation results and the current round target calculation results to obtain the current round target matching value and the current round new difference report between the source calculation results and the current round target calculation results. Based on the current round target matching value, determine the current round detection result of the current round target SQL statement. When the current round of detection results indicates that the target SQL statement fails the current round of detection, the target SQL statement for the next round is generated based on the current round of difference report, the source SQL statement, and the target SQL statement for the current round.

[0008] In one optional embodiment, row matching and field matching are performed on the source calculation result and the initial target calculation result to obtain the target matching value and difference report between the source calculation result and the initial target calculation result, including: Each first row with a primary key in the source calculation result and each second row with a primary key in the initial target calculation result are compared field by field to determine the comparison result for each first row with a primary key. The comparison results include: comparison pass result and comparison fail result. The comparison pass result indicates that a first row with a primary key is completely matched with the associated second row with a primary key. The comparison fail result includes: two rows with primary keys that are not completely matched and the difference fields between the two rows with primary keys. Two rows with primary keys include: a first row with a primary key and a second row with a primary key associated with a first row with a primary key. Perform row matching and field comparison on each first row without a primary key in the source calculation result and each second row without a primary key in the initial target calculation result to determine the matching result of each first row without a primary key. The matching result includes: matching pass result and matching fail result. The matching pass result indicates that the comprehensive matching value between a first row without a primary key and the associated second row without a primary key is greater than the second matching threshold. The matching fail result includes: two non-matching rows without a primary key and the difference field between the two rows without a primary key. The two rows without a primary key include: a first row without a primary key and a second row without a primary key associated with a first row without a primary key. Based on the obtained comparison pass results and matching pass results, the target matching value between the source calculation result and the initial target calculation result is determined, and the comparison failure results and matching failure results are summarized to obtain a difference report.

[0009] In one optional embodiment, row matching and field comparison are performed on each first row without a primary key in the source calculation result and each second row without a primary key in the initial target calculation result to determine the matching result of each first row without a primary key, including: For each row that has no primary key, perform the following operations: In each second row without a primary key, the target second row without a primary key is selected that is most similar to the target first row without a primary key. The row matching degree between the target first row without a primary key and the target second row without a primary key is calculated. Field comparison is performed on the target first row without a primary key and the target second row without a primary key to obtain the field comparison results of each target first field contained in the target first row without a primary key. The field comparison results indicate whether the corresponding target first field is consistent with the associated target second field. The target first row without a primary key is any one of the first rows without a primary key. Based on the row matching score and field comparison results, determine the matching result of the first target row without a primary key.

[0010] In one optional embodiment, the matching result of the target first row without a primary key is determined based on the row matching degree value and the field comparison result, including: Based on the number of consistent field pairs in the field comparison results and the total number of field pairs, determine the field consistency rate between the target first row without a primary key and the target second row without a primary key; Based on the row matching score and field consistency rate, determine the comprehensive matching value between the first target row without a primary key and the second target row without a primary key; When the overall matching value is greater than the second matching threshold, it is determined that the target first row without a primary key and the target second row without a primary key have matched successfully. When the overall matching value is less than or equal to the second matching threshold, it is determined that the target first row without a primary key and the target second row without a primary key do not match, and a difference field is generated based on the field comparison results.

[0011] In one optional embodiment, based on the obtained comparison pass results and matching pass results, determining the target matching value between the source calculation result and the initial target calculation result includes: Based on the obtained comparison and matching results, determine the number of matching rows in each first row of the source calculation result, and based on the number of matching rows and the total number of first rows, determine the target matching value between the source calculation result and the initial target calculation result; or, Based on the comparison and matching results, determine the number of primary key row matches in each first primary key row and the number of primary key-free row matches in each first primary key-free row. Based on the number of primary key row matches and the total number of primary key row matches in each first primary key row, determine the primary key match value. Based on the number of primary key-free row matches and the total number of primary key-free row matches in each first primary key row, determine the primary key-free match value. Based on the primary key match value and the primary key-free match value, determine the target match value between the source calculation result and the initial target calculation result.

[0012] In one optional embodiment, a new target SQL statement is generated based on the difference report, the source SQL statement, and the initial target SQL statement, including: Input the difference report, source SQL statement, initial target SQL statement, and preset prompt words into the large model to obtain the new target SQL statement and root cause of the difference output by the large model.

[0013] In an optional embodiment, before inputting the difference report, source SQL statement, initial target SQL statement, and preset prompt words into the large model to obtain the new target SQL statement and difference root cause output by the large model, the method further includes: Feature extraction is performed on the difference report, source SQL statement, and initial target SQL statement to obtain the target difference features corresponding to the difference report; The optimization knowledge base is queried to determine whether there are matching historical difference features in the optimization knowledge base that match the target difference feature. The optimization knowledge base is used to store each historical difference feature and the root causes and optimization measures associated with each historical difference feature. When there are historical difference features in the knowledge base that match the target difference features, the optimization measures associated with the historical difference features are adopted to generate a new target SQL statement.

[0014] Secondly, embodiments of this application also provide an SQL statement conversion device, the device comprising: The conversion module is used to convert the source SQL statement into the initial target SQL statement, obtain the source calculation result obtained by using the source SQL statement to calculate the data source on the source calculation engine, and obtain the initial target calculation result obtained by using the initial target SQL statement to calculate the data source on the target calculation engine. The detection module is used to perform row matching and field matching on the source calculation result and the initial target calculation result to obtain the target matching value and difference report between the source calculation result and the initial target calculation result. Based on the target matching value and the first matching threshold, the detection result of the initial target SQL statement is determined. The difference report includes: the difference rows and difference fields that do not match in the source calculation result and the initial target calculation result. The optimization module is used to generate a new target SQL statement based on the difference report, the source SQL statement, and the initial target SQL statement when the detection result indicates that the initial target SQL statement fails the detection.

[0015] In an optional embodiment, after generating a new target SQL statement based on the difference report, the source SQL statement, and the initial target SQL statement, the optimization module is further configured to: The new target SQL statement is used as the first target SQL statement, and multiple rounds of transformation and optimization operations are performed until the current loop count exceeds the loop count threshold or the current target SQL statement passes the test. One round of transformation and optimization operations includes: Retrieve the current round target calculation result obtained by using the current round target SQL statement to calculate the data source on the target calculation engine; Perform row and field matching on the source calculation results and the current round target calculation results to obtain the current round target matching value and the current round new difference report between the source calculation results and the current round target calculation results. Based on the current round target matching value, determine the current round detection result of the current round target SQL statement. When the current round of detection results indicates that the target SQL statement fails the current round of detection, the target SQL statement for the next round is generated based on the current round of difference report, the source SQL statement, and the target SQL statement for the current round.

[0016] In an optional embodiment, when performing row matching and field matching on the source calculation result and the initial target calculation result to obtain the target matching value and difference report between the source calculation result and the initial target calculation result, the detection module is further configured to: Each first row with a primary key in the source calculation result and each second row with a primary key in the initial target calculation result are compared field by field to determine the comparison result for each first row with a primary key. The comparison results include: comparison pass result and comparison fail result. The comparison pass result indicates that a first row with a primary key is completely matched with the associated second row with a primary key. The comparison fail result includes: two rows with primary keys that are not completely matched and the difference fields between the two rows with primary keys. Two rows with primary keys include: a first row with a primary key and a second row with a primary key associated with a first row with a primary key. Perform row matching and field comparison on each first row without a primary key in the source calculation result and each second row without a primary key in the initial target calculation result to determine the matching result of each first row without a primary key. The matching result includes: matching pass result and matching fail result. The matching pass result indicates that the comprehensive matching value between a first row without a primary key and the associated second row without a primary key is greater than the second matching threshold. The matching fail result includes: two non-matching rows without a primary key and the difference field between the two rows without a primary key. The two rows without a primary key include: a first row without a primary key and a second row without a primary key associated with a first row without a primary key. Based on the obtained comparison pass results and matching pass results, the target matching value between the source calculation result and the initial target calculation result is determined, and the comparison failure results and matching failure results are summarized to obtain a difference report.

[0017] In an optional embodiment, when performing row matching and field comparison on each first row without a primary key in the source calculation result and each second row without a primary key in the initial target calculation result to determine the matching result of each first row without a primary key, the detection module is further configured to: For each row that has no primary key, perform the following operations: In each second row without a primary key, the target second row without a primary key is selected that is most similar to the target first row without a primary key. The row matching degree between the target first row without a primary key and the target second row without a primary key is calculated. Field comparison is performed on the target first row without a primary key and the target second row without a primary key to obtain the field comparison results of each target first field contained in the target first row without a primary key. The field comparison results indicate whether the corresponding target first field is consistent with the associated target second field. The target first row without a primary key is any one of the first rows without a primary key. Based on the row matching score and field comparison results, determine the matching result of the first target row without a primary key.

[0018] In an optional embodiment, when determining the matching result of the target first row without a primary key based on the row matching degree value and the field comparison result, the detection module is further configured to: Based on the number of consistent field pairs in the field comparison results and the total number of field pairs, determine the field consistency rate between the target first row without a primary key and the target second row without a primary key; Based on the row matching score and field consistency rate, determine the comprehensive matching value between the first target row without a primary key and the second target row without a primary key; When the overall matching value is greater than the second matching threshold, it is determined that the target first row without a primary key and the target second row without a primary key have matched successfully. When the overall matching value is less than or equal to the second matching threshold, it is determined that the target first row without a primary key and the target second row without a primary key do not match, and a difference field is generated based on the field comparison results.

[0019] In an optional embodiment, when determining the target matching value between the source calculation result and the initial target calculation result based on the obtained comparison pass results and matching pass results, the detection module is further configured to: Based on the obtained comparison and matching results, determine the number of matching rows in each first row of the source calculation result, and based on the number of matching rows and the total number of first rows, determine the target matching value between the source calculation result and the initial target calculation result; or, Based on the comparison and matching results, determine the number of primary key row matches in each first primary key row and the number of primary key-free row matches in each first primary key-free row. Based on the number of primary key row matches and the total number of primary key row matches in each first primary key row, determine the primary key match value. Based on the number of primary key-free row matches and the total number of primary key-free row matches in each first primary key row, determine the primary key-free match value. Based on the primary key match value and the primary key-free match value, determine the target match value between the source calculation result and the initial target calculation result.

[0020] In an optional embodiment, when generating a new target SQL statement based on the difference report, the source SQL statement, and the initial target SQL statement, the optimization module is further configured to: Input the difference report, source SQL statement, initial target SQL statement, and preset prompt words into the large model to obtain the new target SQL statement and root cause of the difference output by the large model.

[0021] In an optional embodiment, before inputting the difference report, source SQL statement, initial target SQL statement, and preset prompt words into the large model to obtain the new target SQL statement and root cause of the difference output by the large model, the optimization module is further configured to: Feature extraction is performed on the difference report, source SQL statement, and initial target SQL statement to obtain the target difference features corresponding to the difference report; The optimization knowledge base is queried to determine whether there are matching historical difference features in the optimization knowledge base that match the target difference feature. The optimization knowledge base is used to store each historical difference feature and the root causes and optimization measures associated with each historical difference feature. When there are historical difference features in the knowledge base that match the target difference features, the optimization measures associated with the historical difference features are adopted to generate a new target SQL statement.

[0022] Thirdly, embodiments of this application also provide an electronic device, including: Processor; and Stored program memory, The program includes instructions that, when executed by the processor, cause the processor to perform the SQL statement conversion method as described in the first aspect.

[0023] Fourthly, embodiments of this application also provide a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause a computer to execute the SQL statement conversion method as described in the first aspect.

[0024] Fifthly, this application provides a computer program product that, when invoked by a computer, causes the computer to execute the SQL statement conversion method steps as described in the first aspect.

[0025] The beneficial effects of this application are as follows: In the SQL statement conversion method provided in this application embodiment, the source SQL statement is first converted into an initial target SQL statement. The source calculation result obtained by using the source SQL statement to calculate the data source on the source calculation engine, and the initial target calculation result obtained by using the initial target SQL statement to calculate the data source on the target calculation engine, are then obtained. Row matching and field matching are performed on the source calculation result and the initial target calculation result to obtain the target matching value and difference report between the source calculation result and the initial target calculation result. Based on the target matching value and a first matching threshold, the detection result of the initial target SQL statement is determined. The difference report includes the mismatched rows and fields in the source calculation result and the initial target calculation result. Finally, when the detection result indicates that the initial target SQL statement fails detection, a new target SQL statement is generated based on the difference report, the source SQL statement, and the initial target SQL statement. This establishes a complete automated process of "conversion-verification-optimization," solving the problem of separation between conversion and verification in traditional technologies and significantly reducing the cost of manual intervention. Furthermore, through a dual verification mechanism of row matching and field matching, it not only determines whether the detection passes, but also generates a detailed difference report, providing accurate input basis for subsequent optimization, ensuring the reliability of the final generated target SQL statement, ensuring high reliability of cross-engine SQL conversion in data results, and significantly improving migration efficiency.

[0026] Furthermore, other features and advantages of this application will be set forth in the following description and will be apparent in part from the description, or may be learned by practicing the application. The objectives and other advantages of this application may be realized and obtained by means of the structures particularly pointed out in the written description, claims, and drawings. Attached Figure Description

[0027] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described herein are used to provide a further understanding of this application, constitute a part of this application, and do not constitute an improper limitation of this application. In the accompanying drawings: Figure 1 This is a schematic diagram of an optional system architecture applicable to the embodiments of this application.

[0028] Figure 2 This is a schematic diagram illustrating the implementation process of an SQL statement conversion method provided in an embodiment of this application.

[0029] Figure 3 This is a schematic diagram illustrating another implementation of an SQL statement conversion method provided in this application.

[0030] Figure 4 This is a schematic diagram of the structure of an SQL statement conversion device provided in an embodiment of this application.

[0031] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0032] Embodiments of this application will now be described in more detail with reference to the accompanying drawings. While some embodiments of this application are shown in the drawings, it should be understood that this application can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this application. It should be understood that the drawings and embodiments of this application are for illustrative purposes only and are not intended to limit the scope of protection of this application.

[0033] It should be understood that the steps described in the method embodiments of this application may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this application is not limited in this respect.

[0034] The term "comprising" and its variations as used herein are open-ended, meaning "including but not limited to". The term "based on" means "at least partially based 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". Definitions of other terms will be given in the following description. It should be noted that the concepts of "first", "second", etc., mentioned in this application are used only to distinguish different devices, modules, or units, and are not intended to limit the order of functions performed by these devices, modules, or units or their interdependencies.

[0035] It should be noted that the terms "a" and "a plurality of" used in this application are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".

[0036] The names of the messages or information exchanged between multiple devices in the embodiments of this application are for illustrative purposes only and are not intended to limit the scope of these messages or information.

[0037] The following explanations of some terms used in the embodiments of this application are provided to facilitate understanding by those skilled in the art.

[0038] (1) Offline data warehouse: refers to a data warehouse system that performs batch storage, computation and analysis of massive data. It is usually based on distributed architectures such as Hadoop and ODPS, and the computation tasks are run in the form of scheduled jobs.

[0039] (2) Large Language Model (LLM): Refers to large models, such as GPT and Tongyi 1000 Questions. Large models represent a significant technological breakthrough in the field of artificial intelligence in recent years. Based on deep learning and neural network architecture, they generate complex language models through training on massive amounts of data. Their core advantage lies in their powerful language understanding and generation capabilities, enabling them to handle various tasks in Natural Language Processing (NLP), such as text generation, translation, and question answering. By learning patterns and relationships in a large amount of text, large models can generate coherent and accurate text content, demonstrating broad application potential in multiple fields.

[0040] (3) Computing engine: The software framework responsible for executing data computing tasks. In the embodiments of this application, it specifically refers to big data SQL engines such as Hive (based on MapReduce), Spark SQL (based on in-memory computing), and Flink SQL (supporting stream and batch processing).

[0041] (4) Unique primary key: A field or combination of fields in a database table that can uniquely identify a record.

[0042] Based on the above explanations of terms and related terminology, the design concept of the embodiments of this application will be briefly introduced below: With the rapid development of big data technology, enterprise data warehouses generally adopt big data SQL engines to meet business scenario requirements. In offline data warehouse engine migration (e.g., from Hive to Spark SQL) or mixed query scenarios (e.g., queries involving both Hive and Spark SQL), the automated conversion of cross-engine SQL statements has gradually become a core technical means to improve data link efficiency and ensure business consistency.

[0043] In existing technologies, rule-based SQL syntax transformation tools are typically used to transform SQL statements into target SQL statements. These rule bases include predefined mapping rules (e.g., function name replacement, syntax structure rewriting). However, rule bases only guarantee syntactic executableness and cannot perceive the semantic equivalence of business logic, leading to discrepancies between the target calculation result and the source calculation result in the transformed target SQL statement.

[0044] Furthermore, verifying the target calculation results relies on manual full-scale comparison or sampling comparison. Full-scale comparison is resource and time-consuming, while sampling comparison carries high risks. When discrepancies are found between the target and source calculation results, it is necessary to manually check logs, analyze data differences, rely on experience to guess the problem in the converted SQL, and then modify the SQL. The entire process is inefficient and error-prone. In other words, existing technologies struggle to effectively verify and correct errors in SQL statements, resulting in low accuracy of the generated target SQL statements.

[0045] In view of this, this application provides an SQL statement conversion method, which specifically includes: converting a source SQL statement into an initial target SQL statement, and obtaining the source calculation result obtained by using the source SQL statement to calculate the data source on the source calculation engine, and obtaining the initial target calculation result obtained by using the initial target SQL statement to calculate the data source on the target calculation engine; then performing row matching and field matching on the source calculation result and the initial target calculation result to obtain the target matching value and difference report between the source calculation result and the initial target calculation result, and determining the detection result of the initial target SQL statement based on the target matching value and a first matching threshold, wherein the difference report includes: mismatched rows and fields in the source calculation result and the initial target calculation result; finally, when the detection result indicates that the initial target SQL statement fails detection, a new target SQL statement is generated based on the difference report, the source SQL statement, and the initial target SQL statement. This establishes a complete automated process of "conversion-verification-optimization," solving the problem of separation between conversion and verification in traditional technologies and significantly reducing the cost of manual intervention. Furthermore, through a dual verification mechanism of row matching and field matching, it not only determines whether the detection passes, but also generates a detailed difference report, providing accurate input basis for subsequent optimization, ensuring the reliability of the final generated target SQL statement, ensuring high reliability of cross-engine SQL conversion in data results, and significantly improving migration efficiency.

[0046] In particular, the preferred embodiments of this application will be described below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are for illustration and explanation only and are not intended to limit this application. Furthermore, the embodiments of this application and the features in the embodiments can be combined with each other without conflict.

[0047] See Figure 1 The diagram illustrates an optional system architecture applicable to an embodiment of this application. This system architecture may include: terminal devices (101a, 101b) and server 102. The terminal devices (101a, 101b) and server 102 can interact via a communication network. The communication network may employ wireless communication or wired communication methods. For example, the terminal devices (101a, 101b) can access the network and communicate with server 102 via cellular mobile communication technology. This cellular mobile communication technology may include, for example, 5G (5th generation mobile networks) or next-generation mobile communication technology. Optionally, the terminal devices (101a, 101b) can access the network and communicate with server 102 via short-range wireless communication. This short-range wireless communication method may include, for example, wireless fidelity (Wi-Fi) technology.

[0048] This application embodiment does not impose any limitation on the number of communication devices involved in the above system architecture. For example, the above system architecture may include more terminal devices, or it may include fewer terminal devices, or it may also include other network devices. Figure 1 As shown, only terminal devices (101a, 101b) and server 102 are described as examples. The following is a brief introduction to the above communication devices and their respective functions.

[0049] A terminal device (101a, 101b) is a device that can provide voice and / or data connectivity to a user, and may be a device that supports wired and / or wireless connections.

[0050] For example, terminal devices (101a, 101b) may include, but are not limited to: mobile phones, tablets, laptops, handheld computers, mobile internet devices (MID), wearable devices, virtual reality (VR) devices, augmented reality (AR) devices, wireless terminal devices in industrial control, wireless terminal devices in autonomous driving, wireless terminal devices in smart grids, wireless terminal devices in transportation safety, wireless terminal devices in smart cities, or wireless terminal devices in smart homes, etc.

[0051] In addition, the terminal devices (101a, 101b) may have related clients installed. These clients may be software, such as applications (APPs), browsers, short video software, web pages, mini-programs, etc. It should be noted that the terminal devices (101a, 101b) in this embodiment may be SQL statement conversion related clients.

[0052] Server 102 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.

[0053] Optionally, a pre-trained large model can be deployed on server 102. When the detection result indicates that the initial target SQL statement fails detection, server 102 inputs the difference report, the source SQL statement, the initial target SQL statement, and preset prompts into the large model to obtain a new target SQL statement and the root cause of the difference. The large model can be any large language model (e.g., GPT-4, CodeLlama), and this application does not limit its scope.

[0054] The SQL statement conversion method provided by the exemplary embodiments of this application will be described below in conjunction with the above system architecture and with reference to the accompanying drawings. It should be noted that the above system architecture is only shown for the purpose of understanding the spirit and principles of this application, and the embodiments of this application are not limited in any way.

[0055] See Figure 2 The diagram shown illustrates the implementation flow of an SQL statement conversion method provided in this application embodiment. Taking a server as an example, the specific implementation flow of this method is as follows: S20: Convert the source SQL statement into the initial target SQL statement, and obtain the source calculation result obtained by using the source SQL statement to calculate the data source on the source calculation engine, and obtain the initial target calculation result obtained by using the initial target SQL statement to calculate the data source on the target calculation engine.

[0056] Optionally, in this embodiment of the application, when converting the source SQL statement into the initial target SQL statement, an Abstract Syntax Tree (AST) method can be used to convert the source SQL statement into the initial target SQL statement. Specifically, the parser parses the source SQL statement into an AST, then traverses the AST to identify specific nodes related to the source computing engine, queries the rule base for the corresponding target computing engine rewriting rules, applies the rules, reconstructs the AST, and generates the target SQL statement.

[0057] The parser is either Apache Calcite or ANTLR, and the rule base is a structured database table or XML / YAML configuration file that stores mapping rules. These rules include not only function name mappings but also clause rewriting rules (e.g., converting a Hive LATERAL VIEW json_tuple to a combination of Spark's EXPLODE and GET_JSON_OBJECT), data type mappings, and more.

[0058] Optionally, in this embodiment of the application, when converting the source SQL statement into the initial target SQL statement, a large model conversion method can also be used. Specifically, the source SQL statement, the source computing engine type, and the target computing engine type are input into the large model to obtain the initial target SQL statement output by the large model.

[0059] Optionally, in this embodiment, the acquisition of the source computation result and the acquisition of the initial target computation result are performed in parallel. Specifically, corresponding computation tasks are submitted to both the source computation engine and the target computation engine simultaneously (i.e., the computation task corresponding to the source SQL statement is submitted to the source computation engine, and the computation task corresponding to the target SQL statement is submitted to the target computation engine). The two computation tasks are configured to use the same test dataset (i.e., to perform computation on the same data source). After the two computation tasks are completed, the source computation result and the initial target computation result are retrieved to a neutral storage area (e.g., a specific directory in HDFS) by means of SQL query or reading the output file, in preparation for subsequent detection.

[0060] In this process, Apache Airflow or DolphinScheduler is used as the scheduler of the scheduling framework, and a directed acyclic graph for parallel execution is written to enable the two computational tasks to be executed in parallel.

[0061] S21: Perform row matching and field matching on the source calculation result and the initial target calculation result to obtain the target matching value and difference report between the source calculation result and the initial target calculation result, and determine the detection result of the initial target SQL statement based on the target matching value and the first matching threshold.

[0062] The difference report includes: the difference rows and difference fields that do not match between the source calculation results and the initial target calculation results.

[0063] In this embodiment, row matching and field matching are performed on the source calculation result and the initial target calculation result to obtain the target matching value and difference report between the source calculation result and the initial target calculation result. Then, it is determined whether the target matching value is greater than a first matching threshold. If it is, the detection result of the initial target SQL statement is determined to be a successful detection; otherwise, the detection result of the initial target SQL statement is determined to be a failed detection. The first matching threshold can be 0.995, and this embodiment does not limit it.

[0064] Optionally, in this embodiment of the application, a possible implementation is provided for performing row matching and field matching on the source calculation result and the initial target calculation result to obtain the target matching value and difference report between the source calculation result and the initial target calculation result, specifically by performing the following operations: S210: Compare each row with a primary key in the source calculation result and each row with a primary key in the initial target calculation result field by field to determine the comparison result of each row with a primary key.

[0065] The comparison results include: comparison pass and comparison fail. A comparison pass indicates that a first row with a primary key and its associated second row with a primary key are completely matched. A comparison fail includes: two rows with primary keys that are not completely matched, and the difference fields between the two rows with primary keys. The two rows with primary keys include: a first row with a primary key and a second row with a primary key associated with the first row with a primary key. A row with a primary key is a row with a unique primary key. Difference fields are fields that are inconsistent.

[0066] In this embodiment of the application, primary key association is performed on each first primary key row and each second primary key row to obtain the second primary key row associated with each first primary key row. Then, each matching pair of primary key rows (a first primary key row and a second primary key row associated with a first primary key row) is compared field by field to obtain the comparison result for each first primary key row.

[0067] For example, assuming a primary key row H1 is associated with a primary key row H2, a field-by-field comparison is performed on the first primary key row H1 and the second primary key row H2. If all fields of the first primary key row H1 completely match all fields of the second primary key row H2, then the comparison result of the first primary key row H1 is determined to be a complete match between the first primary key row H1 and the second primary key row H2. If the first field of the first primary key row H1 differs from the first field of the second primary key row H2, then the comparison result of the first primary key row H1 is determined to be a mismatch between the first primary key row H1 and the second primary key row H2, and the first primary key row H1 and the second primary key row H2 have a different field, which is the first field.

[0068] Optionally, in this embodiment, the primary key is joined between each first primary key row and each second primary key row using the SQL "FULL OUTER JOIN". The matching primary key row pairs are compared field-by-field using the logic "CASE WHEN A.col1 IS NULL OR B.col1 IS NULL OR A.col1 != B.col1 THEN 1 ELSE 0 END". "FULL OUTER JOIN" compares all rows from both tables, returning all records from both tables. If a row has no match in the other table, it is filled with a NULL value. "CASE WHEN A.col1 IS NULL OR B.col1 IS NULL OR A.col1 != B.col1 THEN 1 ELSE 0 END" is an SQL conditional expression used to mark data differences field-by-field. Specifically, if a field is NULL or has a different value on either side, it is marked as 1 (indicating a difference); otherwise, it is marked as 0.

[0069] This allows for precise comparison of rows with primary keys, ensuring the accuracy of the target matching value.

[0070] S211: Perform row matching and field comparison on each first row without a primary key in the source calculation result and each second row without a primary key in the initial target calculation result to determine the matching result of each first row without a primary key.

[0071] The matching results include: successful matches and unsuccessful matches. A successful match indicates that the combined match value between a first row without a primary key and its associated second row without a primary key is greater than a second matching threshold. Unsuccessful matches include: two rows without a primary key that do not match and the difference field between the two rows without a primary key. Two rows without a primary key include: a first row without a primary key and a second row without a primary key associated with the first row without a primary key. A row without a primary key is a row without a unique primary key.

[0072] Optionally, in this embodiment of the application, a possible implementation is provided for performing row matching and field comparison on each first row without a primary key in the source calculation result and each second row without a primary key in the initial target calculation result to determine the matching result of each first row without a primary key. Specifically, the following operations are performed: For each row that has no primary key, perform the following operations: S2110: Filter out the target second keyless row that is most similar to the target first keyless row from each second keyless row, calculate the row matching degree between the target first keyless row and the target second keyless row, and perform field comparison between the target first keyless row and the target second keyless row to obtain the field comparison results of each target first field contained in the target first keyless row.

[0073] The field comparison result indicates whether the first field of the corresponding target is consistent with the second field of the associated target. The first row without a primary key is any one of the first rows without a primary key.

[0074] Optionally, in this embodiment of the application, when selecting the target second keyless row that is most similar to the target first keyless row from each second keyless row, and calculating the row matching degree value between the target first keyless row and the target second keyless row, any one of the three methods—vector method, hash method, and field method—can be used. The three methods are described below: (1) Vector method: Concatenate the comparable fields contained in each first row without a primary key to obtain the text string of each first row without a primary key. Vectorize the text string of each first row without a primary key to obtain the first semantic vector of each first row without a primary key. Concatenate the comparable fields contained in each second row without a primary key to obtain the text string of each second row without a primary key. Vectorize the text string of each second row without a primary key to obtain the second semantic vector of each second row without a primary key. Select the target second semantic vector that is most similar to the target first semantic vector of the target first row without a primary key from the second semantic vectors. Take the second row without a primary key corresponding to the target second semantic vector as the target second row without a primary key that is most similar to the target first row without a primary key. Take the cosine similarity between the target first semantic vector and the target second semantic vector as the row matching degree value between the target first row without a primary key and the target second row without a primary key.

[0075] Among them, the comparable fields are fields that can be compared in terms of row values, such as business fields such as numbers, strings, and dates; when vectorizing, a pre-trained Sentence-BERT model or a text embedding model is used for vectorization, and the approximate nearest neighbor search library of Faiss or Spark MLlib is used to find the most similar target second row without a primary key among the target first semantic vector of the target first row without a primary key.

[0076] In this way, using the vector method can ensure the accuracy of the row matching degree value.

[0077] (2) Hash method: Concatenate the comparable fields contained in each of the first keyless rows to obtain the text string of each of the first keyless rows. Perform hash calculation on the text string of each of the first keyless rows to obtain the first hash signature of each of the first keyless rows. Concatenate the comparable fields contained in each of the second keyless rows to obtain the text string of each of the second keyless rows. Perform hash calculation on the text string of each of the second keyless rows to obtain the second hash signature of each of the second keyless rows. Filter out the target second hash signature that is most similar to the target first hash signature of the target first keyless row from the second hash signatures. Take the second keyless row corresponding to the target second hash signature as the target second keyless row that is most similar to the target first keyless row. Take the similarity between the target first hash signature and the target second hash signature as the row matching degree value between the target first keyless row and the target second keyless row.

[0078] Wherein, the hash signature is either a MinHash signature or a SimHash signature. If the hash signature is a MinHash signature, the similarity between the first target hash signature and the second target hash signature is the Jaccard distance between the first target hash signature and the second target hash signature. If the hash signature is a SimHash signature, the similarity between the first target hash signature and the second target hash signature is the Hamming distance between the first target hash signature and the second target hash signature.

[0079] Thus, the hash method can be applied to fast deduplication and coarse-grained similarity search of large-scale data, improving computational efficiency.

[0080] (3) Field method: For each second row without a primary key, perform the following operations: calculate the similarity between each field in the comparable fields contained in the target first row without a primary key and each field in the comparable fields contained in a second row without a primary key, assign a corresponding weight to each field, and perform a weighted average of the similarity between each pair of fields to obtain the similarity between the target first row without a primary key and a second row without a primary key; then, select the target second row without a primary key that is most similar to the target first row without a primary key from each second row without a primary key, and use the similarity between the target first hash signature and the target second hash signature as the row matching degree value between the target first row without a primary key and the target second row without a primary key.

[0081] When calculating the similarity between fields, if the field is a number, the relative error between the numbers is used as the similarity between the fields; if the field is a character, the Jaccard-Winkler distance between the characters is used as the similarity between the fields.

[0082] In this way, the interpretability of row matching values ​​can be improved by using the field method.

[0083] In addition, it is worth noting that in the embodiments of this application, when selecting the target second keyless row that is most similar to the target first keyless row from each second keyless row and calculating the row matching degree value between the target first keyless row and the target second keyless row, the vector method, hash method and field method can be used in combination. This embodiment of the application does not impose any restrictions on this. For example: Concatenate the comparable fields of each first row without a primary key to obtain a text string for each row. Vectorize this text string to obtain a first semantic vector for each row. Similarly, concatenate the comparable fields of each second row without a primary key to obtain a text string for each row. Vectorize this text string to obtain a second semantic vector for each row. From these second semantic vectors, select the target second semantic vector that is most similar to the target first semantic vector of the target first row without a primary key. Then, select the second row without a primary key corresponding to the target second semantic vector as the target second row without a primary key that is most similar to the target first row without a primary key. Calculate the similarity between each field in the comparable fields of the target first row without a primary key and each field in the comparable fields of the target second row without a primary key. Assign a weight to each field and perform a weighted average of the similarities between each pair of fields to obtain the row matching score between the target first row without a primary key and the target second row without a primary key. For example: using the vector method, the first similarity between the target first row without a primary key and each second row without a primary key is obtained; using the hash method, the second similarity between the target first row without a primary key and each second row without a primary key is obtained; using the field method, the third similarity between the target first row without a primary key and each second row without a primary key is obtained. Then, for each second row without a primary key, the following operations are performed: the first, second, and third similarities between a second row without a primary key and the target first row without a primary key are weighted and averaged to obtain the row similarity between a second row without a primary key and the target first row without a primary key; finally, the target second row without a primary key with the highest row similarity to the target first row without a primary key is selected from all the second rows without a primary key, and the row similarity between the target first row without a primary key and the target second row without a primary key is used as the row matching score between the target first row without a primary key and the target second row without a primary key.

[0084] Optionally, in this embodiment of the application, when comparing the fields of the first target row without a primary key and the second target row without a primary key to obtain the field comparison results of each target first field contained in the first target row without a primary key, a field-by-field comparison is performed on each target first field contained in the first target row without a primary key and each target second field contained in the second target row without a primary key to obtain the field comparison results of each target first field contained in the first target row without a primary key.

[0085] S2111: Based on the row matching score and field comparison results, determine the matching result of the first target row without a primary key.

[0086] In this way, by adopting a similar row filtering mechanism, an effective data row correspondence can be established even without an explicit primary key. Furthermore, by combining row matching degree and field comparison results, the data consistency of rows without primary keys can be evaluated from different perspectives, thereby improving the reliability of the verification.

[0087] Optionally, in this embodiment of the application, a possible implementation is provided for determining the matching result of the target first row without a primary key based on the row matching degree value and the field comparison result, specifically by performing the following operations: S2111-1: Based on the number of consistent field pairs in the field comparison results and the total number of field pairs, determine the field consistency rate between the target first row without a primary key and the target second row without a primary key.

[0088] Among them, a consistent field pair refers to a field pair consisting of a consistent target first field and its associated target second field. The total field pairs include: consistent field pairs and difference field pairs corresponding to the target first row without a primary key and the target second row without a primary key.

[0089] In this embodiment of the application, the ratio of the number of consistent field pairs in the field comparison result to the total number of field pairs is calculated to obtain the field consistency rate between the target first row without a primary key and the target second row without a primary key.

[0090] For example, assuming the number of consistent field pairs in the field comparison results is 4 and the total number of field pairs is 5, then the field consistency rate between the target first row without a primary key and the target second row without a primary key is 4 / 5 = 0.8.

[0091] S2111-2: Based on row matching degree and field consistency rate, determine the comprehensive matching value between the target first row without a primary key and the target second row without a primary key.

[0092] In this embodiment of the application, the row matching degree value and the field consistency rate can be weighted and summed to obtain the comprehensive matching value between the target first row without a primary key and the target second row without a primary key. Alternatively, the product of the row matching degree value and the field consistency rate can be calculated to obtain the comprehensive matching value between the target first row without a primary key and the target second row without a primary key.

[0093] S2111-3: Determine whether the overall matching value is greater than the second matching threshold. If yes, execute S2111-4; otherwise, execute S2111-5.

[0094] The second matching threshold can be 0.97, but this embodiment does not impose any restrictions on it.

[0095] S2111-4: Determine that the matching result of the first row without a primary key in the target is a successful match.

[0096] In this embodiment of the application, when the comprehensive matching value is greater than the second matching threshold, it is determined that the target first row without a primary key and the target second row without a primary key have matched successfully.

[0097] S2111-5: Determine that the matching result of the first row without a primary key is a failed match, and generate a difference field based on the field comparison result.

[0098] In this embodiment of the application, when the comprehensive matching value is less than or equal to the second matching threshold, it is determined that the target first row without a primary key and the target second row without a primary key do not match, and the inconsistent difference fields in the field comparison results are recorded as difference fields.

[0099] In this way, by comprehensively calculating the field consistency rate and row matching degree, a multi-dimensional matching evaluation model is established, avoiding the one-sidedness of a single indicator and ensuring the accuracy of the matching results of each first row without a primary key.

[0100] S212: Based on the obtained comparison pass results and matching pass results, determine the target matching value between the source calculation result and the initial target calculation result, and summarize the comparison failure results and matching failure results to obtain a difference report.

[0101] Optionally, in this embodiment of the application, a possible implementation is provided for determining the target matching value between the source calculation result and the initial target calculation result based on the obtained comparison pass results and matching pass results. Specifically, the following operations are performed: based on the obtained comparison pass results and matching pass results, the number of matching rows in each first row included in the source calculation result is determined, and based on the number of matching rows and the total number of each first row, the target matching value between the source calculation result and the initial target calculation result is determined.

[0102] Each first row includes: each first row with a primary key and each first row without a primary key. Matching rows include: each first row with a primary key that completely matches the associated second row with a primary key in the matching results, and each first row without a primary key whose overall match value with the associated second row without a primary key is greater than the second matching threshold in the matching results.

[0103] In this embodiment of the application, the ratio of the number of matching rows to the total number of each first row is calculated to obtain the target matching value between the source calculation result and the initial target calculation result.

[0104] For example, assuming the number of matching rows is 999 and the total number of first rows is 1000, the target matching value between the source calculation result and the initial target calculation result is 999 / 1000=0.999.

[0105] Optionally, in this embodiment of the application, another possible implementation is provided for determining the target matching value between the source calculation result and the initial target calculation result based on the obtained comparison pass results and matching pass results. Specifically, the following operations are performed: based on the comparison pass results and matching pass results, determine the number of primary key row matches in each first primary key row and the number of primary key row matches in each first non-primary key row; based on the number of primary key row matches and the total number of each first primary key row, determine the primary key matching value; based on the number of non-primary key row matches and the total number of each first non-primary key row, determine the non-primary key matching value; and based on the primary key matching value and the non-primary key matching value, determine the target matching value between the source calculation result and the initial target calculation result.

[0106] The number of rows with primary keys that match is the total number of rows with primary keys that completely match the associated second rows with primary keys in each matching result. The number of rows without primary keys that match is the total number of rows without primary keys that have a comprehensive match value greater than the second matching threshold in each matching result.

[0107] In this embodiment, based on the comparison results, the number of matching rows with primary keys in each first row with a primary key is determined. Based on the matching results, the number of matching rows without primary keys in each first row without a primary key is determined. Then, the ratio of the number of matching rows with primary keys to the total number of first rows with primary keys is calculated to obtain the matching value with primary keys. The ratio of the number of matching rows without primary keys to the total number of first rows without primary keys is calculated to obtain the matching value without primary keys. Finally, a weighted average is performed on the matching values ​​with primary keys and the matching values ​​without primary keys to obtain the target matching value between the source calculation result and the initial target calculation result.

[0108] For example, the total number of rows with primary keys is 500, the total number of rows without primary keys is 500, the number of matches for rows with primary keys is 499, and the number of matches for rows without primary keys is 498. Then, the value of a match with a primary key is 499 / 500 = 0.998, and the value of a match without a primary key is 498 / 500 = 0.996. Assuming that the weight of a match with a primary key is 0.6 and the weight of a match without a primary key is 0.4, the target match value between the source calculation result and the initial target calculation result is 0.998 × 0.6 + 0.996 × 0.4 = 0.9972.

[0109] In this way, different verification methods are used for data with and without primary keys, giving full play to their respective advantages and improving the accuracy and efficiency of verification. By comparing rows with primary keys precisely and matching rows without primary keys similarly, it is ensured that various data structures can be effectively verified, thus expanding the scope of application of the solution. The results of comparison failures and matching failures are summarized separately, and the target matching value is generated comprehensively to provide a basis for detection. A structured difference report is also generated to provide detailed evidence for root cause analysis.

[0110] S22: When the detection result indicates that the initial target SQL statement fails the detection, a new target SQL statement is generated based on the difference report, the source SQL statement, and the initial target SQL statement.

[0111] The new target SQL statements are used in the target computing engine for computing tasks such as data querying, updating, performance optimization, data access, and integration.

[0112] Optionally, in this embodiment of the application, when the detection result indicates that the initial target SQL statement has passed the detection, the initial target SQL statement is used as the final target SQL statement.

[0113] Optionally, in this application embodiment, a possible implementation is provided for generating a new target SQL statement based on the difference report, the source SQL statement, and the initial target SQL statement. Specifically, the difference report, the source SQL statement, the initial target SQL statement, and the preset prompt words are input into the large model to obtain the new target SQL statement and the root cause of the difference output by the large model.

[0114] The large model can be the original large model or a finely tuned large model, and this application embodiment does not impose any restrictions on this. The finely tuned large model is obtained by collecting a large amount of SQL transformation difference information (including: difference reports, source SQL statements and initial target SQL statements) and corresponding repair cases, and supervising the fine-tuning of an LLM (e.g., CodeGen) to obtain a finely tuned large model specifically for this scenario.

[0115] In this embodiment, a prompt word template is constructed, and the source SQL statement, initial target SQL statement, difference report, and table structure are sent to the large model as input context to obtain the new target SQL statement and root cause of difference output by the large model.

[0116] For example, the prompt template is: "Please analyze the reasons for the difference in execution results between the following source SQL statement in Hive and the initial target SQL statement in the Spark engine, and directly provide the corrected target SQL statement, and the differences are...".

[0117] In this way, leveraging the powerful code understanding and generation capabilities of LLM improves the accuracy and efficiency of the repair process.

[0118] Optionally, in this application embodiment, another possible implementation is provided for generating a new target SQL statement based on the difference report, the source SQL statement, and the initial target SQL statement. Specifically, based on the difference report, the source SQL statement, and the initial target SQL statement, the difference pattern rules are queried to obtain optimization measures, and the optimization measures are used to repair the initial target SQL statement to obtain a new target SQL statement.

[0119] In this embodiment of the application, a rule engine (e.g., Drools) is constructed. The rule engine has built-in difference pattern rules, which include various optimization measures. The difference pattern rules are formulated by experts.

[0120] For example, if the difference field in the difference report contains a date, the source compute engine is Hive, the target compute engine is Spark, and the initial target SQL contains the "from_unixtime" function, it is recommended to ensure that the time zone settings are consistent in Spark, and try adding "spark.sql.session.timeZone = GMT+8".

[0121] Optionally, in this embodiment of the application, before generating a new target SQL statement using a large model or difference pattern rules, in order to improve conversion efficiency, an optimization knowledge base can be set up, and the optimization knowledge base can be queried to obtain the new target SQL statement. The specific operation is as follows: S220: Extract features from the difference report, source SQL statement, and initial target SQL statement to obtain the target difference features corresponding to the difference report.

[0122] S221: Query the optimization knowledge base to determine whether there is a matching historical difference feature in the optimization knowledge base that matches the target difference feature. If yes, execute S222; otherwise, execute S223 or S224.

[0123] The optimized knowledge base stores historical difference features, their associated root causes, and optimization measures. Optimization measures can be either repairing the transformed target SQL solution or creating a new target SQL statement; this embodiment does not impose any limitations on this.

[0124] S222: Use optimization measures that match historical difference features to generate a new target SQL statement.

[0125] In this embodiment of the application, when there are matching historical difference features in the optimization knowledge base that match the target difference features, optimization measures associated with the matching historical difference features are adopted to generate a new target SQL statement.

[0126] S223: Input the difference report, source SQL statement, initial target SQL statement, and preset prompt words into the large model to obtain the new target SQL statement and root cause of the difference output by the large model.

[0127] In this embodiment of the application, when there are matching historical difference features in the optimization knowledge base that match the target difference features, the difference report, source SQL statement, initial target SQL statement and preset prompt words are input into the large model to obtain the new target SQL statement and difference root cause output by the large model.

[0128] S224: Optimization measures are obtained through the difference pattern rules, and these measures are used to repair the initial target SQL statement to obtain a new target SQL statement.

[0129] In this embodiment of the application, when there are matching historical difference features in the optimization knowledge base that match the target difference features, optimization measures are obtained through difference pattern rules, and the optimization measures are used to repair the initial target SQL statement to obtain a new target SQL statement.

[0130] In this way, by optimizing the storage of historical cases in the knowledge base, we can accumulate and reuse experience, avoid repeatedly solving the same problems, and quickly find similar cases in the knowledge base, thus significantly improving optimization efficiency.

[0131] Furthermore, in this embodiment of the application, after generating a new target SQL statement based on the difference report, the source SQL statement, and the initial target SQL statement, the new target SQL statement is used as the first round of target SQL statements, and multiple rounds of transformation optimization operations are performed until the current loop count is greater than the loop count threshold (e.g., the loop count threshold is 4 times) or the detection result of the current round of target SQL statements is passed, and the loop stops. One round of transformation optimization operations includes: SA1: Retrieves the current round target calculation result obtained by using the current round target SQL statement to calculate the data source on the target calculation engine.

[0132] In this embodiment, it is possible to either re-execute the acquisition of the source computation result obtained by using the source SQL statement to compute the data source on the source computing engine, or re-execute the acquisition of the source computation result obtained by using the source SQL statement to compute the data source on the source computing engine. If the source computation result is not re-acquired, then the current round target computation result obtained by using the current round target SQL statement to compute the original data source (the data source at the time of the first acquisition of the source computation result) on the target computing engine is acquired. If the source computation result is re-acquired, then corresponding computation tasks are submitted to both the source computing engine and the target computing engine simultaneously (i.e., the computation task corresponding to the source SQL statement is submitted to the source computing engine, and the computation task corresponding to the current round target SQL statement is submitted to the target computing engine). Both computation tasks are configured to use the same test dataset (i.e., compute on the same data source, which can be the original data source or a new data source). After both computation tasks are completed, the source computation result and the initial target computation result are pulled to a neutral storage area (e.g., a specific directory in HDFS) by querying SQL or reading the output file, in preparation for subsequent testing.

[0133] SA2: Perform row and field matching on the source calculation result and the current round target calculation result to obtain the current round target matching value and the current round new difference report between the source calculation result and the current round target calculation result. Based on the current round target matching value, determine the current round detection result of the current round target SQL statement.

[0134] In this embodiment of the application, the step of determining the current round detection result of the target SQL statement in the current round is the same as the step of determining the detection result of the initial target SQL statement. Both are based on the source calculation result and are compared with the source calculation result. Therefore, they will not be described again here.

[0135] SA3: When the current round of detection results indicates that the target SQL statement fails the current round of detection, the target SQL statement for the next round is generated based on the current round of difference report, the source SQL statement, and the target SQL statement for the current round.

[0136] In this embodiment of the application, the step of generating the next round target SQL statement based on the current round difference report, the source SQL statement, and the current round target SQL statement is the same as the step of generating a new target SQL statement based on the difference report, the source SQL statement, and the initial target SQL statement, and will not be repeated here.

[0137] Optionally, in this embodiment, the next round target SQL statement can be generated based on the difference report corresponding to the initial target SQL statement, the current round difference report, the source SQL statement, the initial target SQL statement, and the current round target SQL statement. Specifically, the difference report corresponding to the initial target SQL statement, the current round difference report, the source SQL statement, the initial target SQL statement, the current round target SQL statement, and preset prompts are input into the large model to obtain the next round target SQL statement and the current round difference root cause output by the large model.

[0138] SA4: When the current round of detection results indicates that the target SQL statement of the current round has passed the detection, the target SQL statement of the current round will be used as the final target SQL statement.

[0139] In this way, through multiple rounds of transformation and optimization operations, the SQL statement is continuously improved in the iteration and eventually reaches the optimal state, avoiding the problem of incomplete optimization in a single operation.

[0140] Based on the above embodiments, see Figure 3 The diagram shown illustrates another implementation flow of an SQL statement conversion method according to an embodiment of this application, including: S30: Convert the source SQL statement into the initial target SQL statement.

[0141] S31: Obtain the source calculation result obtained by using the source SQL statement to calculate the data source on the source calculation engine, and obtain the initial target calculation result obtained by using the initial target SQL statement to calculate the data source on the target calculation engine.

[0142] S32: Perform row matching and field matching on the source calculation result and the initial target calculation result to obtain the target matching value and difference report between the source calculation result and the initial target calculation result, and determine the detection result of the initial target SQL statement based on the target matching value and the first matching threshold.

[0143] S33: Determine whether the detection result indicates that the initial target SQL statement has passed the detection. If yes, execute S34; otherwise, execute S35.

[0144] S34: Use the initial target SQL statement as the final target SQL statement.

[0145] S35: Generate a new target SQL statement based on the difference report, source SQL statement, and initial target SQL statement.

[0146] S36: Use the new target SQL statement as the first target SQL statement and perform multiple rounds of transformation and optimization operations until the current loop count is greater than the loop count threshold or the detection result of the current target SQL statement is passed.

[0147] One round of transformation optimization operations includes: obtaining the current round target calculation result obtained by calculating the data source using the current round target SQL statement on the target calculation engine; then performing row matching and field matching on the source calculation result and the current round target calculation result to obtain the current round target matching value and the current round new difference report between the source calculation result and the current round target calculation result, and determining the current round detection result of the current round target SQL statement based on the current round target matching value; finally, when the current round detection result indicates that the current round target SQL statement fails the detection, generating the next round target SQL statement based on the current round difference report, the source SQL statement, and the current round target SQL statement.

[0148] This solves the three major problems in existing technologies: "separation of conversion and verification", "excessive manual intervention", and "difficulty in verifying data without primary keys", ensuring high reliability of cross-engine SQL conversion results in data and significantly improving migration efficiency.

[0149] Furthermore, based on the same technical concept, embodiments of this application provide an SQL statement conversion apparatus, which is used to implement the above-described method flow of embodiments of this application. For example, see [link to relevant documentation]. Figure 4 As shown, the SQL statement conversion device 400 may include: a conversion module 401, a detection module 402, and an optimization module 403.

[0150] The conversion module 401 is used to convert the source SQL statement into the initial target SQL statement, and to obtain the source calculation result obtained by using the source SQL statement to calculate the data source on the source calculation engine, and to obtain the initial target calculation result obtained by using the initial target SQL statement to calculate the data source on the target calculation engine. The detection module 402 is used to perform row matching and field matching on the source calculation result and the initial target calculation result to obtain the target matching value and difference report between the source calculation result and the initial target calculation result, and to determine the detection result of the initial target SQL statement based on the target matching value and the first matching threshold. The difference report includes: the difference rows and difference fields that do not match in the source calculation result and the initial target calculation result. The optimization module 403 is used to generate a new target SQL statement based on the difference report, the source SQL statement, and the initial target SQL statement when the detection result indicates that the initial target SQL statement fails the detection.

[0151] In an optional embodiment, after generating a new target SQL statement based on the difference report, the source SQL statement, and the initial target SQL statement, the optimization module 403 is further configured to: The new target SQL statement is used as the first target SQL statement, and multiple rounds of transformation and optimization operations are performed until the current loop count exceeds the loop count threshold or the current target SQL statement passes the test. One round of transformation and optimization operations includes: Retrieve the current round target calculation result obtained by using the current round target SQL statement to calculate the data source on the target calculation engine; Perform row and field matching on the source calculation results and the current round target calculation results to obtain the current round target matching value and the current round new difference report between the source calculation results and the current round target calculation results. Based on the current round target matching value, determine the current round detection result of the current round target SQL statement. When the current round of detection results indicates that the target SQL statement fails the current round of detection, the target SQL statement for the next round is generated based on the current round of difference report, the source SQL statement, and the target SQL statement for the current round.

[0152] In an optional embodiment, when performing row matching and field matching on the source calculation result and the initial target calculation result to obtain the target matching value and difference report between the source calculation result and the initial target calculation result, the detection module 402 is further configured to: Each first row with a primary key in the source calculation result and each second row with a primary key in the initial target calculation result are compared field by field to determine the comparison result for each first row with a primary key. The comparison results include: comparison pass result and comparison fail result. The comparison pass result indicates that a first row with a primary key is completely matched with the associated second row with a primary key. The comparison fail result includes: two rows with primary keys that are not completely matched and the difference fields between the two rows with primary keys. Two rows with primary keys include: a first row with a primary key and a second row with a primary key associated with a first row with a primary key. Perform row matching and field comparison on each first row without a primary key in the source calculation result and each second row without a primary key in the initial target calculation result to determine the matching result of each first row without a primary key. The matching result includes: matching pass result and matching fail result. The matching pass result indicates that the comprehensive matching value between a first row without a primary key and the associated second row without a primary key is greater than the second matching threshold. The matching fail result includes: two non-matching rows without a primary key and the difference field between the two rows without a primary key. The two rows without a primary key include: a first row without a primary key and a second row without a primary key associated with a first row without a primary key. Based on the obtained comparison pass results and matching pass results, the target matching value between the source calculation result and the initial target calculation result is determined, and the comparison failure results and matching failure results are summarized to obtain a difference report.

[0153] In an optional embodiment, when performing row matching and field comparison on each first row without a primary key in the source calculation result and each second row without a primary key in the initial target calculation result to determine the matching result of each first row without a primary key, the detection module 402 is further configured to: For each row that has no primary key, perform the following operations: In each second row without a primary key, the target second row without a primary key is selected that is most similar to the target first row without a primary key. The row matching degree between the target first row without a primary key and the target second row without a primary key is calculated. Field comparison is performed on the target first row without a primary key and the target second row without a primary key to obtain the field comparison results of each target first field contained in the target first row without a primary key. The field comparison results indicate whether the corresponding target first field is consistent with the associated target second field. The target first row without a primary key is any one of the first rows without a primary key. Based on the row matching score and field comparison results, determine the matching result of the first target row without a primary key.

[0154] In an optional embodiment, when determining the matching result of the target first row without a primary key based on the row matching degree value and the field comparison result, the detection module 402 is further configured to: Based on the number of consistent field pairs in the field comparison results and the total number of field pairs, determine the field consistency rate between the target first row without a primary key and the target second row without a primary key; Based on the row matching score and field consistency rate, determine the comprehensive matching value between the first target row without a primary key and the second target row without a primary key; When the overall matching value is greater than the second matching threshold, it is determined that the target first row without a primary key and the target second row without a primary key have matched successfully. When the overall matching value is less than or equal to the second matching threshold, it is determined that the target first row without a primary key and the target second row without a primary key do not match, and a difference field is generated based on the field comparison results.

[0155] In an optional embodiment, when determining the target matching value between the source calculation result and the initial target calculation result based on the obtained comparison pass results and matching pass results, the detection module 402 is further configured to: Based on the obtained comparison and matching results, determine the number of matching rows in each first row of the source calculation result, and based on the number of matching rows and the total number of first rows, determine the target matching value between the source calculation result and the initial target calculation result; or, Based on the comparison and matching results, determine the number of primary key row matches in each first primary key row and the number of primary key-free row matches in each first primary key-free row. Based on the number of primary key row matches and the total number of primary key row matches in each first primary key row, determine the primary key match value. Based on the number of primary key-free row matches and the total number of primary key-free row matches in each first primary key row, determine the primary key-free match value. Based on the primary key match value and the primary key-free match value, determine the target match value between the source calculation result and the initial target calculation result.

[0156] In an optional embodiment, when generating a new target SQL statement based on the difference report, the source SQL statement, and the initial target SQL statement, the optimization module 403 is further configured to: Input the difference report, source SQL statement, initial target SQL statement, and preset prompt words into the large model to obtain the new target SQL statement and root cause of the difference output by the large model.

[0157] In an optional embodiment, before inputting the difference report, source SQL statement, initial target SQL statement, and preset prompt words into the large model to obtain the new target SQL statement and root cause of the difference output by the large model, the optimization module 403 is further configured to: Feature extraction is performed on the difference report, source SQL statement, and initial target SQL statement to obtain the target difference features corresponding to the difference report; The optimization knowledge base is queried to determine whether there are matching historical difference features in the optimization knowledge base that match the target difference feature. The optimization knowledge base is used to store each historical difference feature and the root causes and optimization measures associated with each historical difference feature. When there are historical difference features in the knowledge base that match the target difference features, the optimization measures associated with the historical difference features are adopted to generate a new target SQL statement.

[0158] Based on the description of the method and apparatus embodiments above, an exemplary embodiment of the present invention also provides an electronic device, including: at least one processor; and a memory communicatively connected to the at least one processor. The memory stores a computer program executable by the at least one processor, which, when executed by the at least one processor, causes the electronic device to perform the method according to an embodiment of the present invention.

[0159] This application also provides a non-transitory computer-readable storage medium storing a computer program, wherein the computer program, when executed by a computer's processor, is used to cause the computer to perform a method according to an embodiment of this application.

[0160] This application also provides a computer program product, including a computer program, wherein the computer program, when executed by a computer's processor, is used to cause the computer to perform a method according to an embodiment of this application.

[0161] See Figure 5 The diagram shown below illustrates the structure of an electronic device 500 that can serve as a server or client in this application, and is an example of a hardware device that can be applied to various aspects of this application. The electronic device is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the application described and / or claimed herein.

[0162] like Figure 5 As shown, the electronic device 500 includes a computing unit 501, which can perform various appropriate actions and processes based on a computer program stored in a read-only memory (ROM) 502 or a computer program loaded from a storage unit 508 into a random access memory (RAM) 503. The RAM 503 may also store various programs and data required for the operation of the device 500. The computing unit 501, ROM 502, and RAM 503 are interconnected via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0163] Multiple components in electronic device 500 are connected to I / O interface 505, including: input unit 506, output unit 507, storage unit 508, and communication unit 509. Input unit 506 can be any type of device capable of inputting information to electronic device 500. Input unit 506 can receive input digital or character information and generate key signal inputs related to user settings and / or function control of electronic device. Output unit 507 can be any type of device capable of presenting information and may include, but is not limited to, a display, speaker, video / audio output terminal, vibrator, and / or printer. Storage unit 508 may include, but is not limited to, disks and optical discs. Communication unit 509 allows electronic device 500 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks, and may include, but is not limited to, modems, network cards, infrared communication devices, wireless communication transceivers and / or chipsets, such as Bluetooth devices, WiFi devices, worldwide interoperability for microwave access (WiMax) devices, cellular communication devices, and / or the like.

[0164] The computing unit 501 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 501 performs the various methods and processes described above. For example, in some embodiments, the above-described SQL statement conversion method can be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 508. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 500 via ROM 502 and / or communication unit 509. In some embodiments, the computing unit 501 can be configured to perform the above-described SQL statement conversion method by any other suitable means (e.g., by means of firmware).

[0165] The program code used to implement the methods of this application may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when executed by the processor or controller, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0166] In the context of this application, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, RAM, ROM, erasable programmable read-only memory (EPROM) or flash memory, optical fibers, compact disc read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0167] As used in this application, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, device, and / or apparatus (e.g., disk, optical disk, memory, programmable logic device, PLD) used to provide machine instructions and / or data to a programmable processor, including machine-readable media that receive machine instructions as machine-readable signals. The term "machine-readable signal" refers to any signal used to provide machine instructions and / or data to a programmable processor.

[0168] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a cathode ray tube (CRT) or liquid crystal display (LCD) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0169] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.

[0170] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other.

[0171] Furthermore, it should be understood that the above-disclosed embodiments are merely preferred embodiments of this application and should not be construed as limiting the scope of the invention. Therefore, any equivalent variations made in accordance with the claims of this invention are still within the scope of this application.

Claims

1. A method for converting SQL statements, characterized in that, include: The source SQL statement is converted into the initial target SQL statement, and the source calculation result obtained by using the source SQL statement to calculate the data source on the source calculation engine is obtained, as well as the initial target calculation result obtained by using the initial target SQL statement to calculate the data source on the target calculation engine. Row matching and field matching are performed on the source calculation result and the initial target calculation result to obtain the target matching value and difference report between the source calculation result and the initial target calculation result. Based on the target matching value and the first matching threshold, the detection result of the initial target SQL statement is determined. The difference report includes: the difference rows and difference fields that do not match in the source calculation result and the initial target calculation result. When the detection result indicates that the initial target SQL statement fails the detection, a new target SQL statement is generated based on the difference report, the source SQL statement, and the initial target SQL statement.

2. The method as described in claim 1, characterized in that, After generating the new target SQL statement based on the difference report, the source SQL statement, and the initial target SQL statement, the process further includes: The new target SQL statement is used as the first round of target SQL statements, and multiple rounds of transformation and optimization operations are performed until the current loop count is greater than the loop count threshold or the detection result of the current round of target SQL statements is passed. One round of transformation and optimization operations includes: Obtain the current round target calculation result obtained by calculating the data source using the current round target SQL statement on the target calculation engine; Perform row matching and field matching on the source calculation result and the current round target calculation result to obtain the current round target matching value and the current round new difference report between the source calculation result and the current round target calculation result, and determine the current round detection result of the current round target SQL statement based on the current round target matching value; When the current round detection result indicates that the current round target SQL statement fails the detection, the next round target SQL statement is generated based on the current round difference report, the source SQL statement, and the current round target SQL statement.

3. The method as described in claim 1, characterized in that, The step of performing row and field matching on the source calculation result and the initial target calculation result to obtain the target matching value and difference report between the source calculation result and the initial target calculation result includes: Each first row with a primary key in the source calculation result and each second row with a primary key in the initial target calculation result are compared field by field to determine the comparison result of each first row with a primary key. The comparison result includes: comparison pass result and comparison fail result. The comparison pass result indicates that a first row with a primary key is completely matched with the associated second row with a primary key. The comparison fail result includes: two rows with primary keys that are not completely matched and the difference fields between the two rows with primary keys. The two rows with primary keys include: a first row with a primary key and a second row with a primary key associated with the first row with a primary key. Row matching and field comparison are performed on each first row without a primary key in the source calculation result and each second row without a primary key in the initial target calculation result to determine the matching result of each first row without a primary key. The matching result includes: a successful match result and a failed match result. The successful match result indicates that the comprehensive matching value between a first row without a primary key and the associated second row without a primary key is greater than a second matching threshold. The failed match result includes: two rows without a primary key that do not match and the difference field between the two rows without a primary key. The two rows without a primary key include: a first row without a primary key and a second row without a primary key associated with the first row without a primary key. Based on the obtained comparison pass results and matching pass results, the target matching value between the source calculation result and the initial target calculation result is determined, and the comparison failure results and matching failure results are summarized to obtain a difference report.

4. The method as described in claim 3, characterized in that, The step of performing row matching and field comparison on each first row without a primary key in the source calculation result and each second row without a primary key in the initial target calculation result to determine the matching result of each first row without a primary key includes: For each of the first rows without a primary key, perform the following operations respectively: In each of the second keyless rows, the target second keyless row that is most similar to the target first keyless row is selected, and the row matching degree value between the target first keyless row and the target second keyless row is calculated. In addition, the target first keyless row and the target second keyless row are compared by field to obtain the field comparison result of each target first field contained in the target first keyless row. The field comparison result indicates whether the corresponding target first field is consistent with the associated target second field. The target first keyless row is any one of the first keyless rows. Based on the row matching score and the field comparison results, the matching result of the target first row without a primary key is determined.

5. The method as described in claim 4, characterized in that, The step of determining the matching result of the target first row without a primary key based on the row matching degree value and the field comparison result includes: Based on the number of consistent field pairs and the total number of field pairs in the field comparison results, the field consistency rate between the target first row without a primary key and the target second row without a primary key is determined. Based on the row matching degree value and the field consistency rate, determine the comprehensive matching value between the target first row without a primary key and the target second row without a primary key; When the overall matching value is greater than the second matching threshold, it is determined that the target first row without a primary key and the target second row without a primary key have matched successfully. When the overall matching value is less than or equal to the second matching threshold, it is determined that the target first row without a primary key and the target second row without a primary key do not match, and a difference field is generated based on the field comparison result.

6. The method as described in claim 3, characterized in that, The step of determining the target matching value between the source calculation result and the initial target calculation result based on the obtained comparison pass results and matching pass results includes: Based on the obtained comparison pass results and matching pass results, determine the number of matching rows in each first row contained in the source calculation result, and based on the number of matching rows and the total number of the first rows, determine the target matching value between the source calculation result and the initial target calculation result; or, Based on the comparison results and the matching results, the number of matching rows with primary keys in each of the first rows with primary keys and the number of matching rows without primary keys in each of the first rows without primary keys are determined. Based on the number of matching rows with primary keys and the total number of the first rows with primary keys, a matching value with a primary key is determined. Based on the number of matching rows without primary keys and the total number of the first rows without primary keys, a matching value without a primary key is determined. Based on the matching values ​​with primary keys and the matching values ​​without primary keys, a target matching value between the source calculation result and the initial target calculation result is determined.

7. The method as described in claim 1, characterized in that, The process of generating a new target SQL statement based on the difference report, the source SQL statement, and the initial target SQL statement includes: The difference report, the source SQL statement, the initial target SQL statement, and the preset prompt words are input into the large model to obtain the new target SQL statement and the root cause of the difference output by the large model.

8. The method as described in claim 7, characterized in that, Before inputting the difference report, the source SQL statement, the initial target SQL statement, and the preset prompt words into the large model to obtain the new target SQL statement and the root cause of the difference output by the large model, the process further includes: Feature extraction is performed on the difference report, the source SQL statement, and the initial target SQL statement to obtain the target difference features corresponding to the difference report; The optimization knowledge base is queried to determine whether there are matching historical difference features in the optimization knowledge base that match the target difference feature. The optimization knowledge base is used to store each historical difference feature and the root causes and optimization measures associated with each historical difference feature. When the optimization knowledge base contains a matching historical difference feature that matches the target difference feature, the optimization measures associated with the matching historical difference feature are used to generate a new target SQL statement.

9. An SQL statement conversion device, characterized in that, include: The conversion module is used to convert the source SQL statement into the initial target SQL statement, obtain the source calculation result obtained by using the source SQL statement to calculate the data source on the source calculation engine, and obtain the initial target calculation result obtained by using the initial target SQL statement to calculate the data source on the target calculation engine. The detection module is used to perform row matching and field matching on the source calculation result and the initial target calculation result to obtain the target matching value and difference report between the source calculation result and the initial target calculation result, and to determine the detection result of the initial target SQL statement based on the target matching value and a first matching threshold. The difference report includes: the difference rows and difference fields that do not match in the source calculation result and the initial target calculation result. An optimization module is used to generate a new target SQL statement based on the difference report, the source SQL statement, and the initial target SQL statement when the detection result indicates that the initial target SQL statement fails the detection.

10. An electronic device, comprising: processor; as well as Stored program memory, The program includes instructions that, when executed by the processor, cause the processor to perform the method as described in any one of claims 1-8.