hive的基础语法

1、在linux命令行模式下,查询变量名称
$ hive -S -e "set"| grep warhouse
hive.metastore.warehouse.dir=/user/hive/warehouse
hive.warehouse.subdir.inherit.perms=true


2、linux命令行下,执行hive查询语句,并将结果写入本地文件
$ hive -S -e "select * from mytable limit 3" > /tmp/myquery


3、执行脚本文件,hive的查询脚本以.q或.hql后缀结尾
$ hive -f /path/to/file/withqueries.hql


4、在hive命令行中加载hive脚本
$ hive
hive > source /path/to/file/withqueries.hql;


5、导入本地目录,在hive中生成文件
$ hive
hive > create table src (s string );
$ echo "one world" > /tmp/myfile
$ hive -e "load data local inpath '/tmp/myfile' into table src;"


6、在hive命令窗口中,查询结果打印字段名
hive> set hive.cli.print.header = true;


7、将string的类型转化为int
cast(s AS INT)


8、hive的分隔符
create table employees(
name string,
salary double,
subordinates array<string>,
deductions map<string ,double>,
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;


8、hive对模式和文件中的内容不匹配的而处理,即为文件中的列,与hive的定义不匹配
每行中记录中的字段个数少于对应的模式定义的字段个数的话,用户将会看到查询的结果中包括很多null 值,hive会根据字段的属性和列的属性进行匹配
如果匹配不成功,则返回null


9、查看hive数据库的命令
describe database spacename;


10、修改数据库的定义
alter database wanglijie set dbproperties('owner'='wanglijie');
查看数据的特性
describe database extended wanglijie;


11、TableProperties的主要作用是按照键值对的格式为表增加额外的文档说明。
hive和DymamoDB数据库连接时候,提供必要的连接信息。


12、hive中拷贝表模式
create table if not exists mydb.emplooy1
like mydb.emplooy;


13、查看表的属性 
desc extended table_name;
desc formated table_name;
查看表的扩展属性;


14、表名+列名,可以查看列的属性
desc mydb.employee.salary


15、分区表的作用,将数据从物理上转移到和使用最频繁的用户更近的地方。


16、使用show partitions employees;//查看表中的存在的所有分区;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值