創建表
創建內表
create table customer(
customerId int,
firstName string,
lastName STRING,
birstDay timestamp
) row format delimited fields terminated by ','
創建外表
CREATE EXTERNAL table salaries(
gender string,
age int ,
salary DOUBLE,
zip int
)row format delimited fields terminated by ',' LOCATION '/user/train/salaries/';
載入數據
load DATA LOCAL inpath '/root/user/customer.txt' overwrite into table customer;
load DATA LOCAL inpath '/root/user/salaries.txt' overwrite into table salaries;
查看文本數據
[root@centos172 user]# cat /root/user/customer.txt
1,f,jack,,
2,f,luccy,,
[root@centos172 user]# cat /root/user/salaries.txt
male,21,10000,1
female,22,12000,2
查看數據庫數據
hive> desc customer;
OK
customerid int
firstname string
lastname string
birstday timestamp
Time taken: 0.053 seconds, Fetched: 4 row(s)
hive> desc salaries;
OK
gender string
age int
salary double
zip int
Time taken: 0.041 seconds, Fetched: 4 row(s)
hive> select * from customer;
OK
1 f jack NULL
2 f luccy NULL
Time taken: 0.067 seconds, Fetched: 2 row(s)
hive> select * from salaries;
OK
male 21 10000.0 1
female 22 12000.0 2
Time taken: 0.066 seconds, Fetched: 2 row(s)
hive>
區別
因為我hive也是剛開始了解,所以只講一部分
1.內表主要放在hdfs中默認的hive目錄。外表指定了location
2.刪除內表,重新創建一個一樣的內表,數據不會裝載
刪除外表,重新創建一個一樣的外表,數據會自動的裝載
刪除外表的操作如下
hive> drop table salaries;
OK
Time taken: 0.092 seconds
hive> select * from salaries;
FAILED: SemanticException [Error 10001]: Line 1:14 Table not found 'salaries'
hive> show tables;
OK
customer
Time taken: 0.035 seconds, Fetched: 1 row(s)
hive> CREATE EXTERNAL table salaries(
> gender string,
> age int ,
> salary DOUBLE,
> zip int
> )row format delimited fields terminated by ',' LOCATION '/user/train/salaries/';
OK
Time taken: 0.058 seconds
hive> show tables;
OK
customer
salaries
Time taken: 0.025 seconds, Fetched: 2 row(s)
hive> select * from salaries;
OK
male 21 10000.0 1
female 22 12000.0 2
Time taken: 0.058 seconds, Fetched: 2 row(s)
hive>
區別1的:
內表的默認路徑
指定外表的路徑如圖:
hive是什么
我當前接觸到就是:
1.把hdf文件具體為table
2.用來查詢,類似sql語句處理