Skip to content

Commit

Permalink
chore(client): revert negative exponent double serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
puzpuzpuz committed Jun 10, 2022
1 parent 822b1b9 commit 304f043
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 59 deletions.
13 changes: 2 additions & 11 deletions sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,15 +737,6 @@ func (b *buffer) WriteFloat(f float64) {
}
// We need up to 24 bytes to fit a float64, including a sign.
var a [24]byte
s := strconv.AppendFloat(a[0:0], f, 'g', -1, 64)
var prev byte
for i := 0; i < len(s); i++ {
// Server doesn't support 4.2e+100 notation and expects
// 4.2e100 instead. So, we make sure to erase '+'.
if prev == 'e' && s[i] == '+' {
continue
}
b.WriteByte(s[i])
prev = s[i]
}
s := strconv.AppendFloat(a[0:0], f, 'G', -1, 64)
b.Write(s)
}
42 changes: 1 addition & 41 deletions sender_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func TestE2EValidWrites(t *testing.T) {
},
},
{
"small double value with exponent",
"double value with exponent",
testTable,
func(s *qdb.LineSender) error {
return s.
Expand All @@ -350,46 +350,6 @@ func TestE2EValidWrites(t *testing.T) {
Count: 1,
},
},
{
"large double value with exponent",
testTable,
func(s *qdb.LineSender) error {
return s.
Table(testTable).
Float64Column("foobar", 4.2e100).
At(ctx, 1000)
},
tableData{
Columns: []column{
{"foobar", "DOUBLE"},
{"timestamp", "TIMESTAMP"},
},
Dataset: [][]interface{}{
{4.2e100, "1970-01-01T00:00:00.000001Z"},
},
Count: 1,
},
},
{
"negative double value with exponent",
testTable,
func(s *qdb.LineSender) error {
return s.
Table(testTable).
Float64Column("foobar", -4.2e100).
At(ctx, 1000)
},
tableData{
Columns: []column{
{"foobar", "DOUBLE"},
{"timestamp", "TIMESTAMP"},
},
Dataset: [][]interface{}{
{-4.2e100, "1970-01-01T00:00:00.000001Z"},
},
Count: 1,
},
},
}

for _, tc := range testCases {
Expand Down
14 changes: 7 additions & 7 deletions sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestValidWrites(t *testing.T) {
}
}

func TestIntSerialization(t *testing.T) {
func TestInt64Serialization(t *testing.T) {
ctx := context.Background()

testCases := []struct {
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestIntSerialization(t *testing.T) {
}
}

func TestFloatSerialization(t *testing.T) {
func TestFloat64Serialization(t *testing.T) {
ctx := context.Background()

testCases := []struct {
Expand All @@ -162,11 +162,11 @@ func TestFloatSerialization(t *testing.T) {
{"negative infinity", math.Inf(-1), "-Infinity"},
{"positive number", 42.3, "42.3"},
{"negative number", -42.3, "-42.3"},
{"smallest value", math.SmallestNonzeroFloat64, "5e-324"},
{"max value", math.MaxFloat64, "1.7976931348623157e308"},
{"negative with exponent", -4.2e-99, "-4.2e-99"},
{"small with exponent", 4.2e-99, "4.2e-99"},
{"large with exponent", 4.2e99, "4.2e99"},
{"smallest value", math.SmallestNonzeroFloat64, "5E-324"},
{"max value", math.MaxFloat64, "1.7976931348623157E+308"},
{"negative with exponent", -4.2e-99, "-4.2E-99"},
{"small with exponent", 4.2e-99, "4.2E-99"},
{"large with exponent", 4.2e99, "4.2E+99"},
}

for _, tc := range testCases {
Expand Down
77 changes: 77 additions & 0 deletions test/ilp-client-interop-test.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,81 @@
[
{
"testName": "all column types",
"table": "test_table",
"symbols": [
{
"name": "sym_col",
"value": "sym_val"
}
],
"columns": [
{
"type": "STRING",
"name": "str_col",
"value": "foo bar baz"
},
{
"type": "LONG",
"name": "long_col",
"value": 42
},
{
"type": "DOUBLE",
"name": "double_col",
"value": 42.5
},
{
"type": "BOOLEAN",
"name": "bool_col",
"value": true
}
],
"result": {
"status": "SUCCESS",
"line": "test_table,sym_col=sym_val str_col=\"foo bar baz\",long_col=42i,double_col=42.5,bool_col=t"
}
},
{
"testName": "double serialization",
"table": "doubles",
"symbols": [],
"columns": [
{
"type": "DOUBLE",
"name": "d0",
"value": 0.0
},
{
"type": "DOUBLE",
"name": "dm0",
"value": -0.0
},
{
"type": "DOUBLE",
"name": "d1",
"value": 1.0
},
{
"type": "DOUBLE",
"name": "dE100",
"value": 1E100
},
{
"type": "DOUBLE",
"name": "d0000001",
"value": 0.000001
},
{
"type": "DOUBLE",
"name": "dN0000001",
"value": -0.000001
}
],
"result": {
"status": "SUCCESS",
"line": "doubles d0=0,dm0=-0,d1=1,dE100=1E+100,d0000001=1E-06,dN0000001=-1E-06"
}
},
{
"testName": "escaped chars in table name",
"table": "test 1=2",
Expand Down

0 comments on commit 304f043

Please sign in to comment.