CREATE TABLE IF NOT EXISTS student(id int COMMENT '學號,主鍵惟一',name String COMMENT '姓名')
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
STORED AS TEXTFILE;apache
本地系統數據錄入方式app
LOAD DATA LOCAL INPATH '/home/hadoop/software/hive/student.txt' INTO TABLE student;oop
HDFS系統文件錄入方式spa
LOAD DATA INPATH '/data/student.txt' INTO TABLE student;orm
查看全部的hive表
show tables;hadoop
查看錶結構
decribe wordcount;string
刪除表
DROP TABLE IF EXISTS wordcount;it
表重命名
alter table wordcount rename to sb;io
增長字段
alter table wordcount add columns (count int);table
將hive中的數據導出到Hdfs
insert overwrite directory '/lwj/hive_out' select w.* from wordcount w;
將hive中的數據導出到local
insert overwrite local directory '/lwj/hive_out' select w.* from wordcount w;
根據條件導出數據到local,並設置導出數據間的分隔符,好比','分隔
insert overwrite local directory '/opt/software/hive/hive_out'
row format delimited
FIELDS TERMINATED BY ','
COLLECTION ITEMS TERMINATED BY ','
MAP KEYS TERMINATED BY ':'
select userid,cntFollowing,cntFollowers from user_test where entitySectionUrn=195861L;
CREATE EXTERNAL TABLE u_data ( userUrn string, userId string, screenName string) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIE( "hbase.columns.mapping" = ":key,info:userId,info:screenName", "hbase.table.default.storage.type" = "binary" ) TBLPROPERTIES ("hbase.table.name" = "bvuser");