Skip to content

Commit 576423f

Browse files
authored
feat(client): add Long256 support (#7)
* add: Long256Column() function The support for long type has been addded. The implementation is done, but it doesn't seem to be working as expected. * implemented long256Colums() using string as parameter The string method is a temporary fix, it supports data entry in long256 until 64bit. After that it thows an error. Examine it in examples/long/long.go * feat: support for long256 added func Long256Column() added along with unit test. * add: Integration test for long256 * typos: fixed minor typos and added suggestions * fix: expanded defination
1 parent fa4d7bd commit 576423f

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

sender.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,33 @@ func (s *LineSender) Int64Column(name string, val int64) *LineSender {
323323
return s
324324
}
325325

326+
// Long256Column adds a 256-bit unsigned integer (long256) column
327+
// value to the ILP message.
328+
//
329+
// val should contain a hex encoded 256-bit unsigned integer value
330+
// with "0x" prefix and "i" suffix. Any attempt to set a string which is
331+
// not a hexadecimal will not be parsed and rejected by the database.
332+
//
333+
// Column name cannot contain any of the following characters:
334+
// '\n', '\r', '?', '.', ',', ”', '"', '\\', '/', ':', ')', '(', '+',
335+
// '-', '*' '%%', '~', or a non-printable char.
336+
func (s *LineSender) Long256Column(name, val string) *LineSender {
337+
if !s.prepareForField(name) {
338+
return s
339+
}
340+
s.lastErr = s.writeColumnName(name)
341+
if s.lastErr != nil {
342+
return s
343+
}
344+
s.buf.WriteByte('=')
345+
s.lastErr = s.writeStrValue(val, false)
346+
if s.lastErr != nil {
347+
return s
348+
}
349+
s.hasFields = true
350+
return s
351+
}
352+
326353
// TimestampColumn adds a timestamp column value to the ILP
327354
// message. Timestamp is Epoch microseconds.
328355
//

sender_integration_test.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ func TestE2EValidWrites(t *testing.T) {
236236
Symbol("sym_col", "test_ilp1").
237237
Float64Column("double_col", 12.2).
238238
Int64Column("long_col", 12).
239+
Long256Column("long256_col", "0x123a4i").
239240
StringColumn("str_col", "foobar").
240241
BoolColumn("bool_col", true).
241242
TimestampColumn("timestamp_col", 42).
@@ -249,6 +250,7 @@ func TestE2EValidWrites(t *testing.T) {
249250
Symbol("sym_col", "test_ilp2").
250251
Float64Column("double_col", 11.2).
251252
Int64Column("long_col", 11).
253+
Long256Column("long256_col", "0x123a3i").
252254
StringColumn("str_col", "barbaz").
253255
BoolColumn("bool_col", false).
254256
TimestampColumn("timestamp_col", 43).
@@ -259,14 +261,15 @@ func TestE2EValidWrites(t *testing.T) {
259261
{"sym_col", "SYMBOL"},
260262
{"double_col", "DOUBLE"},
261263
{"long_col", "LONG"},
264+
{"long256_col", "LONG256"},
262265
{"str_col", "STRING"},
263266
{"bool_col", "BOOLEAN"},
264267
{"timestamp_col", "TIMESTAMP"},
265268
{"timestamp", "TIMESTAMP"},
266269
},
267270
Dataset: [][]interface{}{
268-
{"test_ilp1", float64(12.2), float64(12), "foobar", true, "1970-01-01T00:00:00.000042Z", "1970-01-01T00:00:00.000001Z"},
269-
{"test_ilp2", float64(11.2), float64(11), "barbaz", false, "1970-01-01T00:00:00.000043Z", "1970-01-01T00:00:00.000002Z"},
271+
{"test_ilp1", float64(12.2), float64(12), "0x0123a4", "foobar", true, "1970-01-01T00:00:00.000042Z", "1970-01-01T00:00:00.000001Z"},
272+
{"test_ilp2", float64(11.2), float64(11), "0x0123a3", "barbaz", false, "1970-01-01T00:00:00.000043Z", "1970-01-01T00:00:00.000002Z"},
270273
},
271274
Count: 2,
272275
},
@@ -333,6 +336,26 @@ func TestE2EValidWrites(t *testing.T) {
333336
Count: 1,
334337
},
335338
},
339+
{
340+
"single column long256",
341+
testTable,
342+
func(s *qdb.LineSender) error {
343+
return s.
344+
Table(testTable).
345+
Long256Column("foobar", "0x123a4i").
346+
At(ctx, 42000)
347+
},
348+
tableData{
349+
Columns: []column{
350+
{"foobar", "LONG256"},
351+
{"timestamp", "TIMESTAMP"},
352+
},
353+
Dataset: [][]interface{}{
354+
{"0x0123a4", "1970-01-01T00:00:00.000042Z"},
355+
},
356+
Count: 1,
357+
},
358+
},
336359
{
337360
"double value with exponent",
338361
testTable,

sender_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,45 @@ func TestInt64Serialization(t *testing.T) {
184184
}
185185
}
186186

187+
func TestLong256Column(t *testing.T) {
188+
ctx := context.Background()
189+
190+
testCases := []struct {
191+
name string
192+
val string
193+
expected string
194+
}{
195+
{"random bits ", "0x0123a4i", "0x0123a4"},
196+
{"8bit max", "0xffffffffi", "0xffffffff"},
197+
{"16bit max", "0xffffffffffffffffi", "0xffffffffffffffff"},
198+
{"32bit max", "0xffffffffffffffffffffffffffffffffi", "0xffffffffffffffffffffffffffffffff"},
199+
{"64bit long", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffi", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},
200+
}
201+
202+
for _, tc := range testCases {
203+
t.Run(tc.name, func(t *testing.T) {
204+
srv, err := newTestServer(sendToBackChannel)
205+
assert.NoError(t, err)
206+
207+
sender, err := qdb.NewLineSender(ctx, qdb.WithAddress(srv.addr))
208+
assert.NoError(t, err)
209+
210+
err = sender.Table(testTable).Long256Column("a_col", tc.val).AtNow(ctx)
211+
assert.NoError(t, err)
212+
213+
err = sender.Flush(ctx)
214+
assert.NoError(t, err)
215+
216+
sender.Close()
217+
218+
// Now check what was received by the server.
219+
expectLines(t, srv.backCh, []string{"my_test_table a_col=" + tc.expected + "i"})
220+
221+
srv.close()
222+
})
223+
}
224+
}
225+
187226
func TestFloat64Serialization(t *testing.T) {
188227
ctx := context.Background()
189228

0 commit comments

Comments
 (0)