There are two types of tables in Hive ,one is Managed table and second is external table.
the difference is , when you drop a table, if it is managed table hive deletes both data and meta data,if it is external table Hive only deletes metadata.
Now we learn few things about these two
1. Table Creation
by default It is Managed table .
If you want to create a external table ,you will use external keyword.
for example assume you have emp.csv file under directory /data/employee
to create a managed table we use normal syntax like below
create table managedemp(col1 datatype,col2 datatype, ....) row format delimited fields terminated by 'delimiter character'
location '/data/employee'
but to create external table ,we use external keyword like below
create external table managedemp(col1 datatype,col2 datatype, ....) row format delimited fields terminated by 'delimiter character'
location '/data/employee'
2. Differentiation
How do you check wether existing table is managed or external table?
To check that we use describe command like below
describe formatted tablename;
It displays complete meta data of a table.you will see one row called table type which will display either MANAGED_TABLE OR EXTERNAL_TABLE
for example if it is managed table ,you will see
Table Type: MANAGED_TABLE
if it is external table ,you will see
Table Type: EXTERNAL_TABLE
3. Drop
As I already said If you drop a managed table both data and meta data will be deleted
if you drop an external table only meta data is deleted ,external table is a way to protect data against accidental drop commands.
You can check this by below process.
use describe formatted tablename command and it gives location details like below.
Location :hdfs://namnodeip:portno/data/employee
after dropping the table if you use
hadoop fs -ls hdfs://namnodeip:portno/data/employee command
you should get no such file or directory exits in case of managed table.
or you should get contents of that directory in case of external table.
and the last line is try to use external table in your project ,once you drop it ,do not forget to remove directory if you do not need it anymore .
the difference is , when you drop a table, if it is managed table hive deletes both data and meta data,if it is external table Hive only deletes metadata.
Now we learn few things about these two
1. Table Creation
by default It is Managed table .
If you want to create a external table ,you will use external keyword.
for example assume you have emp.csv file under directory /data/employee
to create a managed table we use normal syntax like below
create table managedemp(col1 datatype,col2 datatype, ....) row format delimited fields terminated by 'delimiter character'
location '/data/employee'
but to create external table ,we use external keyword like below
create external table managedemp(col1 datatype,col2 datatype, ....) row format delimited fields terminated by 'delimiter character'
location '/data/employee'
2. Differentiation
How do you check wether existing table is managed or external table?
To check that we use describe command like below
describe formatted tablename;
It displays complete meta data of a table.you will see one row called table type which will display either MANAGED_TABLE OR EXTERNAL_TABLE
for example if it is managed table ,you will see
Table Type: MANAGED_TABLE
if it is external table ,you will see
Table Type: EXTERNAL_TABLE
3. Drop
As I already said If you drop a managed table both data and meta data will be deleted
if you drop an external table only meta data is deleted ,external table is a way to protect data against accidental drop commands.
You can check this by below process.
use describe formatted tablename command and it gives location details like below.
Location :hdfs://namnodeip:portno/data/employee
after dropping the table if you use
hadoop fs -ls hdfs://namnodeip:portno/data/employee command
you should get no such file or directory exits in case of managed table.
or you should get contents of that directory in case of external table.
and the last line is try to use external table in your project ,once you drop it ,do not forget to remove directory if you do not need it anymore .
Struggled to find a decent guide on working with tables in Hive, thank you!
ReplyDeleteGood explanation. Thanks dear!
ReplyDeleteMua vé tại đại lý vé máy bay Aivivu, tham khảo
ReplyDeleteVé máy bay đi Mỹ
chuyến bay từ mỹ về việt nam hôm nay
giá vé nhật việt
vé máy bay từ đức về việt nam giá rẻ
lịch bay từ canada về việt nam
Chuyến bay từ Hàn Quốc về Việt Nam
khách sạn cách ly ở hà nội
Good Document. Helped me to understand types of tables in Hive. Thank you.
ReplyDeleteI've never tried creating this one. Thanks for sharing! https://www.aaaroofcompany.com
ReplyDeleteGood article about hadoop technology You may like Updated content at Hadoop Quiz all about hadoop
ReplyDeleteyurtdışı kargo
ReplyDeleteresimli magnet
instagram takipçi satın al
yurtdışı kargo
sms onay
dijital kartvizit
dijital kartvizit
https://nobetci-eczane.org/
6C3
salt likit
ReplyDeletesalt likit
dr mood likit
big boss likit
dl likit
dark likit
Q06Aİ