rename() 函数
rename()
重命名表中的列。
如果组键中的列被重命名,则组键中的列名也会更新。
函数类型签名
(<-tables: stream[B], ?columns: A, ?fn: (column: string) => string) => stream[C] where A: Record, B: Record, C: Record
有关更多信息,请参阅 函数类型签名。
参数
columns
将旧列名映射到新列名的记录。
fn
接受当前列名 (column
) 并返回新列名的函数。
tables
输入数据。默认为管道转发数据 (<-
)。
示例
显式映射列名到新列名
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
},
)
此页是否对您有帮助?
感谢您的反馈!