在 Hive 表中拆分单词

问题描述 投票:0回答:1

我是新来的 我正在尝试使用 Apache hive 对推文进行分析。 我能够在 csv.file 中检索推文

然后我简单地创建一个表 如果外部表不存在,则创建 tweets3 ( ID 大整数, 文本字符串) 行格式 SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde';

enter image description here

然后我在文本列中使用 split 函数来创建另一个表。

如果不存在则创建表 split_word as select id as id, split(text, ' ') as Words from tweets3;

但是当我运行查询时 select * from split_word 这就是我所看到的 enter image description here 单词没有分开

我对此很陌生。 请帮忙

我想也许我应该尝试以 json 格式保存推文?

split hive tweets twitterapi-python
1个回答
0
投票

我有更好的解决方案。您的推文中可能有数百个单词,因此您需要创建许多列。您可以使用单词创建行,而不是列。

例如,字符串

'Air canada is bad...'
看起来像这样 -

Air
canada
is
bad...

解决方案-

with cte as (select split('Air canada is bad...',' ') as c)
select cte_ex words
from cte
LATERAL VIEW explode(c) exploded_table as cte_ex
  1. 首先,我们将整条推文分成单词数组,就像您的解决方案一样。
  2. 然后分解数组以获取不同行中的各个单词。

现在,如果您愿意,您可以轻松地将这些数据转移到不同的列中,但我再次认为它不会有用,但它符合您的要求。

© www.soinside.com 2019 - 2024. All rights reserved.