登陆(docker中):
beeline -u "jdbc:hive2://localhost:10000/default
建库:
select current_databases();
usedefault
create database myhive1
use myhive1
建表:(有LOCATION的是外部表)
CREATE EXTERNAL TABLE IF NOT EXISTS employee_external (
name string,
work_place ARRAY<string>,
sex_age STRUCT<sex:string,age:int>,
skills_score MAP<string,int>,
depart_title MAP<STRING,ARRAY<STRING>>
)
COMMENT 'This is an external table'
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '|'
COLLECTION ITEMS TERMINATED BY ','
MAP KEYS TERMINATED BY ':'
STORED AS TEXTFILE
LOCATION '/user/dayongd/employee';
(ppt P26)
查表:
select * from <table_name>
推文件(docker 中):
外部表:
hdfs dfs -put xxx.txt /cjr/<table_name>/
内部表:
hdfs dfs -put xxx.txt /apps/hive/warehouse/<db_name>/<table_name>
删除表:
drop table <table_name>;
-------------------------------------------------------------------------------------------
CREATE EXTERNAL TABLE IF NOT EXISTS customers_internal2 (
number int,
name string,
name2 string,
useless1 string,
useless2 string,
info1 string,
info2 string,
info3 string,
info4 int
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
COLLECTION ITEMS TERMINATED BY ' '
MAP KEYS TERMINATED BY ':'
STORED AS TEXTFILE;