【问题标题】:Get the unique word count of each word in Hive获取 Hive 中每个单词的唯一字数
【发布时间】:2016-08-31 21:59:35
【问题描述】:

我有一张如下表,

从表名中选择 *;

ID                   sentence
1              This is a sentence
2              This might be a test
3                     America
4                    This this 

我想编写一个查询来将句子拆分为单词并按降序获取单词的计数。我想要一个类似的输出,

word     count    Unique(ids)

This       4          3
a          2          2
might      1          1
.
.
.

其中 count 是该词在列中出现的次数,Unique(ids) 是使用该词的用户数。

我在想我们可以通过什么方式编写查询来做到这一点?

谁能帮我在蜂巢里做这个?

谢谢

【问题讨论】:

  • 我删除了不合适的数据库标签。

标签: sql hadoop hive


【解决方案1】:

侧视图

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+LateralView

select id, word
from tablename tn lateral view explode( split( tn.sentense, ' ' ) ) tb as word

结果将是:

1 This
1 is 
1 a
1 sentense
2 This
2 might
2 be
2 a
2 test
3 america

汇总结果

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-08
    • 2013-10-07
    • 1970-01-01
    • 1970-01-01
    • 2016-03-01
    相关资源
    最近更新 更多