Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Bug in "ns" precision when updating influxDB with string format of time #667

Closed
xinlongxu opened this issue Dec 19, 2018 · 2 comments
Closed

Comments

@xinlongxu
Copy link

Floating point calculation cause difference record when updating with string format of time.

"2018-12-19T05:33:59.999Z" is the raw time of string format
"2018-12-19T05:33:59.999000064Z" is the new time record when updating with the above time, but insert a new record

image

That happened becouse of the floating point calculation in line_protocal.py

def _convert_timestamp(timestamp, precision=None):
    if isinstance(timestamp, Integral):
        return timestamp  # assume precision is correct if timestamp is int

    if isinstance(_get_unicode(timestamp), text_type):
        timestamp = parse(timestamp)

    if isinstance(timestamp, datetime):
        if not timestamp.tzinfo:
            timestamp = UTC.localize(timestamp)
    ns = (timestamp - EPOCH).total_seconds() * 1e9
        if precision is None or precision == 'n':
            return ns
        elif precision == 'u':
            return ns / 1e3
        elif precision == 'ms':
            return ns / 1e6
        elif precision == 's':
            return ns / 1e9
        elif precision == 'm':
            return ns / 1e9 / 60
        elif precision == 'h':
            return ns / 1e9 / 3600

    raise ValueError(timestamp)

image

@clslgrnc
Copy link
Contributor

Duplicate of #649?

@xginn8
Copy link
Collaborator

xginn8 commented Apr 7, 2019

Closing as duplicate of #649

@xginn8 xginn8 closed this as completed Apr 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants