Data processing method and device

By disassembling the SQL statements in Java applications into DML fragments for preprocessing and parsing, the SQL syntax conversion from Oracle to MySQL is realized, which solves the problem of low efficiency in manually modifying the differences between Oracle syntax and MySQL syntax, and improves the efficiency of database migration. Accuracy and efficiency.

CN118606342APending Publication Date: 2024-09-06CCB FINTECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202410755360.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-12
Publication Date
2024-09-06

AI Technical Summary

Technical Problem

The difference between Oracle syntax and MySQL syntax for SQL statements in Java applications makes manual identification and modification cumbersome, time-consuming and prone to human errors, affecting the efficiency and quality of database migration.

Method used

By disassembling the mapping file of the source database into DML fragments, performing preprocessing and parsing, generating the SQL statement of the target database, and performing post-processing to generate the mapping file of the target database, the SQL interpreter and key-value pair records are used to implement Oracle to SQL syntax conversion for MySQL.

Benefits of technology

It improves the accuracy and efficiency of data conversion, reduces errors caused by manual operations, and simplifies the conversion process of SQL statements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118606342A
    Figure CN118606342A
Patent Text Reader

Abstract

The invention provides a data processing method and device, and relates to the technical field of computers, a first mapping file corresponding to a source database is disassembled into a first DML fragment, and the first DML fragment is composed of an XML language and a first SQL language corresponding to the source database; preprocessing the first DML fragment to obtain a first SQL statement, wherein preprocessing comprises the steps of converting target content in the first DML fragment into an SQL annotation and generating a key value pair record; analyzing the first SQL statement based on an SQL interpreter to obtain an abstract syntax tree, and converting an expression corresponding to the abstract syntax tree based on a conversion rule from a source database to a target database to obtain a second SQL statement corresponding to the target database; post-processing the second SQL statement to generate a second DML fragment, the post-processing including restoring the second SQL statement according to the key value pair record, the second DML fragment being composed of an XML language and a second SQL language corresponding to the target database; and forming a second mapping file corresponding to the target database based on the second DML fragment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] As the level of informatization of financial institutions improves, database transformation has become the focus of the industry. In this process, migrating the traditional Oracle database to the MySQL database to meet the needs of business development and cost control has become an important task. However, due to the differences in the syntax and functions of the Structured Query Language (SQL) between Oracle and MySQL, the SQL statements in Java applications need to be transformed accordingly to ensure the normal operation and performance optimization of the program.

[0003] The mapping files in Java applications usually contain a large number of SQL statements and Extensible Markup Language (XML) statements. Manually identifying and modifying the differences between Oracle syntax and MySQL syntax is tedious and time-consuming, requiring a lot of human resources and time costs, and is prone to human errors, affecting migration efficiency and quality. Summary of the invention

[0004] The present disclosure provides a data processing method and a device thereof, so as to at least solve the problem of low efficiency in manually identifying and modifying the difference between Oracle syntax and MySQL syntax in the related art.

[0005] The first aspect of the present application provides a data processing method, comprising: decomposing a first mapping file corresponding to a source database into a first data manipulation language DML fragment, wherein the first DML fragment consists of an extensible markup language XML language and a first structured query language SQL language corresponding to the source database; preprocessing the first DML fragment to obtain a first SQL statement generated after the preprocessing, wherein the preprocessing includes converting target content in the first DML fragment into an SQL comment and generating a key-value pair record; parsing the first SQL statement based on an SQL interpreter to obtain an abstract syntax tree, and converting an expression corresponding to the abstract syntax tree based on a conversion rule from the source database to a target database to obtain a second SQL statement corresponding to the target database; post-processing the second SQL statement to generate a second DML fragment corresponding to the target database, wherein the post-processing includes restoring the second SQL statement according to the key-value pair record, wherein the second DML fragment consists of an XML language and a second SQL language corresponding to the target database; and composing a second mapping file corresponding to the target database based on the second DML fragment.

[0006] According to one embodiment of the present application, the source database is an Oracle database, the target database is a MySQL database, and the first DML fragment is preprocessed to obtain a first SQL statement generated after the preprocessing, including: formatting the first DML fragment to obtain a formatted DML fragment; marking each line of code in the formatted DML fragment, and the marking content is the first line, comment line, data line or tail line; converting the comment line into an SQL comment, and generating a key-value pair record based on the SQL comment and the comment line; converting the escape characters in the data line according to the conversion rules; converting the opening tag and the closing tag of the dynamic SQL statement in the data line into SQL comments in sequence, and generating a key-value pair record of the SQL comment and the opening tag and a key-value pair record of the SQL comment and the closing tag; splicing the comment line and the data line to generate the first SQL statement.

