Hive 版本 0.13.1 中的性能问题

Performance issue in hive version 0.13.1

我使用 AWS-EMR 来 运行 我的 Hive 查询,我在 运行ning Hive 版本 0.13.1 时遇到性能问题。

较新版本的 hive 需要大约 5 分钟的时间来处理 运行10 行数据。但是 230804 行的相同脚本需要 2 天,并且仍然 运行ning。我应该如何分析和解决问题?

示例数据:

Table 1:

hive> describe foo;
OK
orderno    string
Time taken: 0.101 seconds, Fetched: 1 row(s)

Sample data for table1:

hive>select * from foo;        
OK
1826203307
1826207803
1826179498
1826179657

Table 2:

hive> describe de_geo_ip_logs;
OK
id          bigint                                      
startorderno        bigint                                      
endorderno          bigint                                      
itemcode                int                                         
Time taken: 0.047 seconds, Fetched: 4 row(s)

Sample data for Table 2:

hive> select * from bar;

127698025   417880320   417880575   306
127698025   3038626048  3038626303  584
127698025   3038626304  3038626431  269
127698025   3038626560  3038626815  163

我的查询:

SELECT b.itemcode
FROM foo a,  bar b
WHERE a.orderno BETWEEN b.startorderno AND b.endorderno;

在 Hive 日志输出的最顶部,它指出 "Warning: Shuffle Join JOIN[4][Tables a, b] in Stage 'Stage-1 Mapred' is a cross product."

编辑: 'cross product' 或笛卡尔积是没有条件的连接,return 是 'b' table 中的每一行,对于 'a' [=44] 中的每一行=].因此,如果您以 'a' 为 5 行,而 'b' 为 10 行为例,您将得到乘积,或者,5 乘以 10 = 50 行 returned。会有很多行完全 'null' 一个或另一个 tables.

现在,如果您有一个 table 'a' 的 20,000 行并将其连接到另一个 table 'b' 的 500,000 行,您正在询问 SQL引擎return给你一个10,000,000,000行的数据集'a, b',然后对1000万行执行BETWEEN操作。

因此,如果您减少 'b' 行的数量,您会发现您将获得比 'a' 更多的好处 - 在您的示例中,如果您可以过滤 ip_logs table, table 2,因为我猜测它的行数比您的订单号table多,所以它会减少执行时间。 结束编辑

您通过不指定连接条件来强制执行引擎通过笛卡尔积工作。它必须一遍又一遍地扫描所有 table。有 10 行,你不会有问题。有了 20k,你就 运行 进入几十个 map/reduce 波。

试试这个查询:

 SELECT b.itemcode
 FROM foo a JOIN bar b on <SomeKey>
 WHERE a.orderno BETWEEN b.startorderno AND b.endorderno;

但我无法确定您的模型允许加入的列。也许可以改进此表达式的数据模型?可能是我没看清楚样本

无论哪种方式,您都需要在 where 子句之前过滤比较次数。我在 Hive 中完成此操作的其他方法是使用较小的数据集创建视图,并且 join/match 视图而不是原始视图 table.