apache / apache/paimon

[Bug] Precision Loss in `castFromStringInternal` for Valid Float Values (e.g., -0.0009163)

Open
#4,656 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
3.4k
Forks
1.4k
Avg merge
1d 11h
Merged PRs (30d)
396

Description

### Search before asking

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

### Paimon version

paimon-flink-1.18-1.0-SNAPSHOT.jar

### Compute Engine

flink

### Minimal reproduce step

create table in mysql
``` sql
CREATE TABLE `example_table` (
`id` bigint NOT NULL,
`value` float DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
```
and insert data

``` sql
INSERT INTO example_table (id, value) VALUES (1, -0.0009163);
```

### What doesn't meet your expectations?

``` java
Float f = Float.valueOf(s);
if (f.toString().length() != s.length()) {
throw new NumberFormatException(
s + " cannot be cast to float due to precision loss");
} else {
return f;
}
```

Precision checking should not strictly rely on comparing the lengths of the values. As a result, values such as `-0.0009163` and similar ones, which can be safely represented in MySQL FLOAT, are mistakenly rejected.

### Anything else?

_No response_

### Are you willing to submit a PR?

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating castFromStringInternal and reproduce the conversion with the MySQL FLOAT value -0.0009163 shown in the issue. Determine how the current string-length check rejects that value; done means valid FLOAT values are accepted without false precision-loss errors, with coverage for the reported example.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mysql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.