Skip to content

(go/adbc/driver/snowflake): Large date values are not being returned correctly #2811

@davidhcoe

Description

@davidhcoe

What happened?

If you run the query for

select TO_TIMESTAMP('9999-12-31 00:00:00') As December31, TO_TIMESTAMP('9999-12-30 00:00:00') As December30"

You get incorrect values because the epoch from Snowflake (253402214400) gets converted to -4852202631933722624, which is actually March 29, 1816 at 05:56:08.066278. I believe this is because during the call to:

v, err := arrow.TimestampFromTime(time.Unix(epoch[i], int64(fraction[i])), dt.TimeUnit())

The correct epoch value gets passed in, but with the TimeUnit of Nanoseconds, the internals of TimestampFromTime convert the large epoch value to nanoseconds again, causing the int64 value to overflow to the negative number:

func TimestampFromTime(val time.Time, unit TimeUnit) (Timestamp, error) {
	switch unit {
	case Second:
		return Timestamp(val.Unix()), nil
	case Millisecond:
		return Timestamp(val.Unix()*1e3 + int64(val.Nanosecond())/1e6), nil
	case Microsecond:
		return Timestamp(val.Unix()*1e6 + int64(val.Nanosecond())/1e3), nil
	case Nanosecond:
		return Timestamp(val.UnixNano()), nil // <------- problematic line
	default:
		return 0, fmt.Errorf("%w: unexpected timestamp unit: %s", ErrInvalid, unit)
	}
}

However, the Time value already comes in at the correct date.

Stack Trace

No response

How can we reproduce the bug?

No response

Environment/Setup

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions