Skip to main content
Jmeks
Silver ⭐️⭐️
February 21, 2022
Solved

Delete partition Hive error

Hi guys, i am trying some hive partitions but i am getting the following errors. kindly help figure out the problem.

 

0: jdbc:hive2://svdt5hadoopms02.bigdatadev.sa> ALTER TABLE customer_transaction_extract DROP IF EXISTS PARTITION (date='date=2019-11-13') PURGE;
Error: Error while compiling statement: FAILED: ParseException line 1:67 cannot recognize input near 'date' '=' ''date=2019-11-13'' in drop partition statement (state=42000,code=40000)


0: jdbc:hive2://svdt5hadoopms02.bigdatadev.sa> ALTER TABLE customer_transaction_extract DROP IF EXISTS PARTITION (date='date="2019-11-13"') PURGE;
Error: Error while compiling statement: FAILED: ParseException line 1:67 cannot recognize input near 'date' '=' ''date="2019-11-13"'' in drop partition statement (state=42000,code=40000)



0: jdbc:hive2://svdt5hadoopms02.bigdatadev.sa> ALTER TABLE customer_transaction_extract DROP IF EXISTS PARTITION (date=`2019-11-13`) PURGE;
Error: Error while compiling statement: FAILED: ParseException line 1:67 cannot recognize input near 'date' '=' '2019-11-13' in drop partition statement (state=42000,code=40000)


0: jdbc:hive2://svdt5hadoopms02.bigdatadev.sa> ALTER TABLE customer_transaction_extract DROP IF EXISTS PARTITION (date >='1648-10-03', date <='2022-02-15') ;
Error: Error while compiling statement: FAILED: ParseException line 1:67 cannot recognize input near 'date' '>=' ''1648-10-03'' in drop partition statement (state=42000,code=40000)


0: jdbc:hive2://svdt5hadoopms02.bigdatadev.sa> ALTER TABLE customer_transaction_extract DROP IF EXISTS PARTITION (date >='1648-10-03');
Error: Error while compiling statement: FAILED: ParseException line 1:67 cannot recognize input near 'date' '>=' ''1648-10-03'' in drop partition statement (state=42000,code=40000)


0: jdbc:hive2://svdt5hadoopms02.bigdatadev.sa> ALTER TABLE customer_transaction_extract DROP PARTITION (date >='1644948900', date <='1644949001');
Error: Error while compiling statement: FAILED: ParseException line 1:57 cannot recognize input near 'date' '>=' ''1644948900'' in drop partition statement (state=42000,code=40000)

0: jdbc:hive2://svdt5hadoopms02.bigdatadev.sa> ALTER TABLE customer_transaction_extract DROP PARTITION (date >='1644948900', date <='1644949001');
Error: Error while compiling statement: FAILED: ParseException line 1:57 cannot recognize input near 'date' '>=' ''164494

mszurap
mszurapAnswer
Platinum ⭐️
February 22, 2022

Hi @Jmeks ,Please check again how the table has been created or how those partitions were created ("describe formatted <table> partition <partspec>"), as the same is still working for me even on HDP 3.1.0:

create table mdatetest (col1 string) partitioned by (`date` date) location '/tmp/md';

alter table mdatetest add partition (`date`="2022-02-22");



show partitions mdatetest;

+------------------+
| partition |
+------------------+
| date=2022-02-22 |
+------------------+



alter table mdatetest drop partition (`date`="2022-02-22");

 

6 replies

mszurap
Platinum ⭐️
Platinum ⭐️
February 21, 2022

Hi @Jmeks ,

I assume the partitioning column for this table is literally named as "date". Please note that "date" is a reserved word in Hive (see the docs for reference), so it is not recommended to use it in table names and column identifiers. If you really need to use it as an identifier, then encapsulate it within backticks. For example:

ALTER TABLE customer_transaction_extract DROP IF EXISTS PARTITION (`date`="2019-11-13");

Hope this helps.

 Best regards, Miklos

Translate
Jmeks
JmeksAuthor
Silver ⭐️⭐️
February 21, 2022

Hi Miklos,

 

I appreciate your help but using your code still throws the following error:

 


| date=2019-11-13 |
| date=2022-02-15 |
| date=2022-02-16 |
| date=2022-02-17 |
| date=2022-02-19 |
| date=2022-02-20 |
| date=__HIVE_DEFAULT_PARTITION__ |
+----------------------------------+
790 rows selected (0.284 seconds)


0: jdbc:hive2://svdt5hadoopms02.bigdatadev.sa> ALTER TABLE customer_transaction_extract DROP IF EXISTS PARTITION (`date`="2019-11-13");


Error: Error while compiling statement: FAILED: SemanticException Unexpected unknown partitions for (date = DATE'2019-11-13') (state=42000,code=40000)

Translate
mszurap
Platinum ⭐️
Platinum ⭐️
February 21, 2022

Hi @Jmeks ,

Can you clarify which CDH/HDP/CDP version do you have?

What is the datatype of that "date" partitioning column?

The mentioned syntax works for both string and date datatypes in CDH 6.x.

Translate