选择时序 ID 的最佳做法Best practices for choosing a Time Series ID

本文总结了 Azure 时序见解第 2 代环境的时序 ID 的重要性,以及有关选择时序 ID 的最佳做法。This article summarizes the importance of the Time Series ID for your Azure Time Series Insights Gen2 environment, and best practices for choosing one.

选择时间序列 IDChoose a Time Series ID

选择适当的时序 ID 至关重要。Selecting an appropriate Time Series ID is critical. 选择时序 ID 与为数据库选择分区键相同。Choosing a Time Series ID is like choosing a partition key for a database. 它在创建时序见解第 2 代环境时是必需的。It's required when you create a Azure Time Series Insights Gen2 environment.

重要

时序 ID 如下:Time Series IDs are:

  • 区分大小写的属性:搜索、比较和更新以及分区都会用到字母和字符的大小写。A case-sensitive property: letter and character casings are used in searches, comparisons, updates, and when partitioning.
  • 不可变属性:一旦创建,无法更改。An immutable property: once created it cannot be changed.

提示

如果事件源是 IoT 中心,则时序 ID 可能是 iothub-connection-device-id。If your event source is an IoT hub, your Time Series ID will likely be iothub-connection-device-id.

要遵守的主要最佳做法包括:Key best practices to follow include:

  • 选择具有许多(例如,几百甚至几千个)非重复值的分区键。Pick a partition key with many distinct values (for example, hundreds or thousands). 在许多情况下,该键可能是 JSON 中的设备 ID、传感器 ID 或标记 ID。In many cases, this might be the device ID, sensor ID, or tag ID in your JSON.
  • 时序模型的叶节点级别,时序 ID 应是唯一的。The Time Series ID should be unique at the leaf node level of your Time Series Model.
  • 时序 ID 属性名称字符串的字符数限制为 128 个。The character limit for the Time Series ID's property name string is 128. 时序 ID 属性值的字符数限制为 1024 个。For the Time Series ID's property value, the character limit is 1,024.
  • 如果时序 ID 的某个唯一属性值缺失,该值将被视为 null 值,并遵循相同的唯一性约束规则。If a unique property value for the Time Series ID is missing, it's treated as a null value and follows the same rule of the uniqueness constraint.
  • 如果时序 ID 嵌套在复杂的 JSON 对象中,请确保在提供属性名称时遵循入口平展规则If your Time Series ID is nested within a complex JSON object be sure to follow the ingress flattening rules when providing your property name. 查看示例 BCheck out example B.
  • 此外,最多可以选择三个键属性作为时序 ID。You can also select up to three key properties as your Time Series ID. 这些属性的组合将是表示时序 ID 的组合键。Their combination will be a composite key that represents the Time Series ID.

    备注

    三个键属性必须是字符串。Your three key properties must be strings. 必须针对此组合键运行查询,而不能每次查询一个属性。You would have to query against this composite key instead of one property at a time.

选择多个键属性Select more than one key property

以下方案描述如何选择多个键属性作为时序 ID。The following scenarios describe selecting more than one key property as your Time Series ID.

示例 1:具有唯一键的时序 IDExample 1: Time Series ID with a unique key

  • 你有两个传统的资产群。You have legacy fleets of assets. 每个群有一个唯一键。Each has a unique key.
  • 其中一个群以属性 deviceId 进行唯一标识。One fleet is uniquely identified by the property deviceId. 另一个群的唯一属性为 objectIdFor another fleet, the unique property is objectId. 这两个群都不包含对方的唯一属性。Neither fleet contains the other fleet's unique property. 在此示例中,可选择两个键 deviceIdobjectId 作为唯一键。In this example, you would select two keys, deviceId and objectId, as unique keys.
  • 我们接受 null 值,且如果事件有效负载中缺少某个属性,则计为 null 值。We accept null values, and the lack of a property's presence in the event payload counts as a null value. 向两个事件源发送数据时,这种方法同样合适,其中每个事件源中的数据具有唯一的时序 ID。This is also the appropriate way to handle sending data to two event sources where the data in each event source has a unique Time Series ID.

示例 2:具有组合键的时序 IDExample 2: Time Series ID with a composite key

  • 同一组资产中需要多个唯一的属性。You require multiple properties to be unique within the same fleet of assets.
  • 你是一家智能建筑制造商,希望在每个房间部署传感器。You're a manufacturer of smart buildings and deploy sensors in every room. 对于每个房间,通常对 sensorId 使用相同的值。In each room, you typically have the same values for sensorId. 例如,sensor1sensor2sensor3Examples are sensor1, sensor2, and sensor3.
  • 建筑物在属性 flrRm 中包含不同场地的重叠楼层号和房间号。Your building has overlapping floor and room numbers across sites in the property flrRm. 这些数字使用类似于 1a2b3a 的值。These numbers have values such as 1a, 2b, and 3a.
  • location 属性包含类似于 RedmondBarcelonaTokyo 的值。You have a property, location, that contains values such as Redmond, Barcelona, and Tokyo. 若要实现唯一性,可将以下三个属性指定为时序 ID 键:sensorIdflrRmlocationTo create uniqueness, you designate the following three properties as your Time Series ID keys: sensorId, flrRm, and location.

示例原始事件:Example raw event:

{
  "sensorId": "sensor1",
  "flrRm": "1a",
  "location": "Redmond",
  "temperature": 78
}

然后,可在 Azure 门户中输入组合键,如下所示:In the Azure portal, you can then enter the composite key as follows:

配置环境的时序 ID。Configure Time Series ID for the environment.

备注

在 Azure 门户中,请不要在一个文本框中输入以逗号分隔的属性名称,否则,它将被视为单个包含逗号的属性名称。In Azure portal, don't enter comma-separated names of properties in one texbox, otherwise, it will be treated as a single property name that contains commas. 请在每个属性名称自己的文本框中输入每个属性名称。Enter each property name in its own texbox.

后续步骤Next steps