[0007] According to one embodiment of the present application, after generating the key-value pair record of the SQL comment and the opening tag and the key-value pair record of the SQL comment and the closing tag, it also includes: determining whether the mybatis variable in the data row contains a comma symbol; if the mybatis variable contains a comma symbol, converting the mybatis variable into an SQL comment, and generating a key-value pair record based on the SQL comment and the mybatis variable.

[0008] According to an embodiment of the present application, the SQL comment carries a digital identifier, and the digital identifier increases in order according to the time when the SQL comment is generated.

[0009] According to one embodiment of the present application, parsing a first SQL statement based on a SQL interpreter to obtain an abstract syntax tree includes: performing grammatical analysis and semantic analysis on the first SQL statement based on the SQL interpreter to obtain an abstract syntax tree, wherein the comment line is attached as an attribute to an expression corresponding to the abstract syntax tree.

[0010] According to one embodiment of the present application, post-processing the second SQL statement to generate a second DML fragment corresponding to the target database includes: restoring the escape characters in the second SQL statement according to the conversion rules; restoring the SQL comments in the second SQL statement according to the key-value pair records to obtain a restoration result; and adding a first row and a last row to the restoration result to generate the second DML fragment.

[0011] According to one embodiment of the present application, a first mapping file corresponding to a source database is disassembled into first data manipulation language DML fragments, including: identifying a specific keyword at the header of each code segment in the first mapping file; based on the specific keyword, disassembling the first mapping file into a first DML fragment, the first DML fragment being one of a select fragment, an insert fragment, an update fragment, and a delete fragment.

[0012] A second aspect of the present application provides a data processing device, including: a disassembly module, used to disassemble a first mapping file corresponding to a source database into a first data manipulation language DML fragment, wherein the first DML fragment consists of an extensible markup language XML language and a first structured query language SQL language corresponding to the source database; a preprocessing module, used to preprocess the first DML fragment to obtain a first SQL statement generated after the preprocessing, wherein the preprocessing includes converting the target content in the first DML fragment into an SQL comment and generating a key-value pair record; a conversion module, used to parse the first SQL statement based on an SQL interpreter to obtain an abstract syntax tree, and convert the expression corresponding to the abstract syntax tree based on a conversion rule from the source database to the target database to obtain a second SQL statement corresponding to the target database; a post-processing module, used to post-process the second SQL statement to generate a second DML fragment corresponding to the target database, wherein the post-processing includes restoring the second SQL statement according to the key-value pair record, wherein the second DML fragment consists of an XML language and a second SQL language corresponding to the target database; and an assembling module, used to compose a second mapping file corresponding to the target database based on the second DML fragment. According to one embodiment of the present application, the source database is an Oracle database, the target database is a MySQL database, and the preprocessing module is further used to: format the first DML fragment to obtain a formatted DML fragment; mark each line of code in the formatted DML fragment, and the marked content is the first line, comment line, data line or tail line; convert the comment line into an SQL comment, and generate a key-value pair record based on the SQL comment and the comment line; convert the escape characters in the data line according to the conversion rules; convert the opening tag and closing tag of the dynamic SQL statement in the data line into SQL comments in sequence, and generate a key-value pair record of the SQL comment and the opening tag and a key-value pair record of the SQL comment and the closing tag; splice the comment line and the data line to generate a first SQL statement.

[0013] According to one embodiment of the present application, the preprocessing module is also used to: determine whether the mybatis variable in the data row contains a comma symbol; if the mybatis variable contains a comma symbol, convert the mybatis variable into an SQL comment, and generate a key-value pair record based on the SQL comment and the mybatis variable.

[0014] According to an embodiment of the present application, the SQL comments involved in the preprocessing module carry digital identifiers, and the digital identifiers increase in order according to the time sequence of generating the SQL comments.

[0015] According to one embodiment of the present application, the conversion module is further used to: perform syntax analysis and semantic analysis on the first SQL statement based on the SQL interpreter to obtain an abstract syntax tree, wherein the comment line is attached as an attribute to the expression corresponding to the abstract syntax tree.

[0016] According to one embodiment of the present application, the post-processing module is further used to: restore the escape characters in the second SQL statement according to the conversion rules; restore the SQL comments in the second SQL statement according to the key-value pair records to obtain a restoration result; and add a first line and a last line to the restoration result to generate a second DML fragment.

[0017] According to one embodiment of the present application, the disassembly module is also used to: identify specific keywords in the header of each code segment in the first mapping file; based on the specific keywords, disassemble the first mapping file into a first DML fragment, and the first DML fragment is one of a select fragment, an insert fragment, an update fragment and a delete fragment.

[0018] The third aspect embodiment of the present application proposes an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to implement the data processing method as described in the first aspect embodiment of the present application.

[0019] The fourth aspect embodiment of the present application proposes a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to implement the data processing method as described in the first aspect embodiment of the present application.

[0020] The fifth aspect embodiment of the present application proposes a computer program product, including a computer program, which, when executed by a processor, implements the data processing method as described in the first aspect embodiment of the present application.

[0021] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects: before generating an abstract syntax tree, the present application first disassembles the first mapping file corresponding to the source database to generate a first DML fragment, and pre-processes the first DML fragment to convert the first DML fragment from two languages ​​into a first SQL statement that only exists in one SQL language. After SQL parsing and conversion to a second SQL statement based on the abstract syntax tree corresponding to the first SQL statement, post-processing is performed to restore other relevant parts of the second SQL statement, thereby generating a second DML fragment containing two languages. The present application realizes the conversion of the mapping file corresponding to the source database from two languages ​​to one language, and then converts it into a mapping file containing two languages ​​corresponding to the target database, which can improve the accuracy and efficiency of data conversion and reduce errors that may be caused by manual operations.

[0022] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:

[0024] Figure 1 It is a schematic diagram of an exemplary implementation of a data processing method shown in an embodiment of the present application.

[0025] Figure 2 It is an overall flow chart of an exemplary implementation of a data processing method shown in one embodiment of the present application.

[0026] Figure 3 It is a schematic diagram of a data processing device shown in one embodiment of the present application.

[0027] Figure 4 It is a schematic diagram of an electronic device shown in one embodiment of the present application. DETAILED DESCRIPTION

[0028] Embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limiting the present application.

[0029] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.) and signals involved in this application are all authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.

[0030] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.

[0031] Figure 1 is a schematic diagram of an exemplary implementation of a data processing method shown in the present application, such as Figure 1 As shown, the data processing method comprises the following steps:

[0032] S101, decomposing a first mapping file corresponding to a source database into first data manipulation language DML segments, wherein the first DML segments are composed of an extensible markup language XML language and a first structured query language SQL language corresponding to the source database.

[0033] The present application is dedicated to realizing the conversion from a first mapping file corresponding to a source database to a second mapping file corresponding to a target database.

[0034] It is not difficult to understand that the first mapping file is generally composed of multiple data manipulation language (DML) fragments. In order to improve conversion efficiency and accuracy, in this application, it is first necessary to disassemble the first mapping file into multiple DML fragments, and use the DML fragments obtained after disassembly as the first DML fragment.

[0035] DML is used to retrieve, insert, update, and delete data in a database. Common DML commands include select (used to retrieve data), insert (used to insert new data), update (used to update existing data), and delete (used to delete data). By using DML, users can effectively operate data in the database and achieve data management and control.

[0036] In the present application, the first mapping file corresponding to the source database is identified according to the select, update, delete, and insert keywords, and the first mapping file corresponding to the source database is disassembled according to the identification result to obtain at least one first DML fragment contained in the first mapping file. Each first DML fragment includes one of the select, update, delete, and insert tags.

[0037] The first DML fragment is composed of XML language and the first SQL language corresponding to the source database. XML language, as a markup language, can provide structured data representation and is used to describe the structure and relationship of data mapping; the first SQL language, as a structured query language, is a standard language for processing database operations and is used to perform data operations.

[0038] S102 : Preprocess the first DML fragment to obtain a first SQL statement generated after the preprocessing, wherein the preprocessing includes converting target content in the first DML fragment into an SQL comment and generating a key-value pair record.

[0039] It should be noted that the SQL language (which can generally be directly expressed in SQL dialect) in the mapping files corresponding to different databases is generally different.

[0040] If the present application is to realize the conversion from the first mapping file corresponding to the source database to the second mapping file corresponding to the target database, the conversion between the SQL languages ​​cannot be directly performed under the premise that the first mapping file contains the XML language in addition to the first SQL language. Therefore, it is first necessary to reduce the dimension of the first DML fragment from containing two languages ​​to containing only the SQL language, that is, it is necessary to preprocess the first DML fragment. In the present application, in order to make the subsequent conversion of SQL statements more accurate, during preprocessing, the target content in the first DML fragment is first converted into a structured query language SQL comment and a key-value pair record is generated. The target content includes but is not limited to comment lines, opening tags and closing tags of dynamic SQL statements, etc. After preprocessing, the first SQL statement containing only one language can be obtained according to the preprocessing result, thereby realizing the dimensionality reduction of the first DML fragment containing two languages ​​to the first SQL statement containing only one language.

[0041] S103, parsing the first SQL statement based on the SQL interpreter to obtain an abstract syntax tree, and converting the expression corresponding to the abstract syntax tree based on the conversion rule from the source database to the target database to obtain a second SQL statement corresponding to the target database.

