Hive Query to sort data

0 votes

I have a simple table employee (id int, fname string, lname string) with data. I am trying to sort the data fname by asc order and lname by desc order into the local file location /home/cert/problem5/solution.sql so that executing 

hive -f solution.sql 

should provide the output. Please advise how to accomplish this?

Jul 14, 2019 in Big Data Hadoop by Esha
48 views

1 answer to this question.

0 votes

If you are trying to sort first name by asc and lname by desc, it does not make sense since the fname and lname are related columns that is even if we succeed in sorting both columns differently, the names are going to change for example, If we have a name Elena Gilbert, her surname might change which defeats the logic.

Here is the commands for sorting in fname acsending order :

create table emp_script (EmpId Int, Fname String, Lname String) row format delimited fields terminated by ",";

load data inpath "emp.txt" into table emp_sript;

INSERT OVERWRITE LOCAL DIRECTORY '/user/edureka_425640/emp_script_output' SELECT * from emp_script ORDER BY Fname
answered Jul 14, 2019 by Tina

Related Questions In Big Data Hadoop

0 votes
1 answer

How Impala is fast compared to Hive in terms of query response?

Impala provides faster response as it uses MPP(massively ...READ MORE

answered Mar 21, 2018 in Big Data Hadoop by nitinrawat895
• 10,850 points
505 views
+2 votes
5 answers

How to transpose/pivot data in hive?

Below is also a way for Pivot SELECT ...READ MORE

answered Oct 12, 2018 in Big Data Hadoop by Rahul
8,302 views
0 votes
1 answer

Hive: How to use insert query like SQL

It is now possible to insert like ...READ MORE

answered Nov 5, 2018 in Big Data Hadoop by Omkar
• 68,980 points
99 views
0 votes
1 answer

Hadoop Hive: How to insert data in Hive table?

First, copy data into HDFS. Then create ...READ MORE

answered Nov 12, 2018 in Big Data Hadoop by Omkar
• 68,980 points
3,554 views
0 votes
1 answer

Hadoop Hive Hbase: How to insert data into Hbase using Hive (JSON file)?

You can use the get_json_object function to parse the ...READ MORE

answered Nov 15, 2018 in Big Data Hadoop by Omkar
• 68,980 points
962 views
+1 vote
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,850 points
4,492 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,850 points
638 views
+1 vote
11 answers

hadoop fs -put command?

put syntax: put <localSrc> <dest> copy syntax: copyFr ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Aditya
25,270 views
–1 vote
1 answer

Hadoop dfs -ls command?

In your case there is no difference ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by kurt_cobain
• 9,310 points
1,689 views
0 votes
1 answer

Creating a hive script and execute in the edureka cloudlab.

Please remove -f option from hive arguments and use hql extension ...READ MORE

answered Jul 14, 2019 in Big Data Hadoop by Karan
44 views