Updated on 2026-06-27 GMT+08:00

Historical Hudi Data Deletion

Scenarios

As data grows in Hudi tables, the value of older data records often decreases while they continue to consume significant storage space. To optimize storage resources and reduce costs, Hudi provides mechanisms for deleting outdated data.

Notes and Constraints

This section applies only to MRS 3.3.0-LTS or later.

Deleting Historical Data by Running the DELETE or DROP PARTITION Statement

You can run the DELETE or DROP PARTITION statement to delete historical data.

  • Use DELETE statements to remove specific records from a table. Hudi allows you to delete data based on specific conditions, such as a defined time range or a particular partition.
  • Use DROP PARTITION statements to remove specific partitions from a table. Partitions organize Hudi tables to significantly improve query performance and data management efficiency. Dropping these partitions allows you to quickly reclaim storage space.

Advantages: The operation is simple and COW and MOR tables are supported.

Disadvantages: The concurrency is low. Executing DELETE or DROP PARTITION statements during active real-time writes to Hudi tables may cause data ingestion jobs to fail due to concurrency conflicts.

For details about how to use the DELETE and DROP PARTITION statements, see sections DELETE and Drop Partition.

Deleting Historical Data by Running the call clean_data Command

The call clean_data command deletes outdated data files, including expired file versions and records marked for deletion. Regularly executing call clean_data ensures operational efficiency and continuous storage optimization for Hudi tables. Before running call clean_data, back up critical data to prevent accidental data loss.

  • Function

    The call clean_data is used to delete historical data from MOR tables.

    Advantages: The deletion operation can be executed concurrently with the data import task, which does not affect the real-time import of data.

    Disadvantages: Only MOR tables are supported, and lazy deletion depends on compaction.

  • Syntax

    call clean_data(table => 'table_name', sql => 'delete statement')

  • Parameter description
    Table 1 Parameter description

    Parameter

    Description

    table_name

    Name of the Hudi table whose data is to be deleted. The value can be in the database.tablename format.

    delete statement

    SQL statement of the select type, which is used to find the data to be deleted.

  • Example

    Delete all data whose primaryKey is smaller than 100 from the mytable table:

    call clean_data(table => 'mytable', sql=>'select *  from mytable where primaryKey < 100') 

    Clear the residual files of the clean_data command. If cleanData fails, temporary files are generated. The following command can be used to clear these temporary files:

    call clean_data(table => 'mytable', sql=>'delete cleanData') 
  • Response

    You can view query results on the client.