Skip to content

Commit 822b1b9

Browse files
committed
fix(client): fix 4.2e+100 notation serialization
1 parent 8c884b4 commit 822b1b9

File tree

3 files changed

+76
-5
lines changed

3 files changed

+76
-5
lines changed

sender.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,5 +738,14 @@ func (b *buffer) WriteFloat(f float64) {
738738
// We need up to 24 bytes to fit a float64, including a sign.
739739
var a [24]byte
740740
s := strconv.AppendFloat(a[0:0], f, 'g', -1, 64)
741-
b.Write(s)
741+
var prev byte
742+
for i := 0; i < len(s); i++ {
743+
// Server doesn't support 4.2e+100 notation and expects
744+
// 4.2e100 instead. So, we make sure to erase '+'.
745+
if prev == 'e' && s[i] == '+' {
746+
continue
747+
}
748+
b.WriteByte(s[i])
749+
prev = s[i]
750+
}
742751
}

sender_integration_test.go

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,16 +316,76 @@ func TestE2EValidWrites(t *testing.T) {
316316
func(s *qdb.LineSender) error {
317317
return s.
318318
Table(testTable).
319-
BoolColumn("foobar", true).
319+
Int64Column("foobar", 1_000_042).
320320
At(ctx, 42000)
321321
},
322322
tableData{
323323
Columns: []column{
324-
{"foobar", "BOOLEAN"},
324+
{"foobar", "LONG"},
325325
{"timestamp", "TIMESTAMP"},
326326
},
327327
Dataset: [][]interface{}{
328-
{true, "1970-01-01T00:00:00.000042Z"},
328+
{float64(1_000_042), "1970-01-01T00:00:00.000042Z"},
329+
},
330+
Count: 1,
331+
},
332+
},
333+
{
334+
"small double value with exponent",
335+
testTable,
336+
func(s *qdb.LineSender) error {
337+
return s.
338+
Table(testTable).
339+
Float64Column("foobar", 4.2e-100).
340+
At(ctx, 1000)
341+
},
342+
tableData{
343+
Columns: []column{
344+
{"foobar", "DOUBLE"},
345+
{"timestamp", "TIMESTAMP"},
346+
},
347+
Dataset: [][]interface{}{
348+
{4.2e-100, "1970-01-01T00:00:00.000001Z"},
349+
},
350+
Count: 1,
351+
},
352+
},
353+
{
354+
"large double value with exponent",
355+
testTable,
356+
func(s *qdb.LineSender) error {
357+
return s.
358+
Table(testTable).
359+
Float64Column("foobar", 4.2e100).
360+
At(ctx, 1000)
361+
},
362+
tableData{
363+
Columns: []column{
364+
{"foobar", "DOUBLE"},
365+
{"timestamp", "TIMESTAMP"},
366+
},
367+
Dataset: [][]interface{}{
368+
{4.2e100, "1970-01-01T00:00:00.000001Z"},
369+
},
370+
Count: 1,
371+
},
372+
},
373+
{
374+
"negative double value with exponent",
375+
testTable,
376+
func(s *qdb.LineSender) error {
377+
return s.
378+
Table(testTable).
379+
Float64Column("foobar", -4.2e100).
380+
At(ctx, 1000)
381+
},
382+
tableData{
383+
Columns: []column{
384+
{"foobar", "DOUBLE"},
385+
{"timestamp", "TIMESTAMP"},
386+
},
387+
Dataset: [][]interface{}{
388+
{-4.2e100, "1970-01-01T00:00:00.000001Z"},
329389
},
330390
Count: 1,
331391
},

sender_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ func TestFloatSerialization(t *testing.T) {
163163
{"positive number", 42.3, "42.3"},
164164
{"negative number", -42.3, "-42.3"},
165165
{"smallest value", math.SmallestNonzeroFloat64, "5e-324"},
166-
{"max value", math.MaxFloat64, "1.7976931348623157e+308"},
166+
{"max value", math.MaxFloat64, "1.7976931348623157e308"},
167167
{"negative with exponent", -4.2e-99, "-4.2e-99"},
168+
{"small with exponent", 4.2e-99, "4.2e-99"},
169+
{"large with exponent", 4.2e99, "4.2e99"},
168170
}
169171

170172
for _, tc := range testCases {

0 commit comments

Comments
 (0)