Skip to content

Commit

Permalink
Support reading float literals returned as strings
Browse files Browse the repository at this point in the history
Trino 428 removed the deprecated parse_decimal_literals_as_double
property which caused the server to return decimal literals as strings,
not floats. Support reading such values when scanning results.
  • Loading branch information
nineinchnick authored and losipiuk committed Oct 8, 2023
1 parent 2fa1fc1 commit 0fcb544
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 1 addition & 2 deletions trino/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func TestIntegrationTypeConversion(t *testing.T) {
t.Fatal(err)
}
dsn := *integrationServerFlag
dsn += "?session_properties=parse_decimal_literals_as_double=true&custom_client=uncompressed"
dsn += "?custom_client=uncompressed"
db := integrationOpen(t, dsn)
var (
goTime time.Time
Expand Down Expand Up @@ -410,7 +410,6 @@ func TestIntegrationTypeConversion(t *testing.T) {

func TestIntegrationArgsConversion(t *testing.T) {
dsn := *integrationServerFlag
dsn += "?session_properties=parse_decimal_literals_as_double=true"
db := integrationOpen(t, dsn)
value := 0
err := db.QueryRow(`
Expand Down
12 changes: 10 additions & 2 deletions trino/trino.go
Original file line number Diff line number Diff line change
Expand Up @@ -1808,7 +1808,7 @@ func scanNullFloat64(v interface{}) (sql.NullFloat64, error) {
if ok {
vFloat, err := vNumber.Float64()
if err != nil {
return sql.NullFloat64{}, fmt.Errorf("cannot convert %v (%T) to float64", vNumber, vNumber)
return sql.NullFloat64{}, fmt.Errorf("cannot convert %v (%T) to float64: %w", vNumber, vNumber, err)
}
return sql.NullFloat64{Valid: true, Float64: vFloat}, nil
}
Expand All @@ -1820,7 +1820,15 @@ func scanNullFloat64(v interface{}) (sql.NullFloat64, error) {
case "-Infinity":
return sql.NullFloat64{Valid: true, Float64: math.Inf(-1)}, nil
default:
return sql.NullFloat64{}, fmt.Errorf("cannot convert %v (%T) to float64", v, v)
vString, ok := v.(string)
if !ok {
return sql.NullFloat64{}, fmt.Errorf("cannot convert %v (%T) to float64", v, v)
}
vFloat, err := strconv.ParseFloat(vString, 64)
if err != nil {
return sql.NullFloat64{}, fmt.Errorf("cannot convert %v (%T) to float64: %w", v, v, err)
}
return sql.NullFloat64{Valid: true, Float64: vFloat}, nil
}
}

Expand Down

0 comments on commit 0fcb544

Please sign in to comment.