我应该如何更新Amazon Timestream中的唱片字段?
我正在尝试更新时间流中的记录中的字段,但它不断插入新的记录。 这是我的代码:
$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);
我不明白我在这里做错了什么,缺乏文档和示例使发现更加困难! 感谢您的建议!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在时间流中,尺寸与时间一起是一个“关键”,以升级。如果您的维度不同,它将插入具有新维度的新记录。
仅当所有维度和时间完全相同时,才使用版本字段。然后,将使用新值更新这些措施。
您可以在此处找到更好的信息:,在“选择尺寸”下,第一个子弹点。
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.