A data table storage method and query method
By dividing the data table into multiple sub-data sets and generating meta-information, and using multi-threaded parallel storage and configuration parameter processing, the problem of low data table storage efficiency and low query efficiency is solved, and fast response and data security are achieved.
Patent Information
- Application Number
- CN202410707331.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-03
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-06-03
AI Technical Summary
Existing data table storage methods lead to low storage efficiency, low query efficiency, and long query response time when the amount of data is large.
Split the data table into multiple sub-data sets, and generate meta-information of the data table and sub-data sets. It uses multi-threaded parallel storage and configuration parameter processing to improve storage and query efficiency, and supports compression and encrypted storage.
It improves the storage efficiency and query response speed of data tables, ensures data security, and simplifies subsequent queries and integrity verification.
Smart Images

Figure CN118277390B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing, and in particular to a data table storage method and a query method. Background Art
[0002] With the advent of the big data era, more and more companies are beginning to explore the commercial value of user behavior data and use it for accurate and effective digital marketing. While these data bring huge value to companies, they also put tremendous pressure on companies in terms of data storage and query.
[0003] In the existing data table storage scenario, the data table to be stored is simply stored as a single file. When the amount of data in the data table is very large, it will lead to low storage efficiency, low query efficiency, and long query response time. Summary of the invention
[0004] In order to solve the above technical problems, the present invention provides a data table storage method and a query method, which divide the data in a data table into multiple sub-data sets for storage, and generate data table meta information corresponding to the data table and sub-data set meta information corresponding to the sub-data set, thereby improving storage efficiency and query efficiency and achieving rapid query response.
[0005] In order to solve the above problems, the present invention adopts the following technical solutions:
[0006] A data table storage method of the present invention is characterized by comprising the following steps:
[0007] S1: Split each column of data in the data table to be stored into m sub-data sets, and assign a corresponding number to each sub-data set;
[0008] S2: Read the configuration parameters of each sub-dataset set by the user;
[0009] S3: After processing each sub-dataset according to the corresponding configuration parameters, store it into a data file, and generate the sub-dataset meta information corresponding to the data file, the sub-dataset meta information includes the sub-dataset number, column name, column type, number of rows, configuration parameters, and storage address;
[0010] S4: Summarize all sub-dataset meta-information to generate data table meta-information, which includes the column name, column type, number of rows, number of sub-datasets, and sub-dataset meta-information of the data table.
[0011] In this scheme, the data table to be stored has n rows and k columns, and each column of data has a corresponding column name and column type. The n rows of the data table to be stored are divided into m segments, and each column of data in each segment constitutes a sub-data set. The sub-data sets constituted by each column of data in each segment have the same number, so each sub-data set can be located by coordinates (number, column name) for easy query. After the data table to be stored is divided into multiple sub-data sets, each sub-data set is processed according to the corresponding configuration parameters and stored as a data file. Multiple threads can be used to perform storage tasks in parallel, which improves storage efficiency. Each sub-data set can have a separate corresponding configuration parameter, which is convenient for different storage processing of sub-data sets with different storage requirements. Finally, the data table meta information and sub-data set meta information are generated to facilitate query verification, data set integrity verification, and sub-data set location when querying the data table later.
[0012] Preferably, the method of dividing each column of data in the data table to be stored into m sub-data sets in step S1 is as follows:
[0013] Count the number of rows in the data table to be stored, and divide each column of the data table into m sub-data sets according to the number of rows in the data table. The i-th sub-data set of each column of data includes the data from the N(i-1)+1th row to the N*ith row of the column, and the m-th sub-data set of each column of data includes the data from the N(m-1)+1th row to the nth row of the column. , n is the number of rows in the data table, 1≤i≤m-1, Indicates rounding up.
[0014] Preferably, the method of assigning a corresponding number to each sub-data set in step S1 is as follows: assigning a corresponding number j to the j-th sub-data set in each column of data, 1≤j≤m.
[0015] Preferably, the configuration parameters include one or more of a method for handling null values, a method for handling abnormal type data, whether the data is compressed, and whether the data is encrypted.
[0016] Preferably, when the configuration parameters of the sub-data set include a method for processing null values, a method for processing abnormal data types, data compression required, data encryption required, and an encryption key, the method for storing the sub-data set as a data file after processing it according to the corresponding configuration parameters in step S3 is as follows:
[0017] Handle the null values in the sub-dataset in the same way as null values;
[0018] Process the abnormal type data in the sub-data set according to the processing method of abnormal type data;
[0019] Compress the sub-dataset into a compressed file according to a preset compression mechanism;
[0020] The compressed file is encrypted into an encrypted file using an encryption key, and the encrypted file is stored as a data file.
[0021] Preferably, m threads are used to execute step S3, and the m threads correspond one-to-one to the m sub-data sets of each column of data respectively. Each thread processes the corresponding sub-data set in each column of data according to the corresponding configuration parameters and stores it as a data file, and generates sub-data set metadata corresponding to the data file.
[0022] A data table query method of the present invention, wherein the data table is stored using the above-mentioned data table storage method, comprises the following steps:
[0023] M1: Receives the query request sent by the querying party;
[0024] M2: Read the data table meta information to determine whether the query request is legal. If so, execute step M3; otherwise, reject the query request.
[0025] M3: Determine whether the data table is complete. If so, execute step M4; otherwise, output a warning indicating that the data table is incomplete;
[0026] M4: Obtain the corresponding data file according to the column name and number of the sub-dataset to be queried recorded in the query request, and determine whether the data file is encrypted. If so, decrypt the data file and send it to the query party; otherwise, directly send the data file to the query party.
[0027] Preferably, the query request includes the column name, number and encryption key of the sub-dataset to be queried.
[0028] Preferably, the step M2 comprises the following steps:
[0029] M21: Read data table meta information;
[0030] M22: Determine whether the column name and number of the sub-dataset recorded in the query request exist in the data table meta-information. If yes, execute step M23; otherwise, determine that the query request is illegal and reject the query request.
[0031] M23: Determine whether the encryption key recorded in the query request is consistent with the encryption key recorded in the configuration parameter in the sub-dataset metadata corresponding to the sub-dataset to be queried. If so, determine that the query request is legal and execute step M3; otherwise, determine that the query request is illegal and reject the query request.
[0032] Preferably, the method for determining whether the data table is complete in step M3 is as follows: check whether each sub-data set exists one by one according to the column name, column type, number of rows, and number of sub-data sets recorded in the data table meta-information; if each sub-data set exists, the data table is determined to be complete; otherwise, the data table is determined to be incomplete.
[0033] The beneficial effects of the present invention are as follows: (1) the data in the data table is divided into multiple sub-data sets for storage, and the data can be read and divided and stored in the case of low memory, thereby improving the efficiency of subsequent data storage and query, and the query response is fast. (2) Multiple threads can be used to execute the sub-data set storage task in parallel, thereby improving the storage efficiency. (3) Each sub-data set can have a separate corresponding configuration parameter, which is convenient for performing different storage processing on sub-data sets with different storage requirements. (4) Data table meta information and sub-data set meta information are generated, which is convenient for query verification, data set integrity verification, and sub-data set positioning when querying the data table later, thereby improving the query efficiency. (5) The sub-data set can be compressed and encrypted for storage. The compression and encryption can ensure that the data security is protected without occupying a large amount of storage, thereby reducing the storage occupancy of the data. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 is a flow chart of an embodiment;
[0035] Figure 2 is a schematic diagram illustrating an example of an embodiment. DETAILED DESCRIPTION
[0036] The technical solution of the present invention is further specifically described below through embodiments and in conjunction with the accompanying drawings.
[0037] Embodiment: A data table storage method of this embodiment, such as Figure 1 As shown, the following steps are included:
[0038] S1: Split each column of data in the data table to be stored into m sub-data sets, and assign a corresponding number to each sub-data set.
[0039] The method of dividing each column of data in the data table to be stored into m sub-data sets in step S1 is as follows:
[0040] Count the number of rows in the data table to be stored, and divide each column of the data table into m sub-data sets according to the number of rows in the data table. The i-th sub-data set of each column of data includes the data from the N(i-1)+1th row to the N*ith row of the column, and the m-th sub-data set of each column of data includes the data from the N(m-1)+1th row to the nth row of the column. , n is the number of rows in the data table, 1≤i≤m-1, Indicates rounding up.
[0041] The method of assigning a corresponding number to each sub-data set in step S1 is as follows: assign a corresponding number j to the j-th sub-data set in each column of data, 1≤j≤m.
[0042] For example, if the data table to be stored has 1 billion rows and 10 columns, it is first split into 10 data sets of 1 billion rows and 1 column, and marked by column name ColumnName; then, each data set of 1 billion rows and 1 column is split into 1,000 data sets of 1 million rows and 1 column, and each 1 million rows is marked with a unique number ChunkId that increases from 1, and each 1 million 1 column data set is stored as an independent sub-dataset. Therefore, this data table of 1 billion rows and 10 columns to be stored will eventually be split into 10,000 sub-datasets, each of which has a unique number column name pair (ChunkId, ColumnName) coordinate, and this sub-dataset can be accessed later by the coordinate.
[0043] S2: Read the configuration parameters of each sub-data set set by the user, where the configuration parameters include one or more of a method for handling null values, a method for handling abnormal data types, whether the data is compressed, and whether the data is encrypted.
[0044] The way to handle null values and abnormal data types is to fill them with a default value, such as 0, average value, median, etc.
[0045] In this embodiment, the configuration parameters include that the processing method for null values is filling with 0, the processing method for abnormal type data is filling with 0, the data needs to be compressed, the compression mechanism is the LZ4 compression algorithm mechanism, the data needs to be encrypted, and the encryption key is the key of the AES-GCM encryption algorithm.
[0046] S3: Each sub-dataset is processed according to the corresponding configuration parameters and stored as a data file, and the sub-dataset metadata corresponding to the data file is generated. The sub-dataset metadata includes the sub-dataset number, column name, column type, number of rows, configuration parameters, and storage address.
[0047] The method to process the sub-dataset according to the corresponding configuration parameters and store it as a data file is as follows:
[0048] Handle the null values in the sub-dataset in the same way as null values;
[0049] Process the abnormal type data in the sub-data set according to the processing method of abnormal type data;
[0050] Compress the sub-dataset into a compressed file according to a preset compression mechanism;
[0051] The compressed file is encrypted into an encrypted file using an encryption key, and the encrypted file is stored as a data file.
[0052] In this embodiment, m threads are used to execute step S3, and the m threads correspond one-to-one to the m sub-data sets of each column of data. Each thread processes the corresponding sub-data set in each column of data according to the corresponding configuration parameters and stores it as a data file, and generates the sub-data set metadata corresponding to the data file.
[0053] S4: Summarize all sub-dataset meta-information to generate data table meta-information, which includes the column name, column type, number of rows, number of sub-datasets, and sub-dataset meta-information of the data table.
[0054] In this solution, the data table to be stored has n rows and k columns, and each column of data has a corresponding column name and column type. The n rows of the data table to be stored are divided into m segments, and each column of data in each segment constitutes a sub-data set. The sub-data sets constituted by each column of data in each segment have the same number, so each sub-data set can be located by coordinates (number, column name) for easy query. Users can set the maximum number of rows that each sub-data set can have. Dividing each column of data into m segments to form m sub-data sets can make highly correlated data in the same sub-data set, improving the efficiency of subsequent data queries.
[0055] After the data table to be stored is divided into multiple sub-datasets, each sub-dataset is processed according to the corresponding configuration parameters and stored as a data file. Multiple threads can be used to perform storage tasks in parallel, which improves storage efficiency. Each sub-dataset can have a separate corresponding configuration parameter, which facilitates different storage processing for sub-datasets with different storage requirements. Through encryption and compression mechanisms, the storage occupancy of actual files is reduced and data security is guaranteed.
[0056] Finally, the metadata of the data table and the sub-dataset metadata are generated to facilitate query verification, data set integrity verification, and sub-dataset location when querying the data table later. This solution uses Apache Arrow as the byte specification standard to enable unified standard communication and data transmission between multiple programs.
[0057] For example:
[0058] A data table with n rows and k columns is named ColumnName. The column names of k columns are Column1, Column2, ... Columnk. Figure 2 As shown, the following steps are included:
[0059] Each column of data in the data table is divided into m sub-datasets. The i-th sub-dataset of each column of data includes the data from the N(i-1)+1th row to the N*ith row of the column of data. The m-th sub-dataset of each column of data includes the data from the N(m-1)+1th row to the nth row of the column of data. , n is the number of rows in the data table, 1≤i≤m-1, It means rounding up, and assigning the corresponding number j to the j-th sub-dataset of each column of data, 1≤j≤m.
[0060] The steps to split the sub-datasets are as follows:
[0061] Get N rows of the data table one by one, for a total of m-1 times. The last time gets the N(m-1)+1th row to the nth row. Each time it is obtained, it is marked with a unique corresponding number ChunkId. The numbers ChunkId marked in sequence for m times of acquisition are Chunk1, Chunk2, ... Chunkk. Split the data obtained each time by column to get k sub-datasets. Each sub-dataset has a unique coordinate (ChunkId, ColumnName). For example, the coordinates of the second sub-dataset of column 1 are (Chunk2, column 1). Split the data table into k*m sub-datasets.
[0062] Read the configuration parameters of each sub-dataset set by the user. If the configuration parameter is null, fill it with 0. If the abnormal type data is processed, fill it with 0. The data needs to be compressed and the compression mechanism is the LZ4 compression algorithm mechanism. The data needs to be encrypted and the encryption key is the key of the AES-GCM encryption algorithm.
[0063] Each sub-dataset is processed according to the corresponding configuration parameters and stored as a data file, and the sub-dataset metadata corresponding to the data file is generated, recorded as Chunk-Meta. The sub-dataset metadata includes the sub-dataset number, column name, column type, number of rows, configuration parameters, and storage address.
[0064] Summarize all sub-dataset metadata to generate data table metadata, denoted as Meta. The data table metadata includes the data table column name, column type, number of rows, number of sub-datasets, and sub-dataset metadata.
[0065] A data table query method of this embodiment, in which a data table is stored using the above-mentioned data table storage method, includes the following steps:
[0066] M1: Receives the query request sent by the query party, which includes the column name, number, and encryption key of the sub-dataset to be queried;
[0067] M2: Read the data table meta information to determine whether the query request is legal. If so, execute step M3; otherwise, reject the query request.
[0068] M3: Determine whether the data table is complete. If so, execute step M4; otherwise, output a warning that the data table is incomplete, indicating that the data may have been modified;
[0069] M4: Obtain the corresponding data file according to the column name and number of the sub-dataset to be queried recorded in the query request, and determine whether the data file is encrypted. If so, decrypt the data file and send it to the query party; otherwise, directly send the data file to the query party.
[0070] Step M2 includes the following steps:
[0071] M21: Read data table meta information;
[0072] M22: Determine whether the column name and number of the sub-dataset recorded in the query request exist in the data table meta-information. If yes, execute step M23; otherwise, determine that the query request is illegal and reject the query request.
[0073] M23: Determine whether the encryption key recorded in the query request is consistent with the encryption key recorded in the configuration parameter in the sub-dataset metadata corresponding to the sub-dataset to be queried. If so, determine that the query request is legal and execute step M3; otherwise, determine that the query request is illegal and reject the query request.
[0074] The method for determining whether the data table is complete in step M3 is as follows: check whether each sub-data set exists one by one according to the column name, column type, number of rows, and number of sub-data sets recorded in the data table meta-information. If each sub-data set exists, the data table is determined to be complete; otherwise, the data table is determined to be incomplete.
[0075] This method can be used in scenarios such as privacy computing and machine learning. For example: User A needs to use a large amount of data for privacy computing and machine learning, but the entire data table must be read each time it is used, causing memory burden and waste of computing resources. When using data in a streaming manner, the data system has to continue to maintain the file descriptor and wait for the calculation to complete, which reduces the flexibility of the system. Moreover, each time the test set and development set are used, unnecessary data has to be read repeatedly, which increases the time and cost of data reading and loading, and it is impossible to rerun the breakpoint. User A uses the data table storage method of this embodiment to store the data table, configures the storage method of each sub-data set by configuring parameters, and uses the data table query method of this embodiment to query a specific sub-data set in the data table, avoiding redundant data reading, improving the flexibility of data use, and significantly improving computing efficiency.
Claims
1. A data table storage method, wherein the data table to be stored has n rows and k columns, and each column of data has a corresponding column name and column type, characterized in that: The following steps are involved: S1: Split each column of data in the data table to be stored into m sub-data sets, and assign a corresponding number to each sub-data set; S2: Read the configuration parameters of each sub-data set set by the user. Each sub-data set may have a corresponding configuration parameter. The configuration parameter includes one or more of a null value processing method, an abnormal type of data processing method, whether the data is compressed, and whether the data is encrypted; S3: After processing each sub-dataset according to the corresponding configuration parameters, store it into a data file, and generate the sub-dataset meta information corresponding to the data file, the sub-dataset meta information includes the sub-dataset number, column name, column type, number of rows, configuration parameters, and storage address; S4: Summarize all sub-dataset meta-information to generate data table meta-information, which includes the column name, column type, number of rows, number of sub-datasets, and sub-dataset meta-information of the data table; The method of dividing each column of data in the data table to be stored into m sub-data sets in step S1 is as follows: Count the number of rows in the data table to be stored, and divide each column of the data table into m sub-data sets according to the number of rows in the data table. The i-th sub-data set of each column of data includes the data from the N(i-1)+1th row to the N*ith row of the column, and the m-th sub-data set of each column of data includes the data from the N(m-1)+1th row to the nth row of the column. , n is the number of rows in the data table, 1≤i≤m-1, Indicates rounding up; The method of assigning a corresponding number to each sub-data set in step S1 is as follows: assigning a corresponding number j, 1≤j≤m, to the j-th sub-data set of each column of data; When the configuration parameters of the sub-dataset include the processing method of null values, the processing method of abnormal type data, data compression required, data encryption required, and encryption key, the method of storing the sub-dataset as a data file after processing it according to the corresponding configuration parameters in step S3 is as follows: Handle the null values in the sub-dataset in the same way as null values; Process the abnormal type data in the sub-data set according to the processing method of abnormal type data; Compress the sub-dataset into a compressed file according to a preset compression mechanism; The compressed file is encrypted into an encrypted file using an encryption key, and the encrypted file is stored as a data file.
2. A data table storage method according to claim 1, characterized in that: Step S3 is performed using m threads, and the m threads correspond one-to-one to the m sub-datasets of each column of data respectively. Each thread processes the corresponding sub-dataset in each column of data according to the corresponding configuration parameters and stores it as a data file, and generates the sub-dataset metadata corresponding to the data file.
3. A data table query method, wherein the data table is stored using a data table storage method according to any one of claims 1 to 2, characterized in that: The following steps are involved: M1: Receives the query request sent by the querying party; M2: Read the data table meta information to determine whether the query request is legal. If so, execute step M3; otherwise, reject the query request. M3: Determine whether the data table is complete. If so, execute step M4; otherwise, output a warning indicating that the data table is incomplete; M4: Obtain the corresponding data file according to the column name and number of the sub-dataset to be queried recorded in the query request, and determine whether the data file is encrypted. If so, decrypt the data file and send it to the query party; otherwise, directly send the data file to the query party.
4. A data table query method according to claim 3, characterized in that: The query request includes the column name, number and encryption key of the sub-dataset to be queried.
5. A data table query method according to claim 4, characterized in that: The step M2 comprises the following steps: M21: Read data table meta information; M22: Determine whether the column name and number of the sub-dataset recorded in the query request exist in the data table meta-information. If yes, execute step M23; otherwise, determine that the query request is illegal and reject the query request. M23: Determine whether the encryption key recorded in the query request is consistent with the encryption key recorded in the configuration parameter in the sub-dataset metadata corresponding to the sub-dataset to be queried. If so, determine that the query request is legal and execute step M3; otherwise, determine that the query request is illegal and reject the query request.
6. A data table query method according to claim 3, characterized in that: The method for judging whether the data table is complete in step M3 is as follows: checking whether each sub-data set exists one by one according to the column name, column type, number of rows, and number of sub-data sets recorded in the data table meta-information; if each sub-data set exists, the data table is judged to be complete; Otherwise, the data table is judged to be incomplete.
Citation Information
Patent Citations
Method for dynamically grouping and storing according to columns in column storage engine
CN114706861A
Index generation method and lightweight safe space range query method and device with text constraint
CN117520333A
