我应该如何更新Amazon Timestream中的唱片字段?

发布于 2025-01-25 13:03:43 字数 1632 浏览 3 评论 0 原文

我正在尝试更新时间流中的记录中的字段,但它不断插入新的记录。 这是我的代码:

$dimensions= [];

$dimensions[] = [
 'Dimensions' => [
    [
        'DimensionValueType' => 'VARCHAR',
        'Name' => 'id',
        'Value' => '123456',
    ],
    [
        'DimensionValueType' => 'VARCHAR',
        'Name' => 'remark',
        'Value' => 'Remark test text',
    ],
  ],
];

$query = [
'CommonAttributes' => [
    'MeasureName' => 'table_cnt',
    'MeasureValue' => 'table_cnt',
    'MeasureValueType' => 'VARCHAR',
    'Time' => '1651501311000', 
    'TimeUnit' => 'MILLISECONDS',
    'Version' => 1,
],
'DatabaseName' => 'mydb',
'Records' => $dimensions,
'TableName' => 'table',
];

$db->WriteRecords($query);

现在,我如何尝试将上面插入的相同记录提升:

$dimensions= [];

$dimensions[] = [
 'Dimensions' => [
    [
        'DimensionValueType' => 'VARCHAR',
        'Name' => 'id',
        'Value' => '123456',
    ],
    [
        'DimensionValueType' => 'VARCHAR',
        'Name' => 'remark',
        'Value' => 'New Remark test text', // new text
    ],
  ],
];

$query = [
'CommonAttributes' => [
    'MeasureName' => 'table_cnt',
    'MeasureValue' => 'table_cnt',
    'MeasureValueType' => 'VARCHAR',
    'Time' => '1651501311000',      // same time 
    'TimeUnit' => 'MILLISECONDS',
    'Version' => 2,                 // changed to version 2 when upserting
],
'DatabaseName' => 'mydb',
'Records' => $dimensions,
'TableName' => 'table',
];

$db->WriteRecords($query);

我不明白我在这里做错了什么,缺乏文档和示例使发现更加困难! 感谢您的建议!

I am trying to update a field in a record in Timestream but it keeps inserting new record instead.
Here is my code:

$dimensions= [];

$dimensions[] = [
 'Dimensions' => [
    [
        'DimensionValueType' => 'VARCHAR',
        'Name' => 'id',
        'Value' => '123456',
    ],
    [
        'DimensionValueType' => 'VARCHAR',
        'Name' => 'remark',
        'Value' => 'Remark test text',
    ],
  ],
];

$query = [
'CommonAttributes' => [
    'MeasureName' => 'table_cnt',
    'MeasureValue' => 'table_cnt',
    'MeasureValueType' => 'VARCHAR',
    'Time' => '1651501311000', 
    'TimeUnit' => 'MILLISECONDS',
    'Version' => 1,
],
'DatabaseName' => 'mydb',
'Records' => $dimensions,
'TableName' => 'table',
];

$db->WriteRecords($query);

and now here how I try to upsert the same record inserted above:

$dimensions= [];

$dimensions[] = [
 'Dimensions' => [
    [
        'DimensionValueType' => 'VARCHAR',
        'Name' => 'id',
        'Value' => '123456',
    ],
    [
        'DimensionValueType' => 'VARCHAR',
        'Name' => 'remark',
        'Value' => 'New Remark test text', // new text
    ],
  ],
];

$query = [
'CommonAttributes' => [
    'MeasureName' => 'table_cnt',
    'MeasureValue' => 'table_cnt',
    'MeasureValueType' => 'VARCHAR',
    'Time' => '1651501311000',      // same time 
    'TimeUnit' => 'MILLISECONDS',
    'Version' => 2,                 // changed to version 2 when upserting
],
'DatabaseName' => 'mydb',
'Records' => $dimensions,
'TableName' => 'table',
];

$db->WriteRecords($query);

I dont understand what am I doing wrong here, and the lack of documentations and samples is making it even more difficult to find out!
Thanks for any advice!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆流 2025-02-01 13:03:43

在时间流中,尺寸与时间一起是一个“关键”,以升级。如果您的维度不同,它将插入具有新维度的新记录。
仅当所有维度和时间完全相同时,才使用版本字段。然后,将使用新值更新这些措施。
您可以在此处找到更好的信息:,在“选择尺寸”下,第一个子弹点。

In Timestream, the dimensions together with the time are a "key" for upserting. If you have different dimensions, it will insert a new record with the new dimensions.
The version field is only used if all dimensions and time are exactly the same. Then, the measures will be updated with the new values.
You can find better information here: https://docs.aws.amazon.com/timestream/latest/developerguide/data-modeling.html#data-modeling-dimensionsmeasures, under the "Choosing dimensions", the first bullet point.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文