set hive.cli.print.current.db=true;
創建表
CREATE TABLE sales(
name STRING,
amount INT,
region STRING)
row format delimited
fields terminated by ',';
插入語句
~~~
INSERT INTO TINSERT INTO TABLE sales VALUES("ljs",100,"beijing");
INSERT INTO TINSERT INTO TABLE sales VALUES("zhangs",10,"shanghai");
INSERT INTO TABLE sales VALUES("zhoug",8,"liaoning");
~~~
執行SQL語句后,數據存儲在dhfs /hive/warehouse
創建集合類型的表
~~~
create table employees(
name string,
salary float,
subordinates array<string>,
deductions map<string,float>,
address struct<street:string,city:string,state:string,zip:int>)
row format delimited
fields terminated by '\001'
collection items terminated by '\002'
map keys terminated by '\003'
lines terminated by '\n'
stored as textfile;
~~~
桶表—介紹桶表
~~~
CREATE TABLE bucketed_users(
UserID Int,
Gender string,
Age Int,
Occupation string,
Zipcode string)
CLUSTERED BY (UserID) INTO 4 BUCKETS
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ',';
~~~
要向分桶表中填充成員,需要將 hive.enforce.bucketing 屬性設置為 true,Hive 就知道用表定義中聲明的數量來創建桶。
~~~
hive>set hive.enforce.bucketing = true;
~~~
插入數據
~~~
INSERT OVERWRITE TABLE bucketed_users
SELECT UserID,Gender, Age,Occupation,Zipcode
FROM users;
~~~
每個桶在磁盤上對應一個文件。
- 空白目錄
- 第一章 Linux虛擬機安裝
- 第二章 SSH配置
- 第三章 jdk配置
- 第四章 Hadoop配置-單機
- 第五章 Hadoop配置-集群
- 第六章 HDFS
- 第七章 MapReduce
- 7.1 MapReduce(上)
- 7.2 MapReduce(下)
- 7.3 MapReduce實驗1 去重
- 7.4 MapReduce實驗2 單例排序
- 7.5 MapReduce實驗3 TopK
- 7.6 MapReduce實驗4 倒排索引
- 第八章 Hive
- Hive安裝
- 數據定義
- 數據操作
- 第九章 HBase
- 第十章 SaCa RealRec數據科學平臺
- 第十一章 Spark Core
- 第十二章 Spark Streaming
- 第十章 Spark測試題