A method for implementing flexible field changes in large-scale partitioned tables in Hive

By dividing the Hive partition table by year and integrating it with Hive views, the time-consuming problem of changing large-scale partition table fields is solved, and efficient and flexible field adjustment and data query are achieved.

CN119621723BActive Publication Date: 2025-09-234399 NETWORK
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411694356.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-25
Publication Date
2025-09-23
Estimated Expiration
2044-11-25

AI Technical Summary

Technical Problem

In a Hive environment, when changing fields in large-scale partitioned tables, existing technologies are time-consuming and require reprocessing historical data, resulting in huge resource consumption and making it difficult to achieve flexible and efficient field adjustments.

Method used

Adopting a year-based partitioning strategy, the original large-scale partitioned table was migrated to an independent new data table. Metadata was integrated and updated through Hive views. Logical units were rebuilt using the union all operation and time filter conditions, and field changes were performed at the view level.

Benefits of technology

It greatly simplifies the complexity of field changes and improves operational efficiency. It is suitable for emergency scenarios without interfering with existing businesses. Users can query historical data without noticing, achieving flexibility in field changes and data queries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119621723B_ABST
    Figure CN119621723B_ABST
Patent Text Reader

Abstract

The present invention provides a method for implementing flexible field changes in a Hive large-scale partitioned table, comprising: based on the divide-and-conquer principle, creating an independent new data table for each year for the original large-scale partitioned table; creating a new Hive view to reintegrate the new data tables for each year after the division into a logical unit, while retaining the table name of the original large-scale partitioned table and having the same data architecture as the original large-scale partitioned table; the field addition operation only needs to be performed on the new data table for the latest year, while the same field positions for other years are marked as null values ​​in the Hive view; field deletion and modification operations only need to be performed on the Hive view, thereby greatly improving the flexibility and timeliness of the table structure. The present invention significantly improves the data warehouse's ability to quickly and flexibly adjust the table structure when processing massive amounts of data, ensures that upper-level users' query operations are imperceptible, and realizes a field change process with minimal impact.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of big data processing, and in particular relates to a method for implementing flexible field changes in a large-scale Hive partition table. Background Art

[0002] In the current Hive environment, processing massive amounts of data is particularly critical. Particularly for partitioned tables, data volumes can reach enormous scale, posing significant challenges for field modifications. Generally speaking, for tables with hundreds of thousands of partitions, adding or modifying fields can take dozens of hours and often requires reprocessing historical data, a situation that is clearly unacceptable in real-world applications. The root cause of this problem lies in Hive's design principles, which prioritize optimizing data read operations over dynamically adjusting its structure. In the context of massive data volumes, any modification of the table structure, especially adding or removing fields, requires reconfiguring and processing all historical data according to the new structure, resulting in significant processing time and resource consumption. Therefore, flexible and efficient field modifications for such large-scale Hive partitioned tables have become a pressing technical challenge in the industry. Solutions to this problem can not only significantly improve data processing efficiency but also conserve significant computing resources, bringing economic benefits while enhancing data processing flexibility. Summary of the Invention

[0003] In view of the defects of the existing technology, the present invention provides a method for flexibly changing fields in a large-scale Hive partition table, which can effectively solve the above problems.

[0004] The technical solution adopted in the present invention is as follows:

[0005] The present invention provides a method for flexibly changing fields in a large-scale Hive partition table, comprising the following steps:

[0006] Step 1: Based on the divide-and-conquer principle, for the existing large-scale partitioned table, a year-based partitioning strategy is adopted to create independent new data tables for each year. The naming method of the new data tables is correlated with the original table name of the original large-scale partitioned table. Specifically, the table name of the new data table for the corresponding year is derived based on the original table name followed by an underscore and the corresponding year.

[0007] Step 2: Migrate the data in the original large-scale partitioned table to a new data table for the corresponding year, based on the year. Then, update and repair the metadata for each new data table to ensure metadata integration and maintenance, and guarantee the integrity and consistency of the migrated data. The new data tables for each year are then integrated to form a complete Hive table.

[0008] Step 3: After the data migration and metadata repair are completed, the original large-scale partition table is deleted;

[0009] Step 4: Create a new Hive view. This Hive view uses a union all operation combined with precise time filtering conditions to re-integrate the new data tables for each year into a logical unit, logically rebuilding the original large-scale partitioned table. The Hive view retains the table name of the original large-scale partitioned table and has the same data architecture as the original large-scale partitioned table.

[0010] Step 5: Add fields to the Hive table:

[0011] Step 5.1: For each new data table obtained for each year, first locate the new data table for the latest year and add a new field to the new data table for the latest year;

[0012] In step 5.2, after adding the new fields for the new data table for the latest year, fine-tune the Hive view by inserting null values ​​in the corresponding fields for the new data tables for other years in the Hive view. This adds new fields to the virtual overall Hive table at the view level, integrating the newly added fields into the overall architecture.

[0013] Step 6: To delete a field from a Hive table, you only need to make corresponding adjustments in the Hive view. Modify the Hive view definition and mask the fields to be deleted.

[0014] Step 7: To modify the field name in the Hive table, simply rename the target field to the new field name using the AS keyword in the Hive view.

[0015] Step 8: To change the field type in a Hive table, adjust the field type in the Hive view.

[0016] Preferably, in step 7, when modifying the field name in the Hive table, the field type needs to remain compatible during the conversion process and ensure that the data logic is reasonable.

[0017] The present invention provides a method for flexibly changing fields in a large-scale Hive partitioned table, which has the following advantages:

[0018] This paper provides a method for flexibly changing fields in large-scale partitioned Hive tables. This method significantly simplifies the complexity of field changes in large-scale partitioned tables and improves operational efficiency. It is particularly suitable for scenarios where urgent field changes are required without disrupting existing business operations. Furthermore, users can query historical data as if they were operating a single large table, enjoying the convenience of not having to rewrite historical data on a large scale, effectively achieving flexibility in field changes and data queries. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Figure 1 This is a flow chart of a method for implementing flexible field changes in a large-scale Hive partitioned table provided by the present invention. DETAILED DESCRIPTION

[0020] In order to make the technical problems, technical solutions and beneficial effects solved by the present invention more clearly understood, the present invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0021] This paper provides a method for flexibly changing fields in large-scale partitioned Hive tables. This method significantly simplifies the complexity of field changes in large-scale partitioned tables and improves operational efficiency. It is particularly suitable for scenarios where urgent field changes are required without disrupting existing business operations. Furthermore, users can query historical data as if they were operating a single large table, enjoying the convenience of not having to rewrite historical data on a large scale, effectively achieving flexibility in field changes and data queries.

[0022] The present invention provides a method for implementing flexible field changes in Hive large-scale partition tables. Figure 1 , including the following steps:

[0023] 1. A method for flexibly changing fields in a large-scale Hive partitioned table, comprising the following steps:

[0024] Step 1: Based on the divide-and-conquer principle, for the existing large-scale partitioned table, a year-based partitioning strategy is adopted to create independent new data tables for each year. The naming method of the new data tables is correlated with the original table name of the original large-scale partitioned table. Specifically, the table name of the new data table for the corresponding year is derived based on the original table name followed by an underscore and the corresponding year.

[0025] Step 2: Migrate the data in the original large-scale partitioned table to a new data table for the corresponding year, based on the year. Then, update and repair the metadata for each new data table to ensure metadata integration and maintenance, and guarantee the integrity and consistency of the migrated data. The new data tables for each year are then integrated to form a complete Hive table.

[0026] Step 3: After the data migration and metadata repair are completed, the original large-scale partition table is deleted;

[0027] Step 4: Create a new Hive view. This Hive view uses a union all operation combined with precise time filtering conditions to re-integrate the new data tables for each year into a logical unit, logically rebuilding the original large-scale partitioned table. The Hive view retains the table name of the original large-scale partitioned table and has the same data architecture as the original large-scale partitioned table.

