Skip to content

Commit

Permalink
Change the fieldName field type from string to rowFieldName struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunwoo-Shin authored and losipiuk committed Nov 15, 2022
1 parent 27054e0 commit f57a743
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 5 additions & 1 deletion trino/trino.go
Original file line number Diff line number Diff line change
Expand Up @@ -1070,10 +1070,14 @@ type queryColumn struct {
type queryData []interface{}

type namedTypeSignature struct {
FieldName string `json:"fieldName"`
FieldName rowFieldName `json:"fieldName"`
TypeSignature typeSignature `json:"typeSignature"`
}

type rowFieldName struct {
Name string `json:"name"`
}

type typeSignature struct {
RawType string `json:"rawType"`
Arguments []typeArgument `json:"arguments"`
Expand Down
17 changes: 14 additions & 3 deletions trino/trino_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,15 @@ func TestQueryColumns(t *testing.T) {
map(array['a'], array[1]) AS map,
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`)
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, 31, len(columns), "Expected 31 result column")
assert.Equal(t, 32, len(columns), "Expected 32 result column")
expectedNames := []string{
"bool",
"tinyint",
Expand Down Expand Up @@ -433,14 +434,15 @@ func TestQueryColumns(t *testing.T) {
"map",
"marray",
"row",
"named_row",
"ip",
}
assert.Equal(t, expectedNames, columns)

columnTypes, err := rows.ColumnTypes()
require.NoError(t, err, "Failed reading result column types")

assert.Equal(t, 31, len(columnTypes), "Expected 31 result column type")
assert.Equal(t, 32, len(columnTypes), "Expected 32 result column type")

type columnType struct {
typeName string
Expand Down Expand Up @@ -722,6 +724,15 @@ func TestQueryColumns(t *testing.T) {
0,
reflect.TypeOf(new(interface{})).Elem(),
},
{
"ROW(X VARCHAR, Y DOUBLE)",
false,
0,
0,
false,
0,
reflect.TypeOf(new(interface{})).Elem(),
},
{
"IPADDRESS",
false,
Expand All @@ -732,7 +743,7 @@ func TestQueryColumns(t *testing.T) {
reflect.TypeOf(sql.NullString{}),
},
}
actualTypes := make([]columnType, 31)
actualTypes := make([]columnType, 32)
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 f57a743

Please sign in to comment.