hive 的查询语法

几个参数的设置

设置打印表头

set hive.cli.print.header=true;

设置打开笛卡尔积
set hive.strict.checks.cartesian.product=false;
set hive.mapred.mode=nunstrict;
设置hive 本地模式

开启Hive的本地模式:

hive> set hive.exec.mode.local.auto=true; (默认为false)

当hive的输入数据非常小的时候,可以使用本地模式,会节约很多时间。
因为数据量小的时候,为查询数据,开始执行任务的时间消耗,可能比实际执行job花费的时间还要多。
对于这种情况,使用本地模式,在单台机器上处理所有任务,用时会少很多。

当一个job满足如下条件才能真正使用本地模式:
1.job的输入数据大小必须小于最大输入数据的参数,通过 hive.exec.mode.local.auto.inputbytes.max 设置。(默认是 128MB)
2.job的reduce数必须为0或者1
设置每一个reducetask最终能够加载的数据量
set hive.exec.reducers.bytes.per.reducer=<number>
默认:hive.exec.reducers.bytes.per.reducer=256000000

In order to change the average load for a reducer (in bytes):
每一个reducetask最终能够加载的数据量。默认大约23.84MB,在join大表关联小表时,可以修改此配置,有利于减轻数据倾斜。
设置最大reduce的数量
set hive.exec.reducers.max=<number>
默认:hive.exec.reducers.max=1009

In order to limit the maximum number of reducers:
限制最大reducer的数量
设置一个常数数量的reducetask值
set mapreduce.job.reduces=<number>
默认:mapreduce.job.reduces=-1

In order to set a constant number of reducers:
设置一个常数数量的reducetask值。

-1 代表没有设置。
设置常数reducetask的目的是为了 order by

hive 的查询语法

基本语法结构:

[WITH CommonTableExpression (, CommonTableExpression)*]    (Note: Only available starting with Hive 0.13.0)

SELECT [ALL | DISTINCT] select_expr, select_expr, ...
FROM table_reference
[WHERE where_condition]
[GROUP BY col_list]
[ORDER BY col_list]
[CLUSTER BY col_list  | [DISTRIBUTE BY col_list] [SORT BY col_list]  ]
[LIMIT [offset,] rows]

Hive 中的 SELECT 基础语法和标准 SQL 语法基本一致,支持 WHERE、 DISTINCT、 GROUP BY、ORDER BY、 HAVING、 LIMIT、子查询等。

1、 select * from db.table1
2、 select count(distinct uid) from db.table1
3、支持 select、 union all、 join(left、 right、 full join)、 like、 where、 having、 各种聚合函数、
支持 json 解析
4、 UDF(User Defined Function) / UDAF/UDTF
5、不支持 update 和 delete
6、 hive 虽然支持 in/exists(老版本是不支持的),但是 hive 推荐使用 semi join 的方式来代替
实现,而且效率更高。
7、 支持 case … when …
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值