Documente Academic
Documente Profesional
Documente Cultură
Hive Commands
·0 Class will start with refreshing the previous class with QA…. (30)
·1 Ensure all student successfully installed hive & in hive shell (20)
Today’s topics:
·2 Create, alter and drop table in hive ... … .. . (30)
·3 Create, load and display internal table.. .. .. (30)
·4 Create, load and display external table.. .. .. (30)
·5 Brief discussion – cloudera . .. (10)
·6 Questions / answers.. .. .. .. .. .. .. .. .. .. . (30)
Create, alter and drop table in hive
Remember
·7 Hive shells look like “hive>” in linux
·8 For terminating hive shell, use the command exit; or quit;
·9 All hive commands ends with “ ; “
·10 Successful command execution will show “OK” and time taken for the execution
with other data.
·11 hive commands as shown below are written with red font to be familiar with
hive commands.
·12 Commands are case in-sensitive.
Create table
Be in hadoopuser _-> run hadoop and yarn ->jps ->type 'hive' and press enter.
·13 create table employee(empid int, empname string);
# create a table “employee” with 2 columns with title and type of text.
·14 show tables; # The command will show the name of the table created.
·15 Describe employee; # will display the schema or, desc employee;
·16 show Databases; # The command will show the name of the database (in
this case the name of default Database is “default.”)
Alter table
·17 alter table employee rename to employeenew;
·18 show tables; # The command will show the name of the table
altered.
Drop table
·19 drop table employeenew; # This command will delete the table.
·20 Show tables; # No tables will be displayed
# will delete the table as mentioned. If it is internal table, it will delete the schema
and the data altogether. For external table, data is not lost only the schema will
be deleted.
Loading data from local file ( from local machine into hive)
load data local inpath ‘/tmp/car’ into table vehicle; # loading data to
table.
"local" -- keyword will not be used above if data is loaded from HDFS
Create a table with full schema (create an external table in hive and load data from
HDFS into this external file --data coming from HDFS which is external source, thats why
data will be saved in a external type file in hive) type external file
create external table pupil(fname string, lname string)
row format delimited
fields terminated by ‘\t’
stored as textfile; (# optional) # table schema created in hive
# Check the table again under user/hive/warehouse, and the table will be found to be
existed.