influxdata / influxdata/influxdb-java

Rounding error when reading long from db and then writing it back.

オープン
#440 コメント 10 件 リアクション 0 件 担当者 1 名 GitHub で見る

@fmachado がすでに取り組んでいます。

2019年4月2日 から。

difficulty/high kind/bug
主要言語
Java
スター
1.2k
フォーク
469
PR マージ指標
30日以内にマージされた PR はありません

説明

Hi,

I am observing rounding errors on integer fields when reading from database and writing them back.

I have a measurement with an integer column that represents a timestamps with nanosecond resolution (note, this is not the default time column).
```
SHOW FIELD KEYS ON db
name: latency_1
fieldKey fieldType
-------- ---------
latency_ms integer
msg_name string
msg_type integer
path_id integer
seq_no integer
ts_egr integer <- timestamp_ns
ts_ingr integer
```
I am reading the data from database using influxdb-java. All integer values that I am reading are Doubles now (this I believe related to this [issue](https://github.com/influxdata/influxdb-java/issues/153)).
```
String qstatement = String.format(
"SELECT * FROM %s WHERE time > now() - %dms ORDER BY time ",
table_name, how_far_back_in_time_ms);
Query query = new Query(qstatement, db_name);
influxDB.query(query, TimeUnit.NANOSECONDS);
```
For completeness, before writing values back to db, I am adding one more column where I take original value of the "ts_egr" column and convert it to Long before writing it back, i.e.,:
```
Double ts_egr = (Double)obj; //original "ts_egr" value of the column
Long long_ts = new Long(ts_egr.longValue());
```

Now I am reading a row from the original table and the new table in InfluxDB:

```
> select * from latency_1 where seq_no = 70
name: latency_1
time latency_ms msg_name msg_type path_id seq_no ts_egr ts_ingr
---- ---------- -------- -------- ------- ------ ------ -------
1523264395509000000 72 abcdefgh12345678abcd 1 1 70 1523264395509072018 1523264395509000000
> select * from modified_latency_1 where seq_no = 70
name: modified_latency_1
time latency_ms msg_name msg_type path_id seq_no ts_egr ts_egr_long ts_ingr
---- ---------- -------- -------- ------- ------ ------ ----------- -------
1523264395508999936 72 abcdefgh12345678abcd 1 1 70 1523264395509072100 1523264395509072128 1523264395509000000
```

Note, the original value of "ts_ingr" 152326439550907**2018** has been changed to 152326439550907**2100** (just by reading and writing it back) and if we do conversion back to Long in Java we get another variant 152326439550907**2128**. Overall, I was observing rounding errors up to 100 nanoseconds.

Am I doing something wrong here, and is there a way to avoid the rounding errors?

Thank you

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。