Influxdb: [BUG] one same field key with two different data type

Created on 28 Jun 2017  路  2Comments  路  Source: influxdata/influxdb

Bug report: there has two different data type for one same field key

__System info:

InfluxDB version: ifluxdb-1.2.1-1
operating system name: CentOS7.2.1511 x86_64

  1. execute show field keys

when I execute the cmd 'show field keys', it will show

name: app
fieldKey fieldType
-------- ---------
type boolean
type string

It's normal in influxdb there has two type for one field key? And i try to insert point with the two type of boolean and string,It all cause error like below

input field "type" on measurement "app" is type string, already exists as type boolean dropped=1"

and

input field "type" on measurement "app" is type boolean, already exists as type string dropped=2"

All 2 comments

It's not typically done, but it is possible and there are mechanisms to query both of them. Types for fields are done at the shard level so each shard can have a different type. Typically, the query engine will ask all of the shards what they think the type should be and will choose one of them based on a set of priorities (float > integer > string > boolean > tag). So if you wrote one type to one shard and one type to another shard, this is what you get.

If you want to query something lower on the priority scale (such as if you wanted to query the boolean instead of the string), you would refer to the variable with value::boolean. That forces the query engine to grab the boolean instead of the string. Any values that are of a different type than the one query are just ignored by the query engine.

The exception to that are how floats and integers are dealt with. If you query a float, any integers are converted to floats. If you query for integers (by explicitly saying value::integer), the floats will be truncated and converted to integers.

While this exists, it is recommended to use the same type for each field in a measurement. You cannot write fields of different types into the same measurement within the same shard. If you do that, the points will be dropped.

I hope that helps explain this.

@jsternberg thanks for the explanation. This helps me to understand why i have both types. I dropped old shared due to a wrong migration, but if i recreate them they keep the wrong type, whereas if i play the same process on a new database it works as intended. (i'm on influx 1.7.2)

Was this page helpful?
0 / 5 - 0 ratings