重命名() 函数
rename() 用于重命名表中的列。
如果分组键中的列被重命名,则分组键中的列名会被更新。
函数类型签名
(<-tables: stream[B], ?columns: A, ?fn: (column: string) => string) => stream[C] where A: Record, B: Record, C: Record
有关更多信息,请参见 Function type signatures。
参数
列
记录旧列名与新列名的映射。
函数
该函数接受当前列名 (column) 并返回一个新的列名。
表格
输入数据。默认是管道转发数据 (<-).
示例
将列名明确映射到新列名
import "sampledata"
sampledata.int()
|> rename(columns: {tag: "uid", _value: "val"})
使用函数重命名列
import "sampledata"
sampledata.int()
|> rename(fn: (column) => "${column}_new")
使用函数有条件地重命名列
import "sampledata"
sampledata.int()
|> rename(
fn: (column) => {
_newColumnName = if column =~ /^_/ then "${column} (Reserved)" else column
return _newColumnName
},
)