Data importing method and device
By cleaning and automated processing in the data import solution, the problems of low accuracy and high operating threshold in the existing technology are solved, efficient and safe data import is achieved, and import efficiency is improved.
Patent Information
- Application Number
- CN202410737670.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-07
- Publication Date
- 2024-09-03
AI Technical Summary
The data situation in the existing data import scheme is different, resulting in import errors, low accuracy, high technical requirements for importers, and high operating threshold.
Provide a data import method and device, by receiving the target table and file selected by the user, calling the parsing logic corresponding to the file type, performing data cleaning processing, parsing the data into a data stream, and writing it into the data warehouse through a message queue , supports import and cleaning of multiple data formats, set up an automated data import mechanism, and use the message consumption engine and data import engine of the big data platform to cooperate with each other to ensure the timeliness and security of data import.
It reduces the import error rate, lowers the operation threshold, improves the import efficiency of R&D and business personnel, and ensures the accuracy and security of data import.
Smart Images

Figure CN118585569A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a data import method and device. Background Art
[0002] Currently, offline and real-time data development based on big data platforms is highly dependent on offline data. Business personnel are required to organize the data first, and then production and research personnel who have passed the group's data computing platform certification exam must import the data into the data warehouse Hive to support online data query and analysis.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art: the data situations in the existing data import schemes are inconsistent, which can easily cause import errors, resulting in low import accuracy, and the technical theoretical foundation requirements for the import personnel are high, resulting in a high operational threshold. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a data import method and device, which can at least solve the problem of too high a data import authority threshold and low accuracy in the prior art.
[0005] To achieve the above object, according to one aspect of an embodiment of the present invention, a data import method is provided, comprising:
[0006] Receive the table name of the target table selected by the user and the file to be uploaded, and call the parsing logic corresponding to the file type of the file to read the file content in the file;
[0007] Perform data cleaning on the file content to obtain the target file, parse the data in the target file into a data stream, encapsulate the data stream, table name and user name into a message body, and send the message body to the message queue;
[0008] Get the message body from the message queue and parse it to get the data flow, table name and user name, determine the target table corresponding to the table name in the data warehouse, and write the data flow and user name into the target table.
[0009] Optionally, receiving the table name of the target table selected by the user and the file to be uploaded includes:
[0010] In response to a selection operation of the user on the data import page, a user name is obtained, and a target table name list consisting of table names of target tables with import permissions under the user name is searched from the locally pre-stored permission data, and a target table name selected by the user from the target table name list is determined; and
[0011] In response to the user's selection operation of the upload file option in the data import page, a file selected by the user from a local location is received for upload operation.
[0012] Optionally, the method further comprises: in response to a user selecting a file type in the data import page, acquiring a file upload template corresponding to the selected file type;
[0013] The fields in the target table are input into the file upload template and displayed, so that the user can adjust the file content based on the file upload template.
[0014] Optionally, parse the data in the target file into a data stream, including:
[0015] A distributed lock is acquired based on the table name, and in response to a successful acquisition result, it is determined that the target table is locked successfully, and the data in the target file is parsed into a data stream; wherein, after the data in the target file is successfully written into the target table, the distributed lock is released.
[0016] Optionally, the method also includes: uploading the target file to an object storage service to receive a key name returned by the object storage service; wherein the key name is used to identify the storage location of the target file in the object storage service, and obtaining the target file from the object storage service through the key name.
[0017] Optionally, the data stream and the user name are written into a target table, including one or more of the following:
[0018] In the process of storing the data streams into the target table one by one, the total size of the stored data streams is accumulated. When the total size reaches the maximum value of the preset partition file, a new partition file is created for the target table. In the process of storing the remaining data streams in the new partition file, the total size of the data streams stored in the new partition file is compared with the maximum value of the preset partition file, and the operation of creating a new partition file when the total size of the data streams stored in the new partition file reaches the maximum value of the preset partition file is repeated until the data streams are stored.
[0019] In the process of storing the data streams into the target table one by one, the total time consumed by the stored data streams is accumulated. When the total time consumed reaches the maximum time interval for scrolling the preset partition file, a new partition file is created for the target table. In the process of storing the remaining data streams in the new partition file, the operations of comparing the total time consumed by the data streams stored in the new partition file with the maximum time interval and creating a new partition file when the total time consumed by the data streams stored in the new partition file reaches the maximum time interval are repeated until the data stream is stored.
[0020] Optionally, the method also includes: querying the partition files corresponding to the table name of the same target table, and performing a partition file merging operation when there are multiple partition files whose sizes are smaller than a preset partition file maximum value; wherein the size of the merged file must be smaller than or equal to the preset partition file maximum value.
[0021] Optionally, the method further comprises:
[0022] At a preset time interval, check the execution status of creating a new partition file when the total size of the data stream stored in the partition file reaches the preset partition file maximum value, and trigger the operation of generating a new partition file when it is checked that the total size of the data stream stored in the partition file reaches the preset partition file maximum value and no new partition file is generated;
[0023] According to the preset time interval, check the execution status of creating a new partition file when the total time consumption of the data flow stored in the partition file reaches the maximum time interval. If it is checked that the new partition file is not generated when the total time consumption of the data flow stored in the partition file reaches the maximum time interval, trigger the operation of generating a new partition file.
[0024] To achieve the above object, according to another aspect of an embodiment of the present invention, a data import device is provided, comprising:
[0025] The import module is used to receive the table name of the target table selected by the user and the file to be uploaded, and call the parsing logic corresponding to the file type of the file to read the file content in the file;
[0026] The relay module is used to perform data cleaning on the file content to obtain the target file, parse the data in the target file into a data stream, encapsulate the data stream, table name and user name into a message body, and send the message body to the message queue;
[0027] The writing module is used to obtain the message body from the message queue and parse it to obtain the data flow, table name and user name, determine the target table corresponding to the table name in the data warehouse, and write the data flow and user name into the target table.
[0028] Optionally, the import module is used to: in response to a user's selection operation on the data import page, obtain a user name, query a target table name list consisting of table names of target tables with import permissions under the user name from the locally pre-stored permission data, and determine a target table name selected by the user from the target table name list; and
[0029] In response to the user's selection operation of the upload file option in the data import page, a file selected by the user from a local location is received for upload operation.
[0030] Optionally, the import module is further used to: in response to a user's selection operation of a file type on the data import page, obtain a file upload template corresponding to the selected file type;
[0031] The fields in the target table are input into the file upload template and displayed, so that the user can adjust the file content based on the file upload template.
[0032] Optionally, the relay module is used to: acquire a distributed lock based on a table name, determine that the target table is locked successfully in response to the acquisition result being successful, and parse the data in the target file into a data stream; wherein, after the data in the target file is successfully written to the target table, the distributed lock is released.
[0033] Optionally, it also includes a storage module, which is used to: upload the target file to the object storage service to receive a key name returned by the object storage service; wherein the key name is used to identify the storage location of the target file in the object storage service, and obtain the target file from the object storage service through the key name.
[0034] Optionally, the writing module includes one or more of the following:
[0035] In the process of storing the data streams into the target table one by one, the total size of the stored data streams is accumulated. When the total size reaches the maximum value of the preset partition file, a new partition file is created for the target table. In the process of storing the remaining data streams in the new partition file, the total size of the data streams stored in the new partition file is compared with the maximum value of the preset partition file, and the operation of creating a new partition file when the total size of the data streams stored in the new partition file reaches the maximum value of the preset partition file is repeated until the data streams are stored.
[0036] In the process of storing the data streams into the target table one by one, the total time consumed by the stored data streams is accumulated. When the total time consumed reaches the maximum time interval for scrolling the preset partition file, a new partition file is created for the target table. In the process of storing the remaining data streams in the new partition file, the operations of comparing the total time consumed by the data streams stored in the new partition file with the maximum time interval and creating a new partition file when the total time consumed by the data streams stored in the new partition file reaches the maximum time interval are repeated until the data stream is stored.
[0037] Optionally, the writing module is also used to: query the partition files corresponding to the table name of the same target table, and if there are multiple partition files whose sizes are smaller than the preset partition file maximum value, perform a partition file merging operation; wherein the merged file size must be smaller than or equal to the preset partition file maximum value.
[0038] Optionally, the writing module is further used to: check, at a preset time interval, the execution status of creating a new partition file when the total size of the data stream stored in the partition file reaches the preset partition file maximum value, and trigger the operation of generating a new partition file when it is checked that the new partition file is not generated when the total size of the data stream stored in the partition file reaches the preset partition file maximum value;
[0039] According to the preset time interval, check the execution status of creating a new partition file when the total time consumption of the data flow stored in the partition file reaches the maximum time interval. If it is checked that the new partition file is not generated when the total time consumption of the data flow stored in the partition file reaches the maximum time interval, trigger the operation of generating a new partition file.
[0040] To achieve the above objective, according to another aspect of an embodiment of the present invention, a data import electronic device is provided.
[0041] The electronic device of an embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement any of the data import methods described above.
[0042] To achieve the above-mentioned purpose, according to another aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, any of the above-mentioned data import methods is implemented.
[0043] To achieve the above object, according to another aspect of an embodiment of the present invention, a computer program product is provided. A computer program product according to an embodiment of the present invention includes a computer program, and when the program is executed by a processor, the data import method provided by the embodiment of the present invention is implemented.
[0044] According to the solution provided by the present invention, an embodiment of the above invention has the following advantages or beneficial effects: setting an automated data cleaning mechanism to support the import and cleaning of multiple data formats, setting an automatic derivation mechanism, and importing file data into the target table of the data warehouse through the cooperation of the message consumption engine and the data import engine of the big data platform. This operation ensures the timeliness and security of data import, reduces the import error rate, and at the same time lowers the operational threshold, thereby improving the derivation efficiency of R&D personnel and business personnel.
[0045] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0047] Figure 1 This is a schematic diagram of the main process of a data import method according to an embodiment of the present invention;
[0048] Figure 2(a) is a schematic diagram of the data import interface;
[0049] Figure 2(b) is a schematic diagram of the permission control interface;
[0050] Figure 3 is a flowchart of an optional data import method according to an embodiment of the present invention;
[0051] Figure 4 It is a timing diagram of data import;
[0052] Figure 5 is a flowchart of another optional data import method according to an embodiment of the present invention;
[0053] Figure 6 is a schematic diagram of a framework of a specific data import method according to an embodiment of the present invention;
[0054] Figure 7 is a schematic diagram of main modules of a data import device according to an embodiment of the present invention;
[0055] Figure 8 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0056] Fig. 9 It is a schematic diagram of the structure of a computer system of a mobile device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0057] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0058] It should be noted that the collection, collection, updating, analysis, processing, use, transmission, storage and other aspects of user personal information involved in the technical solution of this disclosure are in compliance with the provisions of relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. Necessary measures are taken for user personal information to prevent illegal access to user personal information data and maintain the security of user personal information, network security and national security.
[0059] It should be noted that this solution is an improved design for the existing derivative process of the big data platform, and is also applicable to other big data platforms that use similar architectures and derivative processes. The data management methods of the existing big data platform have the following problems:
[0060] 1. The derivative entry is difficult to locate: The existing data derivative entry is embedded in the data query interface, which is difficult for users to find quickly;
[0061] 2. The threshold for data import permissions is too high: Currently, data import permissions require a fixed number of hours of study, followed by participation in the group data computing platform certification exam, and data import can only be performed after passing the exam. For business personnel who lack a technical theoretical foundation, the time cost required is too high.
[0062] 3. Single format of imported data: Currently, data import only supports txt format, while offline data is usually in xlsx or csv, which requires the importer to convert the data format before uploading. Offline data is generally large in volume, which can easily cause computer freezes and is difficult to convert.
[0063] 4. Low import accuracy: Existing data import only supports tabs as column separators. Offline data mostly comes from the export of various business systems and manual reporting. Data fields have different line breaks, spaces, and separators, which makes it difficult to summarize them in a unified manner. In actual use, data import errors are often encountered, such as forced line breaks in cells, column separators that are not tabs, etc., which requires a lot of time for R&D and business personnel to verify and troubleshoot. Among them, the tab character is a key on the keyboard, which can be used to insert a tab character in the text. Tabs are usually used to create a horizontal line in the text, or to separate data in a column. Column segmentation refers to the use of tabs or other characters to separate different columns in the data.
[0064] See also Figure 1 , which shows a main flow chart of a data import method provided by an embodiment of the present invention, comprising the following steps:
[0065] S101: receiving the table name of the target table selected by the user and the file to be uploaded, and calling the parsing logic corresponding to the file type of the file to read the file content in the file;
[0066] S102: Perform data cleaning on the file content to obtain a target file, parse the data in the target file into a data stream, encapsulate the data stream, table name and user name into a message body, and send the message body to a message queue;
[0067] S103: Obtain the message body from the message queue and parse it to obtain the data flow, table name and user name, determine the target table corresponding to the table name in the data warehouse, and write the data flow and user name into the target table.
[0068] In the above implementation, it should be noted that the data warehouse of the big data platform is divided into multiple levels. For data security, only the tables in the DEV level are allowed to import data, and the tables in other levels can only be written by programs. Therefore, the target tables described in this solution refer to DEV tables (development tables).
[0069] For step S101, as shown in FIG2(a), the big data platform sets a data import page. After the platform user logs in, if he clicks on the data import page, the data import engine of the big data platform will automatically obtain the user's username, such as the uploader XXXX in the figure. After that, the table name list of the DEV table that the user has the import permission for is queried from the local pre-stored permission data, and then the user selects a DEV table from it, such as dev_xxxxxxxxxxx1 in the figure. It should be noted that the DEV table here is a data storage structure composed of table fields, such as fields A / B / C / D, which may include data or not, and this solution does not limit it here.
[0070] The list of DEV tables that different users have import permissions for is shown in Figure 2(b). The tables that users have permission to read and import come from two parts: 1) DEV tables created by users on the big data platform, which can be obtained through the open interface query provided by DMS (full name Data Management System, data management product); 2) DEV tables authorized by others. Users can only authorize tables created by themselves, and tables authorized by others do not support secondary authorization.
[0071] DMS is a data management product for data warehouses on the big data platform, including the definition and management of Hive tables and views in data warehouses. In data warehouse processing scenarios, it is a metadata management platform that provides data development engineers and data management personnel with standard table creation, table management, table creation standard management, view management, and metadata governance capabilities. JSF: A distributed service framework.
[0072] The data import engine calls the permission module to obtain a list of DEV tables that the user has import permissions for. Whether the table is created by the user or authorized by others is used when authorizing the table, and is not used here. The permission data is persisted in MySQL, and a copy is cached in Redis to improve performance. If there is no import permission, it is an illegal import and a failure is returned.
[0073] FIG2(a) also provides a "File Upload" button. When the user clicks the button, the data import engine responds to the operation by displaying local files, from which the user can select a file to upload. The file type of the file is determined, and the parsing logic corresponding to the file type is called to read the file content of the file. For example, different parsing logics are executed for three types of files: excel, txt, and csv to read their file contents. For example, the excel file calls the excel program parsing logic.
[0074] For steps S102 and S103, after obtaining the file to be uploaded and reading the file content, the file content can be cleaned. For example, based on the fields in the DEV table selected by the user, irrelevant fields in the file content are removed. For example, if the fields in the DEV table are A / B / C / D, but the fields in the file content are C / D / E / F, the content under the E / F field needs to be removed. Here, the content under the A / B field of the file content is empty.
[0075] In addition, other methods can be set. For example, in Figure 2(a), "Please select the type of worksheet to upload (or file type)", the user can select one of them, such as Excel. The data import engine pre-sets different file upload templates for different worksheet types. Therefore, the fields in the DEV table selected by the user can be input into the file upload template for the user to view, so that the user can adjust the file content based on the template, such as deleting the data in the EF column.
[0076] In addition, data cleaning may also include but is not limited to the following: uniformly process illegal characters in the data, replace the forced line breaks in a single cell, and uniformly replace column separators with tabs. For example, it means replacing illegal characters in the data with legal characters, replacing numbers in a string with null characters, and replacing characters in numbers with null characters. Replace the forced line breaks in a single cell with tabs. Uniformly replace column separators with tabs.
[0077] Illegal characters: refers to characters that do not conform to the data type, such as numbers in strings, characters in numbers, etc. Forced line breaks: refers to line breaks inserted in cells, for example, if you enter "hello\nworld" in a cell, "hello\nworld" will be displayed in the cell. Column separator: refers to the separator between cells, for example, in Excel, the default column separator is a comma.
[0078] After cleaning the file contents in the files uploaded by the user, the target file is obtained, and then the data in the target file is parsed into a data stream. The file stream is to parse the data into rows, encapsulate it with the table name of the DEV table and the user's username into a message body and send it to DQ (Data Queue, also known as message queue), which can be uniformly described by data stream. Among them, DQ provides real-time data storage, traffic peak shaving, asynchronous buffering, system decoupling and other services for business scenarios such as logs, monitoring data, and traffic data. It is a unified real-time data bus for the big data platform.
[0079] The above-mentioned DQ is the message queue of Flink, the message consumption engine of the big data platform. The big data platform uses Flink tasks to consume DQ messages. With the help of the Hive Streaming Sink provided by Flink, the data can be streamed into the data warehouse Hive. Specifically, the message body is obtained from DQ and parsed to obtain the data stream, the table name of the DEV table, and the user's user name, determine the DEV table corresponding to the table name in Hive, and write the data stream and user name into the DEV table.
[0080] The method provided in the above embodiment sets up an automated data cleaning mechanism, supports the import and cleaning of multiple data formats, sets up an automatic derivation mechanism, and imports file data into the target table of the data warehouse through the cooperation between the message consumption engine and the data import engine of the big data platform. This operation ensures the timeliness and security of data import, reduces the import error rate, and lowers the operational threshold, thereby improving the derivation efficiency of R&D personnel and business personnel.
[0081] See also Figure 3 , shows a schematic flow chart of an optional data import method according to an embodiment of the present invention, comprising the following steps:
[0082] S301: Upload a target file to an object storage service to receive a key name returned by the object storage service; wherein the key name is used to identify a storage location of the target file in the object storage service;
[0083] S302: acquiring a distributed lock based on the table name, and in response to the acquisition result being successful, determining that the target table is locked successfully; wherein, after the data in the target file is successfully written into the target table, releasing the distributed lock;
[0084] S303: Obtain a target file from the object storage service based on the key name, parse the data in the target file into a data stream, encapsulate the data stream, the table name, and the user name into a message body, and send the message body to a message queue;
[0085] S304: Obtain the message body from the message queue and parse it to obtain the data flow, table name and user name, determine the target table corresponding to the table name in the data warehouse, and write the data flow and user name into the target table.
[0086] In the above implementation, for steps S301 to S304, the overall process is as follows: Figure 4As shown, call the object storage service OSS (full name Object Storage Service, distributed storage service), upload the target file to OSS, and receive the OSS Key returned by OSS; where OSS Key is used to identify the storage location of the target file in OSS. OSS is a distributed storage service for storing massive data, providing highly reliable, low-cost, and highly secure cloud data storage.
[0087] The table name of the OSS Key and DEV table, and the user's username are encapsulated in the form of a message body to be published to the message queue MQ (Message Queue) of the data import engine. When the data import engine detects that there is a message body in the message queue MQ, it obtains the message body and parses it to obtain the table name and user name of the OSS Key and DEV table. This step can be omitted or performed to implement the data import engine to process data import one by one through MQ.
[0088] The data import engine obtains a distributed lock based on the table name of the DEV table. If the acquisition is successful, it means that the DEV table is locked successfully and the subsequent operation continues. If the acquisition is unsuccessful, it waits. When the data in the document is successfully uploaded to the DEV table, the distributed lock is released. It should be noted that multiple users may import data to the same DEV table at the same time. The distributed lock allows only one user to import data to the DEV table at the same time, avoiding the problem of a new file being uploaded before the previous file is uploaded, causing the contents of the two files to be mixed together.
[0089] After the table name of the DEV table is successfully locked, the target file is obtained from the OSS through the OSS Key, and the data in the target file is parsed into a data stream. Assuming there are 10 rows of data, 10 data streams are parsed. Then the data stream, the table name of DEV, and the user name are encapsulated as a message body to be sent to the DQ of the big data platform message consumption engine Flink. When the big data platform Flink program monitors the existence of a message body in DQ, it calls the Flink task to parse the message body, obtains the data stream and the table name and user name of DEV, determines the DEV table corresponding to the table name in the data warehouse Hive, and writes the data stream and user name into the DEV table line by line.
[0090] The method provided in the above embodiment uploads the target file to the object storage service after data cleaning. The object storage service identifies the storage location of the target file in the object storage service as a key name. Even if the subsequent writing to the data warehouse fails, the target file can be quickly obtained from the object storage service without the need for the user to import the file to be uploaded a second time and clean it again. The data import engine implements a locking mechanism for the target table based on the table name, so that only one user can parse the data in the target file into a data stream and import data into the target table at the same time, thereby ensuring the accuracy of data import.
[0091] See also Figure 5 , shows a schematic flow chart of another optional data import method according to an embodiment of the present invention, comprising the following steps:
[0092] S501: Obtain the message body from the message queue and parse it to obtain the data flow, table name and user name, and determine the target table corresponding to the table name in the data warehouse;
[0093] S502: In the process of storing the data streams one by one into the target table, the total size of the stored data streams is accumulated. When the total size reaches the maximum value of the preset partition file, a new partition file is created for the target table. In the process of storing the remaining data streams in the new partition file, the total size of the data streams stored in the new partition file is compared with the maximum value of the preset partition file, and the operation of creating a new partition file when the total size of the data streams stored in the new partition file reaches the maximum value of the preset partition file is repeatedly performed until the data streams are stored.
[0094] S503: In the process of storing the data streams one by one into the target table, the total time consumption of the stored data streams is accumulated. When the total time consumption reaches the maximum time interval of the preset partition file rolling, a new partition file is created for the target table. In the process of storing the remaining data streams in the new partition file, the total time consumption of the data streams stored in the new partition file is compared with the maximum time interval, and the operation of creating a new partition file when the total time consumption of the data streams stored in the new partition file reaches the maximum time interval is repeated until the data streams are stored.
[0095] S504: querying the partition files corresponding to the table name of the same target table, and performing a partition file merging operation when there are multiple partition files whose sizes are smaller than the preset partition file maximum value; wherein the size of the merged file must be smaller than or equal to the preset partition file maximum value;
[0096] S505: at a preset time interval, checking the execution status of creating a new partition file when the total size of the data stream stored in the partition file reaches the preset partition file maximum value, and triggering the operation of generating a new partition file when it is checked that no new partition file is generated when the total size of the data stream stored in the partition file reaches the preset partition file maximum value;
[0097] S506: According to the preset time interval, check the execution status of creating a new partition file when the total time consumption of the data flow stored in the partition file reaches the maximum time interval, and if it is checked that the new partition file is not generated when the total time consumption of the data flow stored in the partition file reaches the maximum time interval, trigger the operation of generating a new partition file.
[0098] In the above implementation, for steps S501 to S503, the Flink task of the big data platform consumes the DQ message, and with the help of the Hive Streaming Sink provided by Flink, the data can be streamed into the data warehouse Hive.
[0099] In the Flink task, set the file rolling policy parameters: sink.rolling-policy.file-size, sink.rolling-policy.rollover-interval, where sink.rolling-policy.file-size is the preset maximum value of the partition file. When this value is exceeded, a new partition file will be created. sink.rolling-policy.rollover-interval is the maximum time interval for partition file rolling. When this time is exceeded, a new partition file will be started.
[0100] Assuming sink.rolling-policy.file-size=128MB,
[0101] sink.rolling-policy.rollover-interval=30min:
[0102] 1) In the process of storing the data streams one by one into the DEV table, the total size of the stored data streams is accumulated. If the total size is 130MB, since 130MB>128MB, a new partition file will be created for the DEV table, that is, the files uploaded so far are split into two files; in the process of storing the remaining data streams in the new partition file, the operation of comparing the total size of the stored data streams with 128MB and creating a new partition file is repeated until the data streams are stored.
[0103] 2) When storing data streams one by one in the DEV table, the total time consumed by the stored data streams is accumulated. If a file upload takes more than 30 minutes to complete, a new partition file will be created for the data stream that has not been uploaded after 30 minutes, and it will not be written to the same partition file as the data uploaded in the previous 30 minutes. When the new partition file stores the remaining data streams, the operation of comparing the total time consumed by the stored data streams with 30 minutes and creating a new partition file is repeated until the data stream is stored.
[0104] The above 1) and 2) can be operated only one or both, so as to realize the adaptive generation of the partition file of the target table.
[0105] For step S504, this solution also sets the file merging parameters: auto-compaction, compaction.file-size to avoid the generation of small files. Among them, auto-compaction: whether to start automatic compression during Flink stream reception, compaction.file-size: compressed file size, the default value is sink.rolling-policy.file-size.
[0106] When data is uploaded and written frequently in the same DEV table, many small files will be generated in each Hive partition. The PartitionCommitPolicy interface is implemented to merge them after the partition is committed. Specifically: query the partition files corresponding to the table name of the same target table. When the size of multiple partition files is smaller than the maximum value of the partition file sink.rolling-policy.file-size, perform the partition file merge operation; the merged file size must be less than or equal to the maximum value of the partition file sink.rolling-policy.file-size.
[0107] For steps S505 and S506, there is no restriction on the execution order of step S504, which can be performed simultaneously or in a sequential order, and there is no restriction on this. In addition to the above-mentioned sink.rolling-policy.file-size and sink.rolling-policy.rollover-interval, this solution also sets the file rolling policy parameter sink.rolling-policy.check-interval to ensure the processing time interval and size of the file. sink.rolling-policy.check-interval is a time interval (i.e., a preset time interval), which regularly checks whether the file is rolled to generate a new file under the above-mentioned configuration policy. You can also check the execution of the above-mentioned configuration policy. When it is found that the partition file generation policy is met but a new partition file is not generated, trigger the operation of generating a new partition file to generate a new partition file. Similarly, you can only check the execution of sink.rolling-policy.file-size, or only check the execution of sink.rolling-policy.rollover-interval, or consider both at the same time, without limitation here.
[0108] The method provided in the above embodiment sets the file rolling policy parameters and customizes the partition submission policy by implementing an interface, so as to trigger a small file merging operation after the partition is submitted. In this way, the number of partition files can be reduced as much as possible while complying with the file rolling policy, thereby avoiding the problem of wasting resources due to the generation of too many small files.
[0109] See also Figure 6 , shows a schematic diagram of the main framework of a data import provided by an embodiment of the present invention, including a business entry, an application layer and a storage layer. The present solution is mainly applied in the application layer, which includes a permission module, an import module, a relay module and a query module, wherein:
[0110] 1. Permission module: Tables that users have permission to read and import come from two parts: 1) DEV tables created by users on the big data platform, which can be obtained through the open JSF interface provided by DMS; 2) DEV tables authorized by others. Users can only authorize tables they created, and tables authorized by others do not support secondary authorization. Permission data is persisted in MySQL, and a copy is cached in Redis to improve performance.
[0111] 2. Import module. As shown in Figure 2(a) and Figure 2(b), the user needs to select the DEV table and select the uploaded file. The file is parsed according to the file type to read the file content, perform data cleaning on the file content, obtain the target file, and then store the target file in OSS to obtain the OSS key.
[0112] 3. Relay module, use Figure 4 In the process shown, the OSS key, table name, and user name are encapsulated as a message body to store the MQ of the data import engine, and then parsed to read the target file from the OSS based on the OSS key, and the table name and user name are encapsulated as a message body to store the DQ of the big data platform. The Flink task of the big data platform parses the message body in the DQ to obtain the target file, table name, and user name, and writes the target file to Hive.
[0113] 4. Query module, upload record query: supports users to query historical file upload records and historical file downloads. DEV table data query: supports users to query data in the DEV table with permissions.
[0114] The method provided in the embodiment of the present invention can solve the problems existing in the existing data import. By means of the technical foundation of the big data platform, a data import tool is designed as follows: EasyFeed, which has the following beneficial effects:
[0115] 1) With the help of Xingyun open platform capabilities, a convenient derivative entry is provided for business parties, solving the problem that the existing derivative entry is difficult to locate;
[0116] 2) Supports importing multiple file formats such as excel, txt, and csv. R&D personnel only need to authorize the tables they created to business personnel in EasyFeed, and business personnel can import data with one click, solving the problem of single import data format and high threshold for import permissions.
[0117] 3) Provide data cleaning in a unified format to ensure that offline data is completely and accurately imported into the DEV table of Hive. At the same time, since data uniqueness needs to be guaranteed in many data analysis scenarios, a deduplication option is added to the existing overwrite import and incremental import methods.
[0118] See also Figure 7 , shows a schematic diagram of main modules of a data import device 700 provided in an embodiment of the present invention, wherein:
[0119] The import module 701 is used to receive the table name of the target table selected by the user and the file to be uploaded, and call the parsing logic corresponding to the file type of the file to read the file content in the file;
[0120] The relay module 702 is used to perform data cleaning processing on the file content to obtain the target file, parse the data in the target file into a data stream, encapsulate the data stream, the table name and the user's username into a message body, and send the message body to the message queue;
[0121] The writing module 703 is used to obtain the message body from the message queue and parse it to obtain the data flow, table name and user name, determine the target table corresponding to the table name in the data warehouse, and write the data flow and user name into the target table.
[0122] In the implementation device of the present invention, the import module 701 is used to:
[0123] In response to a selection operation of the user on the data import page, a user name is obtained, and a target table name list consisting of table names of target tables with import permissions under the user name is searched from the locally pre-stored permission data, and a target table name selected by the user from the target table name list is determined; and
[0124] In response to the user's selection operation of the upload file option in the data import page, a file selected by the user from a local location is received for upload operation.
[0125] In the implementation device of the present invention, the import module 701 is further used to: in response to the user's selection operation of the file type in the data import page, obtain a file upload template corresponding to the selected file type;
[0126] The fields in the target table are input into the file upload template and displayed, so that the user can adjust the file content based on the file upload template.
[0127] In the implementation device of the present invention, the relay module 702 is used to: obtain a distributed lock based on the table name, determine that the target table is locked successfully in response to the acquisition result being successful, and parse the data in the target file into a data stream; wherein, after the data in the target file is successfully written to the target table, the distributed lock is released.
[0128] The implementation device of the present invention also includes a storage module, which is used to: upload the target file to the object storage service to receive the key name returned by the object storage service; wherein the key name is used to identify the storage location of the target file in the object storage service, and obtain the target file from the object storage service through the key name.
[0129] In the implementation device of the present invention, the writing module 703 includes one or more of the following:
[0130] In the process of storing the data streams into the target table one by one, the total size of the stored data streams is accumulated. When the total size reaches the maximum value of the preset partition file, a new partition file is created for the target table. In the process of storing the remaining data streams in the new partition file, the total size of the data streams stored in the new partition file is compared with the maximum value of the preset partition file, and the operation of creating a new partition file when the total size of the data streams stored in the new partition file reaches the maximum value of the preset partition file is repeated until the data streams are stored.
[0131] In the process of storing the data streams into the target table one by one, the total time consumed by the stored data streams is accumulated. When the total time consumed reaches the maximum time interval for scrolling the preset partition file, a new partition file is created for the target table. In the process of storing the remaining data streams in the new partition file, the operations of comparing the total time consumed by the data streams stored in the new partition file with the maximum time interval and creating a new partition file when the total time consumed by the data streams stored in the new partition file reaches the maximum time interval are repeated until the data stream is stored.
[0132] In the implementation device of the present invention, the write module 703 is also used to: query the partition files corresponding to the table name of the same target table, and when there are multiple partition files whose sizes are smaller than the preset partition file maximum value, perform a partition file merging operation; wherein the size of the merged file must be smaller than or equal to the preset partition file maximum value.
[0133] In the implementation device of the present invention, the writing module 703 is also used for:
[0134] At a preset time interval, check the execution status of creating a new partition file when the total size of the data stream stored in the partition file reaches the preset partition file maximum value, and trigger the operation of generating a new partition file when it is checked that the total size of the data stream stored in the partition file reaches the preset partition file maximum value and no new partition file is generated;
[0135] According to the preset time interval, check the execution status of creating a new partition file when the total time consumption of the data flow stored in the partition file reaches the maximum time interval. If it is checked that the new partition file is not generated when the total time consumption of the data flow stored in the partition file reaches the maximum time interval, trigger the operation of generating a new partition file.
[0136] In addition, the specific implementation content of the device described in the embodiment of the present invention has been described in detail in the method described above, so the repeated content will not be described again here.
[0137] Figure 8 An exemplary system architecture 800 to which embodiments of the present invention may be applied is shown, including terminal devices 801 , 802 , 803 , a network 804 and a server 805 (only an example).
[0138] Terminal devices 801, 802, 803 may be various electronic devices with display screens and supporting web browsing, and may be installed with various communication client applications. Users may use terminal devices 801, 802, 803 to interact with server 805 via network 804 to receive or send messages, etc.
[0139] The network 804 is used to provide a medium for communication links between the terminal devices 801, 802, 803 and the server 805. The network 804 may include various connection types, such as wired, wireless communication links or optical fiber cables.
[0140] The server 805 may be a server that provides various services. It should be noted that the method provided in the embodiment of the present invention is generally executed by the server 805 , and accordingly, the device is generally set in the server 805 .
[0141] It should be understood that Figure 8 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0142] Reference below Fig. 9 , which shows a schematic diagram of the structure of a computer system 900 of a terminal device suitable for implementing an embodiment of the present invention. Fig. 9 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0143] like Fig. 9 As shown, the computer system 900 includes a central processing unit (CPU) 901, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage part 908 into a random access memory (RAM) 903. In the RAM 903, various programs and data required for the operation of the system 900 are also stored. The CPU 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0144] The following components are connected to the I / O interface 905: an input section 906 including a keyboard, a mouse, etc.; an output section 907 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a LAN card, a modem, etc. The communication section 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to the I / O interface 905 as needed. A removable medium 911, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 910 as needed, so that a computer program read therefrom is installed into the storage section 908 as needed.
[0145] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 909, and / or installed from the removable medium 911. When the computer program is executed by the central processing unit (CPU) 901, the above-mentioned functions defined in the system of the present invention are executed.
[0146] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-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 of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer 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 of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0147] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0148] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes a permission module, an import module, a relay module, and a query module. The names of these modules do not, in some cases, constitute limitations on the modules themselves.
[0149] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device executes any of the above data import methods.
[0150] The computer program product of the present invention comprises a computer program, and when the computer program is executed by a processor, the data import method in the embodiment of the present invention is implemented.
[0151] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A data import processing method, characterized in that: The method comprises: Receive the table name of the target table selected by the user and the file to be uploaded, and call the parsing logic corresponding to the file type of the file to read the file content in the file; Performing data cleaning processing on the file content to obtain a target file, parsing the data in the target file into a data stream, encapsulating the data stream, the table name and the user name of the user into a message body, and sending the message body to a message queue; The message body is obtained from the message queue and parsed to obtain the data stream, the table name and the user name, the target table corresponding to the table name in the data warehouse is determined, and the data stream and the user name are written into the target table.
2. The method according to claim 1, characterized in that The receiving the table name of the target table selected by the user and the file to be uploaded includes: In response to a user's selection operation on a data import page, the user name is obtained, and a target table name list consisting of table names of target tables with import permissions under the user name is searched from the locally pre-stored permission data, and a target table name selected by the user from the target table name list is determined; and In response to the user's selection operation of the upload file option in the data import page, a file selected by the user from a local location is received for upload operation.
3. The method according to claim 1 or 2, characterized in that: The method further comprises: In response to a user selecting a file type on a data import page, obtaining a file upload template corresponding to the selected file type; The fields in the target table are input into the file upload template and displayed, so that the user can adjust the file content based on the file upload template.
4. The method according to claim 1, characterized in that: The step of parsing the data in the target file into a data stream comprises: A distributed lock is acquired based on the table name, and in response to a successful acquisition result, it is determined that the target table is locked successfully, and the data in the target file is parsed into a data stream; wherein, after the data in the target file is successfully written into the target table, the distributed lock is released.
5. The method according to claim 1, characterized in that The method further comprises: Upload the target file to the object storage service to receive a key name returned by the object storage service; wherein the key name is used to identify the storage location of the target file in the object storage service, and obtain the target file from the object storage service through the key name.
6. The method according to claim 1, characterized in that The step of writing the data stream and the user name into the target table includes one or more of the following: In the process of storing the data streams one by one into the target table, the total size of the stored data streams is accumulated, and when the total size reaches the maximum value of the preset partition file, a new partition file is created for the target table, and in the process of storing the remaining data streams in the new partition file, the total size of the data streams stored in the new partition file is compared with the maximum value of the preset partition file, and the operation of creating a new partition file when the total size of the data streams stored in the new partition file reaches the maximum value of the preset partition file is repeatedly performed until the data streams are stored; In the process of storing the data streams one by one into the target table, the total time consumption of the stored data streams is accumulated. When the total time consumption reaches the maximum time interval of the preset partition file scrolling, a new partition file is created for the target table. In the process of storing the remaining data streams in the new partition file, the operations of comparing the total time consumption of the data streams stored in the new partition file with the maximum time interval and creating a new partition file when the total time consumption of the data streams stored in the new partition file reaches the maximum time interval are repeated until the data streams are stored.
7. The method according to claim 6, characterized in that The method further comprises: Query the partition files corresponding to the table name of the same target table. If there are multiple partition files whose sizes are smaller than the preset partition file maximum value, perform a partition file merge operation; wherein the size of the merged file must be smaller than or equal to the preset partition file maximum value.
8. The method according to claim 6, characterized in that The method further comprises: At a preset time interval, checking the execution status of creating a new partition file when the total size of the data stream stored in the partition file reaches the preset partition file maximum value, and triggering the operation of generating a new partition file when it is checked that no new partition file is generated when the total size of the data stream stored in the partition file reaches the preset partition file maximum value; According to the preset time interval, check the execution status of creating a new partition file when the total time consumption of the data flow stored in the partition file reaches the maximum time interval; if it is checked that the new partition file is not generated when the total time consumption of the data flow stored in the partition file reaches the maximum time interval, trigger the operation of generating a new partition file.
9. A data import processing device, characterized in that: include: The import module is used to receive the table name of the target table selected by the user and the file to be uploaded, and call the parsing logic corresponding to the file type of the file to read the file content in the file; Performing data cleaning on the file content to obtain a target file; A relay module, used for parsing the data in the target file into a data stream, encapsulating the data stream, the table name and the user name of the user into a message body, and sending the message body to a message queue; A writing module is used to obtain and parse the message body from the message queue to obtain the data stream, the table name and the user name, determine the target table corresponding to the table name in the data warehouse, and write the data stream and the user name into the target table.
10. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 8.
11. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
12. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Data extraction method
CN110609826A
Data import method and device
CN111651514A
