Method, device, electronic device and storage medium for importing data
By creating a temporary table consistent with the target table structure in the Oracle database, importing the data and replacing the original table, the problem of data queries being empty or incomplete during the data import process is solved, and the import efficiency and data consistency are improved.
Patent Information
- Application Number
- CN202111456419.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-02
- Publication Date
- 2024-12-20
- Estimated Expiration
- 2041-12-02
AI Technical Summary
When importing data into the target table of Oracle database, data queries are often empty or incomplete. The existing technology requires clearing the target table data before importing, resulting in inefficiency and inconsistency in data.
By creating a temporary table consistent with the original table structure, importing all data into the temporary table, and replacing the target table without clearing the original table data, the problem of empty or incomplete data during the data import process is solved, and the data query is improved Import efficiency.
It realizes updating the target table data to the latest state in a short time, avoiding the situation where data queries are empty or incomplete, and improving the efficiency of data import.
Smart Images

Figure CN114064783B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method, device, electronic device and storage medium for importing data. Background Art
[0002] Since different databases have different external interfaces, the methods of obtaining data in the database are also different, resulting in the need for customized development of data interaction between different databases. Data file interaction is the most convenient and universal method of data interaction between different databases. Oracle, as a commonly used OLTP database, often receives data from the outside in the form of files.
[0003] Currently, when importing file data into a target table in an Oracle database, it is necessary to first clear all the data in the target table before importing the file data into the target table. However, during the process of importing file data into the target table, the data query may be empty or incomplete. Summary of the invention
[0004] To solve the existing technical problems, the embodiments of the present application provide a method, device, electronic device and storage medium for importing data, which can solve the problem that the data query is empty or incomplete when importing data into a target table.
[0005] To achieve the above purpose, the technical solution of the embodiment of the present application is implemented as follows:
[0006] In a first aspect, an embodiment of the present application provides a method for importing data, the method comprising:
[0007] In response to an instruction to fully import data, the full amount of data to be imported is obtained, and a first original table in the database into which the full amount of data to be imported needs to be imported is determined;
[0008] Acquire the table structure of the first original table, and create a temporary table in the database that is consistent with the table structure of the first original table;
[0009] The full amount of data to be imported is imported into the temporary table to obtain a target table, and the first original table is replaced by the target table.
[0010] The method for importing data provided by the embodiment of the present application can obtain the full amount of data to be imported in response to the instruction of importing the data in full, and determine the first original table in the database into which the full amount of data to be imported needs to be imported. After obtaining the table structure of the first original table, a temporary table consistent with the table structure of the first original table can be created in the database to import the full amount of data to be imported into the temporary table to obtain the target table, and replace the first original table with the target table. Since the import of the full amount of data can be completed by first creating a temporary table, importing the full amount of data into the temporary table to obtain the target table, and then replacing the original table with the target table, there is no need to clear the data in the original table in full before importing new data, which prevents the situation where the data query is empty or incomplete during the process of importing the full amount of data, and the data in the original table can be switched to the latest data in a relatively short time, thereby improving the efficiency of importing data.
[0011] In an optional embodiment, the acquiring the table structure of the first original table and creating a temporary table in the database that is consistent with the table structure of the first original table includes:
[0012] Determining configuration parameter information corresponding to the first original table according to the table structure of the first original table;
[0013] Based on the configuration parameter information, a temporary table having a table structure consistent with the first original table is created in the database.
[0014] In this embodiment, the configuration parameter information corresponding to the first original table can be determined according to the table structure of the first original table, and based on the configuration parameter information, a temporary table with the same table structure as the first original table is created in the database. Thus, the created temporary table can be consistent with the table structure of the original table to be imported with full data.
[0015] In an optional embodiment, the configuration parameter information also includes index information and constraint information of the first original table; after obtaining the target table, the method further includes:
[0016] The index information and constraint information of the target table are created, the first original table is deleted, and the index information and constraint information of the target table are changed to be consistent with the index information and constraint information of the first original table.
[0017] In this embodiment, the configuration parameter information may also include the index information and constraint information of the first original table. After the full amount of data to be imported is imported into the temporary table and the target table is obtained, the index information and constraint information of the target table may be created, the first original table may be deleted, and the index information and constraint information of the target table may be changed to be consistent with the index information and constraint information of the first original table. Thus, the original index information and constraint information in the original table may be retained, and the replacement from the original table to the target table may be completed.
[0018] In an optional embodiment, the method further includes:
[0019] In response to an instruction to incrementally import data, the incremental data to be imported is acquired, and a second original table in the database into which the incremental data to be imported needs to be imported is determined;
[0020] Matching the incremental data to be imported with the data in the second original table to determine target data in the second original table that matches the incremental data to be imported;
[0021] The target data is deleted from the second original table, and the incremental data to be imported is imported into the second original table after the target data is deleted.
[0022] In this embodiment, in response to an instruction to incrementally import data, the incremental data to be imported can be obtained, and the second original table in the database into which the incremental data to be imported needs to be imported is determined, the incremental data to be imported is matched with the data in the second original table, the target data in the second original table that matches the incremental data to be imported is determined, and then the target data is deleted from the second original table, and the incremental data to be imported is imported into the second original table after the target data is deleted. Since the incremental data can be imported by first matching the incremental data with the data in the original table into which the incremental data is to be imported, determining the matching target data, deleting the target data from the original table, and then importing the incremental data into the original table, the problem that the related art only supports importing new data into a blank table, does not support importing new data into a table with existing data, and cannot update and replace existing data in the table can be solved.
[0023] In an optional embodiment, matching the incremental data to be imported with the data in the second original table to determine target data in the second original table that matches the incremental data to be imported includes:
[0024] Obtaining configuration parameter information corresponding to the second original table according to the table structure of the second original table, and determining a plurality of table data included in the second original table according to the configuration parameter information;
[0025] For each table data, the following operations are performed respectively: the table data is matched with multiple incremental data included in the incremental data to be imported, and if the table data matches the set incremental data in the multiple incremental data, the table data is used as the target data.
[0026] In this embodiment, the configuration parameter information corresponding to the second original table can be obtained according to the table structure of the second original table, and the multiple table data included in the second original table can be determined according to the configuration parameter information. For each table data, the following operations can be performed respectively: the table data is matched with multiple incremental data included in the incremental data to be imported, and if the table data matches the set incremental data in the multiple incremental data, the table data is used as the target data. Thus, the target data matching the incremental data in the original table can be determined by matching the incremental data with the multiple table data in the original table one by one.
[0027] In an optional embodiment, deleting the target data from the second original table, and importing the incremental data to be imported into the second original table after deleting the target data, includes:
[0028] Determine the set number of table data items and the set number of incremental data items to be matched each time, and perform the following operations for each table data item in each match:
[0029] Matching the table data with the set number of incremental data respectively, if the table data matches the set incremental data in the set number of incremental data, deleting the table data from the second original table, and importing the set number of incremental data into the second original table from which the table data is deleted;
[0030] If the table data does not match the set number of incremental data, the set number of incremental data is imported into the second original table.
[0031] In this embodiment, the set number of table data and the set number of incremental data to be matched each time are determined, and for each table data in each match, the following operations can be performed respectively: the table data is matched with the set number of incremental data respectively, if the table data matches the set incremental data in the set number of incremental data, the table data is deleted from the second original table, and the set number of incremental data is imported into the second original table where the table data is deleted, if the table data does not match the set number of incremental data, the set number of incremental data is imported into the second original table. Thus, the table data in the original table that matches the incremental data can be determined in batches, and the process of deleting the matched table data from the original table and importing the incremental data that is matched this time into the original table is executed each time, and the import of the incremental data is finally completed.
[0032] In a second aspect, an embodiment of the present application further provides a device for importing data, including:
[0033] A first import determination unit, configured to obtain the full amount of data to be imported in response to an instruction to fully import data, and determine a first original table in the database into which the full amount of data to be imported needs to be imported;
[0034] a temporary table creation unit, configured to obtain the table structure of the first original table, and create a temporary table in the database having the same table structure as the first original table;
[0035] The target table replacement unit is used to import the full amount of data to be imported into the temporary table to obtain a target table, and replace the first original table with the target table.
[0036] In an optional embodiment, the temporary table creation unit is specifically used to:
[0037] Determining configuration parameter information corresponding to the first original table according to the table structure of the first original table;
[0038] Based on the configuration parameter information, a temporary table having a table structure consistent with the first original table is created in the database.
[0039] In an optional embodiment, the configuration parameter information also includes index information and constraint information of the first original table; and the target table replacement unit is further configured to:
[0040] The index information and constraint information of the target table are created, the first original table is deleted, and the index information and constraint information of the target table are changed to be consistent with the index information and constraint information of the first original table.
[0041] In an optional embodiment, the device further includes:
[0042] A second import determination unit is used to obtain the incremental data to be imported in response to the instruction of incrementally importing data, and determine a second original table in the database into which the incremental data to be imported needs to be imported;
[0043] a matching data determination unit, configured to match the incremental data to be imported with the data in the second original table, and determine target data in the second original table that matches the incremental data to be imported;
[0044] A data importing unit is used to delete the target data from the second original table, and import the incremental data to be imported into the second original table after deleting the target data.
[0045] In an optional embodiment, the matching data determination unit is specifically configured to:
[0046] Obtaining configuration parameter information corresponding to the second original table according to the table structure of the second original table, and determining a plurality of table data included in the second original table according to the configuration parameter information;
[0047] For each table data, the following operations are performed respectively: the table data is matched with multiple incremental data included in the incremental data to be imported, and if the table data matches the set incremental data in the multiple incremental data, the table data is used as the target data.
[0048] In an optional embodiment, the data importing unit is specifically used to:
[0049] Determine the set number of table data items and the set number of incremental data items to be matched each time, and perform the following operations for each table data item in each match:
[0050] Matching the table data with the set number of incremental data respectively, if the table data matches the set incremental data in the set number of incremental data, deleting the table data from the second original table, and importing the set number of incremental data into the second original table from which the table data is deleted;
[0051] If the table data does not match the set number of incremental data, the set number of incremental data is imported into the second original table.
[0052] In a third aspect, an embodiment of the present application further 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 for importing data of the first aspect is implemented.
[0053] In a fourth aspect, an embodiment of the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the computer program is executed by the processor, the processor implements the method for importing data of the first aspect.
[0054] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes computer instructions, and the computer instructions are stored in a computer-readable storage medium; when a processor of a computer device reads the computer instructions from the computer-readable storage medium, the processor executes the computer instructions, so that the computer device performs the steps of any one of the above-mentioned methods for importing data.
[0055] The technical effects brought about by any one of the implementation methods in the second to fifth aspects can refer to the technical effects brought about by the corresponding implementation method in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0057] Figure 1 A flowchart of a method for importing data provided in an embodiment of the present application;
[0058] Figure 2 A flowchart of another method for importing data provided in an embodiment of the present application;
[0059] Figure 3 A flowchart of another method for importing data provided in an embodiment of the present application;
[0060] Figure 4 A flowchart of another method for importing data provided in an embodiment of the present application;
[0061] Figure 5 A flowchart of another method for importing data provided in an embodiment of the present application;
[0062] Figure 6 A schematic diagram of the structure of a device for importing data provided in an embodiment of the present application;
[0063] Figure 7 A schematic diagram of the structure of another device for importing data provided in an embodiment of the present application;
[0064] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0065] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.
[0066] It should be noted that the terms "including" and "having" and their variations involved in the documents of this application are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0067] Some of the terms used in the embodiments of the present application are explained below to facilitate understanding by those skilled in the art.
[0068] Oracle: It is a relational database management system from Oracle Corporation. It includes a set of programs (database management system software) for logically organizing and accessing data that are interconnected. A relational database management system is a system that manages relational databases and organizes data logically.
[0069] Spring batch: is a lightweight and perfect large-scale batch processing framework. It uses JAVA language and is based on the Spring framework. It provides logging, tracing, transactions, task job statistics, task restart, skip, repeat, and resource management components.
[0070] The technical solution provided in the embodiments of the present application will be described in detail below with reference to the accompanying drawings.
[0071] The word "exemplary" used hereinafter means "serving as an example, embodiment, or illustrative". Any embodiment described as "exemplary" is not necessarily to be interpreted as superior or better than other embodiments. In the description of the embodiments of the present application, unless otherwise specified, "plurality" means two or more.
[0072] The present application embodiment provides a method for importing data, such as Figure 1 As shown, the following steps are included:
[0073] Step S101, in response to an instruction to fully import data, obtain the full amount of data to be imported, and determine a first original table in the database into which the full amount of data to be imported needs to be imported.
[0074] When all data is imported into an Oracle database, the all data to be imported may be obtained, and a first original table into which the all data needs to be imported may be determined in the Oracle database.
[0075] Step S102: Acquire the table structure of the first original table, and create a temporary table in the database that is consistent with the table structure of the first original table.
[0076] Specifically, the configuration parameter information corresponding to the first original table may be determined according to the table structure of the first original table, and based on the configuration parameter information, a temporary table consistent with the table structure of the first original table may be created in the database.
[0077] Step S103: Import the full amount of data to be imported into a temporary table to obtain a target table, and replace the first original table with the target table.
[0078] Specifically, since the determined configuration parameter information also includes the index information and constraint information of the first original table, after the full amount of data to be imported is imported into the temporary table and the target table is obtained, the index information and constraint information of the target table can also be created, and the first original table can be deleted, and the index information and constraint information of the target table can be changed to be consistent with the index information and constraint information of the first original table.
[0079] In one embodiment, the present application also provides a method for importing data, such as Figure 2 As shown, the following steps are included:
[0080] Step S201 , in response to an instruction for incrementally importing data, obtaining incremental data to be imported, and determining a second original table in the database into which the incremental data to be imported needs to be imported.
[0081] When incrementally importing data into an Oracle database, the incremental data to be imported may be obtained, and a second original table into which the incremental data needs to be imported may be determined in the Oracle database.
[0082] Step S202, matching the incremental data to be imported with the data in the second original table, and determining target data in the second original table that matches the incremental data to be imported.
[0083] Specifically, the configuration parameter information corresponding to the second original table can be obtained according to the table structure of the second original table, and the plurality of table data included in the second original table can be determined according to the configuration parameter information.
[0084] Then, for each table data, the following operations may be performed respectively: the table data is matched with multiple incremental data included in the incremental data to be imported respectively, and if the table data matches the set incremental data in the multiple incremental data, the table data is used as the target data.
[0085] Step S203, deleting the target data from the second original table, and importing the incremental data to be imported into the second original table after deleting the target data.
[0086] Specifically, the set number of table data items and the set number of incremental data items to be matched each time may be determined first, and then the following operations may be performed for each table data item in each match:
[0087] Matching the table data with the set number of incremental data respectively, if the table data matches the set incremental data in the set number of incremental data, deleting the table data from the second original table, and importing the set number of incremental data into the second original table from which the table data is deleted;
[0088] If the table data does not match the set number of incremental data, the set number of incremental data is imported into the second original table.
[0089] For example, the incremental data to be imported includes 6 data items, namely data A1, data A2, data A3, data A4, data A5 and data A6. The original table into which the incremental data needs to be imported includes 8 table data items, namely table data B1, table data B2, table data B3, table data B4, table data B5, table data B6, table data B7 and table data B8. Each time, 4 table data items in the original table can be matched with 3 data items in the incremental data respectively.
[0090] First matching: Table data B1, table data B2, table data B3 and table data B4 are matched with data A1, data A2 and data A3 respectively, that is, table data B1 is matched with data A1, data A2 and data A3 respectively, table data B2 is matched with data A1, data A2 and data A3 respectively, table data B3 is matched with data A1, data A2 and data A3 respectively, and table data B4 is matched with data A1, data A2 and data A3 respectively. After matching, it is determined that table data B2 matches data A2 and table data B3 matches data A3, then table data B3 and table data B3 can be deleted from the original table, and data A1, data A2 and data A3 are imported into the original table.
[0091] Second matching: Table data B5, table data B6, table data B7 and table data B8 are matched with data A4, data A5 and data A6 respectively, that is, table data B5 is matched with data A4, data A5 and data A6 respectively, table data B6 is matched with data A4, data A5 and data A6 respectively, table data B7 is matched with data A4, data A5 and data A6 respectively, and table data B8 is matched with data A4, data A5 and data A6 respectively. After matching, it is determined that table data B5, table data B6, table data B7 and table data B8 do not match data A4, data A5 and data A6, then data A4, data A5 and data A6 can be imported into the original table.
[0092] After two matches, the incremental data containing 5 data can be imported into the original table. After the incremental data is imported into the original table, the original table now contains table data B1, table data B4, table data B5, table data B6, table data B7, table data B8, data A1, data A2, data A3, data A4, data A5 and data A6.
[0093] Data file interaction is the most convenient and common method for data interaction between different databases. Oracle, as a commonly used database, often receives data from the outside in the form of files. When importing external data into the Oracle database, Spring batch can be used for data import.
[0094] When using Spring batch to import external data into an Oracle database, two import methods can be used: full import and incremental import.
[0095] Specifically, when using the full import method to import the data to be imported into the target table in the Oracle database, you can follow the Figure 3 The process shown in is implemented. Figure 3 As shown, the following steps may be included:
[0096] Step S301, obtaining the structure of the original table to be imported.
[0097] Step S302: Generate configuration parameter information according to the structure of the original table.
[0098] According to the structure of the original table obtained, spring batch configuration parameter information can be generated.
[0099] The generated configuration parameter information may include field information of the original table, such as field length, field content, etc., and may also include index information and constraint information of the original table.
[0100] Step S303: Create a temporary table based on the configuration parameter information.
[0101] The created temporary table is located in the Oracle database, and the structure of the temporary table is consistent with that of the original table.
[0102] Step S304, import the data to be imported into a temporary table to obtain a target table.
[0103] After creating a temporary table, you can import the data you want to import into the temporary table. In addition, you can use the temporary table after importing the data as the target table.
[0104] Step S305: create index information and constraint information of the target table.
[0105] After importing the data, create the index information and constraint information of the target table according to the configuration parameter information.
[0106] Step S306: Replace the original table with the target table.
[0107] After importing the data into the temporary table to obtain the target table and creating the index information and constraint information corresponding to the target table, the original table in the database can be deleted and only the target table can be retained.
[0108] Step S307: Change the index information and constraint information of the target table to be consistent with the index information and constraint information of the original table.
[0109] After the original table is deleted from the database, the index information and constraint information of the target table can be changed to be consistent with the index information and constraint information of the original table.
[0110] When using incremental import to import the data to the target table in Oracle database, you can follow Figure 4 The process shown in is implemented. Figure 4 As shown, the following steps may be included:
[0111] Step S401, obtaining the structure of the target table to be imported.
[0112] Step S402: Generate configuration parameter information according to the structure of the target table.
[0113] Step S403: determining multiple table data included in the target table according to the configuration parameter information.
[0114] Step S404, determining the set number of table data to be matched each time and the set number of data to be imported.
[0115] There are limits on the number of table data items included in the target table for each match and the number of data items included in the data to be imported, and the number of data items to be matched can be specified based on the actual matching situation and the performance of the server or terminal that executes the matching process. The embodiments of the present application do not limit this.
[0116] Step S405, for each table data in each match, perform the following operations respectively: match the table data with a set number of incremental data respectively; if the table data matches the set data in the set number of data to be imported, delete the table data from the target table, and import the set number of data to be imported into the target table where the table data is deleted.
[0117] Step S406, for each table data in each match, perform the following operations respectively: match the table data with the set number of incremental data respectively, if the table data does not match the set number of data to be imported, import the set number of data to be imported into the target table.
[0118] Specifically, each time the table data in the target table is matched with the data to be imported, the matching process may be performed in a field matching manner.
[0119] When using Spring batch to import all external data into an Oracle database, you can also use the following Figure 4 The incremental import method shown in the figure is used to import data. The overall efficiency of the incremental import method is slightly lower than that of the full import method when importing data, but there is no need to create a new temporary table in the database.
[0120] In some embodiments, when using Spring batch to import external data into an Oracle database, only the process of matching the data to be imported with the table data included in the target table in the Oracle database, determining the matching target data, and deleting the target data from the target table can be performed. Figure 5 As shown, the following steps are included:
[0121] Step S501, obtaining the structure of the target table to be imported.
[0122] Step S502: Generate configuration parameter information according to the structure of the target table.
[0123] Step S503: determining multiple table data included in the target table according to the configuration parameter information.
[0124] Step S504, determining the set number of table data to be matched each time and the set number of data to be imported.
[0125] Step S505 , for each table data in each match, perform the following operations respectively: match the table data with a set number of incremental data respectively, and if the table data matches the set data in the set number of data to be imported, delete the table data from the target table.
[0126] The method for importing data provided in the embodiment of the present application can respectively realize the process of importing the external data in full into the target table in the database and the process of importing the external data incrementally into the target table in the database. When the external data is imported in full into the target table in the database, it is necessary to first create a temporary table consistent with the structure of the target table to be imported by the external data, import the external data into the temporary table, replace the target table with the temporary table, and retain the original index information and constraint information in the target table, thereby solving the problem of empty or incomplete data query caused by the data in the target table being completely cleared in the related technology during the process of importing external data into the target table. The full import method in the embodiment of the present application can switch the target table to the latest data in a very short time, complete the process of importing data into the database, and in the process of importing data, can provide data query services uninterruptedly, and can also improve the efficiency of importing data.
[0127] When incrementally importing external data into a target table in a database, there is no need to add a new temporary table. Instead, the external data is matched with the data in the target table by field matching, target data in the target table that matches the external data is determined, and the external data is imported into the target table after the target data is deleted from the target table. This can solve the problem in related technologies that when data exists in the target table, the existing data in the target table cannot be updated or replaced.
[0128] In addition, the method for importing data provided in the embodiment of the present application can also match the external data with the table data in the target table in the database, and delete the target data in the target table that matches the external data, thereby solving the problem in the related art that the existing data in the target table cannot be partially deleted, and the existing data in the target table can only be completely deleted. Moreover, by providing full data import, incremental import and deletion methods, it is convenient to import data into the database and process the data in the database.
[0129] and Figure 1 The method for importing data shown is based on the same inventive concept, and an apparatus for importing data is also provided in the embodiment of the present application. Since the apparatus is the apparatus corresponding to the method for importing data of the present application, and the principle of solving the problem by the apparatus is similar to that of the method, the implementation of the apparatus can refer to the implementation of the above method, and the repeated parts will not be repeated.
[0130] Figure 6 A schematic diagram of the structure of a device for importing data provided by an embodiment of the present application is shown. Figure 6 As shown, the device for importing data includes a first import determination unit 601, a temporary table creation unit 602 and a target table replacement unit 603.
[0131] The first import determination unit 601 is used to obtain the full amount of data to be imported in response to the instruction of importing the full amount of data, and determine the first original table in the database into which the full amount of data to be imported needs to be imported;
[0132] A temporary table creation unit 602 is used to obtain the table structure of the first original table and create a temporary table in the database that is consistent with the table structure of the first original table;
[0133] The target table replacement unit 603 is used to import the full amount of data to be imported into the temporary table to obtain the target table, and replace the first original table with the target table.
[0134] In an optional embodiment, the temporary table creation unit 602 is specifically configured to:
[0135] Determine configuration parameter information corresponding to the first original table according to the table structure of the first original table;
[0136] Based on the configuration parameter information, a temporary table having a table structure consistent with the first original table is created in the database.
[0137] In an optional embodiment, the configuration parameter information also includes index information and constraint information of the first original table; the target table replacement unit 603 is further configured to:
[0138] The index information and constraint information of the target table are created, the first original table is deleted, and the index information and constraint information of the target table are changed to be consistent with the index information and constraint information of the first original table.
[0139] In an optional embodiment, Figure 2 The method for importing data shown is based on the same inventive concept, and an apparatus for importing data is also provided in the embodiment of the present application. Since the apparatus is the apparatus corresponding to the method for importing data of the present application, and the principle of solving the problem by the apparatus is similar to that of the method, the implementation of the apparatus can refer to the implementation of the above method, and the repeated parts will not be repeated.
[0140] like Figure 7 As shown, the device for importing data may further include a second import determination unit 701 , a matching data determination unit 702 and a data import unit 703 .
[0141] The second import determination unit 701 is used to obtain the incremental data to be imported in response to the instruction of incremental importing data, and determine the second original table in the database into which the incremental data to be imported needs to be imported;
[0142] A matching data determination unit 702 is used to match the incremental data to be imported with the data in the second original table, and determine target data in the second original table that matches the incremental data to be imported;
[0143] The data importing unit 703 is used to delete the target data from the second original table, and import the incremental data to be imported into the second original table after the target data is deleted.
[0144] In an optional embodiment, the matching data determination unit 702 is specifically configured to:
[0145] Obtaining configuration parameter information corresponding to the second original table according to the table structure of the second original table, and determining a plurality of table data included in the second original table according to the configuration parameter information;
[0146] For each table data, the following operations are performed respectively: the table data is matched with multiple incremental data included in the incremental data to be imported respectively, and if the table data matches the set incremental data in the multiple incremental data, the table data is used as the target data.
[0147] In an optional embodiment, the data importing unit 703 is specifically used to:
[0148] Determine the set number of table data items and the set number of incremental data items to be matched each time, and perform the following operations for each table data item in each match:
[0149] Matching the table data with the set number of incremental data respectively, if the table data matches the set incremental data in the set number of incremental data, deleting the table data from the second original table, and importing the set number of incremental data into the second original table from which the table data is deleted;
[0150] If the table data does not match the set number of incremental data, the set number of incremental data is imported into the second original table.
[0151] Based on the same inventive concept as the above method embodiment, an electronic device is also provided in the embodiment of the present application. The electronic device can be used to perform the process of importing data. In this embodiment, the structure of the electronic device can be as follows: Figure 8 As shown, it includes a memory 801 and one or more processors 802 .
[0152] The memory 801 is used to store computer programs executed by the processor 802. The memory 801 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and programs required for running the instant messaging function, etc.; the data storage area may store various instant messaging information and operation instruction sets, etc.
[0153] The memory 801 may be a volatile memory, such as a random-access memory (RAM); the memory 801 may also be a non-volatile memory, such as a read-only memory, a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), or the memory 801 may be any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 801 may be a combination of the above memories.
[0154] The processor 802 may include one or more central processing units (CPU) or a digital processing unit, etc. The processor 802 is used to implement the above-mentioned method of importing data when calling the computer program stored in the memory 801 .
[0155] The specific connection medium between the memory 801 and the processor 802 is not limited in the embodiments of the present application. Figure 8 In the embodiment, the memory 801 and the processor 802 are connected via a bus 803. The bus 803 is connected to the processor 802 via a bus 803. Figure 8 The connections between other components are shown in bold lines, and are not intended to be limiting. Bus 803 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 8 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0156] According to one aspect of the present application, a computer program product or a computer program is provided, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method for importing data in the above-mentioned embodiment.
[0157] The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0158] The above description is only a specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.
Claims
1. A method for importing data, It is characterized in that include: In response to an instruction to fully import data, the full amount of data to be imported is obtained, and a first original table in the database into which the full amount of data to be imported needs to be imported is determined; Acquire the table structure of the first original table, and create a temporary table in the database that is consistent with the table structure of the first original table; Importing the full amount of data to be imported into the temporary table to obtain a target table, and replacing the first original table with the target table; The method further comprises: In response to an instruction to incrementally import data, the incremental data to be imported is acquired, and a second original table in the database into which the incremental data to be imported needs to be imported is determined; Matching the incremental data to be imported with the data in the second original table to determine target data in the second original table that matches the incremental data to be imported; Deleting the target data from the second original table, and importing the incremental data to be imported into the second original table after deleting the target data; The step of matching the incremental data to be imported with the data in the second original table to determine target data in the second original table that matches the incremental data to be imported includes: Obtaining configuration parameter information corresponding to the second original table according to the table structure of the second original table, and determining a plurality of table data included in the second original table according to the configuration parameter information; For each piece of table data, the following operations are performed respectively: the table data is matched with a plurality of incremental data included in the incremental data to be imported, and if the table data matches the set incremental data in the plurality of incremental data, the table data is used as the target data; The step of deleting the target data from the second original table and importing the incremental data to be imported into the second original table after deleting the target data includes: Determine the set number of table data items and the set number of incremental data items to be matched each time, and perform the following operations for each table data item in each match: Matching the table data with the set number of incremental data respectively, if the table data matches the set incremental data in the set number of incremental data, deleting the table data from the second original table, and importing the set number of incremental data into the second original table from which the table data is deleted; If the table data does not match the set number of incremental data, the set number of incremental data is imported into the second original table.
2. The method according to claim 1, It is characterized in that The step of obtaining the table structure of the first original table and creating a temporary table in the database that is consistent with the table structure of the first original table includes: Determining configuration parameter information corresponding to the first original table according to the table structure of the first original table; Based on the configuration parameter information, a temporary table having a table structure consistent with the first original table is created in the database.
3. The method according to claim 2, It is characterized in that The configuration parameter information also includes index information and constraint information of the first original table; After obtaining the target table, the method further includes: The index information and constraint information of the target table are created, the first original table is deleted, and the index information and constraint information of the target table are changed to be consistent with the index information and constraint information of the first original table.
4. A device for importing data, It is characterized in that include: A first import determination unit, configured to obtain the full amount of data to be imported in response to an instruction to fully import data, and determine a first original table in the database into which the full amount of data to be imported needs to be imported; a temporary table creation unit, configured to obtain the table structure of the first original table, and create a temporary table in the database having the same table structure as the first original table; a target table replacement unit, configured to import the full amount of data to be imported into the temporary table to obtain a target table, and replace the first original table with the target table; The device also includes: A second import determination unit is used to obtain the incremental data to be imported in response to the instruction of incrementally importing data, and determine a second original table in the database into which the incremental data to be imported needs to be imported; a matching data determination unit, configured to match the incremental data to be imported with the data in the second original table, and determine target data in the second original table that matches the incremental data to be imported; A data importing unit, used for deleting the target data from the second original table, and importing the incremental data to be imported into the second original table after deleting the target data; The matching data determination unit is specifically used to: Obtaining configuration parameter information corresponding to the second original table according to the table structure of the second original table, and determining a plurality of table data included in the second original table according to the configuration parameter information; For each piece of table data, the following operations are performed respectively: the table data is matched with a plurality of incremental data included in the incremental data to be imported, and if the table data matches the set incremental data in the plurality of incremental data, the table data is used as the target data; The data import unit is specifically used for: Determine the set number of table data items and the set number of incremental data items to be matched each time, and perform the following operations for each table data item in each match: Matching the table data with the set number of incremental data respectively, if the table data matches the set incremental data in the set number of incremental data, deleting the table data from the second original table, and importing the set number of incremental data into the second original table from which the table data is deleted; If the table data does not match the set number of incremental data, the set number of incremental data is imported into the second original table.
5. The device as claimed in claim 4, It is characterized in that The temporary table creation unit is specifically used for: Determining configuration parameter information corresponding to the first original table according to the table structure of the first original table; Based on the configuration parameter information, a temporary table having a table structure consistent with the first original table is created in the database.
6. The device as claimed in claim 5, It is characterized in that The configuration parameter information also includes index information and constraint information of the first original table; the target table replacement unit is further used to: The index information and constraint information of the target table are created, the first original table is deleted, and the index information and constraint information of the target table are changed to be consistent with the index information and constraint information of the first original table.
7. An electronic device, It is characterized in that The method comprises a processor and a memory, wherein the memory stores program codes, and when the program codes are executed by the processor, the processor executes the steps of any one of the methods in claims 1 to 3.
8. A computer-readable storage medium, It is characterized in that The method comprises a program code. When the program code is run on an electronic device, the program code is used to enable the electronic device to execute the steps of any method described in claims 1 to 3.
9. A computer program product comprising a computer program / instructions, It is characterized in that When the computer program / instruction is executed by a processor, the steps of any method described in claims 1 to 3 are implemented.
