A database migration method and system

Through the neural network model, the database statements are automatically converted, which solves the problem of manual modification of statements in database migration, and the efficient and accurate database migration process is achieved.

CN119719078BActive Publication Date: 2025-06-06HUAWEI MARINE NETWORKS CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510237492.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-03
Publication Date
2025-06-06
Estimated Expiration
2045-03-03

AI Technical Summary

Technical Problem

During the database migration process, developers need to manually modify database statements to adapt to the new database syntax, which is not only time-consuming and error-prone, increasing the risk and difficulty of migration.

Method used

By obtaining the conversion request of the database statement, analyzing the database statements to obtain statement features, and using a pre-trained neural network model, the database statement corresponding to the target database type is output based on the statement characteristics, source database type and target database type, thereby realizing the automatic conversion of database statements.

Benefits of technology

It significantly improves the accuracy and efficiency of database statement conversion, reduces the cost of manual participation, and reduces the risk of migration errors caused by grammatical differences.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119719078B_ABST
    Figure CN119719078B_ABST
Patent Text Reader

Abstract

The present application relates to the field of data processing technology, and specifically to a database migration method and system. The method includes: obtaining a conversion request for a database statement, the conversion request includes the type of a source database, a first database statement corresponding to the type of the source database, and the type of a target database; parsing the first database statement based on the database statement specification corresponding to the type of the source database to obtain statement features corresponding to the first database statement; using the statement features, the type of the source database, and the type of the target database as input information of a pre-trained neural network model, and using the neural network model to output a second database statement corresponding to the type of the target database. The database migration method and system provided by the present application can realize automatic conversion of database statements during the database migration process, thereby significantly improving the accuracy and efficiency of database statement conversion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a database migration method and system. Background Art

[0002] As an important part of the information technology innovation industry, databases undertake the core functions of storing and retrieving data. Their importance in data management and processing is self-evident.

[0003] Due to factors such as technology evolution, performance requirements, and cost considerations, an enterprise or organization may need to migrate data from one database to another. In this process, the database statements need to be converted. In the process of converting database statements, developers need to spend a lot of time and effort to modify the original database statements to adapt to the new database syntax (i.e., SQL syntax). However, this manual modification process is not only time-consuming, but also prone to errors, increasing the risk and difficulty of migration. Summary of the invention

[0004] In order to solve the above problems, the embodiments of the present application propose a database migration method and system, which can realize automatic conversion of database statements during the database migration process, thereby significantly improving the accuracy and efficiency of database statement conversion.

[0005] In order to achieve the above-mentioned purpose, in a first aspect, an embodiment of the present application provides a database migration method, including: obtaining a conversion request for a database statement, the conversion request including the type of a source database, a first database statement corresponding to the type of the source database, and the type of a target database; parsing the first database statement based on a database statement specification corresponding to the type of the source database to obtain statement features corresponding to the first database statement; using the statement features, the type of the source database and the type of the target database as input information of a pre-trained neural network model, and using the neural network model to output a second database statement corresponding to the type of the target database.

[0006] The embodiment of the present application receives a conversion request including a first database statement and the type of a source database and the type of a second database, parses the first database statement to obtain statement features, and converts the statement features based on the grammatical rules corresponding to the type of the target database and the grammatical rules corresponding to the type of the source database, thereby generating a second database statement, and then utilizing the second database statement. In this way, efficient conversion of database statements can be achieved, the accuracy and efficiency of the database migration process can be significantly improved, the cost of manual participation can be reduced, and the risk of migration errors caused by grammatical differences can be effectively reduced.

[0007] In an optional implementation, obtaining a conversion request for a database statement includes: obtaining a first database statement in a first window in a first interface of a database statement conversion system; obtaining a type of a source database corresponding to the first database statement in a first selection control in the first interface; obtaining a type of a target database in a second selection control in the first interface; and generating a conversion request based on the first database statement, the type of the source database, and the type of the target database. In this way, by providing an intuitive user interface, allowing a user to quickly select the type of the source database and the type of the target database, and generating a corresponding database statement conversion request, cross-database migration of database statements can be efficiently implemented, human errors can be reduced, development efficiency can be improved, and the needs of multiple database types can be flexibly responded to.

[0008] In an optional implementation, the first database statement is parsed based on the database statement specification corresponding to the type of the source database to obtain the statement feature corresponding to the first database statement, including: based on the grammatical statement rules of the first database in the database statement specification and the grammatical rules of the first database corresponding to the type of the source database, the first database statement is parsed to obtain first information, the first information including first sub-information, the data flow direction of the first database statement and the type of the source database; wherein the first sub-information includes a library for executing the first database statement, a table of the first database statement and a field relationship of the first database statement; based on the keyword of the first database statement in the database statement specification, the first sub-information is parsed to obtain second information; the second information includes at least one of the relationship type of the first database statement, the method of the first database statement, the source element of the first database statement and the target element of the first database statement; based on the second information, the data flow direction of the first database statement and the type of the source database, the statement feature corresponding to the first database statement is determined. In this way, the database statement can be fully parsed and understood, providing an important basis for data migration.

[0009] In an optional implementation, after the first window in the first interface of the database statement conversion system obtains the first database statement, the method further includes: in response to a trigger operation on an update control in the first interface, obtaining the updated first database statement in the first interface. In this way, the accuracy of the first database statement can be effectively improved.

[0010] In an optional implementation, the method further includes: obtaining configuration information corresponding to the type of the target database, the configuration information including the target database address, the target database port information, the target database user name, the target database password and the target database name; and determining the test result of the second database statement based on the configuration information and the second database statement. In this way, the accuracy of generating the second database statement can be improved by implementing the test of the second database statement through the configuration information.

[0011] In an optional implementation, obtaining configuration information corresponding to the type of the target database includes: generating a second interface in response to a triggering operation of a test control in a first interface of a database statement conversion system; obtaining the target database address in a first input control of the second interface; obtaining the target database port in a second input control of the second interface; obtaining the target database user name in a third input control of the second interface; obtaining the target database password in a fourth input control of the second interface; obtaining the target database name in a fifth input control of the second interface; and determining the configuration information corresponding to the type of the target database based on the target database address, the target database port, the target database user name, the target database password, the target database name, and the type of the target database. In this way, by dynamically obtaining the configuration information of the database, the flexibility of the database statement conversion system is improved.

[0012] In an optional implementation, based on the configuration information and the second database statement, determining the test result of the second database statement includes: when the second database statement is a query statement, obtaining query data of the second database statement from the target database corresponding to the target data type; when the query data of the second database statement is obtained, determining the test result of the second database statement as a test success; when the query data of the second database statement is not obtained, determining the test result of the second database statement as a test failure. In this way, the test of the second database statement is implemented through the configuration information, and the accuracy of the generated second database statement can be ensured.

[0013] In an optional implementation, based on the configuration information and the second database statement, determining the test result of the second database statement includes: when the second database statement is a non-query statement, obtaining the execution information of the second database statement from the target database corresponding to the type of the target database, the execution information including the execution status and the execution time; when the second database statement is a non-query statement, obtaining the execution information of the second database statement from the target database corresponding to the target data type, the execution information including the execution status and the execution time; when the execution status is successful and the execution time is obtained, determining the test result of the second database statement as a test success; when the execution status is a failure, or the execution information is not obtained, determining the test result of the second database statement as a test failure. In this way, the test of the second database statement can be implemented through the configuration information to ensure the accuracy of the generated second database statement.

[0014] In an optional implementation, the method further includes: when the test result of the second database statement is a success, the neural network model is updated based on the type of the source database, the first database statement, the type of the target database, and the second database statement to obtain an updated neural network model. In this way, the neural network model can be updated using the database type and database statement, thereby improving the accuracy and adaptability of the model in converting database statements between different database types.

[0015] In an optional implementation, before using the sentence features, the type of the source database and the type of the target database as the input information of the pre-trained neural network model and using the neural network model to output the second database sentence corresponding to the type of the target database, it also includes: obtaining a training set, the training set includes at least one type of source training database, source training database sentence, type of target training database and target training database sentence; the source training database sentence corresponds to the type of the source training database, and the target training database sentence corresponds to the type of the target training database; parsing the source training database sentence based on the database sentence specification corresponding to the type of the source training database to obtain the training sentence features corresponding to the source training database sentence; using the training sentence features corresponding to at least one source training database sentence, the type of the source training database and the type of the target training database as the input information of the neural network model, and using at least one target training database sentence as the output of the neural network model, the neural network model is trained. In this way, the cross-database migration problem is automatically processed using the trained neural network model, reducing manual intervention and improving conversion efficiency and accuracy.

[0016] In an optional implementation, the statement feature includes at least one of a relationship type of the first database statement, a method of the first database statement, a source element of the first database statement, a target element of the first database statement, a data flow direction of the first database statement, an operator of the first database statement, and a type of a source database. In this way, the statement features corresponding to the database statement can be fully acquired, which can effectively improve the accuracy of the conversion.

[0017] In a second aspect, an embodiment of the present application provides a database migration system, including: a dialect acquisition module, configured to: obtain a conversion request for a database statement, the conversion request including a first database statement, the type of a source database corresponding to the first database statement, and the type of a target database corresponding to a second database statement to be converted; a dialect parsing module, configured to: parse the first database statement based on a database statement specification corresponding to the type of the source database, and obtain statement features corresponding to the first database statement; a dialect conversion module, configured to: use the statement features, the type of the source database and the type of the target database as input information of a pre-trained neural network model, and use the neural network model to output a second database statement corresponding to the type of the target database.

[0018] The embodiment of the present application receives a conversion request including a first database statement and the type of the source database and the type of the target database, parses the first database statement to obtain statement features, and converts the statement features based on the grammatical rules corresponding to the type of the target database and the grammatical rules corresponding to the type of the source database, thereby generating a second database statement. In this way, efficient conversion of database statements can be achieved, the accuracy and efficiency of the database migration process can be significantly improved, the cost of manual participation can be reduced, and the risk of migration errors caused by grammatical differences can be effectively reduced.

[0019] In an optional implementation, the method further includes: a dialect acquisition module, further configured to: acquire configuration information of a target database, the configuration information including a target database address, a target database port, a target database user name, a target database password, and a target database name; and a dialect test module, configured to: determine a test result of the second database statement based on the configuration information and the second database statement. In this way, by establishing a connection between the configuration information and the second database statement, and then performing a test, the accuracy of the generated second database statement can be ensured.

[0020] In an optional implementation, it further includes: a dialect update module, which is configured to: when the test result of the second database statement is a successful test, update the parameters of the neural network model based on the type of the source database, the first database statement, the type of the target database, and the second database statement to obtain an updated neural network model. In this way, the parameters of the neural network model can be updated using the types of the source and target databases and the first and second database statements respectively corresponding to them, thereby improving the accuracy and adaptability of the model in converting database statements between different database types. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the technical solution of the present application, the drawings required for use in the embodiments are briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0022] Figure 1 This is the first flow chart of a database statement conversion method provided by an embodiment of the present application;

[0023] Figure 2 This is a schematic diagram of a first interface of a database conversion system provided in an embodiment of the present application;

[0024] Figure 3 This is the second flow chart of a database statement conversion method provided in an embodiment of the present application;

[0025] Figure 4 is a schematic diagram of a syntax tree provided in an embodiment of the present application;

[0026] Figure 5 A training method for a neural network model provided in an embodiment of the present application;

[0027] Figure 6 is a schematic diagram of a second interface of a database conversion system provided in an embodiment of the present application;

[0028] Figure 7 This is a database statement conversion diagram provided in an embodiment of the present application. DETAILED DESCRIPTION

[0029] The technical solutions in the embodiments of the present application will be described clearly below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments of the present application, other embodiments obtained by ordinary technicians in this field without making creative work all belong to the protection scope of the present application.

[0030] In the following, the terms "first", "second", etc. are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first", "second", etc. may explicitly or implicitly include one or more of the features. In the description of this application, unless otherwise specified, "plurality" means two or more.

