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
916 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

To know more, It's recommended to join Big Data Online Course today.

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
• 11,380 points
2,251 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
20,019 views
+1 vote
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
• 69,220 points
900 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
• 69,220 points
9,824 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
• 69,220 points
2,946 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
• 11,380 points
11,071 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
• 11,380 points
2,569 views
+2 votes
11 answers

hadoop fs -put command?

Hi, You can create one directory in HDFS ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by nitinrawat895
• 11,380 points
109,032 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,350 points
4,635 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
754 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP