Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
55 views2 pages

Hive Functions for Data Analysts

This document discusses using advanced functions in Hive such as explode(), upper(), and regex_replace() on a table called "students" that contains student data with fields like name, id, subjects, feeDetails, and phoneNumber. It provides examples of creating the table from data, loading data into the table from a file, and example queries using the advanced functions to explode arrays and maps, convert to uppercase, and replace characters in fields.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views2 pages

Hive Functions for Data Analysts

This document discusses using advanced functions in Hive such as explode(), upper(), and regex_replace() on a table called "students" that contains student data with fields like name, id, subjects, feeDetails, and phoneNumber. It provides examples of creating the table from data, loading data into the table from a file, and example queries using the advanced functions to explode arrays and maps, convert to uppercase, and replace characters in fields.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Using Advanced Functions in Hive

You need to download the “Student.dat” dataset given below the video.

Creating Table from the data


1. To create the table from the data use the below query
CREATE​ ​TABLE​ ​IF​ ​NOT​ ​EXISTS​ students (
name​ ​STRING​,
id​ ​INT​,
subjects ​ARRAY​<​STRING​>,
feeDetails ​MAP​<​STRING​, ​FLOAT​>,
phoneNumber ​STRUCT​<areacode:​INT​, ​number​:​INT​> )
ROW​ ​FORMAT​ ​DELIMITED
FIELDS​ ​TERMINATED​ ​BY​ ​','
COLLECTION ITEMS ​TERMINATED​ ​BY​ ​'#'
MAP​ ​KEYS​ ​TERMINATED​ ​BY​ ​'|'
LINES​ ​TERMINATED​ ​BY​ ​'\n'
STORED​ ​AS​ TEXTFILE;

2. Load the data into the table​(if stored on HDFS)​, remember this will move the file to

load​ ​data​ inpath ​'add path to your file here'​ overwrite ​into​ ​table
students;

Note:​ If you are using the file located on your local directory on VM you will need to use the
below query.

load​ ​data​ ​local​ inpath ​'add path to your file here'​ overwrite ​into
table​ students;
3. To verify if the data has been loaded correctly use the below query

Select​ * ​FROM​ students;


Using Advanced Functions
1. Explode()
Select​ explode(feedetails) ​FROM​ students;
Select​ explode(subjects) ​FROM​ students;
Select​ explode(feedetails) F​ ROM​ students ​WHERE​ ​name​=​"Alexa"​;

2. Upper()
Select​ ​upper​(​name​) ​from​ students;

3. Regex_Replace()
Select​ regexp_replace(​concat​(​upper​(​name​),​id​),​' '​,​''​) ​as​ username ​from
students;

Note:​ Please be careful while copying queries from documents to Hue/CLI for running queries, especially
those involving quotations marks. Sometime the quotes are not properly copied and upon running the
query you may receive an error, replacing the quotes on Hue/CLi should solve the problem.

You might also like