【问题标题】:HiveQL - String contains equivalent in hiveql UDF?HiveQL - 字符串在 hiveql UDF 中包含等效项?
【发布时间】:2016-11-03 19:05:04
【问题描述】:

我想使用 hiveql UDF 来检查字符串是否包含任何特定字符?

我遇到了下面这个。

find_in_set(str, strlist)

这是要使用的正确 UDF 吗?

例如:

下面的列的值包含“1”。

column1 = "test1String"

我需要编写一个 HiveQL,其中返回 column1 值包含 1 的行的条件。

【问题讨论】:

  • 您在最后一个问题的答案中已经有了答案,@Gordon Linoff 一个。 where column1 rlike '[1]'
  • @syadav:谢谢伙计..

标签: sql string hive substring hiveql


【解决方案1】:
int instr(string str, string substr)

返回 str 中第一次出现 substr 的位置。如果任一参数为 null,则返回 null;如果在 str 中找不到 substr,则返回 0。请注意,这不是基于零的。 str 中的第一个字符的索引为 1。

select case when instr (column1, '1') >0 then 'contains' else 'not contains' end from ... 

请参阅此内容:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF

同样使用rlike:

select case when column1 rlike '1'  then 'contains' else 'not contains' end

使用like

select case when column1 like '%1%'  then 'contains' else 'not contains' end

使用locate

select case when locate('1', column1) >0 then 'contains' else 'not contains' end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多