Get DayName in Apache Hive & Impala

It’s sometimes important to display the day name for the specified date when creating summary reports, pivot tables, and charts. We commonly save data in the database in one of two formats: date with timestamp or plain date. Without having to develop User Defined Functions, we can get the part of the date as well as the week day name using built-in functions. Let’s look at how Apache Hive and Apache Impala can help.

Apache Hive:
SELECT DATE_FORMAT(DATE_ADD(TO_DATE(CURRENT_TIMESTAMP()), 0), ‘EEEE’);
The current day, i.e. “Friday,” was returned. Instead of 0 you can enter positive and negative values to see Tomorrow’s or Yesterday’s day name,” as shown below.

SELECT DATE_FORMAT(DATE_ADD(TO_DATE(CURRENT_TIMESTAMP()), 1), ‘EEEE’);
This returned tomorrow’s day name.

SELECT DATE_FORMAT(DATE_ADD(TO_DATE(CURRENT_TIMESTAMP()), -1), ‘EEEE’);
This returned yesterday’s day name.

Apache Impala:
Without having to think about workarounds, Apache Impala provides a large number of built-in functions. One of these is the DAYNAME function, which shows the day-name for the given date.

SELECT DAYNAME(NOW());
Returned: Friday

This slideshow requires JavaScript.


Hope you find this article helpful.

Please subscribe for more interesting updates.

2 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s