InfluxDB2 fields with same name, but different value type

46 views Asked by At

I have setup an influxdb2 and want to write data using the line protocol. My data are CAN-bus messages from different buses.

As measurement I choose the name of the bus (can1 in the example). I also choose COB-ID (MotorBatteryStatus_MS_1 in the example) and format as tags.

"format" could be either

  • raw which is an integer
  • physical which is a float
  • enumeration which is a string

So I want to determine the format of the data by this tag.

The physical value is calculated based on the raw value which is a natural calculation in this domain. Also the enumeration is a string mapping based on the raw value.

This means some fields exists with two datatypes in the same set of data. Here is an example for the current line protocol

can1,cobid=MotorBatteryStatus_MS_1,format=raw MotorSpeed=0i,MotorCurrent=0i,MotorVoltage=0i,BatteryVoltage=29i,BatteryCurrent=0i 1675746059287000000
can1,cobid=MotorBatteryStatus_MS_1,format=physical MotorCurrent=0.0,BatteryCurrent=0.0 1675746059287000000

For Influx it seems not to be possible to have a field with different datatypes distinguished by the tag choosen.

I also have an influxdb1 where the field name is assembled instead of tags, which is not recommend by influx. So for every data type there is a separate field.

This is an example how the data looks like in influx 1

can1,cobid=MotorBatteryStatus_MS_1 MotorSpeed.raw=0i,MotorCurrent.raw=0i,MotorCurrent.physical=0.0,MotorVoltage.raw=0i,BatteryVoltage.raw=29i,BatteryCurrent.raw=0i,BatteryCurrent.physical=0.0 1675746059287000000

Is there a workaround or different schema that can be used to have fields with same name and different datatypes?

1

There are 1 answers

0
Benny On

I figured it out. Obvisiously I have to fix my layout for that.

My new layout is like this:

can1,cobid=MotorBatteryStatus_MS_1,signal=MotorCurrent raw=0i,physical=0.0 1675746059287000000

So I will get more lines as each signal needs to be on a single line and I will only get the fields raw, physical, enumeration instead of the fields with signal names.

I am not sure if I now may run into a high cardinality issue...

Would be perfect if someone can give me his 2 cents on this.