Skip to content

Commit

Permalink
fix: fix long as strings parsing (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepansergeevitch authored Oct 3, 2023
1 parent 782b0f6 commit acac1ff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
16 changes: 13 additions & 3 deletions driver_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ func TestDriverSystemEngine(t *testing.T) {
fmt.Sprintf("ALTER DATABASE %s WITH DESCRIPTION = 'GO SDK Integration test'", databaseName),
fmt.Sprintf("ALTER ENGINE %s RENAME TO %s", engineName, engineNewName),
fmt.Sprintf("START ENGINE %s", engineNewName),
fmt.Sprintf("STOP ENGINE %s", engineNewName)}
fmt.Sprintf("STOP ENGINE %s", engineNewName),
}

for _, query := range ddlStatements {
_, err := db.Query(query)
Expand Down Expand Up @@ -202,9 +203,18 @@ func TestDriverSystemEngine(t *testing.T) {
}

func containsDatabase(rows *sql.Rows, databaseToFind string) (bool, error) {
var databaseName, region, attachedEngines, createdOn, createdBy, errors string
var databaseName, compressed_size, uncompressed_size, description, createdOn, createdBy, region, attachedEngines, errors string
for rows.Next() {
if err := rows.Scan(&databaseName, &region, &attachedEngines, &createdOn, &createdBy, &errors); err != nil {
if err := rows.Scan(
&databaseName,
&compressed_size,
&uncompressed_size,
&description,
&createdOn,
&createdBy,
&region,
&attachedEngines,
&errors); err != nil {
return false, err
}
if databaseToFind == databaseName {
Expand Down
12 changes: 10 additions & 2 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"math"
"reflect"
"strconv"
"strings"
"time"
)
Expand Down Expand Up @@ -102,7 +103,10 @@ func checkTypeValue(columnType string, val interface{}) error {
}
}
}
return fmt.Errorf("expected to convert a value to float64, but couldn't: %v", val)
// Allow string values for long columns
if _, is_str := val.(string); !(columnType == longType && is_str) {
return fmt.Errorf("expected to convert a value to float64, but couldn't: %v", val)
}
}
return nil
case textType, dateType, pgDateType, timestampType, timestampNtzType, timestampTzType, byteaType:
Expand Down Expand Up @@ -178,7 +182,11 @@ func parseSingleValue(columnType string, val interface{}) (driver.Value, error)
case intType:
return int32(val.(float64)), nil
case longType:
return int64(val.(float64)), nil
// long values as passed as strings by system engine
if unpacked, ok := val.(float64); ok {
return int64(unpacked), nil
}
return strconv.ParseInt(val.(string) /*base*/, 10 /*bitSize*/, 64)
case floatType:
v, err := parseFloatValue(val)
return float32(v), err
Expand Down
3 changes: 2 additions & 1 deletion rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func mockRows(isMultiStatement bool) driver.RowsNextResultSet {
],
"data":[
[null,1,0.312321,123213.321321,"text", "2080-12-31","1989-04-15 01:02:03","0002-01-01","1989-04-15 01:02:03.123456","1989-04-15 02:02:03.123456+00",1,[1,2,3],[[]],true, 123.12345678, [123.12345678], "\\x616263313233"],
[2,1,0.312321,123213.321321,"text","1970-01-01","1970-01-01 00:00:00","0001-01-01","1989-04-15 01:02:03.123457","1989-04-15 01:02:03.1234+05:30",1,[1,2,3],[[]],true, -123.12345678, [-123.12345678, 0.0], "\\x6162630A0AE3858D20E3858E5C"],
[2,"37237366456",0.312321,123213.321321,"text","1970-01-01","1970-01-01 00:00:00","0001-01-01","1989-04-15 01:02:03.123457","1989-04-15 01:02:03.1234+05:30",1,[1,2,3],[[]],true, -123.12345678, [-123.12345678, 0.0], "\\x6162630A0AE3858D20E3858E5C"],
[3,null,"inf",123213.321321,"text","1970-01-01","1970-01-01 00:00:00","0001-01-01","1989-04-15 01:02:03.123458","1989-04-15 01:02:03+01",1,[5,2,3,2],[["TEST","TEST1"],["TEST3"]],false, 0.0, [0.0], null],
[2,1,"-inf",123213.321321,"text","1970-01-01","1970-01-01 00:00:00","0001-01-01","1989-04-15 01:02:03.123457","1111-01-05 17:04:42.123456+05:53:28",1,[1,2,3],[[]],false, 123456781234567812345678.123456781234567812345678, [123456781234567812345678.12345678123456781234567812345678], null],
[2,1,"-nan",123213.321321,"text","1970-01-01","1970-01-01 00:00:00","0001-01-01","1989-04-15 01:02:03.123457","1989-04-15 02:02:03.123456-01",1,[1,2,3],[[]],null, null, [null], null]
Expand Down Expand Up @@ -161,6 +161,7 @@ func TestRowsNext(t *testing.T) {
// Second row
err = rows.Next(dest)
assert(err, nil, t, "Next shouldn't return an error")
assert(dest[1], int64(37237366456), t, "results not equal for int64")
// Creating custom timezone with no name (e.g. Europe/Berlin)
// similar to Firebolt's return format
timezone, _ := time.LoadLocation("Asia/Calcutta")
Expand Down

0 comments on commit acac1ff

Please sign in to comment.