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

zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 68241d8a86 GH-40888: [Go][FlightRPC] support conversion from 
array.Duration in FlightSQL driver (#40889)
68241d8a86 is described below

commit 68241d8a86e9923cda2b758d10176b8dfb1cfea7
Author: wayne <[email protected]>
AuthorDate: Mon Apr 1 12:01:49 2024 -0600

    GH-40888: [Go][FlightRPC] support conversion from array.Duration in 
FlightSQL driver (#40889)
    
    
    
    ### Rationale for this change
    
    To enable the use of the flightsql driver's implementation of golang sql 
interfaces.
    
    ### What changes are included in this PR?
    
    A new switch branch for handling `array.Duration`.
    
    ### Are these changes tested?
    
    I manually tested and didn't add new unit tests because none of the other 
types handled in the same switch block are unit tested.
    
    ### Are there any user-facing changes?
    
    Just a more complete set of types handled by the sql driver.
    
    * GitHub Issue: #40888
    
    Authored-by: wayne warren <[email protected]>
    Signed-off-by: Matt Topol <[email protected]>
---
 go/arrow/flight/flightsql/driver/utils.go      |  4 ++++
 go/arrow/flight/flightsql/driver/utils_test.go | 12 ++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/go/arrow/flight/flightsql/driver/utils.go 
b/go/arrow/flight/flightsql/driver/utils.go
index a99c045e2e..84cf2110cc 100644
--- a/go/arrow/flight/flightsql/driver/utils.go
+++ b/go/arrow/flight/flightsql/driver/utils.go
@@ -104,6 +104,10 @@ func fromArrowType(arr arrow.Array, idx int) (interface{}, 
error) {
                return v.ToTime(ts.TimeUnit()), nil
        case *array.Date64:
                return c.Value(idx).ToTime(), nil
+       case *array.Duration:
+               dt := arr.DataType().(*arrow.DurationType)
+               duration := time.Duration(c.Value(idx)) * dt.Unit.Multiplier()
+               return duration, nil
        case *array.DayTimeInterval:
                durationDays := time.Duration(c.Value(idx).Days*24) * time.Hour
                duration := time.Duration(c.Value(idx).Milliseconds) * 
time.Millisecond
diff --git a/go/arrow/flight/flightsql/driver/utils_test.go 
b/go/arrow/flight/flightsql/driver/utils_test.go
index 6b1adfed47..8ea7921b64 100644
--- a/go/arrow/flight/flightsql/driver/utils_test.go
+++ b/go/arrow/flight/flightsql/driver/utils_test.go
@@ -50,6 +50,10 @@ func Test_fromArrowType(t *testing.T) {
                {Name: "f15-ts_us", Type: arrow.FixedWidthTypes.Timestamp_ns},
                {Name: "f16-d64", Type: arrow.FixedWidthTypes.Date64},
                {Name: "f17-dti", Type: arrow.FixedWidthTypes.DayTimeInterval},
+               {Name: "f18-duration_s", Type: 
arrow.FixedWidthTypes.Duration_s},
+               {Name: "f19-duration_ms", Type: 
arrow.FixedWidthTypes.Duration_ms},
+               {Name: "f20-duration_us", Type: 
arrow.FixedWidthTypes.Duration_us},
+               {Name: "f21-duration_ns", Type: 
arrow.FixedWidthTypes.Duration_ns},
        }
 
        schema := arrow.NewSchema(fields, nil)
@@ -90,6 +94,10 @@ func Test_fromArrowType(t *testing.T) {
        testTime := time.Now()
        
b.Field(15).(*array.Date64Builder).Append(arrow.Date64FromTime(testTime))
        
b.Field(16).(*array.DayTimeIntervalBuilder).Append(arrow.DayTimeInterval{Days: 
1, Milliseconds: 1000})
+       b.Field(17).(*array.DurationBuilder).Append(1)
+       b.Field(18).(*array.DurationBuilder).Append(1)
+       b.Field(19).(*array.DurationBuilder).Append(1)
+       b.Field(20).(*array.DurationBuilder).Append(1)
 
        rec := b.NewRecord()
        defer rec.Release()
@@ -123,4 +131,8 @@ func Test_fromArrowType(t *testing.T) {
        tf(t, 14, time.Date(1970, 1, 1, 12, 0, 0, 0, time.UTC))  // "f15-ts_us"
        tf(t, 15, testTime.In(time.UTC).Truncate(24*time.Hour))  // "f16-d64"
        tf(t, 16, time.Duration(24*time.Hour+time.Second))       // "f17-dti"
+       tf(t, 17, time.Duration(1000000000))                     // 
"f18-duration_s"
+       tf(t, 18, time.Duration(1000000))                        // 
"f19-duration_ms"
+       tf(t, 19, time.Duration(1000))                           // 
"f20-duration_us"
+       tf(t, 20, time.Duration(1))                              // 
"f21-duration_ns"
 }

Reply via email to