Replace Column names and datatype in Hive

0 votes
Hi. Can someone tell me how I can replace the name and datatype of a column in Hive table? I have some data in that column of datatype INT and want to change the name of this column, and datatype to STRING. So if I replace the name, will the data still exist or will it be erased?
May 21, 2019 in Big Data Hadoop by Karan
27,123 views

1 answer to this question.

–1 vote

You can replace the column name and the datatype using the ALTER command. Refer to the command below:

hive> ALTER TABLE <tablename> REPLACE COLUMNS (<old column name> INT, <new column name> STRING);

This command will only change the schema of the table i.e., it will change the column name and the datatype but will not affect the data stored in the column. 

answered May 21, 2019 by John

Replace columns removes all existing columns and add the ones mentioned. Better option is using 'Change'.

hive> ALTER TABLE <tablename> CHANGE <old column name>, <new column name> STRING;

Related Questions In Big Data Hadoop

0 votes
1 answer

Hadoop: How to get the column name along with the output in Hive?

You can get the column names by ...READ MORE

answered Nov 21, 2018 in Big Data Hadoop by Omkar
• 69,210 points
4,589 views
0 votes
2 answers

How to get column names from Hive table?

To get all the columns of a ...READ MORE

answered Jun 4, 2019 in Big Data Hadoop by anonymous

edited Jun 4, 2019 by Omkar 18,948 views
0 votes
1 answer

How to replace characters in string in hive?

You can do it using regexp_replace. This is ...READ MORE

answered Nov 30, 2018 in Big Data Hadoop by Omkar
• 69,210 points
16,696 views
–1 vote
1 answer

Beeline and Hive Query Editor in Embedded mode

Running Hive client tools with embedded servers ...READ MORE

answered Dec 31, 2018 in Big Data Hadoop by Omkar
• 69,210 points
1,254 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
10,559 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,185 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
104,217 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,390 points
4,260 views
0 votes
1 answer

How to add column inside a table in Hive?

Hi, Yes, we can add column inside a ...READ MORE

answered May 15, 2019 in Big Data Hadoop by Gitika
• 65,910 points
49,475 views
0 votes
1 answer

Hive: LOCATION and WITH DBPROPERTIES command in create table command

By default, the Hive database will be ...READ MORE

answered May 22, 2019 in Big Data Hadoop by Firoz
3,643 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