我在 Ubuntu 14.0 上运行 Apache Hadoop 2.6.0,并且在 Hive 0.13.0 中创建了一个表,如下所示:
CREATE TABLE IF NOT EXISTS recipes_hive.cuisine (
ID INT COMMENT 'Cuisine ID.',
name STRING COMMENT 'Cusine name - primary key.',
area STRING COMMENT 'Name of the area of origin - foreign key.',
scope STRING COMMENT 'Either country or area.')
COMMENT 'Table containing cuisines data.'
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
STORED AS TEXTFILE;
我用语句填充数据:
LOAD DATA LOCAL INPATH 'path_to_file/CUISINE.csv'
OVERWRITE INTO TABLE recipes_hive.cuisine;
我的数据库有几个这样的表,所有这些表都是用相同的过程创建和填充的。运行简单查询时,例如:
SELECT * FROM cuisine
或者甚至在 WHERE 子句中的某些条件下我得到了预期的结果,但运行更复杂的查询我会蹲下。例如:
SELECT cuisine.name, SUM(IF (ingredient.category = "fruit",1,2))/count(*) AS PERC
FROM cuisine JOIN recipe ON recipe.cuisine = cuisine.name JOIN part_of ON part_of.id_recipe = recipe.id JOIN ingredient ON ingredient.name = part_of.ingredient
GROUP BY cuisine.name
ORDER BY PERC DESC
,或:
SELECT ingredient.id, ingredient.name
FROM cuisine JOIN recipe ON recipe.cuisine = cuisine.name JOIN part_of ON part_of.id_recipe = recipe.id JOIN ingredient ON ingredient.name = part_of.ingredient
WHERE ingredient.id IN (
SELECT ingredient.id
FROM cuisine c JOIN recipe ON recipe.cuisine = c.name JOIN part_of ON part_of.id_recipe = recipe.id JOIN ingredient ON ingredient.name = part_of.ingredient
WHERE c.name = "Pakistan") AND cuisine.name = "Bangladesh"
第一个示例计算一些百分比,第二个示例检查相互元素。
MapReduce 和 Hadoop 被正确调用,并且没有返回任何错误。输出结束于:
Execution completed successfully
MapredLocal task succeeded
OK
Time taken: 122.119 seconds
我查过网络,有人遇到了和我类似的问题。我查了一下:
Hive Table returning empty result set on all queries
但未能解决我的问题。数据实际上位于 HDFS 中,并且如前所述,它适用于简单查询。
因此,要么我的 Hive 实例有问题,要么我的查询编写不正确。
任何帮助将不胜感激。 谨致问候。
最佳答案
如果我们有包含 ID = {1,2,3} 的 Cuisine 表和包含 ID = {5,6,7} 的 Recipe 表,那么即使这些表非空,当我们执行 INNER JOIN Cuisine.ID = Recipe.ID(因为两个表中的 ID 不同) 请您检查一下是否存在这样的情况。
SELECT count(1)
FROM cuisine c JOIN recipe ON recipe.cuisine = c.name WHERE c.name = "Pakistan";
--- must return > 0
select count(1) from recipe as recipe
JOIN part_of ON part_of.id_recipe = recipe.id ;
--- must return > 0
select count(1) from part_of as part_of
JOIN ingredient ON ingredient.name = part_of.ingredient ;
--- must return > 0
因此,当所有 count(*) 均非零时,内部查询将返回一行。现在测试外部选择:
SELECT ingredient.id, ingredient.name
FROM cuisine JOIN recipe ON recipe.cuisine = cuisine.name JOIN part_of ON part_of.id_recipe = recipe.id JOIN ingredient ON ingredient.name = part_of.ingredient
WHERE ingredient.id = <inner query result> and cuisine.name = "Bangladesh";
关于hadoop - HiveQL 查询没有返回结果,也没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33342958/