clickhouse之函数(一·)

时间与日期

SELECT
    toDateTime('2016-06-15 23:00:00') AS time,
    toDate(time) AS date_local,
    toDate(time, 'Asia/Yekaterinburg') AS date_yekat,
    toString(time, 'US/Samoa') AS time_samoa
┌────────────────time─┬─date_local─┬─date_yekat─┬─time_samoa──────────┐
│ 2016-06-15 23:00:00 │ 2016-06-15 │ 2016-06-16 │ 2016-06-15 09:00:00 │

toYear、toMonth、toDayOfMonth……原址虽然是英文挺理解的

timeSlot

    把时间调到半小时,这函数是Yandex特有的。Metrica,因为半小时是将一个会话分成两个会话的最小时间,如果跟踪标记显示单个用户的连续页面浏览量在时间上的差异严格大于这个数量。这意味着元组(标记ID、用户ID和时间槽)可以用于搜索包含在相应会话中的页面视图。

timeSlotss(startTime,duration,[size])

   对于从“StartTime”开始并持续“Duration”秒的时间间隔,它及时返回一个时间点数组,其中包含从该时间间隔四舍五入到以秒为单位的“Size”的点,size可选默认值为1800;用于搜索页面浏览量

String

   empty、notEmpty、length、lengthUTF8/lower/upper/lowerUTF8小写/upperUTF8大写/revverse/reverseUTF8/concat(s1,s2,…)连接、substring(s, offset, length)、substringUTF8(s, offset, length)截取、appendTrailingCharIfAbsent(s, c)追加、convertCharset(s, from, to)转编码、base64Encode(s)、base64Decode(s)解码、tryBase64Decode(s)解码 不报异常返空str

searching strings

   区分大小写,position(haystack, needle)在haystack中查needle返位置,从1开始,0标识未找到

   multiPosition(haystack, [needle_1, needle_2, ..., needle_n])返回array

   firstMatch(haystack, [needle_1, needle_2, ..., needle_n])

扫描二维码关注公众号,回复: 9504019 查看本文章

   multiSearch(haystack, [needle_1, needle_2, ..., needle_n])如果匹配则返1否则0

   match(haystack, pattern)检查字符串是否匹配re2正则表达式,0不匹配1匹,别含null

   extract(haystack, pattern)返回匹配pattern的str,否则返空strign

   extractAll(haystack, pattern)返回所有匹配项,数组

   like(haystack, pattern), haystack LIKE pattern operator检查字符串是否匹配正则,%任意_单字节

   notLike(haystack, pattern), haystack NOT LIKE pattern operator

replacing string

conditional functions

   if(cond, then, else), cond ? operator then : else返回如果cond != 0,或者cond = 0。cond类型必须是UInt8,然后和else类型必须是最小的公共类型;then and else can be NULL

multiIf

  multiIf(cond_1, then_1, cond_2, then_2...else)

┌─x─┬────y─┐
│ 1 │ ᴺᵁᴸᴸ │
│ 2 │    3 │
SELECT multiIf(isNull(y) x, y < 3, y, NULL) FROM t_null
┌─multiIf(isNull(y), x, less(y, 3), y, NULL)─┐
│                                          1 │
│                                       ᴺᵁᴸᴸ │

这个数学函数的支持也是强大了,近乎超过了宝宝的数学范畴

https://clickhouse.yandex/docs/zh/query_language/functions/array_functions/ 虽是英文但是可以自己看

发布了431 篇原创文章 · 获赞 155 · 访问量 44万+

猜你喜欢

转载自blog.csdn.net/ma15732625261/article/details/86621834