Method and system for converting SQL (Structured Query Language) language into language of creative database

CN120994684APending Publication Date: 2025-11-21华数传媒网络有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511013369.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-23
Publication Date
2025-11-21

AI Technical Summary

Technical Problem

现有技术在数据库迁移过程中存在手动迁移繁琐易出错、存储过程和业务逻辑迁移复杂、迁移后性能优化困难的问题,尤其是在迁移到国产信创数据库时,手动操作容易引入错误且耗时费力。

Method used

采用大模型技术,通过解析源SQL语句生成抽象语法树,结合预先建立的SQL语法映射规则库和领域大模型,自动将源SQL语句转换为信创数据库兼容的SQL语句,并集成自动化测试功能,确保转换的准确性和一致性。

Benefits of technology

显著提高了数据库迁移效率和准确性,减少人工干预,增强系统兼容性和灵活性,确保数据一致性与功能正确性,提升了迁移项目的实施效率和质量。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120994684A_ABST
    Figure CN120994684A_ABST
Patent Text Reader

Abstract

The invention provides a method and a system for converting an SQL (Structured Query Language) language into a language of a creative database, and the method comprises the following steps: obtaining a source SQL script of a source SQL database, analyzing a source SQL statement, and decomposing the source SQL statement into a structured form; according to a pre-established SQL grammar mapping rule base, calling a domain large model to convert the analyzed SQL statements into SQL statements compatible with a creative database; mapping and adjusting grammar and data types according to the rule base, and outputting the converted SQL script; and performing a comparison test on the SQL scripts before and after conversion through an automatic test function to check data consistency and function correctness. By means of the method, the SQL language is automatically converted into the SQL language of the creative database, the migration efficiency and accuracy are effectively improved, and manual intervention is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database technology, and in particular to a method and system for converting SQL language into the language of a domestically developed database. Background Technology

[0002] Existing SQL database management systems (DBMS) such as MySQL, PostgreSQL, and Oracle are widely used in various computer systems. However, with the advancement of information technology innovation (IT innovation), more and more systems need to be migrated to domestic databases such as DM Database. However, differences in SQL syntax and functionality exist between different databases. Manual migration is not only time-consuming and labor-intensive but also prone to introducing errors, thus affecting business continuity and data consistency. Therefore, there is an urgent need for an automated tool that can automatically convert existing SQL code into SQL dialects adapted to the IT innovation environment. This tool aims to significantly improve the efficiency and accuracy of migration work, ensure a smooth transition to domestic database platforms, reduce the burden on technical personnel, and accelerate the construction and upgrading of the IT innovation ecosystem.

[0003] Large model technology refers to a technique in the field of artificial intelligence that uses large-scale neural network models to achieve intelligent tasks. In database migration, large models can automatically convert one SQL dialect to another, thereby reducing human error and accelerating the migration process.

[0004] During database migration, existing technologies have the following main objective drawbacks:

[0005] 1. Manual migration is tedious and error-prone. Manually converting SQL syntax requires a significant amount of manual work, which is labor-intensive and time-consuming. Manual operations are prone to human error, leading to functional or performance issues in the migrated database. In complex database environments, manual processing may not cover all details, resulting in omissions or inconsistencies.

[0006] 2. Complex Migration of Stored Procedures and Business Logic. Existing technologies offer limited support for migrating stored procedures, triggers, and other complex business logic, often requiring manual rewriting or adjustments, which increases the difficulty of migration. Different databases have significant differences in the implementation and functional characteristics of stored procedures and triggers, making manual migration of these complex logics time-consuming and error-prone.

[0007] 3. Performance optimization after migration is difficult. Even if the syntax conversion is successfully completed, different databases have different performance characteristics, and the directly migrated database may not achieve optimal performance. Performance tuning of the migrated database is required, which usually involves a lot of testing and adjustments, further increasing the complexity of the migration. Summary of the Invention

[0008] In order to overcome the shortcomings of the prior art, this invention provides a method and system for converting SQL language into the language of a domestically developed database.

[0009] To achieve the above objectives, this invention provides a method for converting SQL language into the language of a domestically developed database, which includes the following steps:

[0010] Obtain the source SQL script from the source SQL database, parse the source SQL statement, and decompose it into a structured form; based on the pre-established SQL syntax mapping rule base, call the domain big model to convert the parsed SQL statement into an SQL statement compatible with the domestic IT innovation database;

[0011] Based on the rule base, the syntax and data types are mapped and adjusted, and the converted SQL script is output.

[0012] The preferred decomposed statement structure is an abstract syntax tree (AST). The steps for generating an AST from an SQL statement are as follows:

[0013] A lexical analyzer is used to segment the SQL script into lexical units; the lexical analyzer performs lexical analysis using regular expressions and finite state automata.

[0014] Based on the lexical unit stream generated by lexical analysis, the parser parses the lexical unit stream into an abstract syntax tree according to SQL syntax rules.

[0015] Preferably, the abstract syntax tree is a tree-like data structure, with statement nodes serving as the top-level nodes of the abstract syntax tree, representing the main operation types of SQL statements; expression nodes, structure nodes, and control structure nodes are distributed in the corresponding child node positions according to the logical hierarchy of the SQL statement.

[0016] Preferably, the steps for establishing an SQL syntax mapping rule base are as follows:

[0017] Collect corresponding syntax rules and features from multiple SQL databases, and identify SQL syntax differences;

[0018] Create conversion rules; these rules include: syntax mapping rules, data type conversion rules, and function and operator conversion rules.

[0019] Adjust the SQL statements based on database characteristics and limitations;

[0020] Detect and analyze updates and improvements to the SQL database and the domestic IT innovation database, and update the rule base in a timely manner.

[0021] Preferably, the syntax mapping rules are used to establish the mapping relationship between the source SQL syntax and the target information technology database syntax; the data type conversion rules are used to define the mapping rules between data types in different databases; and the function and operator conversion rules are used to handle the differences between functions and operators in different databases and to formulate corresponding conversion rules and adjustment strategies.

[0022] Preferably, the steps for creating a large domain model include:

[0023] Select a pre-trained model based on the SQL to SQL conversion requirements;

[0024] Based on the model's scale requirements, diverse SQL statements are collected, transformation pairs are generated, and data augmentation techniques are used to increase the diversity and coverage of the dataset. The SQL transformation pairs are labeled for quality control.

[0025] By using the collected SQL transformations to adjust the pre-trained model, the transformation rules and patterns between the source SQL and the target SQL can be controlled.

[0026] Preferably, based on the output SQL script, the method further includes a testing step: automatically testing the SQL script data and functionality before and after the conversion; the steps for testing the SQL script include:

[0027] Install the Docker engine, pull the database image to create a container and set the running parameters; use the database snapshot function to create a snapshot when the data is stable, and restore to the snapshot state before each test using the restore technique.

[0028] Database connection pooling technology is used for database connection, and an automated execution framework is used to execute SQL statements and capture results. During execution, the execution status of the statements is monitored in real time. After the statements are executed, the execution results are obtained from the relevant data structures or interfaces. At the same time, the execution plan is obtained through specific functions or tools provided by the database.

[0029] The result sets are compared using a data comparison algorithm;

[0030] Test coverage analysis tools are used to evaluate the coverage of test cases with SQL syntax and operations; at the same time, performance monitoring and optimization tools are used to monitor performance indicators during the execution of test scripts, and the test framework and scripts are optimized by analyzing performance indicators.

[0031] This invention provides a system for converting SQL language into the language of a domestically developed database, comprising:

[0032] The input module retrieves the source SQL script from the source SQL database.

[0033] The parsing module parses the source SQL statement and breaks it down into a structured form;

[0034] The conversion module, based on a pre-established SQL syntax mapping rule base, calls the domain-wide model to convert the parsed SQL statements into SQL statements compatible with the domestic IT innovation database;

[0035] The output module maps and adjusts the syntax and data types according to the rule base, and outputs the converted SQL script;

