Qn:最好的方法是通过在IN子句中传递700K item_ids从包含900万行的表中获取一列(比如item_name)

我是Hadoop和Hive的新手,我来自Java背景。是否有任何一种/简便的方法可以一次完成所有操作?还是我需要分块?如果需要分块,您建议的最佳数字是多少(我知道这取决于许多其他因素,但只是为了获得起点)或者您将建议除 hive 以外的任何其他解决方案(类似于Java多线程批处理带有大块item_ids的Hadoop)

我已经通过在IN子句中发送700K进行了尝试,这很令人窒息,什么也没回来,查询被神秘地杀死了。

最佳答案

您有几种选择:

加入。
将所有ID放入HDFS中的文件中,在文件目录顶部创建表。

CREATE EXTERNAL TABLE table_ids(item_id int)
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
STORED AS TEXTFILE
location '/hive/data' --location(directory) in hdfs where the file is
;
select item_name from table a
      inner join table_ids b on a.item_id=b.item_id

使用in_file:
将所有ID放入文件中,连续放置一个ID。
select item_name from table where in_file(item_id, '/tmp/myfilename'); --local file

(如果内存中适合)使用堆栈连接:
select item_name from table a
      inner join
(
select stack(10, --the number of IDs, add more IDs
             0,  1,  2,  3,  4,  5,  6,  7,  8,  9) as (item_id)
 ) b
 on a.item_id=b.item_id

10-06 13:17
查看更多