-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support TIMESTAMP_NTZ #962
Changes from all commits
e40dba8
f12cb67
53d3d01
177a38a
5975821
3a2e340
ebaa657
7933120
fa08b76
40e1520
b60b6ca
7fc43ab
f03fc91
8ebe8f1
8535aab
0459f2b
9c48682
702d5de
e47b817
280fe06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,48 +9,60 @@ import ( | |
|
||
type Timestamp struct{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Do not contain any timezone information. |
||
|
||
func (Timestamp) ToKindDetails() typing.KindDetails { | ||
return typing.NewKindDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType) | ||
func (Timestamp) layout() string { | ||
return ext.RFC3339MillisecondNoTZ | ||
} | ||
|
||
func (Timestamp) Convert(value any) (any, error) { | ||
func (t Timestamp) ToKindDetails() typing.KindDetails { | ||
return typing.NewExtendedTimeDetails(typing.ETime, ext.TimestampNTZKindType, t.layout()) | ||
} | ||
|
||
func (t Timestamp) Convert(value any) (any, error) { | ||
castedValue, err := typing.AssertType[int64](value) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Represents the number of milliseconds since the epoch, and does not include timezone information. | ||
return ext.NewExtendedTime(time.UnixMilli(castedValue).In(time.UTC), ext.TimestampTzKindType, ext.RFC3339Millisecond), nil | ||
return ext.NewExtendedTime(time.UnixMilli(castedValue).In(time.UTC), ext.TimestampNTZKindType, t.layout()), nil | ||
} | ||
|
||
type MicroTimestamp struct{} | ||
|
||
func (MicroTimestamp) ToKindDetails() typing.KindDetails { | ||
return typing.NewKindDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType) | ||
func (MicroTimestamp) layout() string { | ||
return ext.RFC3339MicrosecondNoTZ | ||
} | ||
|
||
func (mt MicroTimestamp) ToKindDetails() typing.KindDetails { | ||
return typing.NewExtendedTimeDetails(typing.ETime, ext.TimestampNTZKindType, mt.layout()) | ||
} | ||
|
||
func (MicroTimestamp) Convert(value any) (any, error) { | ||
func (mt MicroTimestamp) Convert(value any) (any, error) { | ||
castedValue, err := typing.AssertType[int64](value) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Represents the number of microseconds since the epoch, and does not include timezone information. | ||
return ext.NewExtendedTime(time.UnixMicro(castedValue).In(time.UTC), ext.TimestampTzKindType, ext.RFC3339Microsecond), nil | ||
return ext.NewExtendedTime(time.UnixMicro(castedValue).In(time.UTC), ext.TimestampNTZKindType, mt.layout()), nil | ||
} | ||
|
||
type NanoTimestamp struct{} | ||
|
||
func (NanoTimestamp) ToKindDetails() typing.KindDetails { | ||
return typing.NewKindDetailsFromTemplate(typing.ETime, ext.TimestampTzKindType) | ||
func (nt NanoTimestamp) ToKindDetails() typing.KindDetails { | ||
return typing.NewExtendedTimeDetails(typing.ETime, ext.TimestampNTZKindType, nt.layout()) | ||
} | ||
|
||
func (NanoTimestamp) layout() string { | ||
return ext.RFC3339NanosecondNoTZ | ||
} | ||
|
||
func (NanoTimestamp) Convert(value any) (any, error) { | ||
func (nt NanoTimestamp) Convert(value any) (any, error) { | ||
castedValue, err := typing.AssertType[int64](value) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Represents the number of nanoseconds since the epoch, and does not include timezone information. | ||
return ext.NewExtendedTime(time.UnixMicro(castedValue/1_000).In(time.UTC), ext.TimestampTzKindType, ext.RFC3339Nanosecond), nil | ||
return ext.NewExtendedTime(time.UnixMicro(castedValue/1_000).In(time.UTC), ext.TimestampNTZKindType, nt.layout()), nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -293,8 +293,16 @@ func (t *TableData) MergeColumnsFromDestination(destCols ...columns.Column) erro | |
inMemoryCol.KindDetails.ExtendedTimeDetails = &ext.NestedKind{} | ||
} | ||
|
||
// If the column in the destination is a timestamp_tz and the in-memory column is a timestamp_ntz, we should update the layout to contain timezone locale. | ||
if foundColumn.KindDetails.ExtendedTimeDetails.Type == ext.TimestampTzKindType && inMemoryCol.KindDetails.ExtendedTimeDetails.Type == ext.TimestampNTZKindType { | ||
if inMemoryCol.KindDetails.ExtendedTimeDetails.Format != "" { | ||
inMemoryCol.KindDetails.ExtendedTimeDetails.Format += ext.TimezoneOffsetFormat | ||
} | ||
} | ||
|
||
// Just copy over the type since the format wouldn't be present in the destination | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this comment still true? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so, we're still not copying the layout from the destination columns. The only logic we added is that if the destination column is |
||
inMemoryCol.KindDetails.ExtendedTimeDetails.Type = foundColumn.KindDetails.ExtendedTimeDetails.Type | ||
|
||
} | ||
|
||
// Copy over the decimal details | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like before, if we received a timestamp with tz/offset info, we discarded the tz and stored it without it. Now we'll start storing the tz. Is this change going to result in ddl changes to the column type of existing columns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it will. I'll migrate the tables that are in MSSQL from
datetime2
->datetimeoffset
once this change is inThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I don't think this would impact existing columns.
If the existing column is created as
datetime2
, we will then tag the column asTIMESTAMP_NTZ
when we decipher the output from describe table.When we merge our in-memory columns with existing, existing will take precedence.
It is then on the SDK to discard the tz information, which it should be doing already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay so we won't start storing the tz info for existing columns, but if a new column is created that should be tz-aware then we will store it. Seems reasonable 👍