iff()iff()

计算第一个参数 (predicate) 并返回第二个或第三个参数的值,具体取决于 predicate 计算为 true(第二个)还是 false(第三个)。Evaluates the first argument (the predicate), and returns the value of either the second or third arguments, depending on whether the predicate evaluated to true (second) or false (third).

第二个和第三个参数必须属于同一类型。The second and third arguments must be of the same type.

语法Syntax

iff(predicate, ifTrue, ifFalse)iff(predicate, ifTrue, ifFalse)

参数Arguments

  • predicate:一个计算结果为 boolean 值的表达式。predicate: An expression that evaluates to a boolean value.
  • ifTrue:如果 predicate 计算结果为 true,得以计算的表达式以及从函数返回的表达式值。ifTrue: An expression that gets evaluated and its value returned from the function if predicate evaluates to true.
  • ifFalse:如果 predicate 计算结果为 false,得以计算的表达式以及从函数返回的表达式值。ifFalse: An expression that gets evaluated and its value returned from the function if predicate evaluates to false.

返回Returns

如果 predicate 计算结果为 true,此函数返回 ifTrue 的值,否则返回 ifFalse 的值。This function returns the value of ifTrue if predicate evaluates to true, or the value of ifFalse otherwise.

示例Example

T 
| extend day = iff(floor(Timestamp, 1d)==floor(now(), 1d), "today", "anotherday")