[0028] Step 5: Add fields to the Hive table:

[0029] Step 5.1: For each new data table obtained for each year, first locate the new data table for the latest year and add a new field to the new data table for the latest year;

[0030] In step 5.2, after adding the new fields for the new data table for the latest year, fine-tune the Hive view by inserting null values ​​in the corresponding fields for the new data tables for other years in the Hive view. This adds new fields to the virtual overall Hive table at the view level, integrating the newly added fields into the overall architecture.

[0031] Step 6: To delete a field from a Hive table, you only need to make corresponding adjustments in the Hive view. Modify the Hive view definition and mask the fields to be deleted.

[0032] Step 7: To modify the field name in the Hive table, simply rename the target field to the new field name using the AS keyword in the Hive view.

[0033] Step 8: To change the field type in a Hive table, adjust the field type in the Hive view.

[0034] An embodiment is listed below:

[0035] In step 1, using a divide-and-conquer strategy, we create independent new data tables for each year in the existing large-scale partitioned table. These new tables are named to maintain consistency with the original large-scale partitioned table names. Specifically, the new table names for the corresponding year are derived from the original table name followed by an underscore and the corresponding year. This strategy streamlines data management and facilitates subsequent operations.

[0036] For example, consider an app user behavior fact table. The original large-scale partitioned table is named "app_event," with partitions organized in the format (date, event name). It contains all user behavior data from 2019 to 2024. Now, partition it by year. First, create a new table for the 2019 data, named "app_event_2019." Then, create a new table for the 2020 data, named "app_event_2020." And so on, until a new table for the 2024 data, named "app_event_2024," is created.

[0037] This naming method not only preserves the information related to the original table, but also allows you to clearly see the data year corresponding to each new data table, providing convenience for subsequent operations.

[0038] Step 2: Migrate the data in the original large-scale partitioned table to the corresponding new data tables by year. At the same time, carefully update and repair the metadata of each new data table to ensure the integrity and consistency of the migrated data. The new data tables for each year are integrated together to form a complete Hive table.

[0039] For example, for each year's new data table created previously, take the following steps:

[0040] First, migrate all the data from 2019 in the original large-scale partitioned table "app_event". By using the HDFS mv command, all the data from 2019 is successfully transferred to a new data table named "app_event_2019".

[0041] Afterwards, using the same method, flexibly migrate the data of each year into the new data table of the corresponding year until all data is migrated.

[0042] Next, the metadata of the new data tables is updated and repaired. For each new data table for each year, the msck repair table command is executed to perform elastic partition synchronization to ensure smooth metadata integration and maintenance, thereby guaranteeing the integrity and consistency of the data after migration.

[0043] Step 3: After the data migration and metadata repair are completed, the original large-scale partition table is deleted.

[0044] For example, after the data migration and metadata repair steps described above, all data in the original large-scale partitioned table "app_event" has been completely migrated to a new data table partitioned by year. Since the data in the original table is no longer used, deleting it can avoid unnecessary data confusion and redundant storage usage.

[0045] In Hive, you can directly execute the "Drop table app_event" command to safely remove the existing large-scale partitioned table "app_event." After this operation, only the newly created and populated data table, partitioned by year, remains in Hive, laying the foundation for the subsequent field changes.

[0046] Step 4: Create a new Hive view. This Hive view uses a union all operation combined with precise time filtering conditions to re-integrate the new data tables for each year into a logical unit, logically rebuilding the original large-scale partitioned table. The Hive view retains the table name of the original large-scale partitioned table and has the same data architecture as the original large-scale partitioned table.

[0047] Specifically, to logically reconstruct the original large-scale partitioned table and ensure seamless data access, a Hive view is created. This Hive view uses a union all operation combined with precise time filters to reassemble the new data tables from different years into a single logical unit while retaining the original table naming, thus not affecting existing data access patterns.

