CN116467372A - Automatic database conversion method and device, electronic equipment and storage medium - Google Patents

Automatic database conversion method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN116467372A
CN116467372A CN202310146978.8A CN202310146978A CN116467372A CN 116467372 A CN116467372 A CN 116467372A CN 202310146978 A CN202310146978 A CN 202310146978A CN 116467372 A CN116467372 A CN 116467372A
Authority
CN
China
Prior art keywords
target
source
length
database
field
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310146978.8A
Other languages
Chinese (zh)
Inventor
罗兵
黄亮
刘树衎
陈琳
尚聪聪
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Naval University of Engineering PLA
Original Assignee
Naval University of Engineering PLA
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Naval University of Engineering PLA filed Critical Naval University of Engineering PLA
Priority to CN202310146978.8A priority Critical patent/CN116467372A/en
Publication of CN116467372A publication Critical patent/CN116467372A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • G06F16/258Data format conversion from or to a database
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The application provides an automatic database conversion method, and relates to the field of data processing. The method comprises the following steps: acquiring a data request; wherein the data request comprises a database type of the target database, a database type of the source database and a source data type of the source database; if the mapping table of the data model contains a mapping relation between the source database and the target database, determining a target data type of the target database corresponding to the source data type of the source database according to the mapping relation; the source data type is converted into a corresponding target data type to realize the conversion of the source database into a target database. The apparatus is for performing the above method. According to the method and the device, the automatic conversion of the database is realized, and the data processing efficiency is improved.

Description

Automatic database conversion method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of data processing, and in particular, to a method and apparatus for automatically converting a database, an electronic device, and a storage medium.
Background
With the high-speed development of internet technology, mass data is continuously generated, and the data can be efficiently and clearly stored by using a database, and meanwhile, a user can manage the data more quickly and conveniently. However, since the manner in which data is stored in different types of databases is different, when another type of database needs to be accessed, a new database needs to be created again, which is time-consuming and laborious, and thus how to implement automatic conversion between databases is a very important problem.
In the prior art, one database is usually fixedly converted into another database, and the conversion of the database cannot be realized according to actual requirements, so that the efficiency of data processing is not high.
Disclosure of Invention
An object of the embodiments of the present application is to provide a method, an apparatus, an electronic device, and a storage medium for automatically converting databases, so as to improve data processing efficiency.
In a first aspect, an embodiment of the present application provides a method for automatically converting a database, where the method includes: acquiring a data request; wherein the data request comprises a database type of the target database, a database type of the source database and a source data type of the source database; if the mapping table of the data model contains a mapping relation between the source database and the target database, determining a target data type of the target database corresponding to the source data type of the source database according to the mapping relation; the source data type is converted into a corresponding target data type to realize the conversion of the source database into a target database.
In the technical scheme of the embodiment of the application, the source database and the target database are connected through the data model mapping table, and the target data type of the target database is determined according to the mapping relation, so that the source database is converted into the target database. In the process, the data type of the target database to be converted is determined through the data model mapping table, so that conversion of the two databases is completed, the target database is not required to be re-created manually, and the data processing efficiency is improved.
In some embodiments, the source data type includes a source field type; the target data type includes a target field type and a target field length; determining the target data type of the target database corresponding to the source data type of the source database according to the mapping relation, wherein the method comprises the following steps: obtaining a source capacity expansion strategy corresponding to each source field type and a target capacity expansion strategy of a target field type corresponding to the source field type according to the data model mapping table; the target capacity expansion strategy comprises a target field integer bit length capacity expansion strategy; if the target field whole digital length expansion strategy is not null, calculating the target field length according to the source expansion strategy and the target field whole digital length expansion strategy; and determining the target data type of the target database according to the target field type and the target field length.
According to the embodiment of the application, the target field length of the target data type is calculated according to the source capacity expansion strategy of the source field type and the target field integer bit length capacity expansion strategy of the target field type, so that the target data type is obtained. In the process, the capacity expansion strategy based on the source database is calculated, so that the field length of the converted target database meets the conversion requirement, and the field length is not set arbitrarily, thereby providing a basis for the correct conversion between databases. And the calculation is carried out only when the target field integer bit length expansion strategy is not empty, and objects which do not need to be calculated are removed in the screening process, so that the calculation time is reduced, and the data processing efficiency is further improved.
In some embodiments, the target field length includes a target field integer bit length and a target field fractional bit length; the source capacity expansion strategy comprises a source field whole digit length expansion strategy and a source field decimal digit length expansion strategy; the target capacity expansion strategy also comprises a target field decimal length capacity expansion strategy; calculating the length of the target field according to the source capacity expansion strategy and the whole digital length capacity expansion strategy of the target field, comprising: calculating the integer bit length of the target field according to the integer bit length expansion strategy of the source field and the integer bit length expansion strategy of the target field; calculating the decimal length of the target field according to the decimal length expansion strategy of the source field and the decimal length expansion strategy of the target field; and determining the length of the target field according to the integer bit length of the target field and the decimal bit length of the target field.
According to the embodiment of the application, the target capacity expansion strategy further comprises a target field decimal place length capacity expansion strategy, so that the whole digit field length and the decimal place field length of the target database can be calculated respectively, the calculation accuracy is improved through classified calculation, the correctness of data conversion is further verified, and the data processing efficiency is improved.
In some embodiments, calculating the target field integer bit length from the source field integer bit length expansion policy and the target field integer bit length expansion policy includes: if the whole-bit length capacity expansion strategy of the source field is empty, the whole-bit length of the target field is the whole-bit default length of the target field; if the source field integer bit length expansion strategy is not null, performing ternary operation according to the source field integer bit length expansion strategy and the target field integer bit length expansion strategy to obtain the target field integer bit length.
According to the embodiment of the application, whether the whole-bit length of the target field needs to be calculated is judged by whether the whole-bit length capacity expansion strategy of the source field is empty or not, the process is equivalent to one-time screening, the calculation time is shortened in the screening process, the data calculation speed is accelerated, and the data processing efficiency is further improved.
In some embodiments, calculating the target field fractional length from the source field fractional length expansion policy and the target field fractional length expansion policy includes: if the target field decimal length expansion strategy is empty, the target field decimal length is empty; if the source field decimal place length expanding strategy is empty, the target field decimal place length is the decimal default length of the target field length; and if the source field decimal length capacity expansion strategy is not null, performing ternary operation according to the source field decimal length capacity expansion strategy and the target field decimal length capacity expansion strategy to obtain the target field decimal length.
According to the method and the device, whether the target field decimal length is required to be calculated or not is judged through whether the target field decimal length capacity expansion strategy is empty or not and whether the source field decimal length capacity expansion strategy is empty or not, the process is equivalent to one-time screening, the calculation time is shortened in the screening process, the data calculation speed is accelerated, and the data processing efficiency is further improved.
In some embodiments, after converting the source data type to the corresponding target data type to effect converting the source database to the target database, the method further comprises: analyzing the database type and the target data type of the target database to generate a DDL script file; and generating a target database according to the DDL script file.
According to the embodiment of the application, the DDL script file is automatically generated by analyzing the type of the target database and the type of the target data, so that the creation of the target database is automatically completed, the development efficiency corresponding to the database is improved, and the data processing efficiency is further improved.
In some embodiments, after obtaining the data request, the method further comprises: and judging whether the source database can be converted into the target database according to the data model mapping table.
According to the embodiment of the application, before conversion, the data model mapping table is used for judging, if conversion can be performed, the conversion can not be performed, and the conversion can be directly exited, so that invalid conversion can be eliminated, the time utilization rate is improved, and the data processing efficiency is further improved.
In a second aspect, an embodiment of the present application further provides an automatic database conversion device, where the device includes: the acquisition module is used for acquiring the data request; wherein the data request comprises a database type of the target database, a database type of the source database and a source data type of the source database; the determining module is used for determining the target data type of the target database corresponding to the source data type of the source database according to the mapping relation if the mapping relation between the source database and the target database is contained in the data model mapping table; and the conversion module is used for converting the source data type into a corresponding target data type so as to realize conversion of the source database into a target database.
According to the embodiment of the application, the source database and the target database are connected through the data model mapping table, and the target data type of the target database is determined according to the mapping relation, so that the source database is converted into the target database. In the process, the data type of the target database to be converted is determined through the data model mapping table, so that conversion of the two databases is completed, the target database is not required to be re-created manually, and the data processing efficiency is improved.
In a third aspect, an embodiment of the present application provides an electronic device, including: the device comprises a processor, a memory, a storage medium and a bus, wherein the processor and the memory are communicated with each other through the bus; the memory stores program instructions executable by the processor, the processor invoking the program instructions to perform the method steps of the first aspect.
In a fourth aspect, embodiments of the present application provide a non-transitory computer readable storage medium comprising: the computer-readable storage medium stores computer instructions that cause the computer to perform the method steps of the first aspect.
Additional features and advantages of the application will be set forth in the description which follows, and in part will be apparent from the description, or may be learned by practice of the embodiments of the application. The objectives and other advantages of the application will be realized and attained by the structure particularly pointed out in the written description and claims thereof as well as the appended drawings.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the embodiments of the present application will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and should not be considered as limiting the scope, and other related drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flowchart of a database automatic conversion method provided in an embodiment of the present application;
fig. 2 is a specific flowchart of a database automatic conversion method provided in an embodiment of the present application;
fig. 3 is a schematic structural diagram of an automatic database conversion device according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more clear, the technical solutions of the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it should be understood that the accompanying drawings in the present application are only for the purpose of illustration and description, and are not intended to limit the protection scope of the present application. In addition, it should be understood that the schematic drawings are not drawn to scale. A flowchart, as used in this application, illustrates operations implemented according to some embodiments of the present application. It should be understood that the operations of the flow diagrams may be implemented out of order and that steps without logical context may be performed in reverse order or concurrently. Moreover, one or more other operations may be added to the flow diagrams and one or more operations may be removed from the flow diagrams as directed by those skilled in the art.
In addition, the described embodiments are only some, but not all, of the embodiments of the present application. The components of the embodiments of the present application, which are generally described and illustrated in the figures herein, may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present application, as provided in the accompanying drawings, is not intended to limit the scope of the application, as claimed, but is merely representative of selected embodiments of the application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present application without making any inventive effort, are intended to be within the scope of the present application.
It is noted that all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs; the terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application; the terms "comprising" and "having" and any variations thereof in the description and claims of the present application and in the description of the figures above are intended to cover non-exclusive inclusions.
In the description of the embodiments of the present application, the technical terms "first," "second," etc. are used merely to distinguish between different objects and are not to be construed as indicating or implying a relative importance or implicitly indicating the number of technical features indicated, a particular order or a primary or secondary relationship. In the description of the embodiments of the present application, the meaning of "plurality" is two or more unless explicitly defined otherwise.
In the description of the embodiments of the present application, the term "and/or" is merely an association relationship describing an association object, which means that three relationships may exist, for example, a and/or B may mean: a exists alone, A and B exist together, and B exists alone. In addition, the character "/" herein generally indicates that the front and rear associated objects are an "or" relationship.
In the description of the embodiments of the present application, the term "plurality" refers to two or more (including two), and similarly, "plural sets" refers to two or more (including two), and "plural sheets" refers to two or more (including two).
It can be understood that the database automatic conversion method provided in the embodiment of the present application may be applied to a terminal device (may also be referred to as an electronic device) and a server; the terminal equipment can be a smart phone, a tablet personal computer, a personal digital assistant (Personal Digital Assistant, PDA) and the like; the server may be an application server or a Web server.
In order to facilitate understanding, the application scenario of the database automatic conversion method provided in the embodiment of the present application is described below by taking a server as an execution body as an example.
Fig. 1 is a flowchart of a method for automatically converting a database according to an embodiment of the present application, as shown in fig. 1, where the method includes:
step 101, a data request is acquired.
In a specific implementation process, the acquired data request includes, but is not limited to, a database type of the target database, a database type of the source database, a source data type of the source database, a source database name, a source table english name, a source table chinese name, a source field english name, a source field chinese name, a source field type, a source field length, a source field integer bit length, a source field decimal bit length, whether the source field is a primary key, whether the source field is null, a source field default value, and other model attribute values. The source database refers to a database to be converted, the target database refers to a database after the conversion of the source database, and the source data types include, but are not limited to, source field types and source field lengths of the source database. It should be noted that, the information included in the obtained data request may be specifically limited according to the actual situation, which is not specifically limited in the present application.
Specifically, the obtained data request is derived from the physical data model table in the Excel template file provided by the application, and the physical data model table can be specifically called a table source_db_ddl. By configuring the table in advance, the user can know the database type of the target database and the detailed information of the source database through the table, and the detailed information can be referred to the above information and is not repeated here.
It should be noted that, the Excel template file provided in the present application is a template file that has been set in advance. Excel table has the following properties: the Excel table is a standard two-dimensional table design, and can support unified export of physical data models of a source database into files in csv, excel and other formats through a database management tool, and then the files are quickly imported into the Excel template of the physical data model provided by the application. It can be understood that, besides being based on an excel table, the template file corresponding to the format can be provided according to other types of format data, such as XML format data, and the template file can be specifically set according to practical situations, which is not specifically limited in the application.
All information of the SOURCE database and basic information of the target database are initialized through the table SOURCE_DB_DDL, and the information is written into a memory for generating a data request. The specific initialization process is to trigger and execute the VBA program by a user, read the configuration of the table SOURCE_DB_DDL in the Excel template file, and write the configuration into the memory. The VBA program is a macro directly attached to an Excel template file.
Table 1 gives examples of the table SOURCE DB DDL for understanding, and as shown in table 1, the header gives the attribute values contained in the database model and the specific parameter values corresponding to these attribute values. For example, in table 1, it is necessary to convert the source database type MYSQL into the target database type HIVE, and a value intermediate between the source database type attribute and the target database type attribute is detailed information of the source database. It should be noted that table 1 is only an example, and in practical application, the data in the table may be added and deleted according to practical situations, which is not limited in this application.
TABLE 1
Step 102, if the mapping table of the data model includes a mapping relationship between the source database and the target database, determining a target data type of the target database corresponding to the source data type of the source database according to the mapping relationship.
In the implementation process, the data model mapping table contains mapping relations of different physical data model transformations, and can also be simply understood to contain mapping relations of different database transformations, and the table is stored in an Excel template file. The target data types include, but are not limited to, target field types and target field lengths of the target database.
Determining a target data type of a target database corresponding to the source data type of the source database according to the mapping relation, wherein the target data type of the target database can be specifically implemented by triggering a VBA program by a user; at this time, the VBA program will read the configuration of the table modem_trans_defme in the Excel template file, and parse each row of configuration information in the table modem_trans_defme row by row. The read configuration information comprises configurations of a read mapping relation configuration and a source database type, a source database field type, a target database field type, an integer bit maximum length of a target field, an integer bit default length of the target field, an integer bit length expansion strategy, a decimal bit maximum length of the target field, a decimal bit default length of the target field, a decimal bit length expansion strategy and the like. It should be noted that the integer bit length expansion policy includes a source field integer bit length expansion policy and a target field integer bit length expansion policy; the decimal place length expansion strategy comprises a source field decimal place length expansion strategy and a target field decimal place length expansion strategy. The source field integer bit length expansion strategy and the source field decimal bit length expansion strategy are collectively called a source expansion strategy, and the target field integer bit length expansion strategy and the target field decimal bit length expansion strategy are collectively called a target expansion strategy. The whole digit length expansion strategy refers to the length and rule that the whole digit length of the field of the data field length can be expanded, and similarly, the decimal length expansion strategy refers to the length and rule that the decimal length of the field of the data field length can be expanded, wherein the rule is determined by the type of the database.
When mapping relation configuration is read, configuration rows conforming to the source database type, the target database type and the source field type need to be screened out, so that the target field type is determined according to the source database type, the target database type and the source field type. For example, if the source field type is float type, the target field type may be decmal type, double type, or the like, and whether decmal type, double type, or other type is determined according to the database type of the target database.
The configuration of reading the field type of the target database, the maximum length of the integer bit of the target field, the default length of the integer bit of the target field, the integer bit length expansion strategy, the maximum length of the decimal bit of the target field, the default length of the decimal bit of the target field, the decimal bit length expansion strategy and the like is to calculate and obtain the length of the target field in the target data type.
Table 2 gives an example of table mode_trans_define for understanding, and as described in table 2, the header gives the attribute values contained in the data MODEL map table and the specific parameter values corresponding to these attribute values. For example, in table 2, there is a mapping relationship between the source database type HIVE and the target database MYSQL, and the source database field type double corresponds to the target database field type double, so that these two databases can be mutually converted. In addition, table 2 also shows that the maximum length of the integer bit of the target field is 30, the maximum length of the decimal bit of the target field is 30, and the default length of the decimal bit of the target field is 30, wherein the integer bit length expansion strategies listed in table 2 include a source field integer bit length expansion strategy and a target field integer bit length expansion strategy; the decimal place length expansion strategy comprises a source field decimal place length expansion strategy and a target field decimal place length expansion strategy. However, table 2 is merely an example, and may be configured according to practical situations in practical applications, and the present application is not limited thereto.
TABLE 2
Step 103, converting the source data type into a corresponding target data type to realize conversion of the source database into the target database.
In a specific implementation, after the target data type of the target database is obtained, the source database may be converted into the target database.
In the technical scheme of the embodiment of the application, the source database and the target database are connected through the data model mapping table, and the target data type of the target database is determined according to the mapping relation, so that the source database is converted into the target database. In the process, the data type of the target database to be converted is determined through the data model mapping table, so that conversion of the two databases is completed, the target database is not required to be re-created manually, and the data processing efficiency is improved.
In some embodiments, the source data type includes a source field type; the target data type includes a target field type and a target field length; determining the target data type of the target database corresponding to the source data type of the source database according to the mapping relation, wherein the method comprises the following steps: obtaining a source capacity expansion strategy corresponding to each source field type and a target capacity expansion strategy of a target field type corresponding to the source field type according to the data model mapping table; the target capacity expansion strategy comprises a target field integer bit length capacity expansion strategy; if the target field whole digital length expansion strategy is not null, calculating the target field length according to the source expansion strategy and the target field whole digital length expansion strategy; and determining the target data type of the target database according to the target field type and the target field length.
In a specific implementation process, the source field type refers to the type of the data corresponding to the field, for example, the data is integer, character, floating point or boolean; the source field length and the source field type are in one-to-one correspondence, which refers to the length of the data corresponding to the field, wherein each type has a corresponding maximum length, and the actual length of the data corresponding to the field cannot exceed the corresponding maximum length. The same shall explain the target field type and the target field length, and will not be described in detail here.
Specifically, determining the integer bit length of the target field according to the integer bit length expansion strategy of the target field and the integer bit length expansion strategy of the source field; and determining the decimal length of the target field according to the decimal length capacity expansion strategy of the target field and the decimal length capacity expansion strategy of the source field, thereby obtaining the length of the target field.
It should be noted that, if the target field integer bit length expansion policy is null, the target field integer bit length of the target field length is null, and the target field fractional bit length of the target field length is null. The target field integer bit length capacity expansion strategy is empty, that is, the current target field length is not set in integer bit and decimal bit length, and the field types corresponding to the field length are as follows: string type (string, char, verchar, etc.), boolean type (boolean), etc.
According to the embodiment of the application, the target field length of the target data type is calculated according to the source capacity expansion strategy of the source field type and the target field integer bit length capacity expansion strategy of the target field type, so that the target data type is obtained. In the process, the capacity expansion strategy based on the source database is calculated, so that the field length of the converted target database meets the conversion requirement, and the field length is not set arbitrarily, thereby providing a basis for the correct conversion between databases. And the calculation is carried out only when the target field integer bit length expansion strategy is not empty, and objects which do not need to be calculated are removed in the screening process, so that the calculation time is reduced, and the data processing efficiency is further improved.
In some embodiments, the target field length includes a target field integer bit length and a target field fractional bit length; the source capacity expansion strategy comprises a source field whole digit length expansion strategy and a source field decimal digit length expansion strategy; the target capacity expansion strategy also comprises a target field decimal length capacity expansion strategy; calculating the length of the target field according to the source capacity expansion strategy and the whole digital length capacity expansion strategy of the target field, comprising: calculating the integer bit length of the target field according to the integer bit length expansion strategy of the source field and the integer bit length expansion strategy of the target field; calculating the decimal length of the target field according to the decimal length expansion strategy of the source field and the decimal length expansion strategy of the target field; and determining the length of the target field according to the integer bit length of the target field and the decimal bit length of the target field.
In the specific implementation process, calculating the integer bit length of the target field through a source field integer bit length capacity expansion strategy and a target field integer bit length capacity expansion strategy; and calculating the decimal length of the target field through the decimal length expansion strategy of the source field and the decimal length expansion strategy of the target field. For specific calculation procedures, please refer to the following embodiments, which are not described herein.
According to the embodiment of the application, the target capacity expansion strategy further comprises a target field decimal place length capacity expansion strategy, so that the whole digit field length and the decimal place field length of the target database can be calculated respectively, the calculation accuracy is improved through classified calculation, the correctness of data conversion is further verified, and the data processing efficiency is improved.
In some embodiments, calculating the target field integer bit length from the source field integer bit length expansion policy and the target field integer bit length expansion policy includes: if the whole-bit length capacity expansion strategy of the source field is empty, the whole-bit length of the target field is the whole-bit default length of the target field; if the source field integer bit length expansion strategy is not null, performing ternary operation according to the source field integer bit length expansion strategy and the target field integer bit length expansion strategy to obtain the target field integer bit length.
In the implementation process, the specific calculation of the integer bit length of the target field can be divided into the following cases:
(1) If the target field integer bit length expansion policy is 0 and the source field integer bit length expansion policy is null, then: target integer bit length of target field = integer bit default length of target field length.
(2) If the target field integer bit length expansion policy is not 0 and the source field integer bit length expansion policy is null, then: target integer bit length of target field = integer bit default length of target field length.
When the whole-digit length capacity expansion strategy of the source field is not null, calculating the whole-digit length of the target field through ternary operation: the method comprises the following steps:
wherein, the ternary operation is also called three-order operation, its grammar format is "(conditional expression)? Expression 1: expression 2", wherein if the condition is true, the result after the operation is expression 1; if the condition is false, the result after the operation is expression 2. For example, x > yy: and x represents the meaning that if x is larger than y, the value of y is taken, and if x is smaller than or equal to y, the value of x is taken, wherein x and y can represent any type of object.
(3) If the target field integer bit length expansion policy is 0 and the source field integer bit length expansion policy is not null, then: target whole bit length of target field length= (target whole bit maximum length is not null of target field and whole bit length of source field length > whole bit maximum length of target field? Maximum length of integer bits of the target field: integer bit length of source field length.
(4) If the target field integer bit length expansion policy is not 0 and the source field integer bit length expansion policy is not null, then: target whole bit length of target field length= (target whole bit maximum length is not null of target field and whole bit length of source field length+target field whole bit length expansion policy > whole bit maximum length of target field? Maximum length of integer bits of the target field: (integer bit length of source field length + integer bit length of destination field expansion policy).
According to the embodiment of the application, whether the whole-bit length of the target field needs to be calculated is judged by whether the whole-bit length capacity expansion strategy of the source field is empty or not, the process is equivalent to one-time screening, the calculation time is shortened in the screening process, the data calculation speed is accelerated, and the data processing efficiency is further improved.
In some embodiments, calculating the target field fractional length from the source field fractional length expansion policy and the target field fractional length expansion policy includes: if the target field decimal length expansion strategy is empty, the target field decimal length is empty; if the source field decimal place length expanding strategy is empty, the target field decimal place length is the decimal default length of the target field length; and if the source field decimal length capacity expansion strategy is not null, performing ternary operation according to the source field decimal length capacity expansion strategy and the target field decimal length capacity expansion strategy to obtain the target field decimal length.
In the specific implementation process, the decimal length of the target field is calculated only when the integral length capacity expansion strategy of the target field is not empty. The specific calculation can be divided into the following cases:
(1) If the target field decimal length expansion policy is null, then: target decimal length of target field length = null.
(2) If the target field decimal length expansion policy is 0 and the source field decimal length expansion policy is null, then: target decimal length of target field length = decimal default length of target field length.
(3) If the target field decimal length expansion policy is not 0 and the source field decimal length expansion policy is null, then: target decimal length of target field length = decimal default length of target field length.
When the source field decimal length expansion strategy is not null, calculating the target field decimal length through ternary operation: the method comprises the following steps:
(4) If the target field decimal length expansion policy is 0 and the source field decimal length expansion policy is not null, then: target decimal length of target field length= (maximum decimal length is not null of target field and decimal length of source field length > decimal maximum length of target field)? Maximum size bit length of target field: the decimal length of the source field length.
(5) If the target field decimal length expansion policy is not 0 and the source field decimal length expansion policy is not null, then: target fractional length of target field length = (maximum fractional length of target field is not null and fractional length of source field length + target field fractional length expansion policy > fractional maximum length of target field? Maximum size bit length of target field: (decimal length of source field length + decimal length of destination field expansion policy).
According to the method and the device, whether the target field decimal length is required to be calculated or not is judged through whether the target field decimal length capacity expansion strategy is empty or not and whether the source field decimal length capacity expansion strategy is empty or not, the process is equivalent to one-time screening, the calculation time is shortened in the screening process, the data calculation speed is accelerated, and the data processing efficiency is further improved.
In some embodiments, after converting the source data type to the corresponding target data type to effect converting the source database to the target database, the method further comprises: analyzing the database type and the target data type of the target database to generate a DDL script file; and generating a target database according to the DDL script file.
In the specific implementation process, the DDL script file is automatically generated by utilizing a data model converter.
According to the embodiment of the application, the DDL script file is automatically generated by analyzing the type of the target database and the type of the target data, so that the creation of the target database is automatically completed, the productivity of a data engineer is liberated, the development efficiency corresponding to the database is improved, and the data processing efficiency is further improved.
In some embodiments, after obtaining the data request, the method further comprises: and judging whether the source database can be converted into the target database according to the data model mapping table.
In a specific implementation process, the VBA program reads the configuration of the table modem_trans_define (as shown in table 2) in the Excel template file, and parses each row of configuration information in the table modem_trans_define row by row. If the configuration information contains the conversion mapping relation of the data types of the two corresponding databases, the database conversion method described in the above embodiment is executed, and if the configuration information does not contain the conversion mapping relation, the exit conversion flow is directly interrupted.
According to the embodiment of the application, before conversion, the data model mapping table is used for judging, if conversion can be performed, the conversion can not be performed, and the conversion can be directly exited, so that invalid conversion can be eliminated, the time utilization rate is improved, and the data processing efficiency is further improved.
Fig. 2 is a specific flowchart of a database automatic conversion method provided in the embodiment of the present application, and as shown in fig. 2, the method specifically performs the following steps:
step 201, start execution.
In step 202, the source_db_ddl table is read, and the common variable is initialized, and the specific initialization content is referred to the above embodiment or the content included in step 202 in fig. 2, which is not described herein.
In step 203, the MODEL_TRANS_DEFINE table is read, the configuration is analyzed row by row, whether the configured mapping of the physical data MODEL to be converted is supported is checked, and the detailed process for judging is referred to the above embodiment, which is not repeated here.
Step 204, reading the source_db_ddl table, and reading each row configuration row by row, to obtain contents of step 205, including contents such as SOURCE database type, target database type, SOURCE field integer bit length, and SOURCE field decimal bit length. It should be noted that, for convenience of illustration, the content of step 205 includes only a part of the content, and the detailed content may be referred to the content included in step 202 of fig. 2.
In step 206, the mapping relationship configuration in the MODEL_TRANS_DEfine table is read, and the configuration rows conforming to the source database type, the target database type, the source field type, etc. are screened, and the related information is referred to the above embodiments or the content contained in step 206 in FIG. 2, and will not be repeated here.
Step 207, determining whether the target field integer length capacity expansion policy is empty, if so, executing step 208, if not, executing step 209, and processing the target field integer length capacity expansion policy to obtain the target field integer length, where detailed processing is omitted herein.
Step 210 is executed on the basis of step 209, and the target field decimal length expansion policy is processed to obtain the target field decimal length, and the specific processing procedure is referred to the above embodiment, and is not repeated here.
Step 211, obtaining the target database DDL and outputting a DDL script file, and the detailed process is referred to the above embodiment, which is not described herein.
Step 212, end the flow.
Fig. 3 is a schematic structural diagram of an automatic database conversion device according to an embodiment of the present application, as shown in fig. 3, the device includes an obtaining module 301, a determining module 302, and a conversion module 303, where,
an acquiring module 301, configured to acquire a data request; wherein the data request comprises a database type of the target database, a database type of the source database and a source data type of the source database; a determining module 302, configured to determine, if the mapping table of the data model includes a mapping relationship between a source database and a target database, a target data type of the target database corresponding to the source data type of the source database according to the mapping relationship; the conversion module 303 is configured to convert the source data type into a corresponding target data type, so as to convert the source database into a target database.
On the basis of the above embodiment, the source data type includes a source field type; the target data type includes a target field type and a target field length; the determining module 302 is specifically configured to: obtaining a source capacity expansion strategy corresponding to each source field type and a target capacity expansion strategy of a target field type corresponding to the source field type according to the data model mapping table; the target capacity expansion strategy comprises a target field integer bit length capacity expansion strategy; if the target field whole digital length expansion strategy is not null, calculating the target field length according to the source expansion strategy and the target field whole digital length expansion strategy; and determining the target data type of the target database according to the target field type and the target field length.
On the basis of the above embodiment, the target field length includes a target field integer bit length and a target field decimal bit length; the source capacity expansion strategy comprises a source field whole digit length expansion strategy and a source field decimal digit length expansion strategy; the target capacity expansion strategy also comprises a target field decimal length capacity expansion strategy; the determining module 302 is specifically further configured to: calculating the integer bit length of the target field according to the integer bit length expansion strategy of the source field and the integer bit length expansion strategy of the target field; calculating the decimal length of the target field according to the decimal length expansion strategy of the source field and the decimal length expansion strategy of the target field; and determining the length of the target field according to the integer bit length of the target field and the decimal bit length of the target field.
On the basis of the above embodiment, the determining module 302 is specifically further configured to: calculating the integer bit length of the target field according to the integer bit length expansion strategy of the source field and the integer bit length expansion strategy of the target field, comprising: if the whole-bit length capacity expansion strategy of the source field is empty, the whole-bit length of the target field is the whole-bit default length of the target field; if the source field integer bit length expansion strategy is not null, performing ternary operation according to the source field integer bit length expansion strategy and the target field integer bit length expansion strategy to obtain the target field integer bit length.
On the basis of the above embodiment, the determining module 302 is specifically further configured to: calculating the decimal length of the target field according to the decimal length expansion strategy of the source field and the decimal length expansion strategy of the target field, comprising: if the target field decimal length expansion strategy is empty, the target field decimal length is empty; if the source field decimal place length expanding strategy is empty, the target field decimal place length is the decimal default length of the target field length; and if the source field decimal length capacity expansion strategy is not null, performing ternary operation according to the source field decimal length capacity expansion strategy and the target field decimal length capacity expansion strategy to obtain the target field decimal length.
On the basis of the above embodiment, the apparatus further includes: the analysis module is used for analyzing the database type and the target data type of the target database and generating a DDL script file; and the generating module is used for generating a target database according to the DDL script file.
On the basis of the above embodiment, the apparatus further includes: and the judging module is used for judging whether the source database can be converted into the target database according to the data model mapping table.
According to the embodiment of the application, the source database and the target database are connected through the data model mapping table, and the target data type of the target database is determined according to the mapping relation, so that the source database is converted into the target database. In the process, the data type of the target database to be converted is determined through the data model mapping table, so that conversion of the two databases is completed, the target database is not required to be re-created manually, and the data processing efficiency is improved.
Fig. 4 is a schematic structural diagram of an electronic device provided in an embodiment of the present application, as shown in fig. 4, where the electronic device includes a processor (processor) 401, a memory (memory) 402, and a bus 403; wherein the processor 401 and the memory 402 perform communication with each other through the bus 403. The processor 401 is configured to call the program instructions in the memory 402 to perform the methods provided in the above method embodiments.
The processor 401 may be an integrated circuit chip having signal processing capabilities. The processor 401 may be a general-purpose processor, including a central processing unit (CentralProcessingUnit, CPU), a network processor (NetworkProcessor, NP), etc.; but may also be a Digital Signal Processor (DSP), application Specific Integrated Circuit (ASIC), an off-the-shelf programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components. Which may implement or perform the various methods, steps, and logical blocks disclosed in embodiments of the present application. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
Memory 402 may include, but is not limited to, random access memory (RandomAccessMemory, RAM), read-only memory (ReadOnlyMemory, ROM), programmable read-only memory (programmable read-OnlyMemory, PROM), erasable read-only memory (erasabableprogrammable read-OnlyMemory, EPROM), electrically erasable read-only memory (electrically erasable programmable read-OnlyMemory, EEPROM), and the like.
The present embodiment discloses a computer program product comprising a computer program stored on a non-transitory computer readable storage medium, the computer program comprising program instructions which, when executed by a computer, are capable of performing the methods provided by the above-described method embodiments, for example comprising: acquiring a data request; wherein the data request comprises a database type of the target database, a database type of the source database and a source data type of the source database; if the mapping table of the data model contains a mapping relation between the source database and the target database, determining a target data type of the target database corresponding to the source data type of the source database according to the mapping relation; the source data type is converted into a corresponding target data type to realize the conversion of the source database into a target database.
The present embodiment provides a non-transitory computer-readable storage medium storing computer instructions that cause a computer to perform the methods provided by the above-described method embodiments, for example, including: acquiring a data request; wherein the data request comprises a database type of the target database, a database type of the source database and a source data type of the source database; if the mapping table of the data model contains a mapping relation between the source database and the target database, determining a target data type of the target database corresponding to the source data type of the source database according to the mapping relation; the source data type is converted into a corresponding target data type to realize the conversion of the source database into a target database.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other manners. The above-described apparatus embodiments are merely illustrative, for example, the division of the units is merely a logical function division, and there may be other manners of division in actual implementation, and for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be through some communication interface, device or unit indirect coupling or communication connection, which may be in electrical, mechanical or other form.
Further, the units described as separate units may or may not be physically separate, and units displayed as units may or may not be physical units, may be located in one place, or may be distributed over a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
Furthermore, functional modules in various embodiments of the present application may be integrated together to form a single portion, or each module may exist alone, or two or more modules may be integrated to form a single portion.
In this document, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions.
The foregoing is merely exemplary embodiments of the present application and is not intended to limit the scope of the present application, and various modifications and variations may be suggested to one skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.

Claims (10)

1. A method for automatically converting a database, the method comprising:
acquiring a data request; wherein the data request comprises a database type of the target database, a database type of the source database and a source data type of the source database;
if the data model mapping table contains a mapping relation between the source database and the target database, determining a target data type of the target database corresponding to the source data type of the source database according to the mapping relation;
and converting the source data type into the corresponding target data type so as to realize the conversion of the source database into the target database.
2. The method of claim 1, wherein the source data type comprises a source field type; the target data type comprises a target field type and a target field length; the determining the target data type of the target database corresponding to the source data type of the source database according to the mapping relation includes:
obtaining a source capacity expansion strategy corresponding to each source field type and a target capacity expansion strategy corresponding to the target field type according to the data model mapping table; the target capacity expansion strategy comprises a target field integer bit length capacity expansion strategy;
If the target field integer bit length expansion strategy is not null, calculating the target field length according to the source expansion strategy and the target field integer bit length expansion strategy;
and determining the target data type of the target database according to the target field type and the target field length.
3. The method of claim 2, wherein the target field length comprises a target field integer bit length and a target field decimal bit length; the source capacity expansion strategy comprises a source field whole digit length expansion strategy and a source field decimal digit length expansion strategy; the target capacity expansion strategy further comprises a target field decimal length capacity expansion strategy; the calculating the target field length according to the source capacity expansion strategy and the target field integer bit length capacity expansion strategy includes:
calculating the integer bit length of the target field according to the integer bit length expansion strategy of the source field and the integer bit length expansion strategy of the target field;
calculating the decimal length of the target field according to the decimal length capacity expansion strategy of the source field and the decimal length capacity expansion strategy of the target field;
and determining the target field length according to the target field integer bit length and the target field decimal bit length.
4. The method of claim 3, wherein the calculating the target field integer bit length according to the source field integer bit length expansion policy and the target field integer bit length expansion policy comprises:
if the source field integer bit length expansion strategy is empty, the target field integer bit length is the integer bit default length of the target field length;
and if the whole bit length expansion strategy of the source field is not null, performing ternary operation according to the whole bit length expansion strategy of the source field and the whole bit length expansion strategy of the target field to obtain the whole bit length of the target field.
5. The method of claim 3, wherein the calculating the target field fractional length according to the source field fractional length expansion policy and the target field fractional length expansion policy comprises:
if the target field decimal length expansion strategy is empty, the target field decimal length is empty;
if the source field decimal place length expansion strategy is empty, the target field decimal place length is the decimal default length of the target field length;
And if the source field decimal length capacity expansion strategy is not null, performing ternary operation according to the source field decimal length capacity expansion strategy and the target field decimal length capacity expansion strategy to obtain the target field decimal length.
6. The method of claim 1, wherein after said converting said source data type to said corresponding target data type to effect converting said source database to said target database, said method further comprises:
analyzing the database type of the target database and the target data type to generate a DDL script file;
and generating the target database according to the DDL script file.
7. The method of any of claims 1-6, wherein after obtaining the data request, the method further comprises:
and judging whether the source database can be converted into the target database according to the data model mapping table.
8. An automatic database conversion apparatus, comprising:
the acquisition module is used for acquiring the data request; wherein the data request comprises a database type of the target database, a database type of the source database and a source data type of the source database;
The determining module is used for determining the target data type of the target database corresponding to the source data type of the source database according to the mapping relation if the mapping relation between the source database and the target database is contained in the data model mapping table;
and the conversion module is used for converting the source data type into the corresponding target data type so as to realize the conversion of the source database into the target database.
9. An electronic device, comprising: a processor and a memory storing machine-readable instructions executable by the processor to perform the method of any one of claims 1 to 7 when executed by the processor.
10. A computer-readable storage medium, characterized in that it has stored thereon a computer program which, when executed by a processor, performs the method according to any of claims 1 to 7.
CN202310146978.8A 2023-02-21 2023-02-21 Automatic database conversion method and device, electronic equipment and storage medium Pending CN116467372A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310146978.8A CN116467372A (en) 2023-02-21 2023-02-21 Automatic database conversion method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310146978.8A CN116467372A (en) 2023-02-21 2023-02-21 Automatic database conversion method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN116467372A true CN116467372A (en) 2023-07-21

Family

ID=87174195

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310146978.8A Pending CN116467372A (en) 2023-02-21 2023-02-21 Automatic database conversion method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116467372A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116186796A (en) * 2023-02-21 2023-05-30 中国人民解放军海军工程大学 Sequence number generation method, system, electronic equipment and storage medium

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103221949A (en) * 2010-07-27 2013-07-24 甲骨文国际公司 MYSQL database heterogeneous log based replication
CN111291049A (en) * 2020-01-19 2020-06-16 软通动力信息技术有限公司 Method, device, equipment and storage medium for creating table
CN112860793A (en) * 2021-02-03 2021-05-28 浪潮云信息技术股份公司 Method for realizing metadata synchronization between different source databases
CN113051259A (en) * 2020-12-23 2021-06-29 上海海鼎信息工程股份有限公司 Multi-data-source structure difference processing method and system for store operation
CN114077600A (en) * 2021-11-26 2022-02-22 山东福生佳信科技股份有限公司 ARM (advanced RISC machine) kernel-based data heterogeneous migration visual analysis method
CN114398345A (en) * 2022-01-19 2022-04-26 中国平安人寿保险股份有限公司 Data migration method and device, computer equipment and storage medium
CN115599769A (en) * 2022-10-26 2023-01-13 中国农业银行股份有限公司(Cn) Data migration method and device, electronic equipment and storage medium
CN115617773A (en) * 2021-07-16 2023-01-17 中国电信股份有限公司 Data migration method, device and system

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103221949A (en) * 2010-07-27 2013-07-24 甲骨文国际公司 MYSQL database heterogeneous log based replication
CN111291049A (en) * 2020-01-19 2020-06-16 软通动力信息技术有限公司 Method, device, equipment and storage medium for creating table
CN113051259A (en) * 2020-12-23 2021-06-29 上海海鼎信息工程股份有限公司 Multi-data-source structure difference processing method and system for store operation
CN112860793A (en) * 2021-02-03 2021-05-28 浪潮云信息技术股份公司 Method for realizing metadata synchronization between different source databases
CN115617773A (en) * 2021-07-16 2023-01-17 中国电信股份有限公司 Data migration method, device and system
CN114077600A (en) * 2021-11-26 2022-02-22 山东福生佳信科技股份有限公司 ARM (advanced RISC machine) kernel-based data heterogeneous migration visual analysis method
CN114398345A (en) * 2022-01-19 2022-04-26 中国平安人寿保险股份有限公司 Data migration method and device, computer equipment and storage medium
CN115599769A (en) * 2022-10-26 2023-01-13 中国农业银行股份有限公司(Cn) Data migration method and device, electronic equipment and storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116186796A (en) * 2023-02-21 2023-05-30 中国人民解放军海军工程大学 Sequence number generation method, system, electronic equipment and storage medium
CN116186796B (en) * 2023-02-21 2024-01-30 中国人民解放军海军工程大学 Sequence number generation method, system, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN111611813B (en) Document translation method, device, electronic equipment and storage medium
CN112182036A (en) Data sending and writing method and device, electronic equipment and readable storage medium
CN116467372A (en) Automatic database conversion method and device, electronic equipment and storage medium
CN111159215A (en) Mapping method and device of Java class and relational database and computing equipment
CN112035480A (en) Data table management method, device, equipment and storage medium
CN112966478A (en) Format conversion method and device for table data and storage medium
CN116996601A (en) Message format conversion method and device, electronic equipment and storage medium
CN112015831A (en) Method, device and equipment for operating relational database based on C language
CN111507430A (en) Feature coding method, device, equipment and medium based on matrix multiplication
CN113656830B (en) Database desensitization grammar parsing method, system, computer and readable storage medium
CN114328486A (en) Data quality checking method and device based on model
CN112148746B (en) Method, device, electronic device and storage medium for generating database table structure document
CN114595215A (en) Data processing method and device, electronic equipment and storage medium
CN114490651A (en) Data storage method and device
CN113126981B (en) Medical data processing method and device based on Excel
CN114327611A (en) Interface description document generation method and device, computer equipment and storage medium
CN113868138A (en) Method, system, equipment and storage medium for acquiring test data
CN112559613A (en) Voucher data extraction method and device, computer equipment and storage medium
CN113515909A (en) Gate-level netlist processing method and computer storage medium
CN111651438A (en) MapDB-based structured data deduplication method, device, equipment and medium
CN112015425A (en) Data storage method, data reading device, electronic equipment and storage medium
CN117131840A (en) excel document analysis method and device, electronic equipment and storage medium
CN117478723A (en) Data transmission method, device, equipment and storage medium
CN117094292A (en) Form file processing method, form file processing device, form file processing equipment, storage medium and program product
CN116719878A (en) LabVIEW-based data analysis method, system, equipment and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination