You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by li...@apache.org on 2023/09/01 14:38:25 UTC

[arrow-adbc] branch main updated: fix(go/adbc/driver/snowflake): properly handle time fields (#1021)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new d772fd11 fix(go/adbc/driver/snowflake): properly handle time fields (#1021)
d772fd11 is described below

commit d772fd11809361f6671f2255c0b0c571816c6855
Author: Matt Topol <zo...@gmail.com>
AuthorDate: Fri Sep 1 10:38:18 2023 -0400

    fix(go/adbc/driver/snowflake): properly handle time fields (#1021)
    
    Fixes #1019
---
 go/adbc/driver/snowflake/driver_test.go   | 14 +++++++++++++-
 go/adbc/driver/snowflake/record_reader.go | 10 ++++++++--
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/go/adbc/driver/snowflake/driver_test.go b/go/adbc/driver/snowflake/driver_test.go
index 712f730e..89fc566d 100644
--- a/go/adbc/driver/snowflake/driver_test.go
+++ b/go/adbc/driver/snowflake/driver_test.go
@@ -333,13 +333,25 @@ func (suite *SnowflakeTests) TestSqlIngestTimestamp() {
 	sc := arrow.NewSchema([]arrow.Field{{
 		Name: "col", Type: arrow.FixedWidthTypes.Timestamp_us,
 		Nullable: true,
-	}}, nil)
+	}, {
+		Name: "col2", Type: arrow.FixedWidthTypes.Time64us,
+		Nullable: true,
+	}, {
+		Name: "col3", Type: arrow.PrimitiveTypes.Int64,
+		Nullable: true,
+	},
+	}, nil)
 
 	bldr := array.NewRecordBuilder(memory.DefaultAllocator, sc)
 	defer bldr.Release()
 
 	tbldr := bldr.Field(0).(*array.TimestampBuilder)
 	tbldr.AppendValues([]arrow.Timestamp{0, 0, 42}, []bool{false, true, true})
+	tmbldr := bldr.Field(1).(*array.Time64Builder)
+	tmbldr.AppendValues([]arrow.Time64{420000, 0, 86000}, []bool{true, false, true})
+	ibldr := bldr.Field(2).(*array.Int64Builder)
+	ibldr.AppendValues([]int64{-1, 25, 0}, []bool{true, true, false})
+
 	rec := bldr.NewRecord()
 	defer rec.Release()
 
diff --git a/go/adbc/driver/snowflake/record_reader.go b/go/adbc/driver/snowflake/record_reader.go
index db0bf0f8..5b4dbb49 100644
--- a/go/adbc/driver/snowflake/record_reader.go
+++ b/go/adbc/driver/snowflake/record_reader.go
@@ -110,9 +110,15 @@ func getTransformer(sc *arrow.Schema, ld gosnowflake.ArrowStreamLoader) (*arrow.
 				}
 			}
 		case "TIME":
-			f.Type = arrow.FixedWidthTypes.Time64ns
+			var dt arrow.DataType
+			if srcMeta.Scale < 6 {
+				dt = &arrow.Time32Type{Unit: arrow.TimeUnit(srcMeta.Scale / 3)}
+			} else {
+				dt = &arrow.Time64Type{Unit: arrow.TimeUnit(srcMeta.Scale / 3)}
+			}
+			f.Type = dt
 			transformers[i] = func(ctx context.Context, a arrow.Array) (arrow.Array, error) {
-				return compute.CastArray(ctx, a, compute.SafeCastOptions(f.Type))
+				return compute.CastArray(ctx, a, compute.SafeCastOptions(dt))
 			}
 		case "TIMESTAMP_NTZ":
 			dt := &arrow.TimestampType{Unit: arrow.TimeUnit(srcMeta.Scale / 3)}