[0036] The automated testing module automatically tests the SQL script data and functionality before and after the conversion.

[0037] The present invention provides a method and system for converting SQL language into the language of a domestically developed database. Compared with the prior art, its advantages are as follows:

[0038] 1. Improved Database Migration Efficiency and Accuracy: By automatically converting the source SQL language into the SQL language of the domestically developed database, this invention significantly improves the efficiency and accuracy of the database migration process. Traditional manual conversion processes are time-consuming and error-prone, while the automated solution of this invention can complete the conversion task quickly and accurately, thereby accelerating the implementation of database migration projects.

[0039] 2. Reduced Manual Intervention: In this invention, the entire process, from SQL parsing to syntax conversion and final script output, is highly automated, greatly reducing the need for manual operation. This not only lowers labor costs but also avoids the impact of human error on migration quality.

[0040] 3. Enhanced System Compatibility and Flexibility: By maintaining a comprehensive rule base and combining it with a large domain model for syntax transformation, this invention ensures that syntactic differences between different databases are properly handled. This enables the system to support migration from multiple source databases to the domestically developed database, enhancing the system's compatibility and flexibility.

[0041] 4. Improved Data Consistency and Functional Correctness: Integrated automated testing capabilities can perform comparative tests on the SQL scripts before and after conversion, checking data consistency and functional correctness. This process ensures that the converted SQL statements not only conform to the target database's structural requirements but also maintain consistency with the source SQL statements in terms of functionality. Attached Figure Description

[0042] Figure 1 This is a schematic diagram of a system for converting SQL language into the language of a domestically developed database, as provided by the present invention. Detailed Implementation

[0043] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that, unless otherwise specified, the following embodiments and features described therein can be combined with each other.

[0044] This invention provides a method for converting SQL language into the language of a domestically developed database, the specific steps of which include:

[0045] Obtain the source SQL script from the source SQL database, parse the source SQL statement, and decompose it into a structured form; based on the pre-established SQL syntax mapping rule base, call the domain big model to convert the parsed SQL statement into an SQL statement compatible with the domestic IT innovation database;

[0046] Based on the rule base, the syntax and data types are mapped and adjusted, and the converted SQL script is output.

[0047] Specifically, this invention improves migration efficiency and accuracy while reducing manual intervention by automatically converting a specific SQL language into the SQL language of the target domestic database. First, by parsing the source SQL statement, various SQL syntax elements such as table definitions, indexes, views, stored procedures, and functions are identified, decomposing the source SQL statement into a structured form. Next, based on pre-established SQL syntax mapping rules, the elements in the Abstract Syntax Tree (AST) are converted into SQL syntax structures supported by the target domestic database. During the conversion, a pre-trained large-scale model is invoked to analyze the SQL statement. Leveraging its powerful learning capabilities, the model intelligently adjusts the syntax of each statement to ensure it conforms to the requirements of the domestic database in terms of data types and function usage, achieving accurate compatibility conversion. Due to differences in SQL dialects, a comprehensive rule base needs to be maintained, covering the correspondence between various SQL syntax structures (such as functions, keywords, and data types) across different databases to ensure conversion accuracy. For functions or SQL structures unique to the source database, compensation schemes or suggested optimization paths are also provided to ensure that the converted SQL can achieve the same or similar functionality in the target database. To ensure the correctness of the conversion, this invention integrates automated testing functions to perform comparative tests on the SQL scripts before and after the conversion, in order to check data consistency and functional correctness.

[0048] Among them, "IT innovation database" refers to database products that meet the standards and requirements of the information technology application innovation industry (IT innovation industry).

[0049] In this embodiment, the decomposed statement structure is an abstract syntax tree. The steps for generating the abstract syntax tree structure from the SQL statement are as follows:

[0050] A lexical analyzer is used to segment the SQL script into lexical units; the lexical analyzer performs lexical analysis using regular expressions and finite state automata.

[0051] Based on the lexical unit stream generated by lexical analysis, the parser parses the lexical unit stream into an abstract syntax tree according to SQL syntax rules.

[0052] Specifically, the lexical analyzer decomposes the input SQL script into a series of lexical units (tokens), including keywords, identifiers, operators, constants, etc., generating a stream of lexical units as input to the parser. The parser then parses this stream of lexical units based on the SQL grammar rules to generate an Abstract Syntax Tree (AST). This process requires defining Backus-Naur Normal Form (BNF) or other forms of grammar rules for the SQL syntax. The definition of SQL grammar rules is primarily based on official documentation for various databases and common grammatical structures used in practical applications. The AST is presented in a tree structure, where statement nodes are the top-level nodes, representing the main operation types of the SQL statement. Expression nodes, structure nodes, and control structure nodes are distributed in their respective child node positions according to the logical hierarchy of the SQL statement. This format clearly abstracts the logical structure of the SQL statement, removing interference from specific grammatical details.

[0053] The lexical analysis process of this invention uses regular expressions and finite state automata to segment tokens, which is more accurate and flexible. During the syntax analysis, a specific method is used to generate an AST, which can clearly present the sentence structure. Existing parsers cannot be used for the technical solution of this invention because they are customized for the conversion of SQL to the domestic IT database. They need to be closely integrated with the subsequent process and the characteristics of the domestic IT database. Existing parsers cannot provide adapted structured output and are difficult to handle syntactic differences and complex logical conversions.

[0054] An Abstract Syntax Tree (AST) is a tree-like data structure where each node represents a component of an SQL statement, such as a table, column, condition, or function. ASTs are characterized by abstraction and hierarchy. Abstraction means that ASTs abstract away specific syntactic details, retaining only the logical structure of the statement. By removing syntactic details, the focus shifts to the logical structure, making syntax transformation and rule application more efficient. ASTs clearly represent the nesting and hierarchical relationships of SQL statements through their hierarchical node structure. Specific node types include the following:

[0055] Statement nodes: such as SELECT, INSERT, UPDATE, DELETE, etc.

[0056] Expression nodes: such as arithmetic expressions, Boolean expressions, etc.

[0057] Structure nodes: such as table definitions, column definitions, index definitions, etc.

[0058] Control structure nodes: such as IF, LOOP, WHILE, etc.

[0059] During the parsing process, the parsing of stored procedures and triggers is a crucial step in database processing. Stored procedures and triggers contain complex control flow and business logic. For example, variable declarations define various data variables required for program execution, conditional statements execute different operation branches based on different conditions, loops allow specific code blocks to be executed repeatedly according to a set number of times or conditions, and exception handling handles errors in the program to ensure its stability.

[0060] The specific parsing steps also require lexical analysis and syntactic analysis:

[0061] Lexical analysis: Similarly, lexical analysis is performed to decompose stored procedures and trigger scripts into tokens. This process requires accurately identifying each character sequence and converting it into the corresponding lexical unit.

[0062] Syntax analysis: Based on the syntax rules of stored procedures and triggers, the token stream is parsed to generate an AST. This method can clearly show the syntax structure of stored procedures and triggers, which is convenient for subsequent in-depth processing.

[0063] Example of parsing a stored procedure:

[0064] The source stored procedure is:

[0065]

[0066] AST is represented as:

[0067]

[0068]

[0069] In this invention, the steps for establishing an SQL syntax mapping rule base are as follows:

[0070] Collect corresponding syntax rules and features from multiple SQL databases, and identify SQL syntax differences.

[0071] Specifically, the syntax rules and features of common SQL databases (such as MySQL, Oracle, and SQL Server) are collected, including data types, functions, and operators. Before analyzing the data differences, a comprehensive and detailed comparison of the syntax differences and compatibility issues between the target domestic database (DM Database) and the source SQL database is conducted. Regarding functions, the naming conventions, parameter types and numbers, and return value types of the functions are carefully compared to determine if there are any incompatibilities due to different function definitions. For stored procedures, in-depth analysis is performed on their differences in syntax structure, variable declaration methods, and the use of control flow statements. For triggers, the focus is on the syntax differences in trigger conditions, trigger timing, and post-trigger execution logic. Through these multi-faceted comparisons, the differences in advanced features between the two databases are analyzed in detail, providing a solid foundation for subsequent data processing and migration.