[0031] In addition, in the present application, directional terms such as "upper", "lower", "inner" and "outer" are defined relative to the orientation of the components schematically placed in the drawings. It should be understood that these directional terms are relative concepts. They are used for relative description and clarification, and they can change accordingly according to the changes in the orientation of the components placed in the drawings.

[0032] To facilitate understanding of the solution, the following explains the relevant terms:

[0033] A database is a computer software system that stores and manages data according to data structures and is used to store transaction data to be managed.

[0034] Database dialect, also known as database domain-specific language (Domain-Specific Language), is a programming language or language structure designed for the database field. Statements written in database dialect are called database statements.

[0035] SQL (Structured Query Language) is a standard programming language for managing and processing relational databases. It is mainly used to perform tasks such as querying, inserting data, updating data, deleting data, and managing database structures.

[0036] Syntax Tree, also known as Abstract Syntax Tree (AST), is an abstract representation of the grammatical structure of source code. It represents the grammatical structure of a programming language in a tree-like form, and each node in the tree represents a structure in the source code.

[0037] The embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0038] As an important part of the information technology innovation industry, databases bear the core functions of storing and retrieving data. Due to factors such as technological evolution, performance requirements, cost considerations, and policy supervision, enterprises or organizations may need to migrate data from one database to another to meet the ever-increasing performance requirements. Different database management systems have different extensions and support for standard database languages. In the process of migrating from one database to another, database statements (such as SQL statements) often need to be adjusted.

[0039] The following is a schematic description using the databases MySQL and SQL Server as examples.

[0040] MySQL provides a variety of string processing functions, such as the common "CONCAT()" function, which is used to connect (join) multiple strings into a single string. In SQL Server, string concatenation is achieved through the "+" operator. Based on this, when migrating data from one database (MySQL) to another database (SQL Server), it is often necessary to adjust database statements (such as SQL statements).

[0041] Due to the large number and complex structure of database statements, developers usually need to invest a lot of time and effort to manually modify the original database statements to adapt them to the grammatical rules of the target database. This manual transformation process is not only time-consuming, but also prone to errors, resulting in instability of database functions, which further increases the risk and complexity of migration.

[0042] In order to solve the above problems, the embodiments of the present application provide a database statement conversion method, which can realize efficient conversion of database statements, improve the accuracy and efficiency of the database migration process, reduce the cost of manual participation, and effectively reduce the risk of migration errors caused by grammatical differences.

[0043] Figure 1 This is the first flow chart of a database statement conversion method provided in an embodiment of the present application.

[0044] like Figure 1 As shown, the database statement conversion method provided in this embodiment includes the following steps:

[0045] Step S101 : obtaining a conversion request of a database statement, the conversion request including a first database statement, a type of a source database corresponding to the first database statement, and a type of a target database corresponding to a second database statement to be converted.

[0046] The first database statement is a source database statement to be converted, and the second database statement is a target database statement after conversion.

[0047] In an embodiment of the present application, the electronic device may receive a database statement conversion request initiated by a user in an interface of a database conversion system.

[0048] Figure 2 It is a schematic diagram of the first interface of a database conversion system provided in an embodiment of the present application.

[0049] Combination Figure 2As shown in (a) in the figure, the first interface of the database conversion system includes two windows, one for inputting the database statement to be converted, and the other for displaying the converted database statement. Exemplarily, the first window 30 is used to obtain the first database statement, and the second window 31 is used to display the second database statement. In addition, the first interface of the database conversion system also includes a selection control corresponding to each window, and the selection control is used to specify the type of database. Exemplarily, the first selection control 32, the second selection control 33, the update control (statement formatting) 34, the conversion control (statement conversion) 35, the test control (test run) 36, and the check control (provide data model training after the test passes) 38. Among them, the first selection control 32 corresponds to the first window 30, and the second selection control 33 corresponds to the second window 31.

[0050] For example, in combination Figure 2 As shown in (a), the database type is selected as “Mysql” in the first selection control 32 , and the database type is selected as “SQL Server” in the second selection control 33 .

[0051] It should be noted that the first window 30 and the second window 31 can be as follows Figure 2 The first selection control 32 can be arranged in parallel or in a vertical stack. Figure 2 The position of the second selection control 33 may be set above or below the second window 30 as shown in (a) of FIG. 1 , or above or at other positions of the first window 30 . The position is not specifically limited. Similarly, the position of the second selection control 33 may also be set above or below the second window as required.

[0052] Continue to combine Figure 2 As shown in (a), step S101 includes steps S1011 to S1014.

[0053] Step S1011: acquiring a first database statement in a first window 30 in a first interface of a database statement conversion system.

[0054] Exemplarily, a first SQL statement is obtained in the first window 30 of the first interface of the database statement conversion system. For example, select users with the status of "active" from the table named "users", and sort them in descending order according to the creation time, and finally only display the first 10 records, and return the second parameter when the first parameter is "NULL". The first SQL statement is as follows:

[0055] SELECT id, name, IFNULL(email, 'No Email Provided') AS email FROMusers WHERE status = 'active' ORDER BY created_at DESC LIMIT 10;

[0056] Among them, "SELECT" is an SQL command for query, which is used to specify which data to get from the table. "id,name, IFNULL(email, 'No Email Provided') AS email" defines the specific columns to be selected, "id" is the unique identifier of the user, "name" is the user's name, "IFNULL(email, 'No Email Provided') AS email" means that if the user's "email" field is empty (that is, NULL), "No Email Provided" is displayed as an alternative value. "FROM users" means selecting data from the table named "users", "WHERE" is used to specify the conditions for filtering data, "WHERE status" is used to define the filtering conditions based on the "status" field, "WHERE status = 'active'" is used to indicate that the records with the status field value of 'active' are selected, "ORDER BY created_at DESC" is used to specify that the result set should be sorted in descending order according to the created_at field, DESC means descending, and "LIMIT 10" is used to limit the number of results returned to a maximum of 10.

[0057] In one embodiment, after the first database statement is obtained, the method further includes: obtaining an updated first database statement in the first interface. Specifically, the electronic device checks the first database statement in response to the triggering operation of the update control (statement formatting) 34 in the first interface of the database statement conversion system, that is, compares the first database statement with a preset standard database statement, and if the first database statement is not a standard database statement, updates the first database statement to obtain an updated first database statement.

[0058] Among them, standard database statements can be set based on syntax, logic, formatting (form), comments, naming conventions, performance optimization, security and other dimensions.

[0059] Continuing with the above example, after obtaining the first SQL statement, the electronic device checks the first database statement in response to the triggering operation of the update control (statement formatting) 34 in the first interface of the database statement conversion system. The first database statement is not a standard database statement, and the updated first SQL statement is obtained as follows:

[0060] SELECT id, name, IFNULL(email, 'No Email Provided') AS email

[0061] FROM users

[0062] WHERE status = 'active'

[0063] ORDER BY created_at DESC

[0064] LIMIT 10;

[0065] It should be noted that the updated first database statement and the first database statement may be the same or different, and there is no specific limitation on this.

[0066] Step S1012: obtaining the type of the source database corresponding to the first database statement in the first selection control 32 in the first interface.

[0067] Exemplarily, if the first SQL statement comes from a source database of type “MySQL”, in response to a triggering operation of the first selection control 32 in the first interface, the source database type “MySQL” is obtained in the first selection control 32 .

[0068] Step S1013: the second selection control 33 in the first interface obtains the type of the target database.

[0069] Continuing with the above example, if you want to migrate the first SQL statement from a source database of type "MySQL" to a target database of type "PostgreSQL", in response to the triggering operation of the second selection control 33 in the first interface, the target database of type "PostgreSQL" is obtained in the second selection control 33.

[0070] It should be noted that the migration of the database may be the migration of the source database of the type "MySQL" mentioned above to the target database of the type "PostgreSQL", or the migration of the source database of the type "PostgreSQL" to the target database of the type "MySQL", which is not specifically limited here.

[0071] Step S1014: Generate a conversion request based on the first database statement, the type of the source database, and the type of the target database.

[0072] Continue to combine Figure 2 As shown in (a), after acquiring the first database statement, the type of the source database, and the type of the target database, the electronic device generates a conversion request in response to the operation of the conversion control (statement conversion) 35 in the first interface of the database statement conversion system.

[0073] Continuing with the above example, after obtaining the first SQL statement, the source database of type "MySQL" and the target database of type "PostgreSQL", the electronic device responds to the operation of the conversion control (statement conversion) 35 in the first interface of the database statement conversion system, and generates a conversion request to convert the first SQL statement corresponding to the source database of type "MySQL" into the second SQL statement corresponding to the target database of type "PostgreSQL".

[0074] Step S102: parsing the first database statement based on a database statement specification corresponding to the type of the source database to obtain a statement feature corresponding to the first database statement.

[0075] The database statement specification includes the grammatical rules of the database statement, the grammatical rules of the database, and the keywords of the database statement.

[0076] Figure 3 This is the second flow chart of a database statement conversion method provided in an embodiment of the present application.

[0077] like Figure 1 and Figure 3 As shown, in one implementation, step S102 includes steps S1021 to S1023.

[0078] Step S1021: parsing the first database statement based on the grammatical rules of the first database statement in the database statement specification and the grammatical rules of the source database to obtain first information.

[0079] The first information includes the first sub-information, the data flow direction of the first database statement and the type of the source database; the first sub-information includes the library used to execute the first database statement, the table of the first database statement and the field relationship of the first database statement.

[0080] Optionally, the data flow direction of the first database statement refers to the flow direction of data during the execution of the database statement query. Following the example of the first SQL statement above, in the "SELECT" query, the data source is the table specified by the field "FROM", such as the "users" table, and the flow mode can be filtering (WHERE status = 'active')-sorting (ORDER BY created_at DESC)-limiting (LIMIT 10)-calculating fields (IFNULL(email, 'No EmailProvided')). The library used to execute the first database statement is a software component used to interact with a specific type of database. For example, a database driver or library for executing SQL queries. For example, the library "mysql-connector-python" for connecting to and operating a MySQL database in Python. The table of the first database statement refers to the table involved in the first database statement. For example, the "users" table involved in the first SQL statement. The field relationship of the first database statement refers to the fields involved in the first database statement, such as "id", "name", etc. involved in the first SQL statement.

[0081] In one implementation, a parsing algorithm may be used to parse the first database statement based on the rules of the first database statement in the database statement specification and the grammar rules of the source database to generate a syntax tree, and first information may be obtained based on the syntax tree and the type of the source database.

[0082] The database statement specification includes the syntax rules of the first database statement and the syntax rules of the source database. The syntax rules of the first database statement refer to the rules and structures used to write and parse database statements. These rules and structures define how to write or parse database statements to implement various operations on the database, such as database statements need to be composed of keywords (keyword query SELECT). The syntax rules of the source database refer to the syntax and rules of the specific database statements followed by the source database. Different databases (such as MySQL, PostgreSQL, SQL Server, SQLite, etc.) may have some differences and extensions when implementing database statements. For example, in a database of type "SQL Server", the keyword used to limit the number of query results is "TOP", and in a database of type "MySQL", the keyword used to limit the number of query results is "LIMIT".

[0083] In one example, the parsing algorithm may use the JSqlParser algorithm to parse the first database statement. The JSqlParser algorithm is a SQL parsing library written in Java and is used to analyze and process database statements.

[0084] Exemplarily, the JSqlParser algorithm may be used to parse the first database statement based on the rule of the first database statement in the database statement specification and the grammar rule of the first database, generate a syntax tree, and obtain the first information based on the syntax tree.

[0085] A syntax tree is a tree structure in which each node represents a part of a database statement, for example, Figure 4 As shown, the syntax tree is described using the first SQL statement. Figure 4 It is a schematic diagram of a syntax tree provided in an embodiment of the present application.

[0086] like Figure 4 As shown, in the above first SQL statement, the syntax tree includes a root node and child nodes. Root node: the entire first SQL statement, child nodes are "SELECT" clause, "FROM" clause, "ORDER BY" clause, "LIMIT" clause, "WHERE" clause. Further, the syntax tree is traversed to extract the root node and child nodes of each field name, such as table name, field name, expression, alias and other information, and combined with the type of the source database, the first information is obtained.

