首页 > 解决方案 > 如何在蜂巢中进行字数统计

问题描述

我有一张table_a

query
------
apple
no fruit
this is 
not a number

我想编写配置单元查询以根据空间获取字数,例如

query           count
------      ------------
apple           1
no fruit        2
this is         2
not a  number   3

标签: sqlhadoophivehiveql

解决方案


一种方法是拆分为数组并计算元素:

select t.*, size(split(query, ' '))

如果要将多个空格计为单个分隔符:

select t.*, size(split(query, '[ ]+'))

推荐阅读