Data synchronization method and device, equipment and medium
By using columnar data files and parameter files to generate SQL statements and directly synchronizing data to the target table, the problem of repeated code development and performance consumption in the existing technology is solved, and efficient data synchronization and storage space saving are achieved.
Patent Information
- Application Number
- CN202410818429.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-24
- Publication Date
- 2024-09-10
AI Technical Summary
Existing data synchronization methods need to re-modify the code when processing data files in different formats, resulting in cumbersome repeated code development, high performance consumption, and waste of file storage space.
Column data files are used to obtain the data files and parameter files of the target fields, parse the parameter information, generate structured query language SQL statements, and directly synchronize the field values to the target table, avoiding delimiter analysis and repeated development.
It reduces the file size of columnar data files, saves storage space, improves data synchronization efficiency, shields differences in different formats and tables, and reduces code difference development.
Smart Images

Figure CN118626565A
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of big data intelligent analysis, and in particular to data synchronization methods, devices, equipment and media. Background Art
[0002] At present, when performing data synchronization, most software systems have a business scenario of loading business data in a data file into a data table (referred to as a target table) in a target database (referred to as a target database). The format of the data file is generally one line representing a record in the target table, and a record contains multiple fields, which are separated by delimiters.
[0003] In the related art, the synchronization scheme for business data in a data file is: use Java to develop a data loading program, read the data file line by line through the data loading program, split the field data by a specified delimiter, and then splice the data to get an SQL (Structured Query Language) statement, and then write it to the target table in the target library through JDBC (Java Database Connectivity) or mybatis (a persistence layer framework that encapsulates JDBC) technology.
[0004] However, the above data synchronization method has at least the following problems: 1. The delimiters and fields in data files of different formats may be different. For data files of different formats, they need to be written into different data tables, and the code needs to be modified again, that is, different loading programs need to be developed, and the code duplication development is cumbersome; 2. There are delimiters between multiple fields in the data file, and the loading program needs to parse the delimiters, which consumes a lot of performance and also causes a waste of file storage space. Summary of the invention
[0005] The present disclosure provides a data synchronization method, device, equipment and medium to at least solve one of the technical problems in the related art to a certain extent. The technical solution of the present disclosure is as follows:
[0006] According to a first aspect of an embodiment of the present disclosure, a data synchronization method is provided, including:
[0007] Acquire a columnar data file corresponding to a target field to be synchronized; wherein the columnar data file includes a data file and a parameter file; the data file includes at least one field value under the target field; the parameter file includes parameter information associated with the target field and a target table, and the target table is a data table to which the field value is to be synchronized;
[0008] Parsing the parameter file to obtain the parameter information;
[0009] Generate a structured query language SQL statement according to the parameter information and the field values in the data file;
[0010] Execute the SQL statement to synchronize the field value to the target field in the target table.
[0011] According to a second aspect of an embodiment of the present disclosure, there is provided a data synchronization device, including:
[0012] An acquisition module is used to acquire a columnar data file corresponding to a target field to be synchronized; wherein the columnar data file includes a data file and a parameter file; the data file includes at least one field value under the target field; the parameter file includes parameter information associated with the target field and a target table, and the target table is a data table to which the field value is to be synchronized;
[0013] A parsing module, used for parsing the parameter file to obtain the parameter information;
[0014] A generating module, used for generating a structured query language SQL statement according to the parameter information and the field values in the data file;
[0015] An execution module is used to execute the SQL statement to synchronize the field value to the target field in the target table.
[0016] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the data synchronization method as described in the above embodiment of the present disclosure.
[0017] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device can execute the data synchronization method as described in the above embodiment of the present disclosure.
[0018] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, comprising: a computer program, wherein when the computer program is executed by a processor, the data synchronization method as described in the above embodiment of the present disclosure is implemented.
[0019] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects:
[0020] Data synchronization is performed from the field dimension, that is, for each target field to be synchronized, a columnar data file is generated separately. The data file of the columnar data file only includes the field values under the same field, but does not include the field values of other fields and redundant separators. This can not only reduce the file size of the columnar data file and save file storage space, but also, when synchronizing data, there is no need to consider or parse separators, which can improve data synchronization efficiency. In addition, using columnar data files for data synchronization can shield the differences in existing data file files such as different separators, different data tables, and different fields, reducing the repeated development of code, that is, reducing the difference development of data installation programs.
[0021] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.
[0023] Figure 1 It is a flowchart of the data synchronization method shown in the first embodiment of the present disclosure.
[0024] Figure 2 It is a flowchart of a data synchronization method shown in the second embodiment of the present disclosure.
[0025] Figure 3 It is a schematic diagram of a columnar data file shown in an embodiment of the present disclosure.
[0026] Figure 4 It is a flowchart of a data synchronization method shown in the third embodiment of the present disclosure.
[0027] Figure 5 It is a flowchart of a data synchronization method shown in the fourth embodiment of the present disclosure.
[0028] Figure 6 It is a flowchart of the data synchronization method shown in the fifth embodiment of the present disclosure.
[0029] Figure 7 It is a structural diagram of a data synchronization device shown in the sixth embodiment of the present disclosure.
[0030] Figure 8 It is a schematic structural diagram of an electronic device shown in an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION
[0031] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.
[0032] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0033] It should be noted that the acquisition, storage, use, and processing of data in the technical solution disclosed in this disclosure are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0034] It should also be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.) and signals involved in this disclosure are all authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0035] It should also be noted that in the embodiments of the present disclosure, certain software, components, models and other existing solutions in the industry may be mentioned, which should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present disclosure, but it does not mean that the applicant has or will necessarily use the solution.
[0036] The following describes the data synchronization method, apparatus, device and medium of the embodiments of the present disclosure with reference to the accompanying drawings. Before describing the embodiments of the present disclosure in detail, for ease of understanding, common technical terms are first introduced:
[0037] Database: refers to a warehouse that organizes, stores and manages data according to data structure. A database is a collection of large amounts of data that is stored in a computer for a long time, organized, shareable and uniformly managed.
[0038] Data file: usually refers to a file that stores specific data.
[0039] Loading data: refers to loading the data in the data file into the data table of the database.
[0040] Figure 1 It is a flowchart of the data synchronization method shown in the first embodiment of the present disclosure.
[0041] The embodiment of the present disclosure is illustrated by an example in which the data synchronization method is configured in a data synchronization device. The data synchronization device can be applied to any electronic device so that the electronic device can perform a data synchronization function.
[0042] Among them, the electronic device can be any device with computing capabilities, such as a personal computer, a mobile terminal, a server (or cloud), etc. The mobile terminal can be, for example, a vehicle-mounted device, a mobile phone, a tablet computer, a personal digital assistant, a wearable device, and other hardware devices with various operating systems, touch screens and / or display screens.
[0043] like Figure 1 As shown, the data synchronization method may include the following steps S11 to S14.
[0044] In step S11, a columnar data file corresponding to the target field to be synchronized is obtained; wherein the columnar data file includes a data file and a parameter file; the data file includes at least one field value under the target field; the parameter file includes parameter information associated with the target field and the destination table, and the destination table is the data table to which the field value is to be synchronized.
[0045] In the embodiment of the present disclosure, the target field refers to the field or column to be synchronized, wherein the target field includes but is not limited to: gender, age, address and other fields.
[0046] The number of target fields may be one or more, which is not limited in the embodiment of the present disclosure.
[0047] In the embodiment of the present disclosure, the data file includes at least one field value under the target field, and there is no additional separator in the data file. Each line contains only one field value, that is, each field value is located in a separate line in the data file.
[0048] Among them, each field value under the target field refers to the specific value or record value of the target field. For example, taking age as an example of the target field, the field value can be 25 years old, 31 years old, 42 years old, and so on.
[0049] In the embodiment of the present disclosure, the target table refers to a data table in the target database to which each field value under the target field is to be synchronized.
[0050] In an embodiment of the present disclosure, the parameter file includes parameter information associated with the target field and the target table, wherein the parameter information includes but is not limited to the following information: identification information of the target table (recorded as the first identification information in the present disclosure, for example, the first identification information may be the table name of the target table), the primary key of the target table, identification information of the target field (recorded as the second identification information in the present disclosure, for example, the second identification information may be the field name or column name of the target field), the initial value of the primary key, etc.
[0051] The primary key of the target table includes, but is not limited to, ID (Identifier), single-field primary key (unique field), multi-field primary key (composite primary key), natural primary key (field with business meaning and capable of uniquely identifying records), etc.
[0052] The initial value of the primary key is used to indicate the position of the first row of field values in the data file to be synchronized to the target table. For example, the primary key of the target table is ID for exemplary description. Assuming that the initial value of the primary key is n (n is a natural number), the position of the first row of field values in the data file to be synchronized is the n+1th row in the target table.
[0053] As a possible implementation method, there is no additional separator in the parameter file, and each parameter can be located in a separate line in the parameter file to solve the problem of repeated code development and performance consumption caused by different separators of existing data files in different formats.
[0054] In step S12, the parameter file is parsed to obtain parameter information.
[0055] In the disclosed embodiment, the parameter file in the columnar data file may be parsed to obtain parameter information associated with the target field and the destination table.
[0056] In step S13, a SQL (Structured Query Language) statement is generated according to the parameter information and the field values in the data file.
[0057] In the embodiment of the present disclosure, an SQL statement may be generated according to each parameter in the parameter information and according to the field value in the data file. For example, each parameter and field value in the parameter information may be concatenated to obtain an SQL statement.
[0058] In step S14, an SQL statement is executed to synchronize the field value to the target field in the target table.
[0059] In the embodiment of the present disclosure, an SQL statement may be executed to synchronize the field value in the data file to the target field in the target table.
[0060] The data synchronization method of the disclosed embodiment performs data synchronization from the field dimension, that is, for each target field to be synchronized, a columnar data file is generated separately, and the data file of the columnar data file only includes the field values under the same field, and does not include the field values of other fields and redundant separators. This can not only reduce the file size of the columnar data file and save file storage space, but also, when synchronizing data, there is no need to consider or parse separators, which can improve the data synchronization efficiency. In addition, using a columnar data file for data synchronization can shield the differences in existing data file files such as different separators, different data tables, and different fields, reducing the repeated development of code, that is, reducing the difference development of data installation programs.
[0061] In order to clearly explain how the above embodiments of the present disclosure generate SQL statements according to parameter information and field values in a data file, the present disclosure also proposes a data synchronization method.
[0062] Figure 2 It is a flowchart of a data synchronization method shown in the second embodiment of the present disclosure.
[0063] like Figure 2 As shown, the data synchronization method may include the following steps S21-S26.
[0064] In step S21, a column data file corresponding to the target field to be synchronized is obtained.
[0065] Among them, the columnar data file includes a data file and a parameter file; the data file includes at least one field value under the target field; the parameter file includes parameter information associated with the target field and the destination table, and the destination table is the data table to which the field value is to be synchronized.
[0066] In step S22, the parameter file in the column data file is parsed to obtain parameter information.
[0067] For explanations of steps S21 to S22, reference may be made to the relevant descriptions in any embodiment of the present disclosure and will not be repeated here.
[0068] In step S23, the first identification information and the primary key of the target table are extracted from the parameter information.
[0069] The first identification information is used to uniquely identify the destination table. For example, the first identification information may be the table name of the destination table.
[0070] The primary key of the target table includes, but is not limited to, ID, single-field primary key (a unique field), multi-field primary key (composite primary key), natural primary key (a field with business meaning and that can uniquely identify a record), etc.
[0071] In step S24, the second identification information of the target field is extracted from the parameter information.
[0072] The second identification information is used to uniquely identify the target field. For example, the second identification information may be the field name or column name of the target field.
[0073] In step S25, an SQL statement is generated according to the first identification information, the second identification information, the primary key and the field value in the data file in the columnar data file.
[0074] In the embodiment of the present disclosure, the first identification information, the second identification information, the primary key and the field value in the data file may be concatenated or combined to obtain an SQL statement.
[0075] In any embodiment of the present disclosure, the primary key initial value can also be extracted from the parameter information. In the present disclosure, an SQL statement can be generated based on the first identification information, the second identification information, the primary key, the primary key initial value and the field value in the data file.
[0076] The initial value of the primary key is used to indicate the position of the first row of field values in the data file to be synchronized to the target table. For example, the primary key of the target table is ID for exemplary description. Assuming that the initial value of the primary key is n (n is a natural number), the position of the first row of field values in the data file to be synchronized is the n+1th row in the target table.
[0077] Step S26, executing SQL statements to synchronize the field values to the target fields in the target table.
[0078] For the explanation of step S26, please refer to the relevant description in any embodiment of the present disclosure, which will not be repeated here.
[0079] As an example, take the column data file of the target field as Figure 3 As shown in the example, the table name (tablename) of the target table in the parameter file (ddl file) of the columnar data file is CST_INFO, the field name of the target field (columns) is CST_ID, the primary key (primarykey) of the target table is ID, the initial value (index) of the primary key is 0, and the multiple field values included in the data file (dat file) of the columnar data file are: 111111, 222222, 333333, 444444, ...
[0080] Assuming that the target table is stored in a MySQL database, you can use the loading program to read the ddl file and the dat file, parse the columnar data file of the target field into an SQL statement, and then execute the SQL statement to load the field values in the dat file into the target field of the target table in the MySQL database.
[0081] The data synchronization method of the embodiment of the present disclosure can effectively and accurately generate SQL statements based on the first identification information of the target table in the parameter information, the primary key of the target table, the second identification information of the target field, and the field value in the data file, so as to improve the effectiveness and accuracy of data synchronization.
[0082] In order to clearly explain how to generate SQL statements according to the first identification information, the second identification information, the primary key and the field value in the data file in any of the above embodiments of the present disclosure, the present disclosure also proposes a data synchronization method.
[0083] Figure 4 It is a flowchart of a data synchronization method shown in the third embodiment of the present disclosure.
[0084] like Figure 4 As shown, the data synchronization method may include the following steps S41-S48.
[0085] In step S41, a column data file corresponding to the target field to be synchronized is obtained.
[0086] Among them, the columnar data file includes a data file and a parameter file; the data file includes at least one field value under the target field; the parameter file includes parameter information associated with the target field and the destination table, and the destination table is the data table to which the field value is to be synchronized.
[0087] In step S42, the parameter file in the column data file is parsed to obtain parameter information.
[0088] In step S43, the first identification information and the primary key of the target table are extracted from the parameter information.
[0089] In step S44, the second identification information of the target field is extracted from the parameter information.
[0090] The explanation of steps S41 to S44 can be found in the relevant description in any embodiment of the present disclosure, and will not be repeated here.
[0091] In step S45, the primary key initial value is extracted from the parameter information.
[0092] The initial value of the primary key is used to indicate the position of the first row of field values in the data file to be synchronized to the target table.
[0093] For example, the primary key of the target table is ID for illustrative explanation. Assuming that the initial value of the primary key is n (n is a natural number), the position where the first row of field values in the data file needs to be synchronized is the n+1th row in the target table.
[0094] In step S46, each field value in the data file in the column data file is traversed and read in sequence.
[0095] In the embodiment of the present disclosure, each field value in the data file can be traversed and read in sequence through a single thread.
[0096] With data files as Figure 3 Taking the dat file shown as an example, you can first read the field value "111111", then read the field value "222222", and then read the field value "333333", and so on. They are not listed here one by one.
[0097] In step S47, an SQL statement corresponding to the currently read field value is generated according to the first identification information, the second identification information, the primary key, the initial value of the primary key and the currently read field value.
[0098] In the embodiment of the present disclosure, the position of the currently read field value to be synchronized to the target table can be determined according to the primary key of the target table, the initial value of the primary key and the currently read field value, and the SQL statement corresponding to the currently read field value can be generated based on the position, the first identification information, the second identification information, the primary key and the currently read field value.
[0099] In any embodiment of the present disclosure, the SQL statement corresponding to the currently read field value can be generated by following steps A to C:
[0100] Step A: Get the row number of the row where the currently read field value is located in the data file, that is, determine the row number of the currently read field value in the data file.
[0101] Step B: Determine the primary key target value of the target record in the target table based on the primary key initial value and the row number in step A; wherein the target record is the record whose field value is currently read and is to be synchronized to the target table.
[0102] That is, the primary key target value is used to indicate the row number in the target table to which the currently read field value needs to be synchronized, that is, to indicate the row number in the target table to which the currently read field value needs to be synchronized.
[0103] As an example, when the primary key of the target table is ID, the primary key target value of the target record can be determined based on the sum of the initial value of the primary key and the row number in step A.
[0104] For example, for Figure 3 The first row of the dat file in the table has a field value of "111111", the initial value of the primary key is 0, and the target value of the primary key is 0+1=1, that is, the field value "111111" needs to be synchronized to the first row of the target table; Figure 3The second row field value in the dat file is "222222", and the primary key target value is 0+2=2, that is, the field value "222222" needs to be synchronized to the second row in the destination table.
[0105] As another example, when the primary key of the target table is not ID, you can query the ID of the row where the initial value of the primary key is located in the target table, and determine the primary key target value of the target record based on the sum of the ID of the row where the initial value of the primary key is located and the row number in step A.
[0106] That is to say, if the primary key of the target table is not an ID, the primary key can be mapped to an ID to accurately determine the row number in the target table to which the currently read field value needs to be synchronized. That is, the ID of the row where the primary key initial value is located in the target table and the row number of the row where the currently read field value is located in the data file can be added, and the calculated sum is used as the row number of the currently read field value to be synchronized to the target table.
[0107] In summary, based on the primary key of the target table, the primary key target value used to indicate the row number to be synchronized to the target table for the currently read field value is calculated specifically, which can improve the accuracy of the primary key target value calculation and thus improve the accuracy of the synchronization of the currently read field value.
[0108] Step C: Based on the first identification information, the second identification information, the primary key, the primary key target value and the currently traversed field value, generate an SQL statement corresponding to the currently read field value.
[0109] As an example, the first identification information, the second identification information, the primary key of the target table, the primary key target value and the currently traversed field value may be concatenated or combined to obtain an SQL statement corresponding to the currently read field value.
[0110] The parameter file is Figure 3 The ddl file in the current read field value is Figure 3 Take the first row field value "111111" in the dat file as an example. The primary key target value is 0+1=1, that is, "111111" needs to be synchronized to the first row of the destination table. At this time, the SQL statement used to synchronize the field value "111111" to the target field in the destination table is: insert intoCST_INFO(ID,CST_ID)values(1,111111) on duplicate key CST_ID = values(111111).
[0111] Similarly, when the field value currently read is Figure 3In the case of the second row field value "222222" in the dat file, the field value "222222" needs to be synchronized to the second row in the destination table. The SQL statement for synchronizing the field value "222222" to the target field in the destination table is: insert into CST_INFO(ID,CST_ID)values(2,222222)onduplicate key CST_ID=values(222222).
[0112] Similarly, when the field value currently read is Figure 3 In the case of the field value "iiiiii" in the i-th (i is a positive integer greater than 2) row in the dat file, the field value "iiiiii" needs to be synchronized to the i-th row in the target table. The SQL statement for synchronizing the field value "iiiiii" to the target field in the target table is: insert into CST_INFO(ID,CST_ID)values(i,iiiiii)on duplicate key CST_ID=values(iiiiii).
[0113] In summary, based on the initial value of the primary key and the row number of the row where the currently read field value is located in the data file, the specific position (that is, the specific row number) of the currently read field value to be synchronized to the target table can be accurately located, so that the SQL statement generated based on the specific position can accurately synchronize the currently read field value to the target table, thereby improving the accuracy of data synchronization.
[0114] In step S48, the SQL statement corresponding to the currently read field value is executed to synchronize the currently read field value to the target field in the target table.
[0115] In an embodiment of the present disclosure, an SQL statement corresponding to a field value currently read by a single thread may be executed to synchronize the field value currently read by the single thread to a target field in a target table.
[0116] The data synchronization method of the disclosed embodiment can avoid the omission of synchronizing a certain field value by sequentially traversing and reading each field value in the data file through a single-thread, thereby improving the accuracy of data synchronization.
[0117] In order to clearly explain how to generate SQL statements according to the first identification information, the second identification information, the primary key and the field value in the data file in any of the above embodiments of the present disclosure, the present disclosure also proposes a data synchronization method.
[0118] Figure 5 It is a flowchart of a data synchronization method shown in the fourth embodiment of the present disclosure.
[0119] like Figure 5 As shown, the data synchronization method may include the following steps S51 to S56.
[0120] In step S51, a column data file corresponding to the target field to be synchronized is obtained.
[0121] Among them, the columnar data file includes a data file and a parameter file; the data file includes at least one field value under the target field; the parameter file includes parameter information associated with the target field and the destination table, and the destination table is the data table to which the field value is to be synchronized.
[0122] In step S52, the parameter file in the column data file is parsed to obtain parameter information.
[0123] In step S53, the first identification information and the primary key of the target table are extracted from the parameter information.
[0124] In step S54, the second identification information of the target field is extracted from the parameter information.
[0125] For explanations of steps S51 to S54, reference may be made to the relevant descriptions in any embodiment of the present disclosure and will not be repeated here.
[0126] In step S55, multiple threads are called in parallel to execute the statement generation task to generate an SQL statement corresponding to each field value in the data file in the columnar data file.
[0127] In the embodiment of the present disclosure, multiple threads may be called in parallel to execute a statement generation task, wherein any one thread executes a statement generation task, specifically including the following steps 1 to 3:
[0128] Step 1: The thread may extract the initial value of the primary key from the parameter information; wherein the initial value of the primary key is used to indicate the position of the first row of field values in the data file to be synchronized to the target table.
[0129] Step 2: The thread can read the field values that are not read by other threads from the data file.
[0130] As an example, any thread can read field values that have not been read by other threads from the data file according to the read status of each field value in the data file, and update the read status of the field value currently read by the thread to the read status.
[0131] The read status includes a read status and an unread status.
[0132] As another example, any thread may read unmarked field values from various field values in the data file, and mark the field value currently read by the thread; wherein the mark is used to indicate that the field value has been read by the thread.
[0133] In summary, field values that are not read by other threads can be read from the data file in different ways, which can improve the flexibility and applicability of the method.
[0134] Step 3: Generate an SQL statement corresponding to the field value currently read by the thread according to the first identification information, the second identification information, the primary key, the primary key initial value and the field value currently read by the thread. The implementation principle is similar to that of step C in step S47, and will not be repeated here.
[0135] In step S56, the SQL statement corresponding to each field value is executed to synchronize each field value to the target field in the destination table, or the SQL statement corresponding to the field value currently read by each thread is executed to synchronize the currently read field value to the target field in the destination table.
[0136] In the embodiment of the present disclosure, after multiple threads have completed the statement generation task, the SQL statements corresponding to all field values can be uniformly executed to synchronize all field values to the target field in the destination table. Alternatively, each time a thread has completed the statement generation task, the SQL statement corresponding to the field value currently read by the thread can be executed to synchronize the field value currently read by the thread to the target field in the destination table. The embodiment of the present disclosure does not limit this.
[0137] The data synchronization method of the disclosed embodiment can improve the efficiency of data synchronization and shorten the data synchronization cycle by reading various field values in a data file in parallel through multiple threads.
[0138] In order to clearly explain how to obtain a column data file corresponding to a target field to be synchronized in any of the above embodiments of the present disclosure, the present disclosure also proposes a data synchronization method.
[0139] Figure 6 It is a flowchart of the data synchronization method shown in the fifth embodiment of the present disclosure.
[0140] like Figure 6 As shown, the data synchronization method may include the following steps S61 to S66.
[0141] In step S61, a data file is exported from a source table containing the target field to be synchronized; wherein the data file includes the updated field value under the target field in the source table.
[0142] In the embodiment of the present disclosure, the source table refers to a data table in a source database storing all field values under a target field.
[0143] In an embodiment of the present disclosure, the data file may include updated field values under the target field in the source table, wherein the updated field values include but are not limited to: newly added field values, deleted field values, modified field values, etc., that is, the data file includes incrementally updated field values under the target field.
[0144] In step S62, in response to the configuration operation triggered on the target field, a parameter file is configured.
[0145] In the embodiment of the present disclosure, the parameter file associated with the target field can be manually configured by relevant personnel, that is, the parameter file of the target field can be configured in response to the configuration operation triggered by the relevant personnel on the target field. The parameter file includes parameter information associated with the target field and the target table, and the target table is the data table to which the updated field value under the target field is to be synchronized.
[0146] In step S63, a column data file corresponding to the target field is generated according to the data file and the parameter file.
[0147] That is, the column data file of the target field includes both the data file and the parameter file of the target field.
[0148] In step S64, the parameter file is parsed to obtain parameter information.
[0149] In step S65, an SQL statement is generated according to the parameter information and the field values in the data file.
[0150] In step S66, an SQL statement is executed to synchronize the field value to the target field in the target table.
[0151] The explanation of steps S64 to S66 can be found in the relevant description in any embodiment of the present disclosure, and will not be repeated here.
[0152] The data synchronization method of the disclosed embodiment can synchronize only the incremental updated data in the source table, further improving the data synchronization efficiency.
[0153] In any one of the embodiments of the present disclosure, the present disclosure provides a design scheme for a columnar data file for use in database loading, wherein each field of each data table is a column, and a columnar data file is generated separately, and loading is performed from the field dimension, thereby shielding the differences in existing data file files such as different delimiters, different library tables, and different fields.
[0154] Among them, the column data file of a field in a data table consists of two parts: Figure 3 The parameter file (ddl file) and data file (dat file) shown in the figure,
[0155] 1. DDL file: parameter file of columnar data file, providing various loading parameters. The specific parameter configuration is as follows:
[0156] tablename: the name of the database table to be loaded, that is, the name of the target table, for example, it is configured as: CST_INFO;
[0157] columns: the field name of the library table, that is, the field name of the target field to be synchronized, for example, it is configured as: CST_ID;
[0158] primarykey: the primary key of the database table, that is, the primary key of the target table, for example, configured as: ID.
[0159] index: the initial value of the primary key, usually concatenated with the row number of the field value in the dat file of the columnar data file to form the primary key, for example, it is configured as: 0.
[0160] 2. dat file: a data file of a columnar data file, which provides all the field values of the columns field in the ddl file.
[0161] 3. Processing of columnar data files: The data loading program first reads the ddl file to know which table, field, primary key field of this table, how to concatenate primary keys, and other parameters. Then it reads the dat file. Each line is the specific value of the target field in a record, without separator processing. Then the data loading program will parse the field value into SQL statements and load it into the target field of the target table through JDBC or mybatis.
[0162] In summary, the design scheme of the columnar data file for use in database installation provided by the present disclosure can shield the differences in delimiters, library tables, and fields in the existing data file files by using the columnar data files, thereby reducing the difference development of the installation program; and, since the columnar data file has no extra delimiters, the size of the file is reduced, the file storage space is saved, and the transmission efficiency is improved. At the same time, the installation program does not need to consider the delimiters when processing, thereby improving the processing efficiency of the installation program.
[0163] With the above Figures 1 to 6 Corresponding to the data synchronization method provided in the embodiment, the present disclosure also provides a data synchronization device. Figures 1 to 6 The data synchronization method provided in the embodiment corresponds to the embodiment, so the implementation of the data synchronization method is also applicable to the data synchronization device provided in the embodiment of the present disclosure, and will not be described in detail in the embodiment of the present disclosure.
[0164] Figure 7 It is a structural diagram of a data synchronization device shown in the sixth embodiment of the present disclosure.
[0165] Reference Figure 7 The data synchronization device 700 may include: an acquisition module 710, a parsing module 720, a generation module 730 and an execution module 740.
[0166] The acquisition module 710 is used to acquire a columnar data file corresponding to the target field to be synchronized; wherein the columnar data file includes a data file and a parameter file; the data file includes at least one field value under the target field; the parameter file includes parameter information associated with the target field and the target table, and the target table is the data table to which the field value is to be synchronized;
[0167] The parsing module 720 is used to parse the parameter file to obtain parameter information;
[0168] A generating module 730, for generating a structured query language SQL statement according to the parameter information and the field values in the data file;
[0169] The execution module 740 is used to execute SQL statements to synchronize the field value to the target field in the target table.
[0170] In a possible implementation of the embodiment of the present disclosure, the generation module 730 is specifically used to: extract the first identification information and primary key of the target table from the parameter information; extract the second identification information of the target field from the parameter information; generate an SQL statement based on the first identification information, the second identification information, the primary key and the field value in the data file.
[0171] In a possible implementation of the embodiment of the present disclosure, the generation module 730 is specifically used to: extract the initial value of the primary key from the parameter information; wherein the initial value of the primary key is used to indicate the position of the first row of field values in the data file to be synchronized to the target table; traverse and read each field value in the data file in turn; and generate an SQL statement corresponding to the currently read field value based on the first identification information, the second identification information, the primary key, the initial value of the primary key and the currently read field value.
[0172] In a possible implementation of the embodiment of the present disclosure, the generation module 730 is specifically used to: call multiple threads in parallel to execute the statement generation task to generate an SQL statement corresponding to each field value in the data file;
[0173] Among them, any thread executes the statement generation task, specifically: extracting the initial value of the primary key from the parameter information; wherein the initial value of the primary key is used to indicate the position of the first row of field values in the data file to be synchronized to the target table; reading the field values that have not been read by other threads from the data file; generating the SQL statement corresponding to the currently read field value according to the first identification information, the second identification information, the primary key, the initial value of the primary key and the currently read field value.
[0174] In a possible implementation of the embodiments of the present disclosure, the generation module 730 is specifically used to: read field values that have not been read by other threads from the data file according to the reading status of each field value in the data file, and update the reading status of the field value currently read by any thread to the read status; or, read unmarked field values from each field value in the data file, and mark the field value currently read by any thread; wherein the mark is used to indicate that the field value has been read by the thread.
[0175] In a possible implementation of the embodiment of the present disclosure, the generation module 730 is specifically used to: obtain the row number of the row where the currently read field value is located in the data file; determine the primary key target value of the target record in the target table according to the primary key initial value and the row number; wherein the target record is the record in the target table to be synchronized with the currently read field value; based on the first identification information, the second identification information, the primary key, the primary key target value and the currently traversed field value, generate an SQL statement corresponding to the currently read field value.
[0176] In a possible implementation of the embodiment of the present disclosure, the generation module 730 is specifically used to: in response to the primary key being an ID, determine the primary key target value of the target record based on the sum of the primary key initial value and the row number; in response to the primary key not being an ID, query the ID of the row where the primary key initial value is located in the target table; determine the primary key target value of the target record based on the sum of the ID of the row where the primary key initial value is located and the row number.
[0177] In a possible implementation of the embodiment of the present disclosure, the execution module 740 is specifically used to: execute the SQL statement corresponding to the currently read field value to synchronize the currently read field value to the target field in the target table.
[0178] In a possible implementation of the embodiment of the present disclosure, the acquisition module 710 is specifically used to: export a data file from a source table containing a target field to be synchronized; wherein the data file includes updated field values under the target field in the source table; configure a parameter file in response to a configuration operation triggered on the target field; and generate a columnar data file corresponding to the target field based on the data file and the parameter file.
[0179] The data synchronization device of the disclosed embodiment performs data synchronization from the field dimension, that is, for each target field to be synchronized, a columnar data file is generated separately, and the data file of the columnar data file only includes the field values under the same field, and does not include the field values of other fields and redundant separators. This can not only reduce the file size of the columnar data file and save file storage space, but also, when synchronizing data, there is no need to consider or parse separators, which can improve the data synchronization efficiency. In addition, using a columnar data file for data synchronization can shield the differences in existing data file files such as different separators, different data tables, and different fields, reducing the repeated development of code, that is, reducing the difference development of data installation programs.
[0180] In an exemplary embodiment, the present disclosure also provides an electronic device.
[0181] Among them, electronic equipment includes:
[0182] processor;
[0183] a memory for storing processor-executable instructions;
[0184] The processor is configured to execute instructions to implement the data synchronization method proposed in any of the aforementioned embodiments.
[0185] As an example, Figure 8 is a schematic diagram of the structure of an electronic device 800 shown in an exemplary embodiment of the present disclosure, such as Figure 8 As shown, the electronic device 800 may further include:
[0186] The memory 810 and the processor 820, a bus 830 connecting different components (including the memory 810 and the processor 820), the memory 810 stores a computer program, and when the processor 820 executes the program, the data synchronization method described in the embodiment of the present disclosure is implemented.
[0187] Bus 830 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. For example, these architectures include but are not limited to Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus and Peripheral Component Interconnect (PCI) bus.
[0188] The electronic device 800 typically includes a variety of electronic device readable media. These media can be any available media that can be accessed by the electronic device 800, including volatile and non-volatile media, removable and non-removable media.
[0189] The memory 810 may also include computer system readable media in the form of volatile memory, such as random access memory (RAM) 840 and / or cache memory 850. The server 800 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 860 may be used to read and write non-removable, non-volatile magnetic media ( Figure 8 not shown, usually called a "hard drive"). Although Figure 8 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 830 via one or more data medium interfaces. The memory 810 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present disclosure.
[0190] A program / utility 880 having a set (at least one) of program modules 870 may be stored, for example, in the memory 810, such program modules 870 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules 870 generally perform the functions and / or methods of the embodiments described in the present disclosure.
[0191] The electronic device 800 may also communicate with one or more external devices 890 (e.g., keyboard, pointing device, display 891, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 800, and / or may communicate with any device that enables the electronic device 800 to communicate with one or more other computing devices (e.g., network card, modem, etc.). Such communication may be performed via an input / output (I / O) interface 892. Furthermore, the electronic device 800 may also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN) and / or public network, such as the Internet) via a network adapter 893. As shown, the network adapter 893 communicates with other modules of the electronic device 800 via a bus 830. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 800, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0192] The processor 820 executes various functional applications and data processing by running the programs stored in the memory 810 .
[0193] It should be noted that the implementation process and technical principles of the electronic device of this embodiment refer to the aforementioned explanation of the data synchronization method of the embodiment of the present disclosure, and will not be repeated here.
[0194] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory including instructions, and the above instructions can be executed by a processor of an electronic device to complete the method proposed in any of the above embodiments. Optionally, the computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0195] In an exemplary embodiment, a computer program product is also provided, including a computer program / instruction, wherein the computer program / instruction implements the method proposed in any of the above embodiments when executed by a processor.
[0196] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0197] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A data synchronization method, characterized in that: include: Acquire a columnar data file corresponding to a target field to be synchronized; wherein the columnar data file includes a data file and a parameter file; the data file includes at least one field value under the target field; the parameter file includes parameter information associated with the target field and a target table, and the target table is a data table to which the field value is to be synchronized; Parsing the parameter file to obtain the parameter information; Generate a structured query language SQL statement according to the parameter information and the field values in the data file; Execute the SQL statement to synchronize the field value to the target field in the target table.
2. The method according to claim 1, characterized in that Generating a structured query language SQL statement according to the parameter information and the field value in the data file includes: Extracting the first identification information and the primary key of the target table from the parameter information; Extracting second identification information of the target field from the parameter information; The SQL statement is generated according to the first identification information, the second identification information, the primary key and the field value in the data file.
3. The method according to claim 2, characterized in that The generating the SQL statement according to the first identification information, the second identification information, the primary key and the field value in the data file includes: Extracting the primary key initial value from the parameter information; wherein the primary key initial value is used to indicate the position of the first row of the field value in the data file to be synchronized to the target table; Traverse and read each field value in the data file in sequence; An SQL statement corresponding to the currently read field value is generated according to the first identification information, the second identification information, the primary key, the initial value of the primary key and the currently read field value.
4. The method according to claim 2, characterized in that: The generating the SQL statement according to the first identification information, the second identification information, the primary key and the field value in the data file includes: Invoke multiple threads in parallel to execute statement generation tasks, so as to generate SQL statements corresponding to each field value in the data file; Among them, any thread executes the statement generation task, specifically: Extracting the primary key initial value from the parameter information; wherein the primary key initial value is used to indicate the position of the first row of the field value in the data file to be synchronized to the target table; Reading field values that have not been read by other threads from the data file; An SQL statement corresponding to the currently read field value is generated according to the first identification information, the second identification information, the primary key, the initial value of the primary key and the currently read field value.
5. The method according to claim 4, characterized in that The reading, from the data file, field values that have not been read by other threads includes: According to the read status of each field value in the data file, read the field values that have not been read by other threads from the data file, and update the read status of the field value currently read by any thread to the read status; or, From each field value in the data file, read the unmarked field value, and mark the field value currently read by any thread; wherein the mark is used to indicate that the field value has been read by the thread.
6. The method according to claim 3 or 4, characterized in that: The step of generating an SQL statement corresponding to the currently read field value according to the first identification information, the second identification information, the primary key, the initial value of the primary key, and the currently read field value includes: Obtain the row number of the row where the currently read field value is located in the data file; Determine the primary key target value of the target record in the target table according to the primary key initial value and the row number; wherein the target record is the record whose field value currently read is to be synchronized to the target table; Based on the first identification information, the second identification information, the primary key, the primary key target value and the currently traversed field value, an SQL statement corresponding to the currently read field value is generated.
7. The method according to claim 6, characterized in that Determining the primary key target value of the target record in the target table according to the primary key initial value and the row number includes: In response to the primary key being ID, determining a primary key target value of the target record according to the sum of the primary key initial value and the row number; In response to the primary key not being an ID, querying the ID of the row in the target table where the initial value of the primary key is located; The primary key target value of the target record is determined according to the sum of the ID of the row where the primary key initial value is located and the row number.
8. The method according to claim 3 or 4, characterized in that: The executing the SQL statement to synchronize the field value to the target field in the target table includes: Execute the SQL statement corresponding to the currently read field value to synchronize the currently read field value to the target field in the target table.
9. The method according to any one of claims 1 to 4, characterized in that: The step of obtaining a column-based data file corresponding to a target field to be synchronized includes: Exporting the data file from a source table containing the target field to be synchronized; wherein the data file includes the updated field value under the target field in the source table; In response to a configuration operation triggered on the target field, configuring the parameter file; A columnar data file corresponding to the target field is generated according to the data file and the parameter file.
10. A data synchronization device, characterized in that: include: An acquisition module is used to acquire a columnar data file corresponding to a target field to be synchronized; wherein the columnar data file includes a data file and a parameter file; the data file includes at least one field value under the target field; the parameter file includes parameter information associated with the target field and a target table, and the target table is a data table to which the field value is to be synchronized; A parsing module, used for parsing the parameter file to obtain the parameter information; A generating module, used for generating a structured query language SQL statement according to the parameter information and the field values in the data file; An execution module is used to execute the SQL statement to synchronize the field value to the target field in the target table.
11. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the data synchronization method as described in any one of claims 1 to 9. 12 . A computer-readable storage medium, when instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the data synchronization method according to claim 1 .
13. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the data synchronization method according to any one of claims 1 to 9 is implemented.