[0048] For example, create a new Hive view based on the previously split data tables by year. This Hive view retains the same name as the original table, "app_event." Create it as follows: In the create statement, use the "create view" syntax followed by "app_event," then use the as keyword to assign specific content. The specific expression is: create view app_event as select fields from app_event_2020 where datekey >= '20200101' and datekey <= '20201231' union all select fields from app_event_2021 where datekey >= '20210101' and datekey <= '20211231' union all .... Although the data is physically stored in the new data tables for each year, logically, this new Hive view reconstructs the original "app_event" table. That is to say, during data query and operation, the Hive view "app_event" has the same data architecture as the original table "app_event", which undoubtedly provides great convenience for subsequent data query and operation, making data management and use more flexible and efficient.

[0049] Step 5: Add fields to the Hive table:

[0050] Step 5.1: For each new data table obtained for each year, first locate the new data table for the latest year and add a new field to the new data table for the latest year;

[0051] Specifically, adding new fields to the new data table for the latest year is much simpler and faster than directly operating on the historical data table. This is because the size of the new data table after splitting is relatively small, and the addition operation can usually be completed within a few minutes.

[0052] For example, suppose you need to add a new field to the "app_event" table, such as the user device information field "device_info." Since the original table is already finely divided by year, the data size of the new "app_event_2024" table is relatively small. Therefore, by executing the command: ALTER TABLE app_event_2024ADDCOLUMNS(device_info string), you can quickly and efficiently add the new field to this new table. Due to the small data size, this process typically completes smoothly within a few minutes, significantly improving efficiency.

[0053] In step 5.2, after adding the new fields for the new data table for the latest year, fine-tune the Hive view by inserting null values ​​in the corresponding fields for the new data tables for other years in the Hive view. This adds new fields to the virtual overall Hive table at the view level, integrating the newly added fields into the overall architecture.

[0054] Specifically, after adding the new fields of the new data table for the latest year, by fine-tuning the Hive view, null values ​​are inserted in the corresponding field positions for the new data tables of other years, thereby adding new fields to the virtual overall Hive table and perfectly integrating the new field operations into the overall architecture.

[0055] For example, a new field "device_info" has been added to the new data table "app_event_2024." Next, you need to modify the Hive view to synchronize this new field with the new data tables for other years. Because there is no actual "device_info" information for data from 2019 to 2023, "null" values ​​are inserted into the corresponding locations in the Hive view. To do this, use the following SQL to add null values ​​as the "device_info" field for the new data tables for other years in a union query:

[0056] CREATE OR REPLACE VIEW app_event AS SELECT*,null as device_info FROMapp_event_2019UNION ALL SELECT*,null as device_info FROM app_event_2020UNIONALL SELECT*,null as device_info FROM app_event_2021UNION ALL......SELECT*,device_info FROM app_event_2024. After this operation, when users query the Hive view "app_event", they will see the "device_info" field in all new data tables. Although this field is actually null in the new data tables from 2019 to 2023, the field structure remains consistent in the entire table (Hive view) regardless of the year's data.

[0057] Step 6: To delete a field from a Hive table, you only need to make corresponding adjustments in the Hive view. Modify the Hive view definition and mask the fields to be deleted.

[0058] For example, suppose you need to delete the previously mentioned "device_info" field. Since this field was added at the view level, you only need to make adjustments within the Hive view. To do this, modify the view definition by deleting or commenting out the portion related to the "device_info" field. This effectively deletes the field from the entire Hive table while avoiding physical table operations, significantly improving work efficiency.

[0059] Step 7: To modify the field name in the Hive table, simply rename the target field to the new field name using the AS keyword in the Hive view.

[0060] For example, suppose you need to change the name of the "device_info" field in "app_event" to "device_detail." You can do this in the Hive view without having to modify the original partitioned table. Specifically, execute the following command in the Hive view: ALTER VIEW app_event AS SELECT...,device_info AS device_detail,... This will modify the field name at the view level, changing the original "device_info" field name to "display_detail," thus updating the field name.

[0061] Step 8: To change the field type in a Hive table, adjust the field type in the Hive view.