[0042] The first SQL statement is subjected to syntax analysis and semantic analysis based on the SQL interpreter to obtain an abstract syntax tree.

[0043] Determine the content to be converted from the source database to the target database, where the content to be converted includes at least one of paging statements, time functions, decode functions, string concatenation, system time, paging query, and date format conversion.

[0044] Based on the conversion rule from the source database to the target database, the to-be-converted content of the expression corresponding to the abstract syntax tree is converted to obtain a conversion result, and the abstract syntax tree and the conversion result are assembled to obtain a second SQL statement corresponding to the target database.

[0045] The second SQL statement contains only one language, that is, the conversion from the first SQL statement to the second SQL statement can be understood as a conversion from one-dimensional data to another one-dimensional data.

[0046] S104, post-processing the second SQL statement to generate a second DML fragment corresponding to the target database, wherein the post-processing includes restoring the second SQL statement according to the key-value pair record, wherein the second DML fragment consists of XML language and a second SQL language corresponding to the target database.

[0047] Since the second mapping file corresponding to the target database is also composed of two languages, that is, the second mapping file corresponding to the target database includes XML language and the second SQL language corresponding to the target database.

[0048] In the present application, after obtaining the second SQL statement as described above, it is necessary to restore the second SQL statement according to the key-value pair record, and use the restored fragment as the second DML fragment, thereby achieving dimensionality upgrade from the second SQL statement containing only one language to the second DML fragment containing two languages.

[0049] S105: Compose a second mapping file corresponding to the target database based on the second DML fragment.

[0050] After all the first DML segments disassembled from the first mapping file are converted into second DML segments, the second DML segments are merged according to the order of the first DML segments to generate a second mapping file corresponding to the target database.

[0051] The embodiment of the present application proposes a data processing method, which comprises the following steps: decomposing a first mapping file corresponding to a source database into a first data manipulation language DML fragment, wherein the first DML fragment consists of an extensible markup language XML language and a first structured query language SQL language corresponding to the source database; preprocessing the first DML fragment to obtain a first SQL statement generated after the preprocessing, wherein the preprocessing comprises converting a target content in the first DML fragment into an SQL comment and generating a key-value pair record; parsing the first SQL statement based on an SQL interpreter to obtain an abstract syntax tree, and converting an expression corresponding to the abstract syntax tree based on a conversion rule from the source database to the target database to obtain a second SQL statement corresponding to the target database; post-processing the second SQL statement to generate a second DML fragment corresponding to the target database, wherein the post-processing comprises restoring the second SQL statement according to the key-value pair record, wherein the second DML fragment consists of an XML language and a second SQL language corresponding to the target database; and forming a second mapping file corresponding to the target database based on the second DML fragment.

[0052] Before generating an abstract syntax tree, the present application first disassembles the first mapping file corresponding to the source database to generate a first DML fragment, and pre-processes the first DML fragment to convert the first DML fragment from two languages ​​into a first SQL statement in only one language. After SQL parsing and conversion to a second SQL statement based on the abstract syntax tree corresponding to the first SQL statement, post-processing is performed to restore other relevant parts of the second SQL statement, thereby generating a second DML fragment containing two languages. The present application realizes the conversion of the mapping file corresponding to the source database from two languages ​​to one language, and then converts it into a mapping file containing two languages ​​corresponding to the target database, which can improve the accuracy and efficiency of data conversion and reduce errors that may be caused by manual operations.

[0053] In some implementations, if conversion from an Oracle database to a MySQL database is to be achieved, preprocessing the first DML fragment in S102 to obtain a first SQL statement generated after preprocessing includes the following steps:

[0054] S1021: Format the first DML segment to obtain a formatted DML segment.

[0055] Each line of code in the formatted DML fragment generated after formatting contains only one xml element tag. For example, <if> 、 <trim> 、 <set> 、 <where> 、 <foreach>wait.

[0056] S1022, marking each line of code in the formatted DML fragment, where the marking content is the first line, comment line, data line or tail line.

[0057] Generally, the first line of a formatted DML snippet is the first line, and the last line is the last line. Code lines other than the first line and the last line are identified. Lines carrying comment symbols are comment lines, and the remaining code lines are data lines.

[0058] S1023, converting the comment line into an SQL comment, and generating a key-value pair record according to the SQL comment and the comment line.

[0059] In this application, the key of a key-value pair record is a SQL comment, and the value is a comment line. If there are multiple comment lines, they are numbered sequentially starting from 1 and the sequence number is represented in the key.

[0060] Optionally, in this application, the format of SQL comment is / *@number* / .

[0061] The numbers included in the SQL comment represent digital identifiers, which increase in order according to the time when the SQL comment is generated, so as to prevent confusion during subsequent restoration.

[0062] Exemplarily, after the first comment line to be converted is converted into an SQL comment, the SQL comment carries a digital identifier 1.

[0063] S1024: convert the escape characters in the data row according to the conversion rules.

[0064] Next, the data line is processed. If the data line contains escape characters, the escape characters in the data line are converted according to the conversion rules.

[0065] Exemplarily, the escape character '>' is converted to 'gt;', and the escape character '<' is converted to 'lt;'.

[0066] S1025, converting the opening tag and closing tag of the dynamic SQL statement in the data row into SQL comments in sequence, and generating a key-value pair record of the SQL comment and the opening tag and a key-value pair record of the SQL comment and the closing tag.

[0067] Dynamic SQL statements include but are not limited to <if> 、 <trim> 、 <set> 、 <where> 、 <foreach>statement.

[0068] In this application, the numbers contained in the SQL comments represent digital identifiers, and the digital identifiers increase in order according to the time when the SQL comments were generated.

[0069] For example, if there is only one comment line, after the comment line is converted as described above, the SQL comment carries the number 1. Then, according to the order of conversion of the opening tag and the closing tag of the first dynamic SQL statement, the SQL comments generated after conversion carry the numbers 2 and 3 respectively.

[0070] It is not difficult to understand that there will be a situation with multiple comment lines. In this case, the comment lines are converted into SQL comments in the order of the comment lines. The number identifier carried by each SQL comment increases in the order of the time when the SQL comments are generated. If there are 5 comment lines, after the above conversion of the comment lines, the last SQL comment carries the number 5. Here, according to the order of conversion of the opening and closing tags of the first dynamic SQL statement, the SQL comments generated after conversion carry the numbers 6 and 7 respectively.

[0071] In the case where dynamic SQL statements are not nested, if multiple dynamic SQL statements are included, SQL comments are generated in sequence according to the order in which the opening and closing tags of the dynamic SQL statements are converted.

[0072] As a possible situation, if similar statements such as if, trim, foreach, etc. are nested in the data row, corresponding SQL statement completion rules can be formulated based on usage habits.

[0073] As a possible situation, if there are parallel if statements in the data row, it is determined from the second if whether the first string in the text is and or or. If it is, it does not need to be completed; if not, it is completed in the second one according to the text content. <if>Statement plus and or OR.

[0074] S1026, determine whether the mybatis variable in the data row contains a comma symbol. If the mybatis variable contains a comma symbol, convert the mybatis variable into an SQL comment, and generate a key-value pair record based on the SQL comment and the mybatis variable.

[0075] For example, if the mybatis variable contains a comma symbol, the mybatis variable is converted into an SQL comment, and a key-value pair record is generated according to the SQL comment and the mybatis variable. The generated SQL comment has the same format as the SQL comment described above, and the digital identifier contained in the SQL comment is incremented following the digital identifier contained in the generated SQL comment.

[0076] S1027, concatenate the comment row and the data row to generate a first SQL statement.

[0077] After the preprocessing under the above rules is completed, the comment lines and data lines obtained after the preprocessing are spliced ​​to generate the first SQL statement. At this point, the dimension reduction from the first DML fragment containing two languages ​​to the first SQL statement containing only one language is achieved.

[0078] Furthermore, when the first SQL statement is parsed based on the SQL interpreter to obtain an abstract syntax tree in the above S103, the first SQL statement is firstly subjected to syntax analysis and semantic analysis based on the SQL interpreter to obtain an abstract syntax tree, wherein the comment line is attached to the expression corresponding to the abstract syntax tree as an attribute to avoid loss of information in the comment line. Analysis by the SQL interpreter can improve development efficiency. Developers do not need to manually parse comments and data, but can use automated tools to quickly generate and analyze SQL statements.

[0079] Furthermore, the post-processing of the second SQL statement in S104 to generate a second DML fragment corresponding to the target database includes the following steps:

[0080] S1041, restore the escape characters in the second SQL statement according to the conversion rules.

[0081] For example, the escape character 'gt;' is converted to '>', and the escape character 'lt;' is converted to '<'.

[0082] S1042: Restore the SQL comments in the second SQL statement according to the key-value pair record to obtain a restoration result.

[0083] Exemplarily, if the key in a key-value pair record carries the digital identifier 1, the value in the key-value pair record is replaced with the location of the SQL comment carrying the digital identifier 1 in the second SQL statement.

[0084] And so on, until all SQL comments in the second SQL statement are restored according to the key-value pair records.

[0085] S1043: Add the first row and the last row to the restoration result to generate a second DML fragment.

[0086] Since the above is the first SQL statement obtained by splicing the comment row and the data row generated after preprocessing, the first row and the last row are added to the result to be restored to generate the second DML fragment.

[0087] At this point, post-processing of the second SQL statement has been implemented, and the obtained DML fragment is used as the second DML fragment corresponding to the target database. At this point, the dimension upgrade from the second SQL statement containing only one language to the second DML fragment containing two languages ​​is achieved.

[0088] Figure 2 is a general flow chart of an exemplary implementation of a data processing method shown in the present application, such as Figure 2 As shown, the data processing method comprises the following steps:

[0089] S201, identifying a specific keyword at the head of each code segment in a first mapping file corresponding to a source database.

[0090] Scan the mapping files of the Java project, record the file name and file path of each mapping file and save them in the intermediate database, and determine the first mapping file corresponding to the source database according to the order in which they are saved in the intermediate database.

[0091] According to the order in which they are saved in the intermediate database, the first mapping file corresponding to the source database can be accurately determined, which helps to quickly locate and manage the mapping files of the source database and realize the automated management and analysis of mapping files. This reduces the need for manual operations and improves efficiency.

[0092] S202: Based on a specific keyword, decompose the first mapping file into a first DML segment, where the first DML segment is one of a select segment, an insert segment, an update segment, and a delete segment.

[0093] The first mapping file is read, and the select, update, delete, and insert keywords are identified and the mapping file corresponding to the source database is disassembled according to the identification result to obtain at least one first DML fragment included in the mapping file, and the first DML fragments are saved in sequence to the intermediate database.

[0094] Each first DML fragment includes one of the tags of select, update, delete, and insert.

[0095] After the first mapping file is disassembled into the first DML fragment, the data operation logic in the first mapping file can be accurately extracted, and the sequence of data operation statements can be determined, thereby ensuring the correctness and completeness of the data operation, which helps to avoid errors or inconsistencies caused by the data operation sequence.

[0096] S203: Format a first DML segment corresponding to a source database to obtain a formatted DML segment, wherein the source database is an Oracle database.

[0097] S204, marking each line of code in the formatted DML fragment, where the marking content is the first line, comment line, data line or tail line.

[0098] S205, converting the comment line into an SQL comment, and generating a key-value pair record according to the SQL comment and the comment line.

[0099] S206, converting the escape characters in the data row according to the conversion rule.

[0100] S207, converting the opening tag and closing tag of the dynamic SQL statement in the data row into SQL comments in sequence, and generating a key-value pair record of the SQL comment and the opening tag and a key-value pair record of the SQL comment and the closing tag.

[0101] S208, determining whether the mybatis variable in the data row contains a comma symbol, if the mybatis variable contains a comma symbol, converting the mybatis variable into an SQL comment, and generating a key-value pair record according to the SQL comment and the mybatis variable.

[0102] S209, concatenating the comment lines and data lines generated after the preprocessing to obtain a first SQL statement, and parsing the first SQL statement based on a SQL interpreter to obtain an abstract syntax tree.

[0103] S210, converting the expression corresponding to the abstract syntax tree based on the conversion rule from the source database to the target database to obtain a second SQL statement corresponding to the target database, wherein the target database is a MySQL database.

[0104] S211, restoring the escape characters in the second SQL statement according to the conversion rules.

[0105] S212: restore the SQL comments in the second SQL statement according to the key-value pair record to obtain a restoration result.

[0106] S213: Add the first row and the last row to the restoration result to generate a second DML fragment.

[0107] Regarding the specific implementation of steps S203 to S213, reference may be made to the specific introduction of the relevant parts in the above embodiments, which will not be elaborated here.

[0108] S214: Generate a second mapping file corresponding to the target database based on the second DML fragment.

[0109] After all the first DML segments disassembled from the first mapping file are converted into second DML segments, the second DML segments are merged according to the order of the first DML segments to generate a second mapping file corresponding to the target database.

[0110] Furthermore, after the operation of converting the first mapping file into the second mapping file is completed, the conversion of the next mapping file corresponding to the source database is performed in the order stored in the intermediate database.

[0111] The embodiment of the present application introduces in detail the process of preprocessing and postprocessing DML fragments. In addition, it also introduces the process of disassembling the source database mapping file and the process of generating the mapping file corresponding to the target database according to the generated multiple DML fragments, so that the data processing operation flow is clearer, the accuracy and efficiency of data conversion can be improved, and the errors that may be caused by manual operations can be reduced.

[0112] Figure 3 is a schematic diagram of a data processing device shown in the present application, such as Figure 3 As shown, the data processing device 300 includes a disassembly module 301, a pre-processing module 302, a conversion module 303, a post-processing module 304 and an assembly module 305, wherein:

[0113] The disassembly module 301 is used to disassemble the first mapping file corresponding to the source database into a first data manipulation language DML segment, wherein the first DML segment is composed of an extensible markup language XML language and a first structured query language SQL language corresponding to the source database.

[0114] The preprocessing module 302 is configured to preprocess the first DML fragment to obtain a first SQL statement generated after the preprocessing, wherein the preprocessing includes converting target content in the first DML fragment into SQL comments and generating key-value pair records.

[0115] The conversion module 303 is used to parse the first SQL statement based on the SQL interpreter to obtain an abstract syntax tree, and convert the expression corresponding to the abstract syntax tree based on the conversion rule from the source database to the target database to obtain a second SQL statement corresponding to the target database.

[0116] The post-processing module 304 is used to post-process the second SQL statement to generate a second DML fragment corresponding to the target database, wherein the post-processing includes restoring the second SQL statement according to the key-value pair record, wherein the second DML fragment consists of XML language and a second SQL language corresponding to the target database.

[0117] The assembly module 305 is used to compose a second mapping file corresponding to the target database based on the second DML fragment. Before generating an abstract syntax tree, the device first disassembles the first mapping file corresponding to the source database to generate a first DML fragment, and pre-processes the first DML fragment to convert the first DML fragment from two languages ​​to a first SQL statement in only one language. After performing SQL parsing and converting the first SQL statement to a second SQL statement based on the abstract syntax tree corresponding to the first SQL statement, the other relevant parts of the second SQL statement are restored through post-processing, thereby generating a second DML fragment containing two languages. The application realizes the conversion of the mapping file corresponding to the source database from two languages ​​to one language, and then converts it into a mapping file containing two languages ​​corresponding to the target database, which can improve the accuracy and efficiency of data conversion and reduce errors that may be caused by manual operations.

[0118] Furthermore, the source database is an Oracle database, the target database is a MySQL database, and the preprocessing module 302 is further used to: format the first DML fragment to obtain a formatted DML fragment; mark each line of code in the formatted DML fragment, and the marked content is the first line, comment line, data line or tail line; convert the comment line into an SQL comment, and generate a key-value pair record based on the SQL comment and the comment line; convert the escape characters in the data line according to the conversion rule; convert the opening tag and the closing tag of the dynamic SQL statement in the data line into SQL comments in sequence, and generate a key-value pair record of the SQL comment and the opening tag and a key-value pair record of the SQL comment and the closing tag; splice the comment line and the data line to generate the first SQL statement.

[0119] Furthermore, the preprocessing module 302 is also used to: determine whether the mybatis variable in the data row contains a comma symbol; if the mybatis variable contains a comma symbol, convert the mybatis variable into an SQL comment, and generate a key-value pair record based on the SQL comment and the mybatis variable.

[0120] Furthermore, the SQL comments involved in the preprocessing module 302 carry digital identifiers, and the digital identifiers increase in order according to the time sequence of generating the SQL comments.

[0121] Furthermore, the conversion module 303 is further configured to: perform syntax analysis and semantic analysis on the first SQL statement based on the SQL interpreter to obtain an abstract syntax tree, wherein the comment line is attached as an attribute to an expression corresponding to the abstract syntax tree.

[0122] Furthermore, the post-processing module 304 is further used to: restore the escape characters in the second SQL statement according to the conversion rules; restore the SQL comments in the second SQL statement according to the key-value pair records to obtain a restoration result; and add a first line and a last line to the restoration result to generate a second DML fragment.

[0123] Furthermore, the disassembly module 301 is also used to: identify a specific keyword at the head of each code segment in the first mapping file; based on the specific keyword, disassemble the first mapping file into a first DML fragment, the first DML fragment being one of a select fragment, an insert fragment, an update fragment and a delete fragment.

[0124] In order to implement the above embodiment, the present application embodiment also proposes an electronic device 400, such as Figure 4 As shown, the electronic device 400 includes: a processor 401 and a memory 402 communicatively connected to the processor, the memory 402 stores instructions executable by at least one processor, and the instructions are executed by at least one processor 401 to implement the data processing method shown in the above embodiment.

[0125] In order to implement the above embodiments, the embodiments of the present application further propose a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to implement the data processing method shown in the above embodiments.

[0126] In order to implement the above embodiments, the embodiments of the present application also provide a computer program product, including a computer program, which implements the data processing method shown in the above embodiments when executed by a processor.

[0127] In the description of the present application, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", "clockwise", "counterclockwise", "axial", "radial", "circumferential", etc., indicating orientations or positional relationships, are based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the present application.

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

[0129] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.

[0130] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.

[0131] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations on the present application. Ordinary technicians in this field can change, modify, replace and modify the above embodiments within the scope of the present application.< / if> < / foreach> < / where> < / set> < / trim> < / if> < / foreach> < / where> < / set> < / trim> < / if>

Claims