[0072] Create conversion rules, which include: rules for syntax mapping, rules for data type conversion, and rules for function and operator conversion.

[0073] Specifically, the syntax mapping rules are used to establish the mapping relationship between the source SQL syntax and the target domestically developed database syntax, including keyword substitution and syntax structure adjustment. Traditional syntax mapping is mostly based on simple rule tables for one-to-one substitution, while this invention, on the other hand, uses semantic analysis technology to deeply understand the semantic logic of SQL statements, enabling more accurate keyword substitution and syntax structure adjustment. Data type conversion rules are used to define the mapping rules between data types in different databases. The specific steps are: first, comprehensively review all data types in the source SQL database and the target domestically developed database, compare their storage range, precision, and other characteristics, and then establish a detailed mapping table based on these characteristics. Function and operator conversion rules are used to handle the differences between functions and operators in different databases, and formulate corresponding conversion rules and adjustment strategies. The specific steps are: first, list all functions and operators in both databases in detail, compare their functions, parameter requirements, etc., and formulate conversion rules for different situations. If the functions are similar but the parameter order is different, adjust the parameter order; if one side has a unique function, find an alternative implementation method. This invention provides an example of language rules, as shown in Table 1.

[0074]

[0075]

[0076] Table 1

[0077] Code example of an Abstract Syntax Tree (AST):

[0078] Source SQL: SELECT name, age FROM users WHERE age>18. The AST code representation is:

[0079]

[0080] Adjust the SQL statements based on database characteristics and limitations.

[0081] Specifically, regarding feature compatibility: conduct in-depth research on the transaction processing mechanism of the target database, understand in detail its transaction initiation, commit, and rollback rules, as well as the characteristics and applicable scenarios of different transaction isolation levels, to ensure that the converted SQL statements conform to the specifications of the target database in transaction operations.

[0082] For concurrency control, analyze its locking mechanism and concurrent access handling methods, and adjust the data access logic in SQL statements to avoid problems such as deadlocks or data inconsistency.

[0083] Regarding stored procedure support, we carefully compared the differences in syntax, variable declarations, control flow statements, and other aspects of stored procedures between the source and target databases to accurately convert and adapt the stored procedures.

[0084] For performance optimization strategies: closely integrate the performance characteristics of the domestically developed database, such as its unique storage engine's support for indexes, conduct in-depth analysis of data distribution, query frequency and patterns, and design more efficient indexes accordingly.

[0085] In terms of query optimization, existing technologies may only perform some conventional syntax-level optimizations. This invention, however, delves into the query execution plan generation mechanism of domestically developed databases, utilizing their internal optimizer hints and other functions to deeply optimize query statements, thereby significantly improving the execution efficiency of the converted database. This optimization method cannot achieve the same effect simply by adjusting existing technologies. Specifically, this invention utilizes reinforcement learning of a large model to achieve query optimization, generating the optimal execution plan through interactive learning with the database environment. The query structure (tables, join conditions, etc.) and data statistics (table size, indexes, etc.) are encoded as states and input into the large model; optimization operations such as query rewriting, join order selection, and index usage are set as action spaces. Using the actual cost of the execution plan (IO, CPU consumption) as a reward, the large model outputs action probabilities through a policy network, generates and executes the plan, and adjusts parameters based on feedback. Through continuous iteration, the large model gradually learns the optimal strategies for different scenarios, efficiently handling complex queries and adapting to changes in data distribution, overcoming the limitations of traditional optimizers that rely on manual rules and statistical information.

[0086] Detect and analyze updates and improvements to the SQL database and the domestically developed database, update the rule base in a timely manner, and ensure that the conversion can always support the latest database features and syntax.

[0087] In this invention, the steps for creating a large domain model include:

[0088] Select a pre-trained model based on the SQL to SQL conversion requirements.

