

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 在公式表达式中使用函数
<a name="expression-functions"></a>

您可以使用以下函数对公式表达式中的数据进行操作。

转换和指标支持不同的功能。下表显示了哪些类型的函数与每种类型的公式属性兼容。

**注意**  
一个公式表达式中最多可以包含 10 个函数。


| 函数类型 | 转换 | 指标 | 
| --- | --- | --- | 
| [在公式表达式中使用常用函数](expression-common-functions.md) | <a name="polaris-yes-para"></a>![A green circle with a checkmark for yes.](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/images/icon-yes.png) 是 | <a name="polaris-yes-para"></a>![A green circle with a checkmark for yes.](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/images/icon-yes.png) 是 | 
| [在公式表达式中使用比较函数](expression-comparison-functions.md) | <a name="polaris-yes-para"></a>![A green circle with a checkmark for yes.](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/images/icon-yes.png) 是 | <a name="polaris-yes-para"></a>![A green circle with a checkmark for yes.](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/images/icon-yes.png) 是 | 
| [在公式表达式中使用条件函数](expression-conditional-functions.md) | <a name="polaris-yes-para"></a>![A green circle with a checkmark for yes.](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/images/icon-yes.png) 是 | <a name="polaris-yes-para"></a>![A green circle with a checkmark for yes.](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/images/icon-yes.png) 是 | 
| [在公式表达式中使用字符串函数](expression-string-functions.md) | <a name="polaris-yes-para"></a>![A green circle with a checkmark for yes.](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/images/icon-yes.png) 是 | <a name="polaris-yes-para"></a>![A green circle with a checkmark for yes.](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/images/icon-yes.png) 是 | 
| [在公式表达式中使用聚合函数](expression-aggregation-functions.md) | <a name="polaris-no-para"></a>![A red circle with the letter x for no.](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/images/icon-no.png)没有 | <a name="polaris-yes-para"></a>![A green circle with a checkmark for yes.](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/images/icon-yes.png) 是 | 
| [在公式表达式中使用时间函数](expression-temporal-functions.md) | <a name="polaris-yes-para"></a>![A green circle with a checkmark for yes.](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/images/icon-yes.png) 是 | <a name="polaris-yes-para"></a>![A green circle with a checkmark for yes.](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/images/icon-yes.png) 是 | 
| [在公式表达式中使用日期和时间函数](expression-date-and-time-functions.md) | <a name="polaris-yes-para"></a>![A green circle with a checkmark for yes.](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/images/icon-yes.png) 是 | <a name="polaris-yes-para"></a>![A green circle with a checkmark for yes.](http://docs.aws.amazon.com/zh_cn/iot-sitewise/latest/userguide/images/icon-yes.png) 是 | 

## 函数语法
<a name="expression-function-syntax"></a>

您可以使用以下语法来创建函数：

常规语法  
在常规语法中，函数名称后面是带有零个或多个参数的圆括号。  
`{{function_name}}({{argument1, argument2, argument3, ...}})`。例如，使用常规语法的函数可能看起来像 `log(x)` 和 `contains(s, substring)`。

统一函数调用语法 (UFCS)  
UFCS 允许您在面向对象编程中使用方法调用的语法来调用函数。在 UFCS 中，第一个参数后面跟着点 (`.`)，然后是函数名和括号内的其余参数（如果有）。  
`{{argument1}}.{{function_name}}({{argument2}}, {{argument3}}, ...)`。例如，带有 UFCS 的函数可能看起来像 `x.log()` 和 `s.contains(substring)`。  
您也可以使用 UFCS 来链接后续函数。 AWS IoT SiteWise 使用当前函数的计算结果作为下一个函数的第一个参数。  
例如，您可以使用 `message.jp('$.status').lower().contains('fail')`，而不使用 `contains(lower(jp(message, '$.status')),'fail')`。  
有关更多信息，请参阅 [D Programming Language](https://tour.dlang.org/tour/en/gems/uniform-function-call-syntax-ufcs) 页面。

**注意**  
您可以将 UFCS 用于所有 AWS IoT SiteWise 功能。  
AWS IoT SiteWise 函数不区分大小写。例如，可以互换使用 `lower(s)` 和 `Lower(s)`。