Hello:
I’m trying to use a bucket schema to restrict the writing to the bucket.
Using the InfluxDB v2 API I have created the schema showed below:
[
{
"links": {
"self": "/api/v2/buckets/a7d9eb85c8c223b8/schema/measurements/0aef4bcd49e56000"
},
"id": "0aef4bcd49e56000",
"orgID": "XXXXX",
"bucketID": "a7d9eb85c8c223b8",
"name": "SmartMeter",
"columns": [
{
"name": "time",
"type": "timestamp"
},
{
"name": "iddispositivo",
"type": "tag"
},
{
"name": "pactiva",
"type": "field",
"dataType": "float"
},
{
"name": "preactiva",
"type": "field",
"dataType": "float"
},
{
"name": "creation",
"type": "field",
"dataType": "float"
}
],
"createdAt": "2023-03-23T06:39:41Z",
"updatedAt": "2023-03-23T06:39:41Z"
}
]
When I write the next two data points using the Python client library, both are correct:
data = [{
"measurement": "SmartMeter3",
"tags": {"iddispositivo": "id001"},
"fields": {"pactiva": 38.5, "preactiva": 54.5, "creation": time.time()},
"time": time.time_ns()
},
{
"measurement": "SmartMeter",
"tags": {"iddispositivo": "id002"},
"fields": {"pactiva": 36.5, "preactiva": 'two', "creation": time.time()},
"time": time.time_ns()
},
]
As far as I understood in the documentation, the first line should not be allowed because only “Smarmeter” measurement is defined. In the second case “Smartmeter” should not allow to insert “preactiva” as string.
When I write the two data point using the InfluxDB CLI, the first data point is also allowed but not the second one. In this case I get the error:
failed to write data: 400 Bad Request: failed to parse line protocol: error parsing line 1 (1-based): Could not parse entire line. Found trailing content: ‘preactiva=two,creation=56.54’
Any help to understand how to restrict the fields datatype using the schema and the python client library? And how to restrict new measurements not included in the schema?
Thank you