InfluxDB Flux: type conflict: int != float

In a Flux query I was writing I wanted to negate the fetched values using a map function to multiply each value by -1:

map(fn: (r) => ({ _value: r._value * -1 }))

To my surprise this yielded an error:

type conflict: int != float

Took me a few Google Search Coupons to realize the error got trigger not by the type of the _value, but by the -1 in there. The solution therefore is really simple: don’t multiply by an integer (e.g. -1) but multiply by a float (e.g. -1.0); like so:

map(fn: (r) => ({ _value: r._value * -1.0 }))

😅

Did this help you out? Like what you see?
Thank me with a coffee.

I don't do this for profit but a small one-time donation would surely put a smile on my face. Thanks!

☕️ Buy me a Coffee (€3)

To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Unless noted otherwise, the contents of this post are licensed under the Creative Commons Attribution 4.0 License and code samples are licensed under the MIT License

Join the Conversation

3 Comments

  1. Hi, I am also new with flux and do struggle quite a lot. I have the opposite issue.
    I wanted to map the integer values (r._value) 1 and 0 to float 49.9 and 50.1 so I tried
    |> map(fn: (r) => ({ r with _value: 49.9+0.2*r._value }))

    So I get the same issue. But I can’t just switch to int, can I? Is there a solution to do that?

  2. I found the solution for the opposite: map int to float. it is not the map function, it seams to be an issue that int can not multiply with float. Change the type first.
    This works:
    |> map(fn: (r) => ({ r with _value: 49.985+0.03*float(v:r._value)}))
    where r._value is of type int.

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.