0
点赞
收藏
分享

微信扫一扫

hive查找字符出现的位置find_in_set和locate 函数

color_小浣熊 2022-05-06 阅读 106
hive

问题场景

查找Face这个标签在image_labels字段中出现的位置。

尝试了2个函数,find_in_set和locate 函数,如下所示

select feed_id,db_time, user_id,image_labels,
    find_in_set('Face',image_labels) as a,
	locate('Face',image_labels)  as b 
    from gravity.ods_gravity_items_hourly
    where d_s between 20220505 and 20220505
    and image_labels like '%Face%' 
    and user_id != 1000000000

结果如图:
在这里插入图片描述
可以看出两者区别如下:

  • find_in_set 将image_labels作为一个以逗号分割的集合,返回的是’Face’ 出现的位置(从1开始)
  • locate 将image_labels作为一个字符串,返回的是’Face’ 在该字符串中第一次出现的位置(从1开始)
举报

相关推荐

0 条评论