Writing record with MeasureValues error: Please use measureValue to send the data

Writing record with MeasureValues error: Please use measureValue to send the data

我正在向 Timestream 写入维度列表和度量值列表,但我不断收到此错误:

"Message":"measureValues (list) not supported for BOOL, DOUBLE, VARCHAR and BIGINT data types. Please use measureValue to send the data."

这是我的代码:

$dimensions= [];

$dimensions[] = [
 'Dimensions' => [
    [
        'DimensionValueType' => 'VARCHAR',
        'Name' => 'id',
        'Value' => '123456',
    ],
  ],
'MeasureValues' => [
    [
        'Name' => 'remark',
        'Type' => 'VARCHAR',
        'Value' => 'Some 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);

根据此处的 AWS 文档 (Parameter Syntax),它清楚地表明支持的数据类型是“DOUBLE|BIGINT|VARCHAR|BOOLEAN|TIMESTAMP|MULTI”。如果您在下面的“MeasureValues”要点下稍微检查一下,它会显示相反的内容:“This is only allowed for type MULTI”。 .不管怎样,我确实尝试将类型更改为 MULTI,但它仍然抛出相同的错误。

如您所愿使用格式

[
    'Name' => 'remark',
    'Type' => 'VARCHAR',
    'Value' => 'Some test text',
],

作为度量的输入,您需要将 MeasureValueType 声明为 'MULTI',而不是在请求正文中发送 MeasureValue。在您的示例中,最终请求将是这样的:

$dimensions= [];

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

$query = [
'CommonAttributes' => [
    'MeasureName' => 'table_cnt',
     // Removed MeasureValue from here as it's MULTI
    'MeasureValueType' => 'MULTI', // <- changed from 'VARCHAR' to 'MULTI'
    'Time' => '1651501311000', 
    'TimeUnit' => 'MILLISECONDS',
    'Version' => 1,
],
'DatabaseName' => 'mydb',
'Records' => $dimensions,
'TableName' => 'table',
];

$db->WriteRecords($query); 

作为参考,我建议您先尝试不使用 CommonAttributes,因为您只插入一条记录,就像我在这篇文章中演示的那样:https://du7.medium.com/aws-timestream-multi-measures-71b41c089af4