Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How can I delete/truncate data older than 7 days from a hive table.

Highlighted

How can I delete/truncate data older than 7 days from a hive table.

Rising Star
There is no date field in this table but the "input_file_name" contains date & time.

Ex: p_unicast.binary.ate.dk.20170117223832.947.dat

hive> desc mi_data;
OK
input_file_name  string
p_id             string
r_name           string
i_name           string
o_tag            string
pre_value        bigint
crnt_value       bigint
pre_out_value    bigint

2 REPLIES 2
Highlighted

Re: How can I delete/truncate data older than 7 days from a hive table.

Expert Contributor

you have to partition the table by date, then you can delete older partitions.

Highlighted

Re: How can I delete/truncate data older than 7 days from a hive table.

Expert Contributor

Is this an external table? if it is an external table then write a perl/shell script that runs daily based on a pattern it will remove files older than a certain date.

If it is not, and if it is a managed table with ORC/Parquet format, then it depends on how you load the table. While loading the table you could setup logic to populate the date in the table partition by that date and as @Avijeet Dash mentioned drop the partition that is 7 days old.

Don't have an account?
Coming from Hortonworks? Activate your account here