Tech Tidbit #1 — Write Hive data to CSV file using Shell Script

--

This script basically consumes a databasename and tablename as an argument and gets the hive data of the table into a CSV in a local file.

Tidbit:

Explanation:

Line 1–2 : Getting command line arguments for database name and table name.

Line 3 : Getting the username of the current session so that we can write the CSV to the user’s local folder later.

Line 5–6 : Making sure we have received both database name and table name from the user.

Line 7–8 : Cleaning up existing HDFS folders and local folders from previous writes.

Line 11 : Executing an hive query to write all table data to a particular HDFS directory as part files.

Line 12 : Merging the part files on HDFS and writing it out to the local directory as a CSV file.

Line 15 : Usage error printed if one of the arguments is missing.

Sample run:

Sample output:

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Sindhu Murugavel
Sindhu Murugavel

Written by Sindhu Murugavel

Bringing Tech and Principles together!

No responses yet

Write a response