2

Just wondering if anyone has worked out how to store null values in a timestream database:

I have the following code:

                dimensions = [ 
                   {'Name': 'gatewayId', 'Value': gatewayId}                   
                  ]

                 connectedDays = { 
                   'Dimensions': dimensions, 
                   'MeasureName': 'connectedDays', 
                   'MeasureValue': str(data[3]), 
                   'MeasureValueType': 'BIGINT', 
                   'Time': current_time 
                    }

Either gatewayId or data[3] could be any empty strings and would need storing a nulls in the DB but I am not sure how to do this. I've tried passing all sorts like None (etc) but AWS timestream complains every time.

I am using python.

Its so new the documentation doesn't even cover it.

Thanks

dx4100
  • 21
  • 4

1 Answers1

2

In kotlin we can do some filtering to make it work:

    val dimensions = listOf(
        Dimension.builder().name("principal").value(auditLogData.principal).build(),
        if (auditLogData.customerAccount.isNotEmpty()) Dimension.builder().name("customerAccount").value(auditLogData.customerAccount).build() else null,
        if (auditLogData.resourceId.isNotEmpty()) Dimension.builder().name("resourceId").value(auditLogData.resourceId).build() else null
    ).filterNotNull()

This removes empty dimensions before doing the write request.

As long as the dimensions are not there instead of being null it is possible to do a write request.

David Karlsson
  • 9,396
  • 9
  • 58
  • 103
  • Yes, there doesn't seem to be a way to explicitly set null, you have to omit the dimension. This is *really* unclear in the Javascript library, because the `Value` can be set to `undefined` according to the typescript definitions, but doing so triggers a bad request exception. – Mike Rippon Jan 19 '22 at 15:28