apache / apache/iotdb

[Bug] The CAST operator has a logical error causing precision loss when converting floating-point values.

Open
#14,149 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
6.4k
Forks
1.2k
Avg merge
1d 23h
Merged PRs (30d)
115

Description

### Search before asking

- [X] I searched in the [issues](https://github.com/apache/iotdb/issues) and found nothing similar.

### Version

version 1.3.3 (Build: ad95a7e)

### Describe the bug and provide the minimal reproduce step

```
DROP DATABASE root.db0
CREATE DATABASE root.db0

CREATE TIMESERIES root.db0.t1 WITH datatype=FLOAT compressor=GZIP 'MAX_POINT_NUMBER'='6';
INSERT INTO root.db0(timestamp, t1) VALUES (1643027794590, 0.5522);
INSERT INTO root.db0(timestamp, t1) VALUES (1643027794600, 0.8044);

# query 1
select t1 from root.db0 where t1 <= 0.8044

# query 2
select t1 from root.db0 where cast(t1 as float) <= 0.8044
```

### What did you expect to see?

Query 1 returned result set: 0.5522 and 0.8044

Query 2 returned result set: 0.5522 and 0.8044

### What did you see instead?

Query 1 returned result set: 0.5522 and 0.8044

Query 2 returned result set: 0.5522

### Anything else?

Dear IoTDB team, When using the CAST operator to convert a FLOAT value to FLOAT, the value theoretically should remain unchanged. However, the above test case indicates that a logical error causing precision loss occurs after the CAST conversion.

### Are you willing to submit a PR?

- [ ] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Research direction

Run the SQL reproduction from the issue against IoTDB 1.3.3 and compare the two query results. Trace the CAST expression handling and the FLOAT comparison path, then verify that casting FLOAT to FLOAT preserves the value and that both expected rows are returned.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.