[0087] It should be noted that other parsing algorithms may also be used to parse the first database statement, which is not specifically limited here.

[0088] Step S1022: parsing the first sub-information based on the keyword of the first database statement in the database statement specification to obtain the second information.

[0089] The database statement specification also includes keywords of the first database statement, such as "FROM" in the first SQL statement, etc. The second information includes at least one of the relationship type of the first database statement, the method of the first database statement, the source element of the first database statement, and the target element of the first database statement.

[0090] The relation type of the first database statement usually refers to the database object operated by the SQL statement. The database object can be tables, views, etc., such as the relation type in the first SQL statement is the "users" table. The method of the first database statement usually refers to the main type of operation performed, such as the method "SELECT" in the first SQL statement. The source element of the first database statement usually refers to the original data elements involved in the database statement. These elements may include column names, table names, conditional expressions, etc., such as the column names "id", "name", "email", the table name "users", the conditional expression "status = 'active '", the sorting field "created_at", and the limit number "10" in the first SQL statement. The target element of the first database statement usually refers to the data value to be inserted, updated, or deleted in the database statement. These elements are mainly related to "INSERT", "UPDATE", and "DELETE" statements. For example, there is an "INSERT" statement of the "MySQL" database type: INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com'); the "INSERT" statement is used to insert a new record into the database table users. "VALUES ('Alice', 'alice@example.com')" refers to the specific values ​​to be inserted, "Alice" is the value of the "name" column, and "alice@example.com" is the value of the "email" column.

[0091] Exemplarily, the JSqlParser algorithm may also be used to parse the first sub-information based on the keywords of the first database statement in the database statement specification to obtain the second information.

[0092] Step S1023: Determine the statement feature corresponding to the first database statement based on the second information, the data flow direction of the first database statement, and the type of the source database. Figure 3 not shown).

[0093] The statement features include at least one of a relationship type of the first database statement, a method of the first database statement, a source element of the first database statement, a target element of the first database statement, a data flow direction of the first database statement, an operator of the first database statement, and a type of a source database.

[0094] In one embodiment, the second information includes at least one of a relationship type of the first database statement, a method of the first database statement, a source element of the first database statement, and a target element of the first database statement. The second information, the data flow direction of the first database statement, and the type of the source database are combined to obtain the second information.

[0095] The specific content of the sentence features in step S1023 can refer to the above steps S1021 and S1022, which will not be repeated here.

[0096] Step S103, using the sentence features, the type of the source database and the type of the target database as input information of the pre-trained neural network model, and using the neural network model to obtain the second database sentence.

[0097] Among them, the pre-trained neural network model refers to a neural network model that has been trained on a large-scale data set before use. In order to ensure the generalization ability of the neural network model, it is necessary to train the neural network model based on a large amount of training data.

[0098] In one embodiment, in combination Figure 5 This section explains how to train a neural network model.

[0099] Figure 5 It is a flowchart of a training method for a neural network model provided in an embodiment of the present application.

[0100] like Figure 5 As shown, the training method of the neural network model includes the following steps: step S1031-step S1033.

[0101] Step S1031, obtaining a training set.

[0102] The training set includes at least one type of a source training database, a source training database statement, a type of a target training database, and a target training database statement; the source training database statement corresponds to the type of the source training database, the target training database statement corresponds to the type of the target training database, and the source training database statement corresponds to the target training database statement.

[0103] For example, the type of the source training database is: MySQL, SQL Server, the source training database statement is: MySQL statement, SQL Server statement, the type information of the target training database is: PostgreSQL, SQLite, the target training database statement is: PostgreSQL statement, SQLite statement. Among them, the MySQL statement corresponds to the PostgreSQL statement, and the SQL Server statement corresponds to the SQLite statement.

[0104] Step S1032: parsing the source training database statements based on the database statement specification corresponding to the type of the source training database to obtain training statement features corresponding to the source training database statements.

[0105] Among them, the training statement features include at least one of the relationship type of the source training database statement, the method of the source training database statement, the source element of the source training database statement, the target element of the source training database statement, the data flow direction of the source training database statement, the operator of the source training database statement and the type of the source training database.

[0106] The specific content of step S1032 can refer to the above step S102 and is not specifically limited here.

[0107] Step S1033, training the neural network model using at least one source training database type, source training database statement and target training database type as input information of the neural network model, and using at least one target training database statement as output information of the neural network model.

[0108] In one example, the type of at least one source training database, source training database statements, and target training database types are input into an initial neural network model, and a predicted database statement is output. Furthermore, a preset loss function is used to determine a loss value between the predicted database statement and the target database statement, and the initial neural network model is continuously adjusted based on the loss value. When the loss value is less than a preset threshold, it indicates that the training of the initial neural network model is completed, and a trained neural network model is obtained.

[0109] Continue to combine Figure 3 As shown, after the neural network model is trained, the neural network model is deployed to the database statement conversion system. Further, during the application process, the statement features, the type of the source database and the type of the target database are input into the trained neural network model for processing, and a second database statement corresponding to the type of the target database is output.

[0110] In one implementation, the type of database can be input into the neural network model in the form of a label of a database statement together with the corresponding database statement. In one example, the type of the source database is used as the label of the first database statement, and the first database statement and the type of the target database are input into the neural network model to obtain a second database statement.

[0111] Exemplarily, a source database of type "MySQL" is used as a label of the first SQL statement, the first database statement and the target database of type "PostgreSQL" are input into the neural network model, a second SQL statement is generated, and the second SQL statement is displayed in the second window 31 in the first interface. For example, users with a status of "active" are selected from the "users" table, and are arranged in descending order according to the creation time, and finally only the first 10 records are displayed, and the second parameter is returned when the first parameter is "NULL". The second SQL statement is as follows:

[0112] SELECT id, name, COALESCE(email, 'No Email Provided') AS email

[0113] FROM users

[0114] WHERE status = 'active'

[0115] ORDER BY created_at DESC

[0116] LIMIT 10;

[0117] The second SQL statement selects the "id", "name", and "email" fields from the "users" table, and replaces them with "No Email Provided" if the "email" field is empty. In addition, the query results only include users whose "status" is 'active', and are sorted in descending order by the "created_at" field, and finally return the first 10 records. Specifically, "SELECT id, name, COALESCE(email, 'No Email Provided') AS email" selects the "id" and "name" fields, and uses the "COALESCE" function to process the "email" field. If the "email" field is empty (NULL), "No Email Provided" is used instead, otherwise the actual value of the "email" field is used, and the result column is named "email". "FROM users" refers to the data source of the query, such as the data source "users" table. "WHERE status = active" refers to selecting records whose "status" field value is "active". "ORDER BY created_at DESC" means sorting the results in descending order by the "created_at" field, with the latest records at the front. "LIMIT 10" means limiting the number of results returned to 10 records.

[0118] In order to ensure the correctness and applicability of the second database statement, the generated database statement needs to be further tested. The main purpose of the test is to verify whether the generated database statement can be correctly executed in the target database corresponding to the type of the target database, while ensuring that its semantics are consistent with the first database statement corresponding to the type of the source database.

[0119] Corresponding to the above embodiment, after the second database statement is generated, the method further includes: performing further testing on the generated second database statement.

[0120] In one implementation, further testing the generated second database statement includes the following steps:

[0121] Step S104: Obtain configuration information corresponding to the type of the target database.

[0122] The configuration information includes the target database address, target database port information, target database user name, target database password and target database name.

[0123] Figure 6 It is a schematic diagram of the second interface of a database conversion system provided in an embodiment of the present application.

[0124] Combination Figure 6 As shown, in one implementation, step S104 includes steps S1041 to S1046.

[0125] Step S1041, in response to the triggering operation of the test control (test run) 36 on the first interface of the database statement conversion system, a second interface is generated.

[0126] The second interface is displayed on the basis of the first interface, and is similar to a "floating window" in form, that is, it is displayed superimposed on the first interface. In other words, the user can directly see the content of the second interface on it without closing or leaving the first interface, just as if the second interface is a floating layer directly covering the first interface.

[0127] Step S1042, obtaining the target database address in the first input control 51 of the second interface.

[0128] Step S1043, obtaining the target database port in the second input control 52 of the second interface.

[0129] Step S1044, obtaining the target database user name in the third input control 53 of the second interface.

[0130] Step S1045, obtaining the target database password in the fourth input control 54 of the second interface.

[0131] Step S1046, obtaining the target database name in the fifth input control 55 of the second interface. It should be noted that the order of steps S1042 to S1046 is not specifically limited.

[0132] Step S1047, determining configuration information corresponding to the type of the target database based on the target database address, the target database port, the target database user name, the target database password, the target database name and the type of the target database.

[0133] In one example, based on the target database address, target database port, target database user name, target database password, target database name and target database type, in response to the triggering operation of the test control 36 on the second interface of the database statement conversion system, the configuration information corresponding to the type of the target database is determined.

[0134] For example, in combination Figure 2 (a) and Figure 6As shown, the electronic device jumps from the first interface to the second interface in response to the triggering operation of the test control (test run) 36 of the first interface of the database statement conversion system. In response to the input operation in the first input control 51 of the second interface, the second database address "172.16.0.27" is obtained in the first input control 51 of the second interface, in response to the input operation in the second acquisition control 52 of the second interface, the second database port "3306" is obtained in the second acquisition control 52 of the second interface, in response to the input operation in the third acquisition control 53 of the second interface, the second database user name "root" is obtained in the third input control 53 of the second interface, in response to the input operation in the fourth acquisition control 54 of the second interface, the second database password "******" is obtained in the fourth input control 54 of the second interface, and in response to the input operation in the fifth acquisition control 55 of the second interface, the second database name "portal" is obtained in the fifth input control 55 of the second interface. Further, in response to the triggering operation of the test control 37 of the second interface of the database statement conversion system, the configuration information corresponding to the type of the target database is determined.

[0135] It should be noted that the configuration information may also include other information, such as second database function information, etc., which will not be described in detail here.

[0136] Step S105: determining a test result of the second database statement based on the configuration information and the second database statement.

[0137] The test result of the second database statement usually includes a test failure or a test success. The second database statement may include two types: a query statement and a non-query statement. The processing methods of query statements and non-query statements are usually different. The following examples are respectively described:

[0138] In one implementation, step S105 includes steps S1051 to S1053.

[0139] Step S1051, when the second database statement is a query statement, query data of the second database statement is obtained from a target database corresponding to the type of target data.

[0140] Exemplarily, for ease of understanding, another example of a second database statement is shown. If the second database statement is a query statement, such as a query statement: SELECT name, age FROM users WHERE age>30; the query data of the second database statement is obtained from the target database. Among them, the query statement refers to selecting the name (name) and age (age) of all users older than 30 years old from the "users" table. Specifically, the "SELECT name, age" part specifies the columns to be included in the query results, and the "name" and "age" columns are selected. The "FROM users" part specifies the table to be queried, such as the "users" table. The "WHERE age>30" part is a conditional clause used to filter the query results. Only those rows whose values ​​in the "age" column are greater than 30 will be selected.

[0141] For example, if the second database statement is an SQL statement in a target database of type "PostgreSQL", assuming that the following data is in the "users" table (Table 1):

[0142] Table 1

[0143] ;

[0144] Step S1052: when the query data of the second database statement is obtained, determining that the test result of the second database statement is a test success.

[0145] Following the above example, combined with Figure 2 As shown in (b) in the figure, the query data returned after executing the query is shown in Table 2 below:

[0146] Table 2

[0147] ;

[0148] Step S1053: if the query data of the second database statement is not obtained, determining that the test result of the second database statement is a test failure.

[0149] Exemplarily, if the generated query statement is executed successfully but the query result is empty, or the query statement is executed unsuccessfully (resulting in an error), it is determined that the test result of the second database statement is a test failure.

[0150] In another embodiment, step S105 includes steps S1054 to S1056.

[0151] Step S1054, when the second database statement is a non-query statement, the execution information of the second database statement is obtained from the target database corresponding to the type of the target data.