[0089] Choose a powerful pre-trained model based on the SQL-to-SQL conversion scenario. The pre-trained model should have been trained on a large amount of text data and possess excellent language understanding and generation capabilities. Specifically, the following points should be considered:

[0090] 1) Extensive pre-training data: During pre-training, a large-scale corpus is used, and deep learning algorithms are employed to perform multiple rounds of feature extraction and learning on these texts. Traditional techniques may only focus on certain text types and lack deep integration and learning of multi-source texts in the SQL domain. Our method, however, comprehensively and deeply mines SQL syntax, semantics, and application scenario information in various texts, building more powerful language understanding and conversion capabilities, thereby better adapting to SQL-to-SQL conversion tasks.

[0091] 2) Model size: Select a large model with a sufficient number of parameters to ensure that it has the ability to handle complex SQL transformation tasks.

[0092] 3) Scalability and adjustability: The model supports fine-tuning and can be further trained according to specific needs to improve performance on specific tasks.

[0093] Based on the model's scale requirements, diverse SQL statements are collected, transformation pairs are generated, and data augmentation techniques are used to increase the diversity and coverage of the dataset. The SQL transformation pairs are labeled for quality control.

[0094] Specifically, based on the model size requirements, SQL transformation pairs are labeled to generate more transformation pairs, thereby enhancing the diversity and coverage of the training dataset. The specific steps are as follows:

[0095] 1) Collect diverse SQL statements: Collect various SQL statements from common SQL databases (such as MySQL, Oracle, SQL Server, etc.), including query, update, insert, delete, DDL, etc.

[0096] 2) Generating Transformation Pairs: Representative SQL statements are selected from the source database. These statements cover various operation types, such as queries, inserts, updates, and deletes, and have different levels of syntax complexity. Simultaneously, based on the syntax rules and characteristics of the target database, corresponding target SQL statements are written for each source SQL statement. Data types also need to be converted according to the target database's specifications. The source SQL statements and their corresponding target SQL statements are then paired to generate SQL transformation pairs, which are used for subsequent model training and optimization.

[0097] 3) Data Augmentation Techniques: Data augmentation techniques are employed to increase the diversity and coverage of the dataset. For example, more transformation pairs can be generated through grammatical transformations, keyword replacements, and parameter adjustments, enriching the training data. Simultaneously, double annotation or expert review is used to ensure annotation quality. This more systematically and accurately improves the diversity and effectiveness of the training dataset than existing techniques, enhancing the model's learning ability for SQL transformation tasks.

[0098] 4) Quality control of labeled data: Ensure the accuracy and consistency of labeled data, and improve data quality by adopting methods such as double labeling or expert review.

[0099] The collected SQL transformation pairs are used to fine-tune the pre-trained model, controlling its learning of transformation rules and patterns between source and target SQL. The specific steps include:

[0100] 1) Define fine-tuning goals: Clarify the goals and evaluation indicators for fine-tuning, such as the accuracy of the conversion and the executability of the generated statements.

[0101] 2) Constructing a fine-tuning dataset: Divide the collected and labeled SQL transformation pair dataset into training, validation, and test sets for model training and evaluation.

[0102] 3) Training process control: Set reasonable training parameters (such as learning rate, batch size, etc.) and fine-tune the training. Regularly evaluate the model's performance on the validation set and adjust the training strategy to optimize model performance.

[0103] 4) Model Evaluation and Validation: The fine-tuned model is evaluated using a test set to check its accuracy in converting different types of SQL statements. Functional validation and performance testing ensure that the generated SQL statements can be correctly executed in the target domestically developed database.

[0104] 5) Iterative Optimization: Based on the evaluation results, iterative optimization is performed to continuously improve the model's conversion capabilities. Training data and conversion rules are continuously updated and improved by combining user feedback and real-world application scenarios to enhance the model's usability and adaptability.

[0105] Based on the output SQL script, this invention also includes a testing step: automatically testing the SQL script data and functionality before and after conversion; the steps for testing the SQL script include:

[0106] Test environment setup:

