column_ifexists()column_ifexists()

采用列名作为字符串和默认值。Takes a column name as a string and a default value. 返回对列的引用(如果存在),否则返回默认值。Returns a reference to the column if it exists, otherwise - returns the default value.

语法Syntax

column_ifexists(columnName, defaultValue )column_ifexists(columnName, defaultValue )

参数Arguments

  • columnName :列的名称columnName : The name of the column
  • defaultValue :在使用函数的上下文中不存在列时要使用的值。defaultValue : The value to use if the column doesn't exist in the context that the function was used in. 此值可以是任何标量表达式(例如,对另一列的引用)。This value can be any scalar expression (e.g. a reference to another column).

返回Returns

如果“columnName”存在,则使用它引用的列。If columnName exists, then the column it refers to. 否则使用“defaultValue”。Otherwise - defaultValue .

示例Examples

.create function with (docstring = "Wraps a table query that allows querying the table even if columnName doesn't exist ", folder="My Functions")
ColumnOrDefault(tableName:string, columnName:string)
{
    // There's no column "Capital" in "StormEvents", therefore, the State column will be used instead
    table(tableName) | project column_ifexists(columnName, State)
}


ColumnOrDefault("StormEvents", "Captial");