[0062] Specifically, when changing a field type in a Hive table, you can adjust the field type by applying the cast (field AS new type) command in the Hive view. This requires that the field type remains compatible during the conversion process and that the data logic is reasonable.

[0063] For example, suppose you need to change the integer field "event_id" in the "app_event" view to a string type. First, confirm that this type conversion is logically sound, both in terms of the usage scenario and the data content itself. Once this is confirmed, apply a cast operation to the "event_id" field in the Hive view using the following HQL statement: ALTER VIEW app_event SELECT other_columns, cast (event_id as string) AS event_id,... This changes the "event_id" field type at the view level, ensuring the logical consistency of the field without requiring any processing of the underlying data storage. This is both simple and efficient.

[0064] The present invention provides a method for flexibly changing fields in a large-scale Hive partitioned table. The idea is:

[0065] Based on the divide-and-conquer principle, massive Hive partitioned data tables are divided according to the year dimension. Each year corresponds to a separate new data table, and the naming rule follows the format of the original table name followed by an underscore and the corresponding year.

[0066] To achieve unified access to data for each year, a Hive view is created to logically connect the newly split data tables using the union all operation and time filter conditions. The original table name is given as the view name.

[0067] Field addition operations only need to be performed on new data tables in the most recent year, while the same field positions in other years are marked as null values ​​in the Hive view. Field deletion and modification operations only need to be performed on the Hive view, greatly improving the flexibility and timeliness of the table structure.

[0068] The present invention provides a method for implementing flexible field changes in Hive large-scale partitioned data tables. This method not only significantly improves the data warehouse's ability to quickly and flexibly adjust the table structure when processing massive amounts of data, but also ensures the imperceptibility of upper-level user query operations, thereby achieving a field change process with minimal impact.

[0069] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A method for implementing flexible field changes in a large-scale Hive partitioned table, characterized in that: The following steps are involved: Step 1: Based on the divide-and-conquer principle, for the existing large-scale partitioned table, adopt a year-based partitioning strategy and create independent new data tables for each year. The naming method of the new data table is related to the original table name of the original large-scale partitioned table. Specifically, the table name of the new data table of the corresponding year is obtained based on the original table name followed by an underscore and the corresponding year. Step 2: Migrate the data in the original large-scale partitioned table to a new data table for the corresponding year, based on the year. Then, update and repair the metadata for each new data table to ensure metadata integration and maintenance, and guarantee the integrity and consistency of the migrated data. The new data tables for each year are then integrated to form a complete Hive table. Step 3: After the data migration and metadata repair are completed, the original large-scale partition table is deleted; Step 4: Create a new Hive view. This Hive view uses a union all operation combined with precise time filtering conditions to re-integrate the new data tables for each year into a logical unit, logically rebuilding the original large-scale partitioned table. The Hive view retains the table name of the original large-scale partitioned table and has the same data architecture as the original large-scale partitioned table. Step 5: Add fields to the Hive table: Step 5.1: For each new data table obtained for each year, first locate the new data table for the latest year and add a new field to the new data table for the latest year; In step 5.2, after adding the new fields for the new data table for the latest year, fine-tune the Hive view by inserting null values ​​in the corresponding fields for the new data tables for other years in the Hive view. This adds new fields to the virtual overall Hive table at the view level, integrating the newly added fields into the overall architecture. Step 6: To delete a field from a Hive table, you only need to make corresponding adjustments in the Hive view. Modify the Hive view definition and mask the fields to be deleted. Step 7: To modify the field name in the Hive table, simply rename the target field to the new field name using the AS keyword in the Hive view. Step 8: To change the field type in a Hive table, adjust the field type in the Hive view.

2. A method for implementing flexible field changes in a large-scale Hive partition table according to claim 1, characterized in that: In step 7, when modifying the field name in the Hive table, the field type must remain compatible during the conversion process and the data logic must be reasonable.

Citation Information

Patent Citations

  • Automatic partitioning method and device for database table, and equipment

    CN110489426A

  • Data migration method and apparatus

    WO2023245941A1