Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] one same field key with two different data type #8535

Closed
peaksnail opened this issue Jun 28, 2017 · 2 comments
Closed

[BUG] one same field key with two different data type #8535

peaksnail opened this issue Jun 28, 2017 · 2 comments

Comments

@peaksnail
Copy link

peaksnail commented Jun 28, 2017

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"

@peaksnail peaksnail changed the title [BUG] one same field key with two different type [BUG] one same field key with two different data type Jun 28, 2017
@jsternberg
Copy link
Contributor

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.

@nerzhul
Copy link

nerzhul commented Jan 2, 2019

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants