series_fill_const()series_fill_const()

用指定的常数值替换序列中缺失的值。Replaces missing values in a series with a specified constant value.

采用包含动态数值阵列作为输入的表达式,将 missing_value_placeholder 的所有实例替换为指定的 constant_value 并返回生成的阵列。Takes an expression containing dynamic numerical array as input, replaces all instances of missing_value_placeholder with the specified constant_value and returns the resulting array.

语法Syntax

series_fill_const(x, constant_value[, missing_value_placeholder])series_fill_const(x, constant_value[, missing_value_placeholder])

  • 将返回序列 x,其中的所有 missing_value_placeholder 实例都被替换为 constant_value。Will return series x with all instances of missing_value_placeholder replaced with constant_value.

参数Arguments

  • x:动态数组标量表达式(数值数组)。x : dynamic array scalar expression that is an array of numeric values.
  • constant_value:替换缺失值的值。constant_value : the value replacing missing values.
  • missing_value_placeholder:可选参数,用于指定要替换的缺失值的占位符。missing_value_placeholder : optional parameter that specifies a placeholder for a missing value to be replaced. 默认值为“double(null)”。Default value is double( null ).

备注Notes

  • 如果使用 make-series 运算符来创建序列,将使用默认值 0 填充缺失值。If you create the series using the make-series operator, it fills in the missing values using default 0. 或者,可以通过在 make-series 语句中指定 default = DefaultValue 来指定要填充的常数值。Alternatively, you can specify a constant value to fill in by specifying default = DefaultValue in the make-series statement.
make-series num=count() default=-1 on TimeStamp from ago(1d) to ago(1h) step 1h by Os, Browser
  • 若要在 make-series 之后应用任何内插函数,请指定“null”作为默认值:To apply any interpolation functions after make-series, specify null as a default value:
make-series num=count() default=long(null) on TimeStamp from ago(1d) to ago(1h) step 1h by Os, Browser
  • missing_value_placeholder 可以是将转换为实际元素类型的任何类型。The missing_value_placeholder can be of any type, which will be converted to actual element types. 因此,“double(null)”、“long(null)”或“int(null)”的含义相同。As such, either double( null ), long( null ) or int( null ) have the same meaning.
  • 此函数会保留数组元素的原始类型。The function preserves original type of the array elements.

示例Example

let data = datatable(`arr`: dynamic)
[
    dynamic([111,null,36,41,23,null,16,61,33,null,null])   
];
data 
| project arr, 
          fill_const1 = series_fill_const(arr, 0.0),
          fill_const2 = series_fill_const(arr, -1)  
arr fill_const1 fill_const2
[111,null,36,41,23,null,16,61,33,null,null][111,null,36,41,23,null,16,61,33,null,null] [111,0.0,36,41,23,0.0,16,61,33,0.0,0.0][111,0.0,36,41,23,0.0,16,61,33,0.0,0.0] [111,-1,36,41,23,-1,16,61,33,-1,-1][111,-1,36,41,23,-1,16,61,33,-1,-1]