This is an automated email from the ASF dual-hosted git repository.

raulcd pushed a commit to branch maint-13.0.0
in repository https://gitbox.apache.org/repos/asf/arrow.git

commit 608669f1c2f86a3eb68def7f03aed17613a4fc2b
Author: Matt Topol <[email protected]>
AuthorDate: Mon Jul 10 16:25:04 2023 -0400

    GH-36568: [Go] Include Timestamp Zone in ValueStr (#36569)
    
    
    
    ### Rationale for this change
    While trying to fix an issue with Snowflake ADBC timestamp handling, I came 
across this as part of the problem.
    
    ### What changes are included in this PR?
    Adds the timezone string indicator to the output of `ValueStr` for a 
timestamp array.
    
    * Closes: #36568
    
    Authored-by: Matt Topol <[email protected]>
    Signed-off-by: Matt Topol <[email protected]>
---
 go/arrow/array/timestamp.go      | 13 +++++++++++--
 go/arrow/array/timestamp_test.go | 18 ++++++++++++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/go/arrow/array/timestamp.go b/go/arrow/array/timestamp.go
index ee38a0eb4f..a992832074 100644
--- a/go/arrow/array/timestamp.go
+++ b/go/arrow/array/timestamp.go
@@ -90,7 +90,10 @@ func (a *Timestamp) ValueStr(i int) string {
        if a.IsNull(i) {
                return NullValueStr
        }
-       return 
a.values[i].ToTime(a.DataType().(*arrow.TimestampType).Unit).Format("2006-01-02 
15:04:05.999999999")
+
+       dt := a.DataType().(*arrow.TimestampType)
+       z, _ := dt.GetZone()
+       return a.values[i].ToTime(dt.Unit).In(z).Format("2006-01-02 
15:04:05.999999999Z0700")
 }
 
 func (a *Timestamp) GetOneForMarshal(i int) interface{} {
@@ -289,7 +292,13 @@ func (b *TimestampBuilder) AppendValueFromString(s string) 
error {
                b.AppendNull()
                return nil
        }
-       v, err := arrow.TimestampFromString(s, b.dtype.Unit)
+
+       loc, err := b.dtype.GetZone()
+       if err != nil {
+               return err
+       }
+
+       v, _, err := arrow.TimestampFromStringInLocation(s, b.dtype.Unit, loc)
        if err != nil {
                b.AppendNull()
                return err
diff --git a/go/arrow/array/timestamp_test.go b/go/arrow/array/timestamp_test.go
index 27978976db..d8d9f8a389 100644
--- a/go/arrow/array/timestamp_test.go
+++ b/go/arrow/array/timestamp_test.go
@@ -233,3 +233,21 @@ func TestTimestampBuilder_Resize(t *testing.T) {
        ab.Resize(32)
        assert.Equal(t, 5, ab.Len())
 }
+
+func TestTimestampValueStr(t *testing.T) {             
+       mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
+       defer mem.AssertSize(t, 0)
+
+       dt := &arrow.TimestampType{Unit: arrow.Second, TimeZone: 
"America/Phoenix"}
+       b := array.NewTimestampBuilder(mem, dt)
+       defer b.Release()
+
+       b.Append(-34226955)
+       b.Append(1456767743)
+
+       arr := b.NewArray()
+       defer arr.Release()
+
+       assert.Equal(t, "1968-11-30 13:30:45-0700", arr.ValueStr(0))
+       assert.Equal(t, "2016-02-29 10:42:23-0700", arr.ValueStr(1))
+}

Reply via email to