【问题标题】:Searching specific word occurrence in document using hive使用 hive 在文档中搜索特定单词出现
【发布时间】:2015-10-23 12:26:09
【问题描述】:

您好,我有一个文档上传到名为 Data 的 Hive 表中,示例行如下:

He is a good boy and but his brother is a bad boy.
He is a naughty boy.

表的架构是:

create table Data(
    document_data STRING)
row format delimited
fields terminated by '\n'
stored as textfile;

我想编写一个查询,只计算单词 boy 和 naughty` 的出现次数,然后输出它们:

 boy 3
 naughty 1 

【问题讨论】:

  • 我们可以知道你的蜂巢表的结构吗?
  • 创建表数据(document_data STRING) 以'\n' 结尾的行格式分隔字段存储为文本文件;

标签: hadoop mapreduce hive hiveql


【解决方案1】:

这里我们将使用LATERAL 功能,它可以将单行转换为多行。

SELECT
    word,
    COUNT(*)
FROM Data
WHERE
    word="boy" OR
    word="naughty"
LATERAL VIEW 
    explode(split(document_data, ' ')) lateralTable AS word GROUP BY word;

我改编了我在Word Count program in Hive 找到的版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2017-08-28
    • 2013-07-03
    • 2015-05-22
    • 1970-01-01
    • 2022-12-06
    相关资源
    最近更新 更多