---
title: 执行Hive引擎业务
description: "Hive算子下推使用Hive命令来执行。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2200/bds/kunpengomnidata_20_0122.html
sourcePath: /source/zh/kunpengboostkithistory/2200/bds/kunpengomnidata_20_0122.html
indexId: fa870e50cf6d5bee0748136b2b048baa73a9b4924024043f8864cb0c40528aea71
---
# 执行Hive引擎业务

Hive算子下推使用Hive命令来执行。

本次任务示例使用tpch的1T数据的非分区表作为测试表，测试SQL为tpch-sql6。

相关的表信息如表1所示。


**表1 相关表信息**

| 表名 | 表格式 | 总数 | 占用空间 |
| --- | --- | --- | --- |
| lineitem | orc | 5999989709 | 169.6 G |


具体步骤如下。

1. 配置参数文件tpch_ndp.setting，这个文件可以放在自定义路径，本次运行放在“/opt/hive”目录中。
  1 2 cd /opt/hive vim tpch_ndp.setting

2. 按“i”进入编辑模式，将下面参数配置添加到tpch_ndp.setting中。
  1 2 3 4 5 6 7 8 9 10 set hive.execution.engine=tez; set hive.mapjoin.hybridgrace.hashtable=false; set hive.vectorized.execution.mapjoin.native.fast.hashtable.enabled=true; set omnidata.hive.enabled=true; set omnidata.hive.filter.selectivity.enabled=false; set omnidata.hive.filter.selectivity=0.5; set omnidata.hive.table.size.threshold=10240; set omnidata.hive.zookeeper.quorum.server=agent1:2181,agent2:2181,agent3:2181; set omnidata.hive.zookeeper.status.node=/sdi/status; set omnidata.hive.zookeeper.conf.path=/usr/local/zookeeper/conf;

  以上的参数也可以通过set命令直接在Hive中设置。

  新增算子下推的参数信息如表2所示。

**表2 算子下推的参数含义**

| 参数 | 缺省值 | 含义 |
| --- | --- | --- |
| omnidata.hive.enabled | true | 开启算子下推。 |
| omnidata.hive.filter.selectivity.enabled | true | 开启filter选择率来判断是否下推。 算子下推的收益和filter过滤的数据量相关，过滤的数据量越多，性能收益越明显，建议打开。 |
| omnidata.hive.filter.selectivity | 0.5 | filter选择率小于该值才会下推（selectivity越小，表示过滤后的剩余的数据量越小），缺省值为0.5，类型为double。取值范围为0.0~1.0。 |
| omnidata.hive.table.size.threshold | 10240 | 查询的表大于该值才会执行下推，单位为字节，取值范围0~102400。 |
| omnidata.hive.zookeeper.quorum.server | localhost:2181 | 连接到ZooKeeper的地址。 客户场景中启动ZooKeeper的IP地址和端口号，可配置多台，以英文逗号分隔。 |
| omnidata.hive.zookeeper.status.node | /sdi/status | OmniData算子下推注册到ZooKeeper的目录。 |
| omnidata.hive.zookeeper.conf.path | /usr/local/zookeeper/conf | ZooKeeper配置文件地址。 |


  omnidata.hive.filter.selectivity和omnidata.hive.table.size.threshold这两个参数是根据规划集群环境给出的推荐值，环境不同性能稍有影响。在实际场景中，如果执行下推的查询时间高于原生查询时间的80%，可配置omnidata.hive.filter.selectivity和omnidata.hive.table.size.threshold参数优化下推性能。 配置omnidata.hive.filter.selectivity参数（优先选择）： 适当调低此参数（例如：0.3、0.2、0.1），从而降低高选择率所带来的负收益。 配置omnidata.hive.table.size.threshold参数： 适当增大此参数（例如：40960、81920），从而降低查询小表所带来的负收益。 如果集群为安全模式，需配置omnidata.hive.zookeeper.conf.path /opt/hive/config参数，参数值为对应krb5的文件路径，omnidata.hive.zookeeper.security.enabled为true时安全模式配置生效。

3. 按“Esc”键，输入:wq!，按“Enter”保存并退出编辑。
4. 运行Hive命令。
  1 /usr/local/hive/bin/hive -i /opt/hive/tpch_ndp.setting -database tpch_flat_orc_date_1000

5. 执行sql6语句。

```
select
sum(l_extendedprice * l_discount) as revenue
from
tpch_flat_orc_1000.lineitem
where
l_shipdate >= '1993-01-01'
and l_shipdate < '1994-01-01'
and l_discount between 0.06 - 0.01 and 0.06 + 0.01
and l_quantity < 25;
```


  执行任务时会打印下推的信息，如下所示。

```
Table [lineitem] Push Down Info [ Select:[DoubleColMultiplyDoubleColumn(col 5:double, col 6:double) -> 17:double], Filter:[GenericUDFOPAnd(GenericUDFOPEqualOrGreaterThan(Column[l_shipdate], Const date 1993-01-01), GenericUDFOPLessThan(Column[l_shipdate], Const date 1994-01-01), GenericUDFBetween(Const boolean false, Column[l_discount], Const double 0.05, Const double 0.07), GenericUDFOPLessThan(Column[l_quantity], Const double 25.0))], Aggregation:[sum(_col0)], Group By:[], Limit:[], Raw Filter:[], Host Map:[hdfs1 -> hdfs1, hdfs2 -> hdfs2, hdfs3 -> hdfs3]
```


  包含了算子信息。
