InterviewSolution
| 1. |
What are the Table types available in Hive? |
|
Answer» There are two types of tables which HIVE supports.
Hive Managed Tables: Example: 1. Create Table hive> create table univercity_db.school_table(name string, roll no int) row format delimited FIELDS terminated by ',';OK Time taken: 0.202 seconds 2. Describe table hive> describe formatted univercity_db.school_table;OK you will get extra information like whether the table is managed or an external table. when the table is created, what kind of file format, Location of the data path in HDFS, whether the object is a table or view. 3. Load the data to table from the local path hive>load data local inpath '/home/pbibhu/Desktop/blog/school' into table univercity_db.school_table;After loading from the local path you can further use hive commands to select/count/describe etc Hive External Tables: Use external tables when files are present in the remote locations, and the files should REMAIN even if the external table is dropped. Example: 1. Create Table CREATE EXTERNAL TABLE IF NOT EXISTS univercity_db.school_table( student_ID INT, FirstName STRING, LastName STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE/ORC LOCATION 'hdfs/pbibhu/school'; 2. Create partition Table CREATE EXTERNAL TABLE IF NOT EXISTS univercity_db.school_table( student_ID INT, FirstName STRING, LastName STRING) partitioned by (student_ID int) STORED AS ORC LOCATION 'hdfs/pbibhu/school'; 3. insert the data to internal table from external table,data structure should be same for both the tables. hive> CREATE TABLE IF NOT EXISTS office(EmployeeID INT,FirstName STRING, Title STRING, State STRING, Laptop STRING) STORED AS ORC;OK hive> CREATE EXTERNAL TABLE IF NOT EXISTS Office_text( EmployeeID INT,FirstName STRING, Title STRING, State STRING, Laptop STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE LOCATION '/user/pbibhu/office';OK hive> INSERT OVERWRITE TABLE office SELECT * FROM office_text; |
|