1. A data processing method, characterized in that: include: Decomposing a first mapping file corresponding to a source database into a first data manipulation language DML segment, wherein the first DML segment is composed of an extensible markup language XML language and a first structured query language SQL language corresponding to the source database; Preprocessing the first DML fragment to obtain a first SQL statement generated after the preprocessing, wherein the preprocessing includes converting target content in the first DML fragment into an SQL comment and generating a key-value pair record; Parsing the first SQL statement based on an SQL interpreter to obtain an abstract syntax tree, and converting an expression corresponding to the abstract syntax tree based on a conversion rule from the source database to the target database to obtain a second SQL statement corresponding to the target database; Post-processing the second SQL statement to generate a second DML fragment corresponding to the target database, wherein the post-processing includes restoring the second SQL statement according to the key-value pair record, wherein the second DML fragment consists of the XML language and a second SQL language corresponding to the target database; A second mapping file corresponding to the target database is composed based on the second DML fragment.

2. The method according to claim 1, characterized in that The source database is an Oracle database, the target database is a MySQL database, and the preprocessing of the first DML fragment to obtain a first SQL statement generated after the preprocessing includes: formatting the first DML segment to obtain a formatted DML segment; Mark each line of code in the formatted DML fragment, where the marked content is the first line, comment line, data line or tail line; Convert the comment line into an SQL comment, and generate a key-value pair record according to the SQL comment and the comment line; Convert the escape characters in the data row according to the conversion rules; Converting the opening tag and the closing tag of the dynamic SQL statement in the data row into SQL comments in sequence, and generating a key-value pair record of the SQL comment and the opening tag and a key-value pair record of the SQL comment and the closing tag; The comment line and the data line are concatenated to generate the first SQL statement.

3. The method according to claim 2, characterized in that After generating the key-value pair record of the SQL comment and the opening tag and the key-value pair record of the SQL comment and the closing tag, the method further includes: Determine whether the mybatis variable in the data row contains a comma symbol; If the mybatis variable contains a comma symbol, the mybatis variable is converted into an SQL comment, and a key-value pair record is generated according to the SQL comment and the mybatis variable.

4. The method according to claim 3, characterized in that The SQL comment carries a digital identifier, and the digital identifier increases in order according to the time when the SQL comment is generated.

5. The method according to claim 4, characterized in that The step of parsing the first SQL statement based on a SQL interpreter to obtain an abstract syntax tree includes: The first SQL statement is subjected to grammatical analysis and semantic analysis based on the SQL interpreter to obtain the abstract syntax tree, wherein the comment line is attached as an attribute to an expression corresponding to the abstract syntax tree.

6. The method according to claim 5, characterized in that The post-processing of the second SQL statement to generate a second DML fragment corresponding to the target database includes: Restoring the escape characters in the second SQL statement according to the conversion rule; Restoring the SQL comments in the second SQL statement according to the key-value pair record to obtain a restoration result; The first row and the last row are added to the restored result to generate the second DML segment.

7. The method according to any one of claims 1 to 6, characterized in that The step of disassembling the first mapping file corresponding to the source database into first data manipulation language DML fragments includes: Identify a specific keyword in the header of each code segment in the first mapping file; Based on the specific keyword, the first mapping file is disassembled into a first DML segment, where the first DML segment is one of a select segment, an insert segment, an update segment, and a delete segment.

8. A data processing device, characterized in that: include: A disassembly module, used for disassembling a first mapping file corresponding to a source database into a first data manipulation language DML fragment, wherein the first DML fragment is composed of an extensible markup language XML language and a first structured query language SQL language corresponding to the source database; A preprocessing module, configured to preprocess the first DML fragment to obtain a first SQL statement generated after the preprocessing, wherein the preprocessing includes converting target content in the first DML fragment into an SQL comment and generating a key-value pair record; a conversion module, configured to parse the first SQL statement based on an SQL interpreter to obtain an abstract syntax tree, and convert an expression corresponding to the abstract syntax tree based on a conversion rule from the source database to a target database to obtain a second SQL statement corresponding to the target database; a post-processing module, configured to post-process the second SQL statement to generate a second DML fragment corresponding to the target database, wherein the post-processing includes restoring the second SQL statement according to the key-value pair record, wherein the second DML fragment is composed of the XML language and a second SQL language corresponding to the target database; An assembling module is used to compose a second mapping file corresponding to the target database based on the second DML fragment.

9. An electronic device, comprising: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 7.

10. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-7.

11. A computer program product comprising a computer program, which, when executed by a processor, implements the steps of the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Code conversion method and device, computer equipment and storage medium

    CN117407002A

  • Database statement conversion method and device, equipment and storage medium

    CN117539887A

  • Heterogeneous database grammar conversion method and device, equipment and storage medium

    CN118012897A

  • Database query system

    US20160063063A1