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

Unexpected behavior - Float vs float #293

Closed
gentry-tran opened this issue Dec 18, 2021 · 1 comment · Fixed by #294
Closed

Unexpected behavior - Float vs float #293

gentry-tran opened this issue Dec 18, 2021 · 1 comment · Fixed by #294
Labels
bug Something isn't working
Milestone

Comments

@gentry-tran
Copy link

Float and float are giving unexpected behavior. Float is converting to double, but float is converting to String. Perhaps it would be better to just throw an IllegalFormatConversionException for the primitive, or disqualify both so the API user is aware. I spent a while trying to look for an answer and stumbled upon this:

https://community.influxdata.com/t/unable-to-use-type-float-solved/7157

Not necessarily a bug, but I think if that same exception was thrown, I would have fixed my implementation in less than a minute. Hope this write up helps!

Steps to reproduce:
List the minimal actions needed to reproduce the behavior.

  1. Create a POJO and mark the columns
@Measurement(name = "DHT11")
public class DHT11 implements Sensor {
    private final SensorType type = SensorType.DHT11;

    @Column(tag = true)
    private int deviceId;

    @Column
    private Float humidity;

    @Column
    private Float temperature;

    @Column(timestamp = true)
    private Instant timestamp;

    public DHT11(Event event) {
        TempEvent e = (TempEvent) event.getEvent();
        try {
            this.temperature = e.getTemperature();
            this.humidity = e.getHumidity();
            this.deviceId = e.getDeviceId();
            this.timestamp = Instant.now();
        } catch (NullPointerException npe) {
            npe.printStackTrace();
        }
    }

    public SensorType getType() {
        return this.type;
    }
}
  1. Write this to influxdb
    @Override
    public void process(Event event) {
        try {
            WriteApiBlocking writeApi = client.getWriteApiBlocking();
            writeApi.writeMeasurement(WritePrecision.S, factory.getSensorDTO(SensorType.DHT11, event));
        } catch (InfluxException ie) {
            ie.printStackTrace();
            logger.error("It is likely that the database service is not running.");
        }
    }
  1. View the raw data for _values
  2. Repeat with primitive float

Expected behavior:
Should throw an exception for incompatible types

Actual behavior:
For Float, converts to double.
Whereas, for float converts to a string.

Specifications:

  • Client Version: Influx CLI 2.2.1 (git: 31ac78361b) build_date: 2021-11-09T21:19:29Z
  • InfluxDB Version:
       <dependency>
           <groupId>com.influxdb</groupId>
           <artifactId>influxdb-client-java</artifactId>
           <version>4.0.0</version>
       </dependency>
  • JDK Version: open-jdk 16 version 16.0.2
  • Platform: MacOS Big Sur 11.4 (20F71) M1 chip
    Model Name: MacBook Pro
    Model Identifier: MacBookPro17,1
    Chip: Apple M1
    Total Number of Cores: 8 (4 performance and 4 efficiency)
    Memory: 16 GB
    System Firmware Version: 6723.120.36
    OS Loader Version: 6723.120.36
    Serial Number (system): C02FT1Q8Q05P
    Hardware UUID: E6057655-2B7F-5D28-A7E4-F8CD37B023B7
    Provisioning UDID: 00008103-000404920CD9001E
    Activation Lock Status: Enabled
@bednar
Copy link
Contributor

bednar commented Jan 7, 2022

Hi @gentry-tran,

thanks for using our client.

The primitive float should be serialised same way as Float object.

I've prepared a fixed version within #294. Development version of the client will be available after #294 acceptance, stable version in regular release cycle.

Regards

@bednar bednar added the bug Something isn't working label Jan 7, 2022
@bednar bednar added this to the 4.1.0 milestone Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants