【发布时间】:2012-04-19 20:42:28
【问题描述】:
我正在尝试学习 Hive。令人惊讶的是,我找不到如何编写简单的字数统计工作的示例。以下是正确的吗?
假设我有一个输入文件input.tsv:
hello, world
this is an example input file
我在 Python 中创建了一个拆分器来将每一行变成单词:
import sys
for line in sys.stdin:
for word in line.split():
print word
然后我的 Hive 脚本中有以下内容:
CREATE TABLE input (line STRING);
LOAD DATA LOCAL INPATH 'input.tsv' OVERWRITE INTO TABLE input;
-- temporary table to hold words...
CREATE TABLE words (word STRING);
add file splitter.py;
INSERT OVERWRITE TABLE words
SELECT TRANSFORM(text)
USING 'python splitter.py'
AS word
FROM input;
SELECT word, count(*) AS count FROM words GROUP BY word;
我不确定我是否遗漏了什么,或者它是否真的这么复杂。 (特别是需要临时的words表,需要写外分器函数吗?)
【问题讨论】: