0
点赞
收藏
分享

微信扫一扫

机器视觉学习(三)—— 保存视频流

千白莫 03-15 06:00 阅读 2

1.CONCAT与CONCAT_WS函数

1.1 CONCAT函数

-- concat(str1, str2, ... strN) - returns the concatenation of str1, str2, ... strN or concat(bin1, bin2, ... binN) - returns the concatenation of bytes in binary data  bin1, bin2, ... binN
Returns NULL if any argument is NULL.
Example:
  > SELECT concat('abc', 'def') FROM src LIMIT 1;
  'abcdef'
Function class:org.apache.hadoop.hive.ql.udf.generic.GenericUDFConcat
Function type:BUILTIN

CONCAT(string A/col, string B/col…): 返回输入字符串连接后的结果,支持任意个输入字符串;

1.2 CONCAT_WS函数

-- concat_ws(separator, [string | array(string)]+) - returns the concatenation of the strings separated by the separator.
Example:
  > SELECT concat_ws('.', 'www', array('facebook', 'com')) FROM src LIMIT 1;
  'www.facebook.com'
Function class:org.apache.hadoop.hive.ql.udf.generic.GenericUDFConcatWS
Function type:BUILTIN

CONCAT_WS(separator, str1, str2,…): 特殊形式的 CONCAT()。第一个参数为剩余参数间的分隔符。分隔符可以是与剩余参数一样的字符串。如果分隔符是 NULL,返回值也将为 NULL。函数会跳过分隔符参数后的任何 NULL 和空字符串。注意: CONCAT_WS must be "string or array<string>

2.COLLECT_SET函数

2.1 函数语法

-- collect_set(x) - Returns a set of objects with duplicate elements eliminated
Function class:org.apache.hadoop.hive.ql.udf.generic.GenericUDAFCollectSet
Function type:BUILTIN

COLLECT_SET(col): 该函数只接受基本数据类型,它的主要作用是将某字段的值进行去重汇总,产生array类型字段。

3.使用案例

3.1 准备数据

nameconstellationblood_type
小明白羊座A
小红射手座A
小刚白羊座B
小丽白羊座A
小虎射手座A
小威白羊座B

3.2 代码实现

SELECT  t1.c_b
       ,CONCAT_WS("|" , collect_set(t1.name))
FROM    (
            SELECT  NAME
                   ,CONCAT_WS(',' , constellation , blood_type) c_b
            FROM    person_info
        ) t1
GROUP BY t1.c_b

4.总结

  • concat 用于连接字符串。
  • concat_ws 用于按照指定的分隔符连接字符串。
  • collect_setgroup byconcat_ws 一起使用可以实现"列转行"。
举报

相关推荐

0 条评论