Loading data into hive tables

we also offer , online and classroom trainings
we support in POC
author: Bharat (sree ram)
contact : 9640892992
_______________________________________________________________



input file :  emp.txt

_____________________
101,amar,m,20000,hyd
102,amala,f,30000,pune
103,siva,m,40000,hyd
104,sivani,f,50000,hyd
105,hari,m,40000,pune
________________________

loading data  from local file to  hive table.


hive> create table  halitics.emp(ecode string, ename string, sex string, esal int, city string)
      > row format  delimited  fields terminated by ',';

hive>  Load  data  local  inpath  'emp.txt' into table  halitcs.emp;

note:  in above example  halitics is database..
    if you have already selected the database,  no need use database name  while using table name

hive>use halitics;
hive>Load  data  local  inpath  'emp.txt' into table  emp;

if you load again....

hive > Load  data  local  inpath  'emp2.txt' into table  emp;

now    the  rows of emp2.txt will be appended to emp table.

 in hdfs, 

     /user/hive/warehouse/halitics.db/emp   directory will have  2 files.. emp.txt   and emp2.txt

_____________________________________
Loading  data    from  hdfs file to hive table.   :
______________________________________

hdfs file :    /user/training/staff.txt

hive> load data  inpath  'staff.txt' into table emp;

note:  each load statement will append rows to the existed table.

_________________________________
Overriding  table data with    load statement
___________________________________

hive>  load  data local inpath 'emp.txt'   overwrite  into table  emp;

now emp table will contain  only  emp.txt data.






0 comments: