欢迎投稿

今日深度:

Hive常用指令,

Hive常用指令,


在Hive目录中的命令:

hive -e “select * …” 执行一条sql语句
hive -f “/x/xxx.hql” 执行一个文件,例如外部脚本

Hive shell中:

直接使用sql语句:
create database logs
库会自动创在/user/用户名/warehouse/logs.db

创建一个.hql文件存储建表语句:

//创建外部表(在logs数据库下创建MyBigdataLogs表;实际内容在hdfs上)
create external table logs.MyBigdataLogs

//(字段名 属性)
(remote_addr string,remote_user string,time_local string,
request string,status string,body_bytes_sent string,
http_referer string,http_user_agent string,
http_x_forwarded_for string)

//分区方法(年月日)
partitioned by(year int,month int,day int)
/
/行格式 :
//字段分隔符 ,
//行分隔符 \n
row format DELIMITED
FIELDS TERMINATED BY “,”
LINES TERMINATED BY “\n”
//存储类型
STORED AS TEXTFILE;

(表的位置在库的目录下 /logs.db/MyBigdataLogs)

手动添加分区:

shell中:
1.use logs;
2.alter table MyBigdataLogs add partition(year=2018,month=10,day=15);

将日志数据通过/bin/hdfs dfs -put 放到分区目录下,如放到/year=2018/month=10/day=15下,
Hive中查询MyBigdataLogs表时就会显示日志数据
如 hive -e “select * from logs.MyBigdataLogs”
就会显示:

因为Hive中这个外部表只是一张表信息,不存储具体内容,具体内容是放在HDFS下的

www.htsjk.Com true http://www.htsjk.com/hive/40975.html NewsArticle Hive常用指令, 在Hive目录中的命令: hive -e “select * …” 执行一条sql语句 hive -f “/x/xxx.hql” 执行一个文件,例如外部脚本 Hive shell中: 直接使用sql语句: create database logs 库会自动创在...
相关文章
    暂无相关文章
评论暂时关闭