Skip to content

Commit

Permalink
fix(go/adbc/driver/snowflake): proper timezone for timestamp_ltz (#1155)
Browse files Browse the repository at this point in the history
Fixes #1154
  • Loading branch information
zeroshade authored Oct 3, 2023
1 parent cf6cf8f commit 9cff03f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
24 changes: 24 additions & 0 deletions go/adbc/driver/snowflake/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,3 +606,27 @@ func (suite *SnowflakeTests) TestNewDatabaseGetSetOptions() {
suite.NoError(err)
suite.Equal(optVal2, val2)
}

func (suite *SnowflakeTests) TestTimestampSnow() {
suite.Require().NoError(suite.stmt.SetSqlQuery(`ALTER SESSION SET TIMEZONE = "America/New_York"`))
_, err := suite.stmt.ExecuteUpdate(suite.ctx)
suite.Require().NoError(err)

suite.Require().NoError(suite.stmt.SetSqlQuery("SHOW WAREHOUSES"))
rdr, _, err := suite.stmt.ExecuteQuery(suite.ctx)
suite.Require().NoError(err)
defer rdr.Release()

suite.True(rdr.Next())
rec := rdr.Record()
for _, f := range rec.Schema().Fields() {
st, ok := f.Metadata.GetValue("SNOWFLAKE_TYPE")
if !ok {
continue
}
if st == "timestamp_ltz" {
suite.Require().IsType(&arrow.TimestampType{}, f.Type)
suite.Equal("America/New_York", f.Type.(*arrow.TimestampType).TimeZone)
}
}
}
5 changes: 3 additions & 2 deletions go/adbc/driver/snowflake/record_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func rowTypesToArrowSchema(ctx context.Context, ld gosnowflake.ArrowStreamLoader
fields[i].Type = arrow.FixedWidthTypes.Timestamp_ns
case "timestamp_ltz":
if loc == nil {
loc = time.Now().Location()
loc = ld.Location()
}
fields[i].Type = &arrow.TimestampType{Unit: arrow.Nanosecond, TimeZone: loc.String()}
case "binary":
Expand Down Expand Up @@ -335,7 +335,8 @@ func jsonDataToArrow(ctx context.Context, bldr *array.RecordBuilder, ld gosnowfl
if err != nil {
return nil, err
}
val := time.Unix(sec, nsec).In(loc)

val := time.Unix(sec, nsec).In(tz)
ts, err := arrow.TimestampFromTime(val, arrow.Nanosecond)
if err != nil {
return nil, err
Expand Down

0 comments on commit 9cff03f

Please sign in to comment.