From 304f04322b67a70ae040686971e31fc47d34000a Mon Sep 17 00:00:00 2001 From: Andrey Pechkurov Date: Fri, 10 Jun 2022 22:21:45 +0300 Subject: [PATCH] chore(client): revert negative exponent double serialization --- sender.go | 13 +----- sender_integration_test.go | 42 +---------------- sender_test.go | 14 +++--- test/ilp-client-interop-test.json | 77 +++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 59 deletions(-) diff --git a/sender.go b/sender.go index 6869cd2..1b1e2ad 100644 --- a/sender.go +++ b/sender.go @@ -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) } diff --git a/sender_integration_test.go b/sender_integration_test.go index 3393611..697eb8f 100644 --- a/sender_integration_test.go +++ b/sender_integration_test.go @@ -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. @@ -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 { diff --git a/sender_test.go b/sender_test.go index efa0952..cdc9f41 100644 --- a/sender_test.go +++ b/sender_test.go @@ -110,7 +110,7 @@ func TestValidWrites(t *testing.T) { } } -func TestIntSerialization(t *testing.T) { +func TestInt64Serialization(t *testing.T) { ctx := context.Background() testCases := []struct { @@ -148,7 +148,7 @@ func TestIntSerialization(t *testing.T) { } } -func TestFloatSerialization(t *testing.T) { +func TestFloat64Serialization(t *testing.T) { ctx := context.Background() testCases := []struct { @@ -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 { diff --git a/test/ilp-client-interop-test.json b/test/ilp-client-interop-test.json index 2e05008..1e97a66 100644 --- a/test/ilp-client-interop-test.json +++ b/test/ilp-client-interop-test.json @@ -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",