[0107] Install the Docker engine, pull the database image to create a container and set the running parameters; use the database snapshot function to create a snapshot when the data is stable, and restore to the snapshot state before each test to ensure the initial data is consistent.

[0108] Source database environment: This is used to determine the type of source SQL database, prepare a suitable server or virtual machine, install the source database software, and configure it according to standard procedures, including setting the port, creating users, etc., to ensure that the database can run normally in order to execute and verify the source SQL statements.

[0109] Target Database Environment: This is used to obtain the installation package of the target domestically developed database and confirm that the server's hardware configuration meets the database's operational requirements. Install a suitable operating system on the server, then follow the domestically developed database installation wizard to install it, configuring basic parameters such as the database port to complete the environment setup and ensure its normal operation. Test Data Preparation: Prepare a set of standard test data in the source database. This data should include various typical table structures, indexes, views, stored procedures, triggers, etc.

[0110] SQL execution and result capture:

[0111] Database connection pooling technology is used for database connection, and an automated execution framework is used to execute SQL statements and capture results. During execution, the execution status of the statements is monitored in real time. After the statements are executed, the execution results are obtained from the relevant data structures or interfaces. At the same time, the execution plan is obtained through specific functions or tools provided by the database.

[0112] Source SQL execution: Executes the source SQL statement in the source database environment, capturing its execution results and execution plan. Target SQL execution: Executes the transformed SQL statement in the target domestic database environment, capturing its execution results and execution plan.

[0113] Results comparison and consistency check: The result sets are compared using a data comparison algorithm.

[0114] The data comparison algorithm accurately compares result sets, including different data types such as numbers, strings, and dates. For example, it compares the specific numerical values ​​for numerical data and compares the characters of strings for identical content. It iterates through each data element in the result set for comparison. An execution plan analysis tool displays key information such as the execution path of SQL statements and index usage to aid in analysis.

[0115] Result Data Comparison: Compare the result sets returned after executing SQL statements in the source and target databases to check data consistency. Execution Plan Comparison: Compare the execution plans of the source and target databases to ensure that the converted SQL statements do not significantly degrade in performance. Exception Handling: Capture and handle exceptions or errors that occur during execution, record and analyze the causes of problems.

[0116] Continuous improvement and optimization:

[0117] The test coverage analysis tool Cobertura was used to evaluate the coverage of test cases for SQL syntax and operations, showing which SQL syntax was covered by the test cases and which was not. Simultaneously, the performance monitoring and optimization tool YourKitJava Profiler was used to monitor performance metrics during test script execution, such as resource consumption and execution time. This data was analyzed to optimize the test framework and scripts, improving execution efficiency.

[0118] User feedback collection: Collect user feedback during actual use, analyze problems, and improve automated testing functions.

[0119] Improved test coverage: Continuously add new test cases to expand test coverage and ensure comprehensive testing of various complex SQL syntax and features.

[0120] Performance optimization: Optimize the automated testing framework and scripts to improve test execution efficiency and reduce test time.

[0121] Based on the above method, the present invention also provides a corresponding system, namely a system for converting SQL language into the language of a domestically developed database, such as... Figure 1 As shown, it includes:

[0122] The input module retrieves the source SQL script from the source SQL database.

[0123] The parsing module parses the source SQL statement and breaks it down into a structured form;

[0124] The conversion module, based on a pre-established SQL syntax mapping rule base, calls the domain-wide model to convert the parsed SQL statements into SQL statements compatible with the domestic IT innovation database;

[0125] The output module maps and adjusts the syntax and data types according to the rule base, and outputs the converted SQL script;

[0126] The automated testing module automatically tests the SQL script data and functionality before and after the conversion.

[0127] The working principle between the modules is similar to the method described above for converting SQL into the language of a domestic database, and will not be repeated here.

[0128] Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort should fall within the scope of protection of the present invention.

Claims

