How to add unique ID when inserting data in AWS Timestream?

666 Views Asked by At

I am inserting some data in Timestream but I cant figure out how to have a unqiue ID.

 $date = new DateTime();
 $time = strval($date->getTimestamp() * 1000);

 $dimensions = [];
 $i = 0;
 while ($i < 1) {
    $expected_delivery = '2022-04-30 18:00:00';
    $created_date = date("Y-m-d H:i:s");
    $completed_date = 'n/a';
    $completed = '0';
    $created_by = 'xxx xxxx';
    $sender_user_id = '1';
    $receiver_user_id = '2';
    $sender_company_id = '10';
    $receiver_company_id = '11';
    $remark = 'TEST REMARK TEST HERE';
    $receiver_address = 'xxxxxxxxxxxx';

    $dimensions[] = [
        'Dimensions' => [
            [
                'DimensionValueType' => 'VARCHAR',
                'Name' => 'expected_delivery', // REQUIRED
                'Value' => $expected_delivery, // REQUIRED
            ],
            [
                'DimensionValueType' => 'VARCHAR',
                'Name' => 'expected_delivery', // REQUIRED
                'Value' => $expected_delivery, // REQUIRED
            ],
            [
                'DimensionValueType' => 'VARCHAR',
                'Name' => 'created_date', // REQUIRED
                'Value' => $created_date, // REQUIRED
            ],
            [
                'DimensionValueType' => 'VARCHAR',
                'Name' => 'completed_date', // REQUIRED
                'Value' => $completed_date, // REQUIRED
            ],
            [
                'DimensionValueType' => 'VARCHAR',
                'Name' => 'completed', // REQUIRED
                'Value' => '0', // REQUIRED
            ],
            [
                'DimensionValueType' => 'VARCHAR',
                'Name' => 'created_by', // REQUIRED
                'Value' => $created_by, // REQUIRED
            ],
            [
                'DimensionValueType' => 'VARCHAR',
                'Name' => 'sender_user_id', // REQUIRED
                'Value' => $sender_user_id, // REQUIRED
            ],
            [
                'DimensionValueType' => 'VARCHAR',
                'Name' => 'receiver_user_id', // REQUIRED
                'Value' => $receiver_user_id, // REQUIRED
            ],
            [
                'DimensionValueType' => 'VARCHAR',
                'Name' => 'sender_company_id', // REQUIRED
                'Value' => $sender_company_id, // REQUIRED
            ],
            [
                'DimensionValueType' => 'VARCHAR',
                'Name' => 'receiver_company_id', // REQUIRED
                'Value' => $receiver_company_id, // REQUIRED
            ],
            [
                'DimensionValueType' => 'VARCHAR',
                'Name' => 'remark', // REQUIRED
                'Value' => $remark, // REQUIRED
            ],
            [
                'DimensionValueType' => 'VARCHAR',
                'Name' => 'receiver_address', // REQUIRED
                'Value' => $receiver_address, // REQUIRED
            ],
        ],
    ];
    $i++;
 }

$query = [
    'CommonAttributes' => [
        'MeasureName' => 'transactions_cnt',
        'MeasureValue' => 'transactions_cnt',
        'MeasureValueType' => 'VARCHAR',
        'Time' => $time,
        'TimeUnit' => 'MILLISECONDS',
        'Version' => 1,
    ],
    'DatabaseName' => 'packaging_app',
    'Records' => $dimensions,
    'TableName' => 'transactions',
];

I was reading the doc where it states the unique IDs but it doesnt give any explanation how to actually do it in the code:

If your application scenario requires you to store an unique identifier for every data point (e.g., a request ID, a transaction ID, or a correlation ID), modeling the ID attribute as a measure value will result in significantly better query latency. When modeling your data with multi-measure records, the ID appears in the same row in context with your other dimensions and time series data, so your queries can continue to use them effectively. For instance, considering a DevOps use case where if every data point emitted by a server has a unique request ID attribute, modeling the request ID as a measure value results in up to 4X lower query latency across different query types as opposed to modeling the unique request ID as a dimension.

0

There are 0 best solutions below