全部产品
Search
文档中心

日志服务:时序补点函数

更新时间:Sep 07, 2023

如果时间序列中存在数据缺失问题,可以使用时序补点函数补齐缺失的数据。

  • 调用方式

    select series_padding(long stamp, double value, long interval, varchar padType)
  • 输入参数

    参数

    说明

    stamp

    数据的UnixTime时间戳。

    value

    每个时刻对应的数据。

    interval

    采集数据的间隔,例如:每10秒进行一次采集,则interval为10。

    padType

    数据缺失时填充的类型,可选值:zero、mean、forward、backward。

    • zero:缺失点数据填充为0。

    • mean:缺失点数据填充为缺失点两端有效值的均值。

    • forward:缺失点数据填充为缺失点左端有效数据。

    • backward:缺失点数据填充为缺失点右端有效数据。

  • 输出结果

    unixtime   |       pad_value
    -------------+-----------------------
     1.5513696E9 |   0.11243584740434608
     1.5513732E9 |   0.09883780706698506
     1.5513768E9 |   0.08240823914341992
     1.5513804E9 |    0.0728240514818139
      1.551384E9 |   0.05888517541914705
     1.5513876E9 |   0.04953931499029833
     1.5513912E9 |  0.043698605551761895
     1.5513948E9 |   0.04400292632222124
     1.5513984E9 |   0.04727081764249449
      1.551402E9 |  0.054632234293121314
     1.5514056E9 |   0.05331214064978596
     1.5514092E9 |   0.05093117289934144
     1.5514128E9 |  0.053620170319174806
     1.5514164E9 |   0.05405914786225842
  • 示例

    下图为通过查询语句得到的原始折线图,存在数据缺失问题。

    * and Method: GetLogStoreLogs and ProjectName: lunar and LogStore: geos and Latency > 800000 | select __time__ - __time__ % 60 as time, COUNT(*) * 1.0 as num from log group by time order by time asc limit 1000
    时序补点函数-001

    执行时序补点函数进行数据补齐,结果如下图所示。

    * and Method: GetLogStoreLogs and ProjectName: lunar and LogStore: geos and Latency > 800000 | select series_padding(time, num, 60, 'zero') from (select __time__ - __time__ % 60 as time, COUNT(*) * 1.0 as num from log group by time order by time asc limit 1000)
    时序补点函数-002.png