時序補點函數(shù)
更新時間:
如果時間序列中存在數(shù)據(jù)缺失問題,可以使用時序補點函數(shù)補齊缺失的數(shù)據(jù)。
調(diào)用方式
select series_padding(long stamp, double value, long interval, varchar padType)
輸入?yún)?shù)
參數(shù)
說明
stamp
數(shù)據(jù)的UnixTime時間戳。
value
每個時刻對應(yīng)的數(shù)據(jù)。
interval
采集數(shù)據(jù)的間隔,例如:每10秒進行一次采集,則interval為10。
padType
數(shù)據(jù)缺失時填充的類型,可選值:zero、mean、forward、backward。
zero:缺失點數(shù)據(jù)填充為0。
mean:缺失點數(shù)據(jù)填充為缺失點兩端有效值的均值。
forward:缺失點數(shù)據(jù)填充為缺失點左端有效數(shù)據(jù)。
backward:缺失點數(shù)據(jù)填充為缺失點右端有效數(shù)據(jù)。
輸出結(jié)果
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
示例
下圖為通過查詢語句得到的原始折線圖,存在數(shù)據(jù)缺失問題。
* 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
執(zhí)行時序補點函數(shù)進行數(shù)據(jù)補齊,結(jié)果如下圖所示。
* 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)
文檔內(nèi)容是否對您有幫助?