Skip to content

Commit

Permalink
Remove test for reading timestamps with Trino's precision greater the…
Browse files Browse the repository at this point in the history
…n Go's
  • Loading branch information
nineinchnick authored and losipiuk committed Mar 3, 2023
1 parent 1ea6571 commit 2df27ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 107 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,12 @@ SELECT * FROM table WHERE col_double = cast(? AS DOUBLE) OR col_timestamp = CAST
### Response rows

When reading response rows, the driver supports most Trino data types, except:
* time and timestamps with precision - all time types are returned as `time.Time`.
All precisions up to nanoseconds (`TIMESTAMP(9)` or `TIME(9)`) are supported (since
this is the maximum precision Golang's `time.Time` supports). If a query returns columns
defined with a greater precision, use `CAST` to reduce the returned precision, or convert the
value to a string that then can be parsed manually.
* time and timestamps with precision - all time types are returned as
`time.Time`. All precisions up to nanoseconds (`TIMESTAMP(9)` or `TIME(9)`)
are supported (since this is the maximum precision Golang's `time.Time`
supports). If a query returns columns defined with a greater precision,
values will be trimmed to 9 decimal digits. Use `CAST` to reduce the returned
precision, or convert the value to a string that then can be parsed manually.
* `DECIMAL` - returned as string
* `IPADDRESS` - returned as string
* `INTERVAL YEAR TO MONTH` and `INTERVAL DAY TO SECOND` - returned as string
Expand Down
102 changes: 0 additions & 102 deletions trino/trino_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,108 +765,6 @@ func TestQueryColumns(t *testing.T) {
assert.Equal(t, actualTypes, expectedTypes)
}

func TestMaxTrinoPrecisionDateTime(t *testing.T) {
c := &Config{
ServerURI: *integrationServerFlag,
SessionProperties: map[string]string{"query_priority": "1"},
}

dsn, err := c.FormatDSN()
require.NoError(t, err)

db, err := sql.Open("trino", dsn)
require.NoError(t, err)

t.Cleanup(func() {
assert.NoError(t, db.Close())
})

rows, err := db.Query(`SELECT
TIME '15:55:23.383345123456' AS timep,
TIME '15:55:23.383345123456 +08:00' AS timeptz,
TIMESTAMP '2020-06-10 15:55:23.383345123456' AS tsp,
TIMESTAMP '2020-06-10 15:55:23.383345123456 UTC' AS tsptz`)
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, 4, len(columns), "Expected 4 result column")
expectedNames := []string{
"timep",
"timeptz",
"tsp",
"tsptz",
}
assert.Equal(t, expectedNames, columns)

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

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

type columnType struct {
typeName string
hasScale bool
precision int64
scale int64
hasLength bool
length int64
scanType reflect.Type
}
expectedTypes := []columnType{
{
"TIME",
true,
12,
0,
false,
0,
reflect.TypeOf(sql.NullTime{}),
},
{
"TIME WITH TIME ZONE",
true,
12,
0,
false,
0,
reflect.TypeOf(sql.NullTime{}),
},
{
"TIMESTAMP",
true,
12,
0,
false,
0,
reflect.TypeOf(sql.NullTime{}),
},
{
"TIMESTAMP WITH TIME ZONE",
true,
12,
0,
false,
0,
reflect.TypeOf(sql.NullTime{}),
},
}
actualTypes := make([]columnType, 4)
for i, column := range columnTypes {
actualTypes[i].typeName = column.DatabaseTypeName()
actualTypes[i].precision, actualTypes[i].scale, actualTypes[i].hasScale = column.DecimalSize()
actualTypes[i].length, actualTypes[i].hasLength = column.Length()
actualTypes[i].scanType = column.ScanType()
}

assert.Equal(t, actualTypes, expectedTypes)

assert.False(t, rows.Next())
assert.EqualError(t, rows.Err(), "parsing time \"15:55:23.383345123456\" as \"2006-01-02 15:04:05.999999999\": cannot parse \"5:23.383345123456\" as \"2006\"")
}

func TestMaxGoPrecisionDateTime(t *testing.T) {
c := &Config{
ServerURI: *integrationServerFlag,
Expand Down

0 comments on commit 2df27ad

Please sign in to comment.