From a0416f717d1399513f742561d113312b9e3580bf Mon Sep 17 00:00:00 2001 From: JP Moresmau Date: Sun, 4 Dec 2022 15:53:31 +0100 Subject: [PATCH] Support UUIDs --- trino/trino.go | 10 +++++----- trino/trino_test.go | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/trino/trino.go b/trino/trino.go index 1fc1f45..dc72ce0 100644 --- a/trino/trino.go +++ b/trino/trino.go @@ -1301,7 +1301,7 @@ func getScanType(typeNames []string) (reflect.Type, error) { switch typeNames[0] { case "boolean": v = sql.NullBool{} - case "json", "char", "varchar", "varbinary", "interval year to month", "interval day to second", "decimal", "ipaddress", "unknown": + case "json", "char", "varchar", "varbinary", "interval year to month", "interval day to second", "decimal", "ipaddress", "uuid", "unknown": v = sql.NullString{} case "tinyint", "smallint": v = sql.NullInt32{} @@ -1322,7 +1322,7 @@ func getScanType(typeNames []string) (reflect.Type, error) { switch typeNames[1] { case "boolean": v = NullSliceBool{} - case "json", "char", "varchar", "varbinary", "interval year to month", "interval day to second", "decimal", "ipaddress", "unknown": + case "json", "char", "varchar", "varbinary", "interval year to month", "interval day to second", "decimal", "ipaddress", "uuid", "unknown": v = NullSliceString{} case "tinyint", "smallint", "integer", "bigint": v = NullSliceInt64{} @@ -1339,7 +1339,7 @@ func getScanType(typeNames []string) (reflect.Type, error) { switch typeNames[2] { case "boolean": v = NullSlice2Bool{} - case "json", "char", "varchar", "varbinary", "interval year to month", "interval day to second", "decimal", "ipaddress", "unknown": + case "json", "char", "varchar", "varbinary", "interval year to month", "interval day to second", "decimal", "ipaddress", "uuid", "unknown": v = NullSlice2String{} case "tinyint", "smallint", "integer", "bigint": v = NullSlice2Int64{} @@ -1356,7 +1356,7 @@ func getScanType(typeNames []string) (reflect.Type, error) { switch typeNames[3] { case "boolean": v = NullSlice3Bool{} - case "json", "char", "varchar", "varbinary", "interval year to month", "interval day to second", "decimal", "ipaddress", "unknown": + case "json", "char", "varchar", "varbinary", "interval year to month", "interval day to second", "decimal", "ipaddress", "uuid", "unknown": v = NullSlice3String{} case "tinyint", "smallint", "integer", "bigint": v = NullSlice3Int64{} @@ -1386,7 +1386,7 @@ func (c *typeConverter) ConvertValue(v interface{}) (driver.Value, error) { return nil, err } return vv.Bool, err - case "json", "char", "varchar", "varbinary", "interval year to month", "interval day to second", "decimal", "ipaddress", "unknown": + case "json", "char", "varchar", "varbinary", "interval year to month", "interval day to second", "decimal", "ipaddress", "uuid", "unknown": vv, err := scanNullString(v) if !vv.Valid { return nil, err diff --git a/trino/trino_test.go b/trino/trino_test.go index 256ce38..c4349c8 100644 --- a/trino/trino_test.go +++ b/trino/trino_test.go @@ -395,14 +395,15 @@ func TestQueryColumns(t *testing.T) { array[map(array['a'], array[1]), map(array['b'], array[2])] AS marray, row('a', 1) AS row, cast(row('a', 1.23) AS row(x varchar, y double)) AS named_row, - ipaddress '10.0.0.1' AS ip`) + ipaddress '10.0.0.1' AS ip, + uuid '12151fd2-7586-11e9-8f9e-2a86e4085a59' AS uuid`) require.NoError(t, err, "Failed executing query") assert.NotNil(t, rows) columns, err := rows.Columns() require.NoError(t, err, "Failed reading result columns") - assert.Equal(t, 32, len(columns), "Expected 32 result column") + assert.Equal(t, 33, len(columns), "Expected 33 result column") expectedNames := []string{ "bool", "tinyint", @@ -436,13 +437,14 @@ func TestQueryColumns(t *testing.T) { "row", "named_row", "ip", + "uuid", } assert.Equal(t, expectedNames, columns) columnTypes, err := rows.ColumnTypes() require.NoError(t, err, "Failed reading result column types") - assert.Equal(t, 32, len(columnTypes), "Expected 32 result column type") + assert.Equal(t, 33, len(columnTypes), "Expected 33 result column type") type columnType struct { typeName string @@ -742,8 +744,17 @@ func TestQueryColumns(t *testing.T) { 0, reflect.TypeOf(sql.NullString{}), }, + { + "UUID", + false, + 0, + 0, + false, + 0, + reflect.TypeOf(sql.NullString{}), + }, } - actualTypes := make([]columnType, 32) + actualTypes := make([]columnType, 33) for i, column := range columnTypes { actualTypes[i].typeName = column.DatabaseTypeName() actualTypes[i].precision, actualTypes[i].scale, actualTypes[i].hasScale = column.DecimalSize()