You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ze...@apache.org on 2023/01/30 17:53:41 UTC

[arrow-adbc] branch main updated: feat(go/sqldriver): implement database/sql/driver.RowsColumnTypeDatabaseTypeName (#392)

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-adbc.git


The following commit(s) were added to refs/heads/main by this push:
     new f773e4e  feat(go/sqldriver): implement database/sql/driver.RowsColumnTypeDatabaseTypeName (#392)
f773e4e is described below

commit f773e4ef26ed72b372585a83a44a7d6c11e2b782
Author: Jacob Marble <ja...@influxdata.com>
AuthorDate: Mon Jan 30 09:53:36 2023 -0800

    feat(go/sqldriver): implement database/sql/driver.RowsColumnTypeDatabaseTypeName (#392)
    
    * feat(go/sqldriver): implement database/sql/driver.RowsColumnTypeDatabaseTypeName
    
    * chore: add unit tests
    
    * chore: small cleanup in new test
    
    * fix whitespace
    
    ---------
    
    Co-authored-by: Matt Topol <zo...@gmail.com>
---
 go/adbc/sqldriver/driver.go                |  4 +++
 go/adbc/sqldriver/driver_internals_test.go | 58 ++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/go/adbc/sqldriver/driver.go b/go/adbc/sqldriver/driver.go
index 53aa40a..9e13b27 100644
--- a/go/adbc/sqldriver/driver.go
+++ b/go/adbc/sqldriver/driver.go
@@ -657,6 +657,10 @@ func (r *rows) Next(dest []driver.Value) error {
 	return nil
 }
 
+func (r *rows) ColumnTypeDatabaseTypeName(index int) string {
+	return r.rdr.Schema().Field(index).Type.String()
+}
+
 func (r *rows) ColumnTypeNullable(index int) (nullable, ok bool) {
 	return r.rdr.Schema().Field(index).Nullable, true
 }
diff --git a/go/adbc/sqldriver/driver_internals_test.go b/go/adbc/sqldriver/driver_internals_test.go
index 74f86e4..f913351 100644
--- a/go/adbc/sqldriver/driver_internals_test.go
+++ b/go/adbc/sqldriver/driver_internals_test.go
@@ -66,6 +66,64 @@ func TestParseConnectStr(t *testing.T) {
 	}
 }
 
+func TestColumnTypeDatabaseTypeName(t *testing.T) {
+	tests := []struct {
+		typ      arrow.DataType
+		typeName string
+	}{
+		{
+			typ:      &arrow.StringType{},
+			typeName: "utf8",
+		},
+		{
+			typ:      &arrow.Date32Type{},
+			typeName: "date32",
+		},
+		{
+			typ:      &arrow.Date64Type{},
+			typeName: "date64",
+		},
+		{
+			typ:      &arrow.TimestampType{Unit: arrow.Second, TimeZone: "utc"},
+			typeName: "timestamp[s, tz=utc]",
+		},
+		{
+			typ:      &arrow.TimestampType{Unit: arrow.Millisecond},
+			typeName: "timestamp[ms]",
+		},
+		{
+			typ:      &arrow.Time32Type{Unit: arrow.Second},
+			typeName: "time32[s]",
+		},
+		{
+			typ:      &arrow.Time32Type{Unit: arrow.Microsecond},
+			typeName: "time32[us]",
+		},
+		{
+			typ:      &arrow.Time64Type{Unit: arrow.Second},
+			typeName: "time64[s]",
+		},
+		{
+			typ:      &arrow.Time64Type{Unit: arrow.Nanosecond},
+			typeName: "time64[ns]",
+		},
+		{
+			typ:      &arrow.DurationType{Unit: arrow.Nanosecond},
+			typeName: "duration[ns]",
+		},
+	}
+
+	for i, test := range tests {
+		t.Run(fmt.Sprintf("%d-%s", i, test.typeName), func(t *testing.T) {
+			schema := arrow.NewSchema([]arrow.Field{{Type: test.typ}}, nil)
+			reader, err := array.NewRecordReader(schema, nil)
+			require.NoError(t, err)
+			r := &rows{rdr: reader}
+			assert.Equal(t, test.typeName, r.ColumnTypeDatabaseTypeName(0))
+		})
+	}
+}
+
 var (
 	tz       = time.FixedZone("North Idaho", -int((8 * time.Hour).Seconds()))
 	testTime = time.Date(2023, time.January, 26, 15, 40, 39, 123456789, tz)