[0152] The execution information includes the execution status and execution time. The execution status includes whether the execution status is successful or failed.

[0153] Exemplarily, for ease of understanding, another example of a second database statement is shown. If the second database statement is a non-query statement, such as a non-query statement:

[0154] UPDATE users

[0155] SET status = 'inactive'

[0156] WHERE last_login<'2024-01-01';

[0157] Among them, this non-query statement refers to updating the "status" field of all users in the users table whose last_login (last login time) is earlier than January 1, 2024, and setting it to 'inactive'. Specifically, the "UPDATE users" part specifies the name of the table to be updated, such as the "users" table. The "SET status = 'inactive'" part specifies the column to be updated and the new value, here setting the value of the "status" column to 'inactive'. The "WHERElast_login<'2024-01-01'" part is a conditional clause used to filter the rows that need to be updated. Only those rows whose "last_login" column value is earlier than January 1, 2024 will be updated.

[0158] If the second database statement is an SQL statement in a target database of type "PostgreSQL", assume that the following data is in the "users" table (Table 3):

[0159] Table 3

[0160] ;

[0161] Step S1055: when the execution status is successful and the execution time is obtained, determine that the test result of the second database statement is a test success.

[0162] Following the above example, combined with Figure 2As shown in (c), the execution information of the second database statement is obtained: the execution status is successful, and the execution time (time consumption) is 10 milliseconds, as shown in the following Table 4:

[0163] Table 4

[0164] ;

[0165] Step S1056: When the execution status is failure or the execution information is not obtained, determine that the test result of the second database statement is test failure.

[0166] Exemplarily, if the execution information of the second database statement is not obtained or the execution status is failure, it is determined that the test result of the second database statement is test failure.

[0167] Figure 7 This is a database statement conversion diagram provided in an embodiment of the present application.

[0168] like Figure 7 As shown, in order to ensure the accuracy and continuous optimization of the neural network model, when the test result of the second database statement is "test successful", if the neural network model is not continuously optimized, there will be conversion abnormalities or test failures. Therefore, in order to ensure normal conversion or successful testing, the database statement conversion system will continue to collect and store the converted second database statements. These second database statements will be used as new training data for continuous optimization and online updating of the neural network model.

[0169] In one embodiment, in step S106, when the test result of the second database statement is a successful test, the parameters of the neural network model are updated based on the type of the source database, the first database statement, the type of the target database, and the second database statement to obtain an updated neural network model.

[0170] The above specific contents can refer to the above steps S2031 to S2033, which will not be described in detail.

[0171] It should be noted that, Figure 2 The neural network model can only be continuously optimized after the check box in (provide data model training after the test passes) 38 is checked.

[0172] In addition to improving the accuracy of database statement conversion by continuously optimizing the neural network model, the database statement conversion system can also support the latest database statements through database-driven uploads and updates.

[0173] Exemplarily, a database driver interface corresponding to the database statement conversion system may be pre-set, and a second database statement corresponding to the type of the target database may be uploaded through the database driver interface, thereby improving the accuracy of database statement conversion by the database statement conversion system.

[0174] In summary, it is possible to achieve efficient conversion of database statements, significantly improve the accuracy and efficiency of the database migration process, reduce the cost of manual participation, and effectively reduce the risk of migration errors caused by syntax differences.

[0175] Corresponding to the above-mentioned embodiment of the database statement conversion method, the present application also provides an embodiment of a database statement conversion system. The database statement conversion system includes:

[0176] The dialect acquisition module is configured to: acquire a conversion request of a database statement, the conversion request including a type of a source database, a first database statement corresponding to the type of the source database, and a type of a target database;

[0177] The dialect analysis module is configured to: parse the first database statement based on the database statement specification corresponding to the type of the source database to obtain a statement feature corresponding to the first database statement;

[0178] The dialect conversion module is configured to: use the sentence features, the type of the source database and the type of the target database as inputs of a pre-trained neural network model, and use the neural network model to obtain the second database sentence.

[0179] The dialect acquisition module is further configured to: acquire configuration information of the second database, the configuration information including a target database address, a target database port, a target database user name, a target database password and a target database name;

[0180] The dialect test module is configured to determine a test result of the second database statement based on the configuration information and the second database statement.

[0181] The dialect update module is configured to: when the test result of the second database statement is a successful test, based on the type of the source database, the first database statement, the type of the target database and the second database statement, update the parameters of the neural network model to obtain an updated neural network model.

[0182] It should be noted that those skilled in the art will easily think of other embodiments of the present application after considering the specification and practicing the application disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary technical means in the art that are not disclosed in the present application. The specification and examples are only regarded as exemplary, and the true scope of the present application is indicated by the claims.

[0183] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A database migration method, characterized in that: include: Obtaining a conversion request for a database statement, the conversion request including a type of a source database, a first database statement corresponding to the type of the source database, and a type of a target database; Parsing the first database statement based on a database statement specification corresponding to the type of the source database to obtain a statement feature corresponding to the first database statement; Taking the statement feature, the type of the source database and the type of the target database as input information of a pre-trained neural network model, and using the neural network model to output a second database statement corresponding to the type of the target database; The step of parsing the first database statement based on a database statement specification corresponding to the type of the source database to obtain a statement feature corresponding to the first database statement includes: Based on the grammatical rule of the first database statement in the database statement specification and the grammatical rule of the source database corresponding to the type of the source database, the first database statement is parsed to obtain first information, wherein the first information includes first sub-information, a data flow direction of the first database statement and the type of the source database; wherein the first sub-information includes a library for executing the first database statement, a table of the first database statement and a field relationship of the first database statement; wherein the data flow direction of the first database statement refers to a flow direction of data during the execution of a database statement query; Based on the keyword of the first database statement in the database statement specification, the first sub-information is parsed to obtain second information; the second information includes at least one of a relation type of the first database statement, a method of the first database statement, a source element of the first database statement, and a target element of the first database statement; wherein the relation type of the first database statement refers to a database object operated by the database statement; the method of the first database statement refers to an operation type performed by the database statement; the source element of the first database statement refers to an original data element in the database statement; and the target element of the first database statement refers to a data value inserted, updated, or deleted in the database statement; The statement feature corresponding to the first database statement is determined based on the second information, the data flow direction of the first database statement, and the type of the source database.

2. The database migration method according to claim 1, characterized in that: The step of obtaining a conversion request for a database statement includes: Acquire the first database statement in a first window of a first interface of a database statement conversion system; Obtaining the type of the source database corresponding to the first database statement in a first selection control in the first interface; Acquire the type of the target database in a second selection control in the first interface; The conversion request is generated based on the first database statement, the type of the source database, and the type of the target database.

3. The database migration method according to claim 2, characterized in that: After the first window in the first interface of the database statement conversion system acquires the first database statement, the method further includes: In response to a triggering operation on an update control in the first interface, the updated first database statement is obtained in the first interface.

4. The database migration method according to claim 1, characterized in that: Also includes: Acquire configuration information corresponding to the type of the target database, the configuration information including the target database address, target database port information, target database user name, target database password and target database name; Based on the configuration information and the second database statement, a test result of the second database statement is determined.

5. The database migration method according to claim 4, characterized in that: The obtaining of configuration information corresponding to the type information of the target database includes: In response to a triggering operation on a test control on the first interface, generating a second interface; Obtaining the target database address in the first input control of the second interface; Obtaining the target database port in a second input control of the second interface; Obtaining the target database user name in the third input control of the second interface; Obtaining the target database password in a fourth input control of the second interface; Obtaining the target database name in the fifth input control of the second interface; The configuration information corresponding to the type of the target database is determined based on the target database address, the target database port, the target database user name, the target database password, the target database name, and the type of the target database.

6. The database migration method according to claim 4, characterized in that: The step of determining a test result of the second database statement based on the configuration information and the second database statement includes: In the case where the second database statement is a query statement, obtaining query data of the second database statement from a target database corresponding to the type of the target database; In the case where the query data of the second database statement is obtained, determining that the test result of the second database statement is a test success; In a case where the query data of the second database statement is not obtained, it is determined that the test result of the second database statement is a test failure.

7. The database migration method according to claim 4, characterized in that: The step of determining a test result of the second database statement based on the configuration information and the second database statement includes: In the case where the second database statement is a non-query statement, acquiring execution information of the second database statement from a target database corresponding to the type of the target database, the execution information including execution status and execution time; When the execution status is successful and the execution time is obtained, determining that the test result of the second database statement is a test success; When the execution status is failure, or the execution information is not obtained, it is determined that the test result of the second database statement is test failure.

8. The database migration method according to claim 6 or 7, characterized in that: Also includes: When the test result of the second database statement is a successful test, the neural network model is updated based on the type of the source database, the first database statement, the type of the target database and the second database statement to obtain the updated neural network model.

9. The database migration method according to claim 1, characterized in that: Before using the sentence feature, the type of the source database and the type of the target database as input information of the pre-trained neural network model and using the neural network model to output a second database sentence corresponding to the type of the target database, the method further includes: Acquire a training set, wherein the training set includes at least one type of a source training database, a source training database statement, a type of a target training database, and a target training database statement; the source training database statement corresponds to the type of the source training database, and the target training database statement corresponds to the type of the target training database; Parsing the source training database statement based on the database statement specification corresponding to the type of the source training database to obtain a training statement feature corresponding to the source training database statement; The neural network model is trained by taking the training statement features corresponding to at least one statement of the source training database, the type of the source training database and the type of the target training database as input information of the neural network model, and taking at least one statement of the target training database as output of the neural network model.

10. The database migration method according to claim 1, characterized in that: The statement features include at least one of a relationship type of the first database statement, a method of the first database statement, a source element of the first database statement, a target element of the first database statement, a data flow direction of the first database statement, an operator of the first database statement, and a type of the source database.

11. A database migration system, characterized in that: include: The dialect acquisition module is configured to: acquire a conversion request of a database statement, wherein the conversion request includes a type of a source database, a first database statement corresponding to the type of the source database, and a type of a target database; the type of the source database; A dialect analysis module is configured to: parse the first database statement based on a database statement specification corresponding to the type of the source database to obtain a statement feature corresponding to the first database statement; The dialect conversion module is configured to: use the sentence features, the type of the source database and the type of the target database as input information of a pre-trained neural network model, and use the neural network model to output a second database sentence corresponding to the type of the target database; The dialect parsing module is further configured to: parse the first database statement based on the grammatical rules of the first database statement in the database statement specification and the grammatical rules of the source database corresponding to the type of the source database, to obtain first information, wherein the first information includes first sub-information, data flow direction of the first database statement and the type of the source database; wherein the first sub-information includes a library for executing the first database statement, a table of the first database statement and a field relationship of the first database statement; wherein the data flow direction of the first database statement refers to the flow direction of data during the execution of the database statement query; parse the first sub-information based on the keywords of the first database statement in the database statement specification to obtain second information; the second information includes at least one of the relationship type of the first database statement, the method of the first database statement, the source element of the first database statement and the target element of the first database statement; wherein the relationship type of the first database statement refers to the database object operated by the database statement; the method of the first database statement refers to the type of operation performed by the database statement; the source element of the first database statement refers to the original data element in the database statement; the target element of the first database statement refers to the data value inserted, updated or deleted in the database statement; and determine the statement feature corresponding to the first database statement based on the second information, the data flow direction of the first database statement and the type of the source database.

12. The database migration system according to claim 11, characterized in that: Also includes: The dialect acquisition module is further configured to: acquire configuration information of the second database, the configuration information including the target database address, the target database port, the target database user name, the target database password and the target database name; The dialect testing module is configured to determine a test result of the second database statement based on the configuration information and the second database statement.

13. The database migration system according to claim 12, characterized in that: Also includes: The dialect update module is configured to: when the test result of the second database statement is a successful test, update the parameters of the neural network model based on the type of the source database, the first database statement, the type of the target database and the second database statement to obtain the updated neural network model.

Citation Information

Patent Citations

  • SQL (Structured Query Language) statement processing method, device and equipment based on database and storage medium

    CN115033592A

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

    CN119201978A