1. A method for converting SQL language into the language of a domestically developed database, characterized in that, Includes the following steps: Obtain the source SQL script from the source SQL database, parse the source SQL statement, and decompose it into a structured form; based on the pre-established SQL syntax mapping rule base, call the domain big model to convert the parsed SQL statement into an SQL statement compatible with the domestic IT innovation database; Based on the rule base, the syntax and data types are mapped and adjusted, and the converted SQL script is output.

2. The method for converting SQL language into the language of a domestically developed database according to claim 1, characterized in that, The decomposed statement structure is an abstract syntax tree. The steps to generate an abstract syntax tree structure from an SQL statement are as follows: A lexical analyzer is used to segment the SQL script into lexical units; the lexical analyzer performs lexical analysis using regular expressions and finite state automata. Based on the lexical unit stream generated by lexical analysis, the parser parses the lexical unit stream into an abstract syntax tree according to SQL syntax rules.

3. The method for converting SQL language into the language of a domestically developed database according to claim 2, characterized in that, The abstract syntax tree is a tree-like data structure. Statement nodes, as the top-level nodes of the abstract syntax tree, represent the main operation types of SQL statements. Expression nodes, structure nodes, and control structure nodes are distributed in the corresponding child node positions according to the logical hierarchy of the SQL statement.

4. The method for converting SQL language into the language of a domestically developed database according to claim 1, characterized in that, The steps to establish an SQL syntax mapping rule base are as follows: Collect corresponding syntax rules and features from multiple SQL databases, and identify SQL syntax differences; Create conversion rules; these rules include: syntax mapping rules, data type conversion rules, and function and operator conversion rules. Adjust the SQL statements based on database characteristics and limitations; Detect and analyze updates and improvements to the SQL database and the domestic IT innovation database, and update the rule base in a timely manner.

5. The method for converting SQL language into the language of a domestically developed database according to claim 4, characterized in that, The syntax mapping rules are used to establish the mapping relationship between the source SQL syntax and the target information technology database syntax; the data type conversion rules are used to define the mapping rules between different databases; the function and operator conversion rules are used to handle the differences between functions and operators in different databases and formulate corresponding conversion rules and adjustment strategies.

6. The method for converting SQL language into the language of a domestically developed database according to claim 1, characterized in that, The steps to create a domain-wide model include: Select a pre-trained model based on the SQL to SQL conversion requirements; Based on the model's scale requirements, diverse SQL statements are collected, transformation pairs are generated, and data augmentation techniques are used to increase the diversity and coverage of the dataset. The SQL transformation pairs are labeled for quality control. By using the collected SQL transformations to adjust the pre-trained model, the transformation rules and patterns between the source SQL and the target SQL can be controlled.

7. The method for converting SQL language into the language of a domestically developed database according to claim 1, characterized in that, Based on the output SQL script, the method also includes a testing step: Automatically test the SQL script data and functionality before and after the conversion; The steps for testing SQL scripts include: Install the Docker engine, pull the database image to create a container and set the running parameters; use the database snapshot function to create a snapshot when the data is stable, and restore to the snapshot state before each test using the restore technique. Database connection pooling technology is used for database connection, and an automated execution framework is used to execute SQL statements and capture results. During execution, the execution status of the statements is monitored in real time. After the statements are executed, the execution results are obtained from the relevant data structures or interfaces. At the same time, the execution plan is obtained through specific functions or tools provided by the database. The result sets are compared using a data comparison algorithm; Test coverage analysis tools are used to evaluate the coverage of test cases with SQL syntax and operations; at the same time, performance monitoring and optimization tools are used to monitor performance indicators during the execution of test scripts, and the test framework and scripts are optimized by analyzing performance indicators.

8. A system for converting SQL language into the language of a domestically developed database, characterized in that, include: The input module retrieves the source SQL script from the source SQL database. The parsing module parses the source SQL statement and breaks it down into a structured form; The conversion module, based on a pre-established SQL syntax mapping rule base, calls the domain-wide model to convert the parsed SQL statements into SQL statements compatible with the domestic IT innovation database; The output module maps and adjusts the syntax and data types according to the rule base, and outputs the converted SQL script; The automated testing module automatically tests the SQL script data and functionality before and after the conversion.