Data synchronization method and device between databases, electronic equipment and medium
Through the automated database field compatibility verification method, the problem of low efficiency of manual verification of data synchronization between heterogeneous databases is solved, and efficient and accurate data synchronization is achieved.
Patent Information
- Application Number
- CN202510932953.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-08
- Publication Date
- 2025-08-15
- Estimated Expiration
- 2045-07-08
AI Technical Summary
When synchronizing data between heterogeneous databases, the prior art relies on manual verification of field compatibility, resulting in huge workload, inefficiency and error-prone.
By obtaining the field metadata information of the source and target databases, using JDBC encoding and preset correspondence between type and type, automatically verify whether the source field and the target field are compatible, and data synchronization is performed when compatible.
Reduces manual operations, improves the efficiency and accuracy of data synchronization, and reduces labor costs.
Smart Images

Figure CN120492545A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data storage technology, and in particular to a method, device, electronic device, and medium for synchronizing data between databases. Background Art
[0002] In today's rapidly developing world of big data and information technology, businesses and organizations commonly use multiple databases to store and manage the business data generated by their operations. The database types used by businesses and organizations at different stages of their history, or within their business departments, are often heterogeneous. Specifically, different databases typically differ in data types, length units, encoding methods, and storage structures. With the increasing demand for data analysis and cross-system collaboration, achieving stable, efficient, and accurate data synchronization between these heterogeneous databases has become a significant challenge.
[0003] Currently, the common practice for data synchronization between heterogeneous databases is to manually map fields between them. Specifically, implementation personnel must rely on a deep understanding of the field types in both the source and target databases to determine whether data in a specific field in the source database can be synchronized to a specific field in the target database. This involves manually verifying the compatibility of the specified fields, and only performing data synchronization if they are compatible. However, this method relies heavily on manual effort. If the data synchronization process involves a large number of fields, for example, hundreds of fields, the workload is enormous, resulting in high labor costs and low efficiency. Furthermore, due to limited experience and energy, verification omissions and errors are prone to occur. Summary of the Invention
[0004] The purpose of the embodiments of the present application is to provide a method, device, electronic device, and medium for synchronizing data between databases to reduce the manual work required for synchronizing data between databases. The specific technical solution is as follows:
[0005] In a first aspect, an embodiment of the present application provides a method for synchronizing data between databases, including:
[0006] Obtain metadata information of a source field of a source data table in a source database and metadata information of a target field of a target data table in a target database, wherein the metadata information includes: a field type and a type code, wherein the type code is a Java Database Connectivity (JDBC) code corresponding to the field type determined based on the database type;
[0007] Determine, based on a preset correspondence between each type code and type category, a first type category corresponding to the type code of the source field and a second type category corresponding to the type code of the target field;
[0008] In a case where the first type is the same as the second type, verifying whether the source field is compatible with the target field based on the metadata information of the source field and the metadata information of the target field;
[0009] When the verification result is compatible, data synchronization is performed on the source field and the target field.
[0010] Optionally, the first type and the second type both represent string types, and the metadata information further includes: column size, string length unit, and encoding mode; and verifying whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field includes:
[0011] If the column size of the source field is not a preset value, converting the column size of the source field into a target column size based on the character string length unit and encoding mode of the source field and the character string length unit and encoding mode of the target field, and determining whether the target column size is less than or equal to the column size of the target field, the target column size indicating a column size required to store the data in the source field into the target field; if so, determining that the verification result is compatible; otherwise, determining that the verification result is incompatible;
[0012] When the column size of the source field is a preset value, determine whether the column size of the target field is greater than or equal to the preset value; if so, determine that the verification result is compatible; otherwise, determine that the verification result is incompatible.
[0013] Optionally, the first type and the second type both represent integer types; and verifying whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field includes:
[0014] Determining, based on a preset correspondence between each type code and range code of an integer type, a first range code corresponding to the type code of the source field and a second range code corresponding to the type code of the target field; wherein the range of values supported for storage by the field type corresponding to the type code is positively correlated with the size of the range code corresponding to the type code;
[0015] determining whether the first range code is less than or equal to the second range code;
[0016] If so, the verification result is determined to be compatible;
[0017] Otherwise, the verification result is determined to be incompatible.
[0018] Optionally, the first type and the second type both represent non-integer types, the non-integer types including floating-point types and fixed-point types, and the metadata information further includes: column size and number of decimal places; and verifying whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field includes:
[0019] If the field type of the source field and the field type of the target field are both fixed-point types, then determining whether the column size of the source field is less than or equal to the column size of the target field, and whether the number of decimal places of the source field is less than or equal to the number of decimal places of the target field; if the judgment results are both yes, determining that the verification result is compatible; otherwise, determining that the verification result is incompatible;
[0020] If the field type of the source field and the field type of the target field are both floating-point types, determining that the verification result is compatible;
[0021] If the field type of the source field is a fixed-point number type, and the field type of the target field is a floating-point number type, determining that the verification result is incompatible;
[0022] If the field type of the source field is a floating-point type and the field type of the target field is a fixed-point type, determine whether the numerical range supported by the field type of the source field is less than or equal to the numerical range supported by the field type of the target field; if so, determine that the verification result is compatible; otherwise, determine that the verification result is incompatible.
[0023] Optionally, the first type and the second type are both other types, including date type, binary type, and Boolean type; and verifying whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field includes:
[0024] Determine whether the type code of the source field is the same as the type code of the target field, or whether there is an equivalent mapping relationship between the type code of the source field and the type code of the target field in a preset equivalent mapping table;
[0025] If any of the judgment results is yes, then the verification result is determined to be compatible;
[0026] Otherwise, the verification result is determined to be incompatible.
[0027] Optionally, after verifying whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field, if the verification result is incompatible, the method further includes:
[0028] If the column size of the source field is a preset value, selecting a field type with a column size greater than or equal to the preset value as the suggested field type for the target field;
[0029] If the column size of the source field is not a preset value, determine whether the target column size of the source field is greater than the upper limit of the column size of the field type of the target field; if so, select the parent field type of the field type of the target field as the recommended field type; if not, select the field type of the target field as the recommended field type, and determine the target column size as the recommended column size.
[0030] Optionally, after verifying whether the source field is compatible with the target field based on the metadata information of the source field and the metadata information of the target field, the method further includes:
[0031] If the verification result is incompatible, determining, from the field types corresponding to the first type category, a candidate field type whose supported storage value range is greater than or equal to the supported storage value range of the source field;
[0032] Select a candidate field type as the suggested field type.
[0033] In a second aspect, an embodiment of the present application provides a data synchronization device between databases, including:
[0034] An acquisition module is configured to acquire metadata information of a source field of a source data table in a source database and metadata information of a target field of a target data table in a target database, wherein the metadata information includes a field type and a type code, wherein the type code is a Java database connection JDBC code corresponding to the field type determined based on the database type;
[0035] a determination module, configured to determine, based on a preset correspondence between each type code and a type category, a first type category corresponding to the type code of the source field and a second type category corresponding to the type code of the target field;
[0036] a verification module, configured to verify whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field when the first type is the same as the second type;
[0037] A synchronization module is used to synchronize data between the source field and the target field when the verification result of the verification module is compatible.
[0038] Optionally, the first type and the second type both represent string types, and the metadata information further includes: column size, string length unit, and encoding method; the verification module is specifically configured to:
[0039] If the column size of the source field is not a preset value, converting the column size of the source field into a target column size based on the character string length unit and encoding mode of the source field and the character string length unit and encoding mode of the target field, and determining whether the target column size is less than or equal to the column size of the target field, the target column size indicating a column size required to store the data in the source field into the target field; if so, determining that the verification result is compatible; otherwise, determining that the verification result is incompatible;
[0040] When the column size of the source field is a preset value, determine whether the column size of the target field is greater than or equal to the preset value; if so, determine that the verification result is compatible; otherwise, determine that the verification result is incompatible.
[0041] Optionally, the first type and the second type both represent integer types; and the verification module is specifically configured to:
[0042] Determining, based on a preset correspondence between each type code and range code of an integer type, a first range code corresponding to the type code of the source field and a second range code corresponding to the type code of the target field; wherein the range of values supported for storage by the field type corresponding to the type code is positively correlated with the size of the range code corresponding to the type code;
[0043] determining whether the first range code is less than or equal to the second range code;
[0044] If so, the verification result is determined to be compatible;
[0045] Otherwise, the verification result is determined to be incompatible.
[0046] Optionally, the first type and the second type both represent non-integer types, the non-integer types including floating-point types and fixed-point types, and the metadata information further includes: column size and number of decimal places; the verification module is specifically configured to:
[0047] If the field type of the source field and the field type of the target field are both fixed-point types, then determining whether the column size of the source field is less than or equal to the column size of the target field, and whether the number of decimal places of the source field is less than or equal to the number of decimal places of the target field; if the judgment results are both yes, determining that the verification result is compatible; otherwise, determining that the verification result is incompatible;
[0048] If the field type of the source field and the field type of the target field are both floating-point types, determining that the verification result is compatible;
[0049] If the field type of the source field is a fixed-point number type, and the field type of the target field is a floating-point number type, determining that the verification result is incompatible;
[0050] If the field type of the source field is a floating-point type and the field type of the target field is a fixed-point type, determine whether the numerical range supported by the field type of the source field is less than or equal to the numerical range supported by the field type of the target field; if so, determine that the verification result is compatible; otherwise, determine that the verification result is incompatible.
[0051] Optionally, the first type and the second type are both other types, including date type, binary type, and Boolean type; the verification module is specifically configured to:
[0052] Determine whether the type code of the source field is the same as the type code of the target field, or whether there is an equivalent mapping relationship between the type code of the source field and the type code of the target field in a preset equivalent mapping table;
[0053] If any of the judgment results is yes, then the verification result is determined to be compatible;
[0054] Otherwise, the verification result is determined to be incompatible.
[0055] Optionally, the device further includes:
[0056] a selection module configured to, after verifying whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field, select, if a verification result shows incompatibility, a field type having a column size greater than or equal to the preset value as a suggested field type for the target field if the column size of the source field is a preset value;
[0057] A generation module is used to verify whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field. If the verification result is incompatible, if the column size of the source field is not a preset value, determine whether the target column size of the source field is greater than the column size upper limit of the field type of the target field; if so, select the parent field type of the field type of the target field as the recommended field type; if not, select the field type of the target field as the recommended field type, and determine the target column size as the recommended column size.
[0058] Optionally, the determining module is further configured to:
[0059] After verifying whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field, if the verification result is incompatible, determining, from the field types corresponding to the first type category, a candidate field type whose supported storage range of numerical values is greater than or equal to the supported storage range of numerical values of the source field;
[0060] Select a candidate field type as the suggested field type.
[0061] In a third aspect, an embodiment of the present application provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus;
[0062] Memory for storing computer programs;
[0063] The processor is configured to implement the method described in any one of the first aspects when executing a program stored in the memory.
[0064] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in any one of the first aspects is implemented.
[0065] In a fifth aspect, an embodiment of the present application further provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the method for synchronizing data between databases as described in any one of the first aspects above.
[0066] Beneficial effects of the embodiments of the present application:
[0067] The data synchronization method, device, electronic device and medium between databases provided by the embodiment of the present application can obtain the JDBC code corresponding to the field type of each source field and target field, and further determine the type category to which the JDBC code belongs. The embodiment of the present application uniformly maps the field type to the JDBC code, which can eliminate the impact of different field type names set for the same field type in different databases on compatibility judgment. Moreover, the embodiment of the present application divides each field type into multiple type categories, so that when the first type category is the same as the second type category, the source field and the target field are automatically verified to be compatible based on the metadata information of the source field and the metadata information of the target field, and when the verification result is compatible, the source field and the target field are synchronized, that is, automatic compatibility verification can be achieved without manual verification, thereby reducing the manual operations required for the data synchronization process between databases, not only reducing labor costs, but also improving verification efficiency and accuracy.
[0068] Of course, it is not necessary to achieve all the advantages described above at the same time when implementing any product or method of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0069] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other embodiments can also be obtained based on these drawings.
[0070] Figure 1 A flowchart of a method for synchronizing data between databases provided in an embodiment of the present application;
[0071] Figure 2 An exemplary schematic diagram of a data synchronization process between databases provided in an embodiment of the present application;
[0072] Figure 3 A flowchart of a method for generating suggestions provided in an embodiment of the present application;
[0073] Figure 4 A schematic diagram of the structure of a data synchronization device between databases provided in an embodiment of the present application;
[0074] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0075] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field based on this application are within the scope of protection of this application.
[0076] In order to reduce the manual operations required for data synchronization between databases, an embodiment of the present application provides a method for data synchronization between databases. The method is applied to electronic devices, such as servers, desktop computers, or laptop computers, which have data processing capabilities. Figure 1 As shown, the data synchronization method between databases provided in the embodiment of the present application includes the following steps:
[0077] S101: Obtain metadata information of a source field of a source data table in a source database, and metadata information of a target field of a target data table in a target database.
[0078] In the embodiments of the present application, a user can configure a data synchronization task through a visual system interface provided by an electronic device. For example, within the visual system interface, the user can select a source field in a source data table in a source database and a target field in a target data table in a target database. There can be multiple source fields, each corresponding to a target field. Each set of source fields and target fields is processed in the same manner. The embodiments of the present application use a set of source fields and target fields as an example for explanation.
[0079] Electronic devices are pre-configured with connection information for the source and target databases. Using this connection information, electronic devices can connect to the databases and access and manipulate data in them. For example, this connection information includes the connection address, authentication credentials, and Java Database Connectivity (JDBC) driver information.
[0080] The electronic device can obtain the metadata information of the field through the JDBC interface of the database according to the database structure (schema), the table name (tablename) of the source data table, and the field name.
[0081] Metadata information includes: field type and type encoding. The type encoding is the JDBC encoding corresponding to the field type determined by the database type. That is, each database type corresponds to a preset correspondence between field type and JDBC encoding. Based on the preset correspondence corresponding to the source database type, the JDBC encoding corresponding to the field type of the source field can be determined. Based on the preset correspondence corresponding to the target database type, the JDBC encoding corresponding to the field type of the target field can be determined.
[0082] S102: Determine a first type category corresponding to the type code of the source field and a second type category corresponding to the type code of the target field according to a preset correspondence between each type code and type category.
[0083] Each type code represents a field type. Multiple similar field types may exist, and these similar field types belong to the same type category. For example, TINYINT, SMALLINT, and INT all belong to the integer type.
[0084] S103: When the first type and the second type are the same, verify whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field.
[0085] The specific verification method can be found in the following description.
[0086] S104: If the verification result is compatible, synchronize the source field and the target field.
[0087] If the verification result is compatible, it means that the data in the source field can be completely synchronized to the target field. Therefore, data synchronization can be performed on the source field and the target field.
[0088] The data synchronization method between databases provided by the embodiment of the present application can obtain the JDBC code corresponding to the field type of each source field and target field, and further determine the type category to which the JDBC code belongs. The embodiment of the present application uniformly maps the field type to the JDBC code, which can eliminate the impact of different field type names set for the same field type in different databases on compatibility judgment. Moreover, the embodiment of the present application divides each field type into multiple type categories, so that when the first type category is the same as the second type category, the source field and the target field are automatically verified to be compatible based on the metadata information of the source field and the metadata information of the target field, and when the verification result is compatible, the source field and the target field are synchronized, that is, automatic compatibility verification can be achieved without manual verification, thereby reducing the manual operations required for the data synchronization process between databases, not only reducing labor costs, but also improving verification efficiency and accuracy.
[0089] The following describes in detail the method for synchronizing data between databases provided in the embodiments of the present application:
[0090] Before synchronizing database data, you can obtain the database configuration and field synchronization configuration information for each database type. Database types include MySQL, Oracle, and SQL Server. MySQL is a relational database management system that uses Structured Query Language (SQL) to access databases; Oracle is a relational database management system with a distributed database as its core; and SQL Server is a scalable and high-performance relational database management system.
[0091] Database configuration information includes: basic database properties and database field types.
[0092] Taking MySQL as an example, basic database properties include: database type, database encoding detection SQL statement, string length unit, maximum length of variable-length string (VARCHAR) fields, field type change syntax template, field addition syntax template, field comment template and table comment template, primary key or distribution key template, and table creation statement template. The database encoding detection SQL statement is used to query the encoding of data stored in the database. Encodings include GBK, Universal Character Set (UTF)-8, and UTF-16. GBK is an extension of the Chinese Internal Code Specification, representing the Chinese character encoding character set. String length units can be characters or bytes. The field type change syntax template is used to construct SQL statements to modify the field type in the database. When using this template, you can specify the modified field type and required type parameters. For example, if the modified field type is a string, the required type parameters include the maximum number of characters that can be stored in the field; if the modified field type is a fixed-point number, the required type parameters include the precision and scale of the data that can be stored in the field. The field addition syntax template is used to construct SQL statements for adding fields to a database. When using this template, you can specify the field name, field type, and required parameters. The field comment template is used to construct SQL statements that store descriptive text information about a field. The table comment template is used to construct SQL statements that store descriptive text information about a specified table. The primary key or distribution key template is used to construct SQL statements for specifying the primary key or distribution key of a table. The table creation statement template is used to construct statements for creating tables in a database.
[0093] Database field types indicate the field types supported in database tables. For example, field types include TINYINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DECIMAL, and NUMERIC.
[0094] Field synchronization configuration information includes: the field types supported by the database type, the correspondence between each field type and JDBC encoding, the conversion strategy for each field type, and the correspondence between each field type and type category.
[0095] Taking MySQL as an example, the field synchronization configuration information includes:
[0096] TINYINT, JDBC code is -6, conversion strategy is no conversion, type is long integer (LONG);
[0097] Character (CHAR), JDBC code is 1, conversion strategy is length conversion, type is string (STRING);
[0098] VARCHAR, JDBC code is 12, the conversion strategy is length conversion, and the type is STRING.
[0099] Length conversion refers to converting the source field's column size (COLUMN_SIZE). COLUMN_SIZE represents the maximum length of data that can be stored in the field. Length conversion includes the following three scenarios:
[0100] If the string length units of both the source and target fields are bytes, the source field is encoded in GBK, and the target field is encoded in UTF-8, multiply the source field's COLUMN_SIZE by 2 to obtain the converted COLUMN_SIZE. You can obtain the string length unit from the database configuration information and execute a database encoding detection SQL statement to determine the field encoding, thereby obtaining a more accurate converted COLUMN_SIZE.
[0101] If the string length unit of the source field is characters, the string length unit of the target field is bytes, and the encoding method of the target field is GBK, multiply the COLUMN_SIZE of the source field by 2 to obtain the converted COLUMN_SIZE.
[0102] If the string length unit of the source field is characters, the string length unit of the target field is bytes, and the encoding mode of the target field is UTF-8, multiply the COLUMN_SIZE of the source field by 4 to obtain the converted COLUMN_SIZE.
[0103] The above three situations are only examples of the length conversion strategy provided in the embodiments of the present application. The length conversion strategy may also include conversion methods in other situations, which can be specifically set based on actual application scenarios.
[0104] In an embodiment of the present application, the conversion strategy corresponding to the field type of the string type can be set to length conversion, and the conversion strategy corresponding to the field type of the integer type can be set to no conversion.
[0105] After receiving the data synchronization task configured by the user, the electronic device can obtain the database type of the source database and the database type of the target database, thereby obtaining database configuration information corresponding to the database type of the source database and the database configuration information corresponding to the database type of the target database.
[0106] In some embodiments of the present application, in S101 above, the electronic device may obtain metadata information of the source field and metadata information of the target field through the JDBC interface. For example, the metadata information includes: column name (COLUMN_NAME), data type (DATA_TYPE), type name (TYPE_NAME), COLUMN_SIZE, number of decimal places (DECIMAL_DIGITS), floating point radix (NUM_PREC_RADIX), and remarks (REMARKS). Among them, DATA_TYPE is the JDBC code mentioned above, TYPE_NAME is the field type mentioned above, DECIMAL_DIGITS indicates the number of decimal places included in the value in the field, NUM_PREC_RADIX can be decimal or binary, etc., and REMARKS may include information such as the purpose and meaning of the field.
[0107] In S102 above, because the electronic device pre-acquires the database configuration information corresponding to the database type of the source database, which includes the preset correspondence between each field type and type category supported by the data type, the electronic device can determine the first type category corresponding to the type code of the source field based on this. Similarly, based on the database configuration information corresponding to the database type of the target database, the electronic device can determine the second type category corresponding to the type code of the target field.
[0108] Among them, the types include: STRING, LONG, DOUBLE, date (DATE), binary (BYTES) and Boolean (BOOLEAN).
[0109] Based on this, in some embodiments of the present application, when the first type category is the same as the second type category, the above S103 verifies whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field, including the following situations.
[0110] Case 1: Both the first and second types represent string types, which are denoted as STRING. In this case, the field metadata may also include: column size, string length unit, and encoding method.
[0111] Because different database drivers implement the JDBC specification incompletely, metadata information obtained from different databases through JDBC interfaces such as DatabaseMetaData or ResultSetMetaData may differ. For example, for the COLUMN_SIZE value of a large text field, some database drivers return the actual column size, while others return a fixed maximum value. For example, when the source database is MySQL and the field type is TEXT, MEDIUMTEXT, or LONGTEXT, the COLUMN_SIZE value returned by the MySQL database driver may be 65535, 16777215, or 2147483647, indicating the maximum number of bytes that may appear in the field.
[0112] During verification, if the column size of the source field is not a preset value, where the preset value is the fixed extreme value, the electronic device may convert the column size of the source field to a target column size based on the string length unit and encoding method of the source field and the string length unit and encoding method of the target field, and determine whether the target column size is less than or equal to the column size of the target field. The target column size represents the column size required to store the data in the source field in the target field. If so, the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible.
[0113] The method of converting the source field column size to the target column size can refer to the above-mentioned length conversion strategy, which will not be repeated here.
[0114] Alternatively, the electronic device may determine whether the column size of the target field is greater than or equal to a preset value when the column size of the source field is a preset value; if so, determine that the verification result is compatible; otherwise, determine that the verification result is incompatible.
[0115] It is understandable that since the preset value can include multiple values, such as 65535, 16777215 or 2147483647, when the column size of the source field is a preset value, it can be determined whether the column size of the target field is greater than or equal to the preset value.
[0116] It should be noted that the DATA_TYPE returned by some databases for a certain field may be the same as the JDBC code corresponding to a common string type, such as 12, but the returned COLUMN_SIZE may be larger, such as 2147483647. This indicates that the field type is a large text field type, not a common string type. Therefore, the embodiments of the present application do not directly use DATA_TYPE to determine whether the field type is a large text field type. Instead, they determine based on COLUMN_SIZE, which improves the accuracy of determining the large text field type.
[0117] When both the first type and the second type are string types, after the compatibility verification is performed in S103, if the verification result is incompatible, the electronic device may further generate suggestion information for the target field, and the generation method includes the following two cases:
[0118] If the column size of the source field is a preset value, a field type with a column size greater than or equal to the preset value is selected as the recommended field type for the target field. The electronic device may select, based on the COLUMN_SIZE upper limits of various string-type field types in the target database, a field type with the smallest COLUMN_SIZE upper limit that is greater than the preset value as the recommended field type, and determine the target column size as the recommended column size.
[0119] If the column size of the source field is not a preset value, determine whether the target column size of the source field is larger than the upper limit of the column size of the field type of the target field; if so, select the parent field type of the field type of the target field as the recommended field type; if not, select the field type of the target field as the recommended field type, and determine the target column size as the recommended column size.
[0120] The target field's parent field type is a field type whose COLUMN_SIZE upper limit is greater than the target column size after the source field is converted. For example, if the source field type is LONGTEXT, you can choose one of the parent field types: LONGTEXT, VARCHAR(MAX), Character Large Object (CLOB), or National Character Large Object (NCLOB). The parent field type with the smallest COLUMN_SIZE upper limit is selected as the recommended field type. The MAX in VARCHAR(MAX) indicates the maximum number of characters / bytes that can be stored in a VARCHAR field.
[0121] Through the above method, the embodiment of the present application can generate a suggested field type and suggested column size for the target field when both the source field and the target field are string types and the verification result is incompatible, thereby assisting the user in modifying the target field, improving the modification efficiency and accuracy, and improving the accuracy of data synchronization after modification.
[0122] Case 2: Both the first type and the second type represent integer types, and the integer type is recorded as LONG. In this case, the verification process of the electronic device includes the following steps:
[0123] Step 1: Determine a first range code corresponding to the type code of the source field and a second range code corresponding to the type code of the target field based on a preset correspondence between each type code and a range code of an integer type.
[0124] In the embodiment of the present application, a range code corresponding to each type code of an integer type can be pre-set, wherein the range code corresponding to each type code is different. The range of values supported by the field type corresponding to the type code is positively correlated with the size of the range code corresponding to the type code, that is, the larger the range of values supported by the field type corresponding to the type code, the larger the range code corresponding to the type code.
[0125] For example, TINYINT supports the storage of values in the range [-128, 127]. The corresponding JDBC code is -6, and the range code for -6 is 0. SMALLINT supports the storage of values in the range [-32768, 32767]. The corresponding JDBC code is 5, and the range code for 5 is 1. INT supports the storage of values in the range [-2147483648, 2147483647]. The corresponding JDBC code is 4, and the range code for 4 is 2.
[0126] Step 2: Determine whether the first range code is less than or equal to the second range code.
[0127] Step 3: If yes, then confirm that the verification result is compatible.
[0128] Step 4: Otherwise, determine that the verification result is incompatible.
[0129] When the first range code is less than or equal to the second range code, it means that the value range supported by the field type of the source field is less than or equal to the value range supported by the field type of the target field. At this time, the data in the source field can be completely stored in the target field, so the verification result is determined to be compatible. Conversely, when the first range code is greater than the second range code, it means that the value range supported by the field type of the source field is greater than the value range supported by the field type of the target field. At this time, the data in the source field may not be completely stored in the target field, so the verification result is determined to be incompatible. When the verification result is compatible, data synchronization of the source field and the target field can reduce abnormal situations such as truncation or overflow of data in the source field when synchronizing to the target field due to insufficient value range supported by the target field, thereby improving the accuracy of data synchronization.
[0130] When the first type category and the second type category are both integer types, after the compatibility verification is performed in the above S103, if the verification result is incompatible, the electronic device can also generate a suggested field type for the target field, including: from the field types corresponding to the first type category, determining a candidate field type whose supported storage range of numerical values is greater than or equal to the supported storage range of the source field, and selecting a candidate field type as the suggested field type.
[0131] For example, if the source field type is SMALLINT and the target field type is TINYINT, you can select SMALLINT, INT, or BIGINT as candidate field types, and then select one from the candidate field types as the recommended field type. For example, select SMALLINT, which supports the smallest storage range of values, as the recommended field type.
[0132] Through the above method, the embodiment of the present application can generate a suggested field type for the target field when both the source field and the target field are integer types and the verification result is incompatible, thereby assisting the user in modifying the target field, improving the modification efficiency and accuracy, and improving the accuracy of data synchronization after modification.
[0133] Case 3: Both the first and second types represent non-integer types, denoted as DOUBLE. Non-integer types include floating-point and fixed-point types. For example, floating-point types include FLOAT and DOUBLE, and fixed-point types include DECIMAL and NUMERIC. In this case, the field type metadata may also include column size and number of decimal places. The column size is COLUMN_SIZE, also known as precision (p); the number of decimal places is DECIMAL_DIGITS, also known as scale (s), indicating the maximum number of decimal places that can be stored in the field.
[0134] Both floating-point and fixed-point numbers can include integer and decimal places. The number of decimal places included in a floating-point number may not be fixed. For example, the number of significant digits of FLOAT is 8, and the number of significant digits of DOUBLE is 16, where the significant digits are the sum of the integer's decimal places.
[0135] Fixed-point numbers include a fixed number of decimal places. For example, in relational databases, fixed-point numbers are usually represented by DECIMAL(p,s) or NUMERIC(p,s), where the maximum integer digits of a fixed-point number are ps, the maximum number of decimal places are s, and the maximum positive value supported is , minimum negative value = -MAX.
[0136] For example, DECIMAL(5,2) means that the number of significant digits is 5, that is, precision=5, the maximum integer digit is 5, the maximum decimal digit is 2, that is, scale=2, and the representable value range is [-999.99, 999.99].
[0137] For example, DECIMAL(10,0) means: precision = 10, scale = 0, and the representable value range is [-99999999999, 99999999999].
[0138] For example, DECIMAL(8,3) means: precision = 8, scale = 3, and the representable value range is [-99999.999, 99999.999].
[0139] The electronic device can determine whether the field is a floating-point type or a fixed-point type based on the JDBC encoding of the field. If both the first type and the second type represent non-integer types, the electronic device verifies whether the source field and the target field are compatible in the following four situations.
[0140] Case 1: If both the source and target fields are fixed-point types, determine whether the source field's column size is less than or equal to the target field's column size, and whether the source field's number of decimal places is less than or equal to the target field's number of decimal places. If both are true, the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible.
[0141] When the precision of the field type of the source field is less than or equal to the precision of the field type of the target field, and the scale of the field type of the source field is less than or equal to the scale of the field type of the target field, it indicates that the data in the source field can be completely stored in the target field, and therefore the verification result is determined to be compatible.
[0142] In an embodiment of the present application, if the verification result of Case 1 is incompatible, a recommended column size for the target field can be generated when the precision of the field type of the source field is greater than the precision of the field type of the target field, where the recommended column size is greater than or equal to the precision of the field type of the source field. If the scale of the field type of the source field is greater than the scale of the field type of the target field, a recommended number of decimal places for the target field is generated, where the recommended number of decimal places is greater than or equal to the scale of the field type of the source field. For example, when the field type of the source field is DECIMAL(28, 8), the recommended field type is DECIMAL(38, 10).
[0143] Case 2: If the field type of the source field and the field type of the target field are both floating-point types, the verification result is determined to be compatible.
[0144] In actual application scenarios, since complete data synchronization can generally be performed between fields of various floating-point types, when the field types of the source field and the target field are both floating-point types, the verification result can be determined to be compatible.
[0145] Case 3: If the field type of the source field is a fixed-point number type and the field type of the target field is a floating-point number type, the verification result is determined to be incompatible.
[0146] In actual application scenarios, it is generally difficult to completely synchronize data in a fixed-point field to a floating-point field. Therefore, the verification result can be determined to be incompatible.
[0147] In an embodiment of the present application, if the verification result of situation 3 is incompatible, the type of the source field can be encoded into the corresponding field type in the target database as the recommended field type of the target field.
[0148] Case 4: If the source field type is a floating-point number type and the target field type is a fixed-point number type, determine whether the range of values supported by the source field type is less than or equal to the range of values supported by the target field type. If so, the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible.
[0149] In actual application scenarios, when synchronizing the data in a field of a floating-point type to a field of a fixed-point type, data synchronization can generally be completed completely. However, when the numerical range supported by the floating-point type for storage is larger than the numerical range supported by the fixed-point type for storage, data synchronization may not be completed completely. For example, when the column size of the floating-point type is larger than the column size of the fixed-point type, or when the number of decimal places of the floating-point type is larger than the number of decimal places of the fixed-point type, data synchronization may not be completed completely. Therefore, the embodiment of the present application can determine whether the numerical range supported by the field type of the source field is less than or equal to the numerical range supported by the field type of the target field for storage. If so, the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible.
[0150] In an embodiment of the present application, if the verification result of situation 4 is incompatible, the type of the source field can be encoded into the corresponding field type in the target database as the recommended field type of the target field.
[0151] In the case where both the first type category and the second type category represent non-integer types, the embodiments of the present application can perform different compatibility judgments for different situations, thereby improving the accuracy of the compatibility judgment.
[0152] Case 4: Both the first type and the second type are other types, where other types include: date type, binary type, and Boolean type.
[0153] The electronic device's verification process can be implemented by determining whether the type code of the source field is the same as the type code of the target field, or whether an equivalent mapping relationship exists between the type code of the source field and the type code of the target field in a preset equivalent mapping table. If either determination result is yes, the verification result is determined to be compatible. Otherwise, the verification result is determined to be incompatible.
[0154] The equivalence mapping table stores multiple preset equivalence mapping relationships, each of which is a mapping relationship between two JDBC codes, and each equivalence mapping relationship corresponds to a database type. That is, each equivalence mapping relationship indicates that it is set for a database and supports equivalence mapping between a field type in the database and another field type. Therefore, after obtaining the JDBC encoding of the source field in the source database and the JDBC encoding of the target field in the target database, you can check the equivalence mapping relationship set for the target database in the equivalence mapping table to see if there is a mapping relationship between the two JDBC codes. If so, the verification result is determined to be compatible.
[0155] For example, the equivalent mapping table includes an equivalent mapping relationship of -7 16, and the database type corresponding to the equivalent mapping relationship is MYSQL, that is, the equivalent mapping relationship indicates that: it is set for MYSQL, and the equivalent mapping between BIT and BOOLEAN in MYSQL is supported. If the source database is SQL Server, the field type of the source field is BIT, and the corresponding JDBC code is -7, and the target database is MySQL, the field type of the target field is BOOLEAN, and the corresponding JDBC code is 16. Since the equivalent mapping table includes the equivalent mapping relationship set for MYSQL: -7 16, so we can confirm that there is an equivalent mapping relationship from SQL Server BIT to MySQL BOOLEAN, and therefore confirm that the two are compatible.
[0156] In actual application scenarios, since the type coding of the source field is the same as the type coding of the target field, data synchronization can generally be completed completely, so the verification result can be determined to be compatible. And the preset equivalence mapping table records the mapping relationship between the type codings that can complete data synchronization completely. Therefore, when there is an equivalence mapping relationship between the type coding of the source field and the type coding of the target field in the preset equivalence mapping table, the verification result can be determined to be compatible. On the contrary, if the type coding of the source field is different from the type coding of the target field, and there is no equivalence mapping relationship between the type coding of the source field and the type coding of the target field in the preset equivalence mapping table, it means that when synchronizing the data in the source field to the target field, data synchronization may not be completed completely, so the verification result is incompatible, which improves the accuracy of verification.
[0157] In an embodiment of the present application, if the verification result of situation four is incompatible, the type of the source field can be encoded into the corresponding field type in the target database as the recommended field type of the target field.
[0158] In some embodiments of the present application, after determining the first type category and the second type category in the above S102, the electronic device may further execute: when the first type category is different from the second type category, generating a recommended field type for the target field based on the metadata information of the source field.
[0159] Among them, the field type corresponding to the JDBC encoding of the source field in the second target database can be used as the recommended field type; or, the field type under the first type in the second target database that supports the storage of a numerical range greater than or equal to the numerical range supported by the source field can be used as the recommended field type.
[0160] Optionally, when the suggested field type is a non-integer type, a suggested column size and suggested number of decimal places in the suggested field type may also be generated, where the suggested column size is greater than or equal to the column size of the source field, and the suggested number of decimal places is greater than or equal to the number of decimal places of the source field.
[0161] The embodiment of the present application can generate suggestion information based on the metadata information of the source field when the first type category is different from the second type category, thereby facilitating users to modify or set the target field more quickly based on the suggestion information, reducing manual workload, and improving the accuracy of data synchronization after modification.
[0162] In an embodiment of the present application, when the target data table does not exist, that is, when the target data table has not been established, suggestion information can be generated in the above manner to assist the user in establishing the target data table, thereby improving the efficiency of table creation. Among them, when creating a table, the user can reference the table creation statement template in the database configuration information of the target database. When modifying the field type, the user can reference the field type change syntax template in the database configuration information of the target database and set the field type of the target field to the suggested field type in the template, thereby automatically generating and executing the corresponding SQL statement, eliminating a large amount of manual operations and improving the efficiency of establishing and modifying the target data table.
[0163] After verifying and generating the recommendation information, the electronic device can generate a field model inference result list, which includes: the column name (Column Name) of each source field, the column name of the target field corresponding to each source field, the verification result of whether each source field is compatible with the target field, and the recommended field type.
[0164] Because the embodiment of the present application verifies the compatibility of the source field and the target field before data synchronization, if the verification result is compatible, the data in the source field is likely to be fully synchronized to the target field, so data synchronization can be performed accurately at this time. If the verification result is incompatible, a suggested field type can be generated, thereby reducing the risk of floating-point synchronization errors or data precision truncation caused by the data synchronization process. Moreover, since the verification result can be provided to the user, that is, the user can understand the incompatible source and target fields, the user can modify the target field before data synchronization, thereby reducing the possibility of abnormal interruption or data loss during the data synchronization process.
[0165] The following is an example of how to synchronize data between databases:
[0166] Example 1: The user configures the source database of the data synchronization task as MySQL, the COLUMN_NAME of the source field in the source data table as name, the target database as Oracle, and the COLUMN_NAME of the target field in the target data table as name through the visual system interface provided by the electronic device. According to the data synchronization task, the electronic device obtains the metadata information of the source field of the source data table in the source database through the JDBC interface, wherein the field type of the source field is CHAR(20), 20 represents COLUMN_SIZE, and the JDBC code is 1, and obtains the metadata information of the target field of the target data table in the target database through the JDBC interface, wherein the field type of the target field is VARCHAR2(50), 50 represents COLUMN_SIZE, and the JDBC code is 12. Afterwards, the electronic device obtains, based on the preset correspondence between each type code and type type, that the type type corresponding to 1 is STRING, and the type type corresponding to 12 is also STRING, that is, the type types of the source field and the target field are both STRING. Since the COLUMN_SIZE of the source field is 20, not the preset value, the obtained metadata information shows that the string length unit of the source field is characters and the encoding method is GBK, while the string length unit of the target field is bytes and the encoding method is UTF-8. In this case, the COLUMN_SIZE of the source field is multiplied by 2 to 40. That is, storing 20 characters encoded in UTF-8 requires 40 bytes. Since the COLUMN_SIZE of the target field is 50, which is greater than 40, the verification results of the source and target fields are determined to be compatible. The source and target fields can then be synchronized.
[0167] Example 2: Assume the source database for a data synchronization task is MySQL. The source field in the source data table in the source database has a field type of DECIMAL(12,4), where 12 represents COLUMN_SIZE and 4 represents DECIMAL_DIGITS. The target database is Oracle, and the target field in the target data table in the target database has a field type of NUMBER(10,3), where 10 represents COLUMN_SIZE and 3 represents DECIMAL_DIGITS. Because both the source and target fields are non-integer types, and 12 > 10 and 4 > 3, the verification result for the source and target fields is determined to be incompatible. The electronic device then generates a suggested field type of NUMBER(12,4), where 12 represents COLUMN_SIZE and 4 represents DECIMAL_DIGITS, and displays the suggested field type to the user. If the user agrees to the suggested field type, the electronic device changes the target field's field type to NUMBER(12,4) and synchronizes the data between the source and target fields.
[0168] The embodiment of the present application pre-configures database configuration information and field synchronization configuration information for each type of database, and before data synchronization, obtains metadata information of the upstream fields, i.e., source fields, and downstream fields, i.e., target fields, of the data synchronization through the JDBC interface. Based on this information, the type categories of the upstream and downstream fields are determined from six type categories, thereby performing fine-grained compatibility verification on the upstream and downstream fields. This can significantly reduce manual operations in the data synchronization process and reduce errors caused by human subjective errors in the data synchronization process, providing an efficient, automatically upgradeable and promptable field synchronization strategy for data exchange between heterogeneous databases in an enterprise.
[0169] See also Figure 2 The following describes the complete process of the data synchronization method between databases provided in the embodiment of the present application:
[0170] S201: Obtain database configuration information and field synchronization configuration information corresponding to each type of database.
[0171] The electronic device may pre-acquire the database configuration information and field synchronization configuration information corresponding to each type of database, and use the pre-acquired database configuration information and field synchronization configuration information each time a data synchronization task is executed. Alternatively, before each data synchronization task is executed, the electronic device may obtain the database configuration information and field synchronization configuration information corresponding to each type of database set for that data synchronization task.
[0172] S202 . Obtain metadata information of a source field of a source data table in a source database and metadata information of a target field of a target data table in a target database through a JDBC interface.
[0173] S203: Determine whether there are unverified source fields and target fields. If yes, execute S204; if no, determine that verification is complete.
[0174] Each data synchronization task may include one or more source fields, and each source field corresponds to a target field.
[0175] S204: Obtain a set of unverified source fields and target fields.
[0176] S205: Determine whether the source field and the target field have the same type. If they are the same, execute S206; if they are different, generate a suggested field type.
[0177] S206: Determine whether the type of the source field and the target field is a string type. If so, execute S207; if not, execute S209.
[0178] S207: Determine whether the column size of the source field is a preset value. If so, determine that the column size of the source field does not need to be converted; if not, convert the column size of the source field. Regardless of whether the result of S207 is yes or no, S208 is executed.
[0179] S208. Determine whether the source field's column size is less than or equal to the target field's column size. If so, the verification result is determined to be compatible; if not, the verification result is determined to be incompatible, and a suggested field type is generated. Regardless of whether the result of S208 is yes or no, the process returns to S203.
[0180] The verification method of S207 and S208 can refer to the description in the above situation 1 and will not be repeated here.
[0181] S209: Determine whether the types of the source field and the target field are integer types. If yes, execute S210; if not, execute S211.
[0182] S210: Determine whether the first range code corresponding to the source field's type code is less than or equal to the second range code corresponding to the target field's type code. If so, the verification result is determined to be compatible; if not, the verification result is determined to be incompatible, and a suggested field type is generated. Regardless of whether the determination result of S210 is yes or no, the process then returns to S203.
[0183] The verification method of S210 can refer to the description in the above situation 2, which will not be repeated here.
[0184] S211: Determine whether the types of the source field and the target field are non-integer types. If so, execute S212; if not, execute S213.
[0185] S212. Verify whether the source and target fields are compatible. If so, determine that the verification result is compatible; if not, determine that the verification result is incompatible and generate a recommended field type. Regardless of whether the judgment result of S212 is yes or no, the process then returns to S203.
[0186] The verification method of S212 can refer to the description in the above situation three and will not be repeated here.
[0187] S213: Determine whether the type code of the source field is the same as the type code of the target field, or whether an equivalent mapping relationship exists between the type code of the source field and the type code of the target field in a preset equivalent mapping table. If so, the verification result is determined to be compatible; if not, the verification result is determined to be incompatible, and a suggested field type is generated. Regardless of whether the judgment result of S213 is yes or no, the process then returns to S203.
[0188] The verification method of S213 can refer to the description in the above situation 4 and will not be repeated here.
[0189] See also Figure 3 The following describes the overall process of generating suggested field types for electronic devices:
[0190] S301: Obtain the type of the source database and the type of the target database.
[0191] S302: Obtain database configuration information and field synchronization configuration information corresponding to the type of the source database, and database configuration information and field synchronization configuration information corresponding to the type of the target database.
[0192] S303: Determine the JDBC encoding corresponding to the field type of the source field and determine whether the JDBC encoding corresponds to the conversion strategy. If so, execute S304. If not, execute S312.
[0193] S304: Determine whether the conversion strategy is length conversion. If yes, execute S305; if not, execute S309.
[0194] S305: Obtain the string length unit and encoding method of the source field and the string length unit and encoding method of the target field.
[0195] S306: Determine whether the column size of the source field is a preset value. If yes, execute S307; if not, execute S308.
[0196] S307 . Select a field type whose column size is greater than or equal to a preset value as the recommended field type for the target field.
[0197] S308: Determine whether the target column size after converting the source field column size to a larger size than the target field type's column size limit based on the string length unit and encoding method of the source field and the string length unit and encoding method of the target field. If so, select the parent field type of the target field type as the recommended field type; if not, select the target field type as the recommended field type and determine the target column size as the recommended column size.
[0198] S309: Determine whether the conversion strategy is precision conversion. If yes, execute S310; if not, execute S311.
[0199] S310. Select a value that is greater than or equal to the column size of the source field as the recommended column size, and select a value that is greater than or equal to the number of decimal places of the source field as the recommended number of decimal places.
[0200] S311. Encode the type of the source field into the corresponding field type in the target database as the recommended field type of the target field.
[0201] S312. Generate a prompt message, which indicates that the source field and the target field are incompatible and the user needs to manually modify the target field.
[0202] First, traditional compatibility verification methods generally rely on manual work, or simply match based on field types. They are unable to conduct in-depth verification of the compatibility between fields, nor can they discover potential precision loss and truncation risks during data synchronization, resulting in errors or data anomalies in the data synchronization process. At this time, manual modification of fields increases duplication of work and brings instability to the data synchronization system. In the embodiment of the present application, the mapping relationship between JDBC encoding and field type is maintained in the field synchronization configuration information, and various field types are abstracted into six categories: STRING, LONG, DOUBLE, DATE, BYTES, and BOOLEAN, thereby avoiding the limitation of point-to-point mapping for each field type. It can make full use of the logic of column size conversion, difference judgment between fixed-point type and floating-point type, and preset value judgment of column size, providing a smarter and more flexible solution for common problems such as precision truncation, numerical range overflow, and character encoding mismatch in real business scenarios.
[0203] Secondly, this embodiment of the application separates the field compatibility verification process from the automatic table creation or data synchronization process, ensuring that field compatibility is verified before data synchronization. Furthermore, when the verification result indicates incompatibility, a suggested field type for the target field can be provided, thereby reducing the likelihood of data synchronization task failures or errors caused by field incompatibility during the data synchronization process.
[0204] In addition, the embodiment of the present application uses the field type classification and verification reasoning mechanism. Even if there is a special preset value for the column size obtained from the database through the JDBC interface, verification reasoning can be automatically performed through the judgment logic of the preset value, thereby ensuring the accuracy of the verification result.
[0205] Furthermore, the embodiment of the present application utilizes the concept of "n→JDBC encoding→n", that is, the field types of different databases are uniformly mapped to the JDBC encoding dimension, so as to centrally manage the mapping configuration of the field types of various databases and provide a visual configuration method. It is not only applicable to the current mainstream databases, but can also be extended to new types of databases or new field types in the database that are subsequently generated, making the evolution process of compatibility verification more maintainable and the implementation cost lower.
[0206] Furthermore, in related technologies, when fields are incompatible, users are either directly asked to reconfigure the fields or the field type with the largest supported storage range is directly recommended without distinction, which not only wastes storage resources, reduces system performance, but also increases the difficulty of subsequent analysis and maintenance. However, the embodiments of the present application can select different suggested field generation methods for different situations, and when selecting a suggested field type, a field type that is compatible with the first field and occupies less storage resources can be selected, thereby reducing storage resource waste, improving system performance, and reducing the difficulty of subsequent analysis and maintenance.
[0207] In summary, the data synchronization method between databases provided in the embodiments of the present application can reduce manual workload while improving the accuracy and robustness of the data synchronization process, making the data distribution and exchange process between large-scale, multi-source heterogeneous databases more efficient and convenient.
[0208] Based on the same inventive concept, corresponding to the above method embodiment, the embodiment of the present application also provides a data synchronization device between databases, such as Figure 4 As shown, the device includes: an acquisition module 401, a determination module 402, a verification module 403 and a synchronization module 404;
[0209] An acquisition module 401 is configured to acquire metadata information of a source field of a source data table in a source database and metadata information of a target field of a target data table in a target database. The metadata information includes a field type and a type code. The type code is a Java Database Connectivity (JDBC) code corresponding to the field type determined based on the database type.
[0210] A determination module 402 is configured to determine a first type category corresponding to the type code of the source field and a second type category corresponding to the type code of the target field based on a preset correspondence between each type code and a type category;
[0211] A verification module 403 is configured to verify whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field when the first type and the second type are the same;
[0212] The synchronization module 404 is used to synchronize data between the source field and the target field when the verification result of the verification module 403 is compatible.
[0213] Optionally, both the first type and the second type represent string types, and the metadata information further includes: column size, string length unit, and encoding method; the verification module 403 is specifically used to:
[0214] If the column size of the source field is not a preset value, the column size of the source field is converted to the target column size based on the string length unit and encoding method of the source field and the string length unit and encoding method of the target field, and a determination is made as to whether the target column size is less than or equal to the column size of the target field, where the target column size indicates the column size required to store the data in the source field in the target field; if so, the verification result is determined to be compatible; otherwise, the verification result is determined to be incompatible;
[0215] When the column size of the source field is a preset value, determine whether the column size of the target field is greater than or equal to the preset value; if so, determine that the verification result is compatible; otherwise, determine that the verification result is incompatible.
[0216] Optionally, both the first type and the second type represent integer types; the verification module 403 is specifically configured to:
[0217] Determine, based on a preset correspondence between each type code and range code of an integer type, a first range code corresponding to the type code of the source field and a second range code corresponding to the type code of the target field; wherein the range of values supported by the field type corresponding to the type code is positively correlated with the size of the range code corresponding to the type code;
[0218] determining whether the first range code is less than or equal to the second range code;
[0219] If so, the verification result is determined to be compatible;
[0220] Otherwise, the verification result is determined to be incompatible.
[0221] Optionally, both the first type and the second type represent non-integer types, which include floating-point types and fixed-point types. The metadata information further includes: column size and number of decimal places. The verification module 403 is specifically configured to:
[0222] If the field types of the source field and the target field are both fixed-point types, determine whether the column size of the source field is less than or equal to the column size of the target field, and whether the number of decimal places of the source field is less than or equal to the number of decimal places of the target field; if the judgment results are both yes, determine the verification result as compatible; otherwise, determine the verification result as incompatible;
[0223] If the field type of the source field and the field type of the target field are both floating-point types, the verification result is determined to be compatible;
[0224] If the field type of the source field is a fixed-point number type, and the field type of the target field is a floating-point number type, the verification result is determined to be incompatible;
[0225] If the field type of the source field is a floating-point type and the field type of the target field is a fixed-point type, determine whether the range of values supported by the field type of the source field is less than or equal to the range of values supported by the field type of the target field; if so, determine that the verification result is compatible; otherwise, determine that the verification result is incompatible.
[0226] Optionally, both the first type and the second type are other types, including date type, binary type, and Boolean type; the verification module 403 is specifically configured to:
[0227] Determine whether the type code of the source field is the same as the type code of the target field, or whether there is an equivalent mapping relationship between the type code of the source field and the type code of the target field in a preset equivalent mapping table;
[0228] If any of the judgment results is yes, then the verification result is determined to be compatible;
[0229] Otherwise, the verification result is determined to be incompatible.
[0230] Optionally, the device further includes:
[0231] A selection module is configured to verify whether the source field and the target field are compatible based on metadata information of the source field and metadata information of the target field. If the verification result shows incompatibility, if the column size of the source field is a preset value, select a field type with a column size greater than or equal to the preset value as a recommended field type for the target field;
[0232] A generation module is used to verify whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field. If the verification result is incompatible, if the column size of the source field is not a preset value, determine whether the target column size of the source field is greater than the column size upper limit of the field type of the target field; if so, select the parent field type of the field type of the target field as the recommended field type; if not, select the field type of the target field as the recommended field type, and determine the target column size as the recommended column size.
[0233] Optionally, the determination module 402 is further configured to:
[0234] After verifying whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field, if the verification result is incompatible, determining, from the field types corresponding to the first type category, a candidate field type whose supported storage range of numerical values is greater than or equal to the supported storage range of numerical values of the source field;
[0235] Select a candidate field type as the suggested field type.
[0236] The present application also provides an electronic device, such as Figure 5 As shown, it includes a processor 501 , a communication interface 502 , a memory 503 and a communication bus 504 , wherein the processor 501 , the communication interface 502 and the memory 503 communicate with each other via the communication bus 504 .
[0237] Memory 503, used for storing computer programs;
[0238] The processor 501 is configured to implement the method steps in the above method embodiment when executing the program stored in the memory 503 .
[0239] The communication bus mentioned in the electronic devices mentioned above can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. This communication bus can be divided into address buses, data buses, control buses, etc. For ease of illustration, only a single thick line is used in the figure, but this does not mean that there is only one bus or only one type of bus.
[0240] The communication interface is used for communication between the above electronic device and other devices.
[0241] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage. Alternatively, the memory may be at least one storage device located away from the processor.
[0242] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components.
[0243] In another embodiment provided by the present application, a computer-readable storage medium is further provided, wherein a computer program is stored in the computer-readable storage medium. When the computer program is executed by a processor, the steps of the above-mentioned method for synchronizing data between any databases are implemented.
[0244] In another embodiment provided by the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any of the data synchronization methods between databases in the above embodiments.
[0245] In the above embodiments, all or part of the embodiments can be implemented using software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, hard disk, tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).
[0246] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply the existence of any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.
[0247] Each embodiment in this specification is described in a related manner. Similar portions between the embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences from other embodiments. In particular, the device embodiments are generally similar to the method embodiments, so their description is relatively simple. For related portions, refer to the description of the method embodiments.
[0248] The above description is only a preferred embodiment of the present application and is not intended to limit the scope of protection of the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application are included in the scope of protection of the present application.
Claims
1. A method for data synchronization between databases, characterized in that: include: Obtain metadata information of a source field of a source data table in a source database and metadata information of a target field of a target data table in a target database, wherein the metadata information includes: a field type and a type code, wherein the type code is a Java Database Connectivity (JDBC) code corresponding to the field type determined based on the database type; Determine, based on a preset correspondence between each type code and type category, a first type category corresponding to the type code of the source field and a second type category corresponding to the type code of the target field; In a case where the first type is the same as the second type, verifying whether the source field is compatible with the target field based on the metadata information of the source field and the metadata information of the target field; When the verification result is compatible, data synchronization is performed on the source field and the target field.
2. The method according to claim 1, characterized in that The first type and the second type both represent string types, and the metadata information further includes: column size, string length unit, and encoding mode; and verifying whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field includes: If the column size of the source field is not a preset value, converting the column size of the source field into a target column size based on the character string length unit and encoding mode of the source field and the character string length unit and encoding mode of the target field, and determining whether the target column size is less than or equal to the column size of the target field, the target column size indicating a column size required to store the data in the source field into the target field; if so, determining that the verification result is compatible; otherwise, determining that the verification result is incompatible; When the column size of the source field is a preset value, determine whether the column size of the target field is greater than or equal to the preset value; if so, determine that the verification result is compatible; otherwise, determine that the verification result is incompatible.
3. The method according to claim 1, characterized in that The first type category and the second type category both represent integer types; The verifying whether the source field is compatible with the target field based on the metadata information of the source field and the metadata information of the target field includes: Determining, based on a preset correspondence between each type code and range code of an integer type, a first range code corresponding to the type code of the source field and a second range code corresponding to the type code of the target field; wherein the range of values supported for storage by the field type corresponding to the type code is positively correlated with the size of the range code corresponding to the type code; determining whether the first range code is less than or equal to the second range code; If so, the verification result is determined to be compatible; Otherwise, the verification result is determined to be incompatible.
4. The method according to claim 1, wherein The first type and the second type both represent non-integer types, the non-integer types including floating-point types and fixed-point types, the metadata information further including: column size and number of decimal places; and verifying whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field, including: If the field type of the source field and the field type of the target field are both fixed-point types, then determining whether the column size of the source field is less than or equal to the column size of the target field, and whether the number of decimal places of the source field is less than or equal to the number of decimal places of the target field; if the judgment results are both yes, determining that the verification result is compatible; otherwise, determining that the verification result is incompatible; If the field type of the source field and the field type of the target field are both floating-point types, determining that the verification result is compatible; If the field type of the source field is a fixed-point number type, and the field type of the target field is a floating-point number type, determining that the verification result is incompatible; If the field type of the source field is a floating-point type and the field type of the target field is a fixed-point type, determine whether the numerical range supported by the field type of the source field is less than or equal to the numerical range supported by the field type of the target field; if so, determine that the verification result is compatible; otherwise, determine that the verification result is incompatible.
5. The method according to claim 1, wherein The first type and the second type are both other types, including date type, binary type, and Boolean type; and verifying whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field includes: Determine whether the type code of the source field is the same as the type code of the target field, or whether there is an equivalent mapping relationship between the type code of the source field and the type code of the target field in a preset equivalent mapping table; If any of the judgment results is yes, then the verification result is determined to be compatible; Otherwise, the verification result is determined to be incompatible.
6. The method according to claim 2, characterized in that After verifying whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field, if the verification result is incompatible, the method further includes: If the column size of the source field is a preset value, selecting a field type with a column size greater than or equal to the preset value as the suggested field type for the target field; If the column size of the source field is not a preset value, determine whether the target column size of the source field is greater than the upper limit of the column size of the field type of the target field; if so, select the parent field type of the field type of the target field as the recommended field type; if not, select the field type of the target field as the recommended field type, and determine the target column size as the recommended column size.
7. The method according to claim 3, characterized in that After verifying whether the source field is compatible with the target field based on the metadata information of the source field and the metadata information of the target field, the method further includes: If the verification result is incompatible, determining, from the field types corresponding to the first type category, a candidate field type whose supported storage value range is greater than or equal to the supported storage value range of the source field; Select a candidate field type as the suggested field type.
8. A data synchronization device between databases, characterized in that: include: An acquisition module is configured to acquire metadata information of a source field of a source data table in a source database and metadata information of a target field of a target data table in a target database, wherein the metadata information includes a field type and a type code, wherein the type code is a Java Database Connectivity (JDBC) code corresponding to the field type determined based on the database type. a determination module, configured to determine, based on a preset correspondence between each type code and a type category, a first type category corresponding to the type code of the source field and a second type category corresponding to the type code of the target field; a verification module, configured to verify whether the source field and the target field are compatible based on the metadata information of the source field and the metadata information of the target field when the first type is the same as the second type; A synchronization module is used to synchronize data between the source field and the target field when the verification result of the verification module is compatible.
9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; Memory for storing computer programs; A processor, configured to implement the method according to any one of claims 1 to 7 when executing a program stored in a memory.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.