简体   繁体   English

DynamoDB 架构 - 对建筑物内的位置进行建模

[英]DynamoDB Schema - Modeling Locations inside a building

New to DynamoDB over here. DynamoDB 新手在这里。 I need to figure out a DynamoDB schema for different locations inside a building.我需要找出建筑物内不同位置的 DynamoDB 架构。 Additionally, I need to be able to identify computers assigned to each of the locations.此外,我需要能够识别分配给每个位置的计算机。 The locations are nested inside other locations.这些位置嵌套在其他位置内。 For instance,例如,

  • Building 1 1号楼
    • Wing A A翼
      • Floor 1 1楼
        • Section A A部分
          • Office 1办公室一
            • Computer A电脑A
            • Computer B电脑B
          • Office 2办公室 2
            • Computer A电脑A
        • Section B B节
          • Office 1办公室一

... and so on. ... 等等。

ACCESS PATTERNS:访问模式:

  • Show all of the locations (wings, Floors, sections, etc) in a building显示建筑物中的所有位置(机翼、楼层、部分等)
  • Show a specific location显示特定位置
  • Show all of the computers assigned to a specific location显示分配到特定位置的所有计算机
  • Show the location of a specific computer显示特定计算机的位置

What I was thinking:我在想什么:

I initially wanted to create something like this:我最初想创建这样的东西:

PartitionKey              SortKey                                 Attributes

Building#1                Building#1 (For metadata)
Building#1                Section#1                                 [...]
Building#1                Section#1|Section#2                       [...]
Building#1                Section#1|Section#2|Section#3             [...]

I know this is the wrong way to think about it, but I can't figure out any other way.我知道这是错误的思考方式,但我想不出任何其他方式。

What is the best way to model the location of sections, offices, etc of a building?对建筑物的部分、办公室等位置进行建模的最佳方法是什么?

If those are really the only access patterns you can probably do something with a simple GSI.如果这些确实是唯一的访问模式,您可能可以使用简单的 GSI 做一些事情。 I wouldn't using Building as the PartitionKey because this will give you a lot of hot spots in the data.我不会使用 Building 作为PartitionKey因为这会在数据中提供很多热点。 Something like this would probably work:像这样的事情可能会奏效:

PartitionKey        SortKey     GSI_PartitionKey GSI_SortKey            Attributes
Building#1          'Location'                                          [...]
Wing#1              'Location'  'Location'       Building#1 .           [...]
Floor#1             'Location'  'Location'       Building#1|Wing#A      [...]
.
.
.
Computer#1          'Computer'  'Computer'       B#1|W#A|F#1|S#A|O#1    [...]
Computer#2          'Computer'  'Computer'       B#1|W#A|F#1|S#B|O#1    [...]
.
.
.

The SortKey values here are more optional, but they tend to allow for changes later without as much work now.此处的SortKey值更具可选性,但它们往往允许稍后进行更改,而无需现在进行太多工作。

To get all the locations in a building you query the GSI where the GSI_PartitionKey is 'Location' and the GSI_SortKey begins with your building ID.要获取建筑物中的所有位置,请查询 GSI,其中GSI_PartitionKey为“位置”, GSI_SortKey以您的建筑物 ID 开头。 You can add sub locations to the string so you can get all the locations in Wing A with a begins with of Building#1|Wing#A|您可以将子位置添加到字符串中,以便您可以获取 Wing A 中所有以Building#1|Wing#A|开头的位置

Get a specific location using the PartitionKey (and optionally the SortKey = 'Location').使用PartitionKey (以及可选的SortKey = 'Location')获取特定位置。

To get all the computers in a locations GSI where the GSI_PartitionKey is 'Computer' and the GSI_SortKey begins with your location ID.获取位置 GSI 中的所有计算机,其中GSI_PartitionKey是“计算机”,而GSI_SortKey以您的位置 ID 开头。

Get a specific computer using the PartitionKey (and optionally the SortKey = 'Computer') the attributes should include it's location.使用PartitionKey (以及可选的SortKey = 'Computer')获取特定计算机,属性应包括它的位置。

I think you're on the right track...我认为你在正确的轨道上......
Having the hierarchical data coded as a delimited sort key seems to follow the recommendations I've seen (though your two sets of example data don't match) Section#1|Section#2|Section#3 vs Wing A|Floor 1|Section A将分层数据编码为分隔排序键似乎遵循我所看到的建议(尽管您的两组示例数据不匹配) Section#1|Section#2|Section#3 vs Wing A|Floor 1|Section A

I'd probably consider having the table with just a hash of "serial number" or "asset ID"我可能会考虑让表格只包含“序列号”或“资产 ID”的散列

Then have a GSI with the key's you describe.然后使用您描述的密钥的 GSI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM