想象一下这张table
text
----
h
he
hel // All above are prefixes
helll123 // hel is a prefix of helll123; this is the first occurrence of helll123
helll123 // second helll123
f
fa
fals
falst0 // fals is a prefix of falst0
下面的查询是伪代码来演示我所追求的
SELECT
unique_by_prefix(text) AS unique_text, // pseudo code
COUNT(*)
FROM
my_table
GROUP BY
1
应生成以下结果
unique_text count
helll123 2
falst0 1
基本上,我们将忽略前缀,只计算唯一的文本。
3条答案
按热度按时间xfb7svmp1#
这里有一种方法。
zazmityj2#
开窗功能https://cwiki.apache.org/confluence/display/hive/languagemanual+windowingandanalytics
结果将是:
然后您可以比较这些值:如果下一个文本以文本开头,则此记录不是您想要的记录,否则获取此记录。
然后删除null并加入我的表,就可以得到文本计数了
x7rlezfr3#
我不认为你可以在Hive里用一个查询来完成这个任务。
有一种可能性:
虽然这抓住了逻辑,但我怀疑hive想要correlation子句的等式。