Skip to content

Bug parsing interval with negative values #4237

@waitingkuo

Description

@waitingkuo

Describe the bug

bug parsing interval that contains negative values

To Reproduce

select (interval '1 month -1 second');
+---------------------------------------------------+
| IntervalMonthDayNano("-1000000000")               |
+---------------------------------------------------+
| 0 years -1 mons -1 days 0 hours 0 mins -1.00 secs |
+---------------------------------------------------+
1 row in set. Query took 0.002 seconds.

this is a parsing issue but not a display issue, underline value is incorrect IntervalMonthDayNano("-1000000000")

Expected behavior

0 year 1 mons 0 days 0 hours 0 mins -1 secs

Additional context

https://github.com/apache/arrow-datafusion/blob/406c1087bc16f8d2a49e5a9b05d2a0e1b67f7aa5/datafusion/common/src/parsers.rs#L151-L152

the binary expression for result nanos (which is 128bit long here) is 111111111111111......... which make months and days becomes negative

negative factional seconds has display issue #4220

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions