Skip to content

Commit

Permalink
Support UUIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
JPMoresmau authored and losipiuk committed Dec 12, 2022
1 parent f57a743 commit a0416f7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
10 changes: 5 additions & 5 deletions trino/trino.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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{}
Expand All @@ -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{}
Expand All @@ -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{}
Expand Down Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions trino/trino_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a0416f7

Please sign in to comment.