Skip to content

Commit 1368400

Browse files
committed
chore(client): improve API consistency
1 parent 07df3d3 commit 1368400

File tree

4 files changed

+54
-54
lines changed

4 files changed

+54
-54
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ func main() {
2929
err = sender.
3030
Table("trades").
3131
Symbol("name", "test_ilp1").
32-
FloatField("value", 12.4).
32+
FloatColumn("value", 12.4).
3333
AtNow(ctx)
3434
if err != nil {
3535
log.Fatal(err)
3636
}
3737
err = sender.
3838
Table("trades").
3939
Symbol("name", "test_ilp2").
40-
FloatField("value", 11.4).
40+
FloatColumn("value", 11.4).
4141
At(ctx, time.Now().UnixNano())
4242
if err != nil {
4343
log.Fatal(err)

sender.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (s *LineSender) Close() error {
9696
return s.conn.Close()
9797
}
9898

99-
// Table sets the table name for a new ILP message. Should be
99+
// Table sets the table name (metric) for a new ILP message. Should be
100100
// called before any Symbol or Field method.
101101
func (s *LineSender) Table(name string) *LineSender {
102102
if s.lastErr != nil {
@@ -113,7 +113,7 @@ func (s *LineSender) Table(name string) *LineSender {
113113
return s
114114
}
115115

116-
// Symbol adds a symbol column value to the ILP message. Should be
116+
// Symbol adds a symbol column (tag) value to the ILP message. Should be
117117
// called before any Field method.
118118
func (s *LineSender) Symbol(name, val string) *LineSender {
119119
if s.lastErr != nil {
@@ -126,7 +126,7 @@ func (s *LineSender) Symbol(name, val string) *LineSender {
126126
return s
127127
}
128128
if s.hasFields {
129-
s.lastErr = errors.New("symbol has to be written before any field")
129+
s.lastErr = errors.New("symbols have to be written before any other column")
130130
return s
131131
}
132132
s.buf.WriteByte(',')
@@ -136,9 +136,9 @@ func (s *LineSender) Symbol(name, val string) *LineSender {
136136
return s
137137
}
138138

139-
// IntField adds an integer (long column type) field value to
139+
// IntColumn adds a long column (integer field) value to
140140
// the ILP message.
141-
func (s *LineSender) IntField(name string, val int64) *LineSender {
141+
func (s *LineSender) IntColumn(name string, val int64) *LineSender {
142142
if !s.prepareForField(name) {
143143
return s
144144
}
@@ -152,9 +152,9 @@ func (s *LineSender) IntField(name string, val int64) *LineSender {
152152
return s
153153
}
154154

155-
// FloatField adds a float (double column type) field value to
155+
// FloatColumn adds a double column (float field) value to
156156
// the ILP message.
157-
func (s *LineSender) FloatField(name string, val float64) *LineSender {
157+
func (s *LineSender) FloatColumn(name string, val float64) *LineSender {
158158
if !s.prepareForField(name) {
159159
return s
160160
}
@@ -167,8 +167,8 @@ func (s *LineSender) FloatField(name string, val float64) *LineSender {
167167
return s
168168
}
169169

170-
// FloatField adds a string field value to the ILP message.
171-
func (s *LineSender) StringField(name, val string) *LineSender {
170+
// StringColumn adds a string column (field) value to the ILP message.
171+
func (s *LineSender) StringColumn(name, val string) *LineSender {
172172
if !s.prepareForField(name) {
173173
return s
174174
}
@@ -181,8 +181,8 @@ func (s *LineSender) StringField(name, val string) *LineSender {
181181
return s
182182
}
183183

184-
// FloatField adds a boolean field value to the ILP message.
185-
func (s *LineSender) BoolField(name string, val bool) *LineSender {
184+
// BoolColumn adds a boolean column (field) value to the ILP message.
185+
func (s *LineSender) BoolColumn(name string, val bool) *LineSender {
186186
if !s.prepareForField(name) {
187187
return s
188188
}

sender_integration_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func setupQuestDB(ctx context.Context) (*questdbContainer, error) {
9595
}, nil
9696
}
9797

98-
func TestAllFieldTypes(t *testing.T) {
98+
func TestAllColumnTypes(t *testing.T) {
9999
if testing.Short() {
100100
t.Skip("skipping integration test")
101101
}
@@ -113,20 +113,20 @@ func TestAllFieldTypes(t *testing.T) {
113113
err = sender.
114114
Table(testTable).
115115
Symbol("sym_col", "test_ilp1").
116-
FloatField("double_col", 12.2).
117-
IntField("long_col", 12).
118-
StringField("str_col", "foobar").
119-
BoolField("bool_col", true).
116+
FloatColumn("double_col", 12.2).
117+
IntColumn("long_col", 12).
118+
StringColumn("str_col", "foobar").
119+
BoolColumn("bool_col", true).
120120
At(ctx, 1000)
121121
assert.NoError(t, err)
122122

123123
err = sender.
124124
Table(testTable).
125125
Symbol("sym_col", "test_ilp2").
126-
FloatField("double_col", 11.2).
127-
IntField("long_col", 11).
128-
StringField("str_col", "barbaz").
129-
BoolField("bool_col", false).
126+
FloatColumn("double_col", 11.2).
127+
IntColumn("long_col", 11).
128+
StringColumn("str_col", "barbaz").
129+
BoolColumn("bool_col", false).
130130
At(ctx, 2000)
131131
assert.NoError(t, err)
132132

@@ -175,7 +175,7 @@ func TestImplicitFlush(t *testing.T) {
175175
for i := 0; i < 10*bufCap; i++ {
176176
err = sender.
177177
Table(testTable).
178-
BoolField("b", true).
178+
BoolColumn("b", true).
179179
AtNow(ctx)
180180
assert.NoError(t, err)
181181
}

sender_test.go

+31-31
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ func TestValidWrites(t *testing.T) {
5555
{
5656
"single string column",
5757
func(s *qdb.LineSender) error {
58-
err := s.Table(testTable).StringField("a_col", "foo").AtNow(ctx)
58+
err := s.Table(testTable).StringColumn("a_col", "foo").AtNow(ctx)
5959
if err != nil {
6060
return err
6161
}
62-
err = s.Table(testTable).StringField("a_col", "bar").At(ctx, 42)
62+
err = s.Table(testTable).StringColumn("a_col", "bar").At(ctx, 42)
6363
if err != nil {
6464
return err
6565
}
@@ -73,7 +73,7 @@ func TestValidWrites(t *testing.T) {
7373
{
7474
"escaped chars in table name",
7575
func(s *qdb.LineSender) error {
76-
return s.Table("test 1,2\"3\\4").IntField("a_col", 42).AtNow(ctx)
76+
return s.Table("test 1,2\"3\\4").IntColumn("a_col", 42).AtNow(ctx)
7777
},
7878
[]string{
7979
"test\\ 1\\,2\\\"3\\\\4 a_col=42i\n",
@@ -82,7 +82,7 @@ func TestValidWrites(t *testing.T) {
8282
{
8383
"escaped chars in column name",
8484
func(s *qdb.LineSender) error {
85-
return s.Table("test_table").FloatField("name 1,2\"3\\4", 42).AtNow(ctx)
85+
return s.Table("test_table").FloatColumn("name 1,2\"3\\4", 42).AtNow(ctx)
8686
},
8787
[]string{
8888
"test_table name\\ 1\\,2\\\"3\\\\4=42.000000\n",
@@ -155,27 +155,27 @@ func TestErrorOnMissingTableCall(t *testing.T) {
155155
},
156156
},
157157
{
158-
"string field",
158+
"string column",
159159
func(s *qdb.LineSender) error {
160-
return s.StringField("str", "abc").AtNow(ctx)
160+
return s.StringColumn("str", "abc").AtNow(ctx)
161161
},
162162
},
163163
{
164-
"boolean field",
164+
"boolean column",
165165
func(s *qdb.LineSender) error {
166-
return s.BoolField("bool", true).AtNow(ctx)
166+
return s.BoolColumn("bool", true).AtNow(ctx)
167167
},
168168
},
169169
{
170-
"integer field",
170+
"long column",
171171
func(s *qdb.LineSender) error {
172-
return s.IntField("int", 42).AtNow(ctx)
172+
return s.IntColumn("int", 42).AtNow(ctx)
173173
},
174174
},
175175
{
176-
"float field",
176+
"double column",
177177
func(s *qdb.LineSender) error {
178-
return s.FloatField("float", 4.2).AtNow(ctx)
178+
return s.FloatColumn("float", 4.2).AtNow(ctx)
179179
},
180180
},
181181
}
@@ -216,35 +216,35 @@ func TestErrorOnMultipleTableCalls(t *testing.T) {
216216
assert.Empty(t, sender.Messages())
217217
}
218218

219-
func TestErrorOnSymbolCallAfterField(t *testing.T) {
219+
func TestErrorOnSymbolCallAfterColumn(t *testing.T) {
220220
ctx := context.Background()
221221

222222
testCases := []struct {
223223
name string
224224
writerFn writer
225225
}{
226226
{
227-
"string field",
227+
"string column",
228228
func(s *qdb.LineSender) error {
229-
return s.Table("awesome_table").StringField("str", "abc").Symbol("sym", "abc").AtNow(ctx)
229+
return s.Table("awesome_table").StringColumn("str", "abc").Symbol("sym", "abc").AtNow(ctx)
230230
},
231231
},
232232
{
233-
"boolean field",
233+
"boolean column",
234234
func(s *qdb.LineSender) error {
235-
return s.Table("awesome_table").BoolField("bool", true).Symbol("sym", "abc").AtNow(ctx)
235+
return s.Table("awesome_table").BoolColumn("bool", true).Symbol("sym", "abc").AtNow(ctx)
236236
},
237237
},
238238
{
239-
"integer field",
239+
"integer column",
240240
func(s *qdb.LineSender) error {
241-
return s.Table("awesome_table").IntField("int", 42).Symbol("sym", "abc").AtNow(ctx)
241+
return s.Table("awesome_table").IntColumn("int", 42).Symbol("sym", "abc").AtNow(ctx)
242242
},
243243
},
244244
{
245-
"float field",
245+
"float column",
246246
func(s *qdb.LineSender) error {
247-
return s.Table("awesome_table").FloatField("float", 4.2).Symbol("sym", "abc").AtNow(ctx)
247+
return s.Table("awesome_table").FloatColumn("float", 4.2).Symbol("sym", "abc").AtNow(ctx)
248248
},
249249
},
250250
}
@@ -259,7 +259,7 @@ func TestErrorOnSymbolCallAfterField(t *testing.T) {
259259

260260
err = tc.writerFn(sender)
261261

262-
assert.EqualError(t, err, "symbol has to be written before any field")
262+
assert.EqualError(t, err, "symbols have to be written before any other column")
263263
assert.Empty(t, sender.Messages())
264264

265265
sender.Close()
@@ -280,10 +280,10 @@ func TestInvalidMessageGetsDiscarded(t *testing.T) {
280280
defer sender.Close()
281281

282282
// Write a valid message.
283-
err = sender.Table(testTable).StringField("foo", "bar").AtNow(ctx)
283+
err = sender.Table(testTable).StringColumn("foo", "bar").AtNow(ctx)
284284
assert.NoError(t, err)
285285
// Then write perform an incorrect chain of calls.
286-
err = sender.Table(testTable).StringField("foo", "bar").Symbol("sym", "42").AtNow(ctx)
286+
err = sender.Table(testTable).StringColumn("foo", "bar").Symbol("sym", "42").AtNow(ctx)
287287
assert.Error(t, err)
288288

289289
// The second message should be discarded.
@@ -311,15 +311,15 @@ func TestErrorOnCancelledContext(t *testing.T) {
311311
defer sender.Close()
312312

313313
// The context is not cancelled yet, so Flush should succeed.
314-
err = sender.Table(testTable).StringField("foo", "bar").AtNow(ctx)
314+
err = sender.Table(testTable).StringColumn("foo", "bar").AtNow(ctx)
315315
assert.NoError(t, err)
316316
err = sender.Flush(ctx)
317317
assert.NoError(t, err)
318318

319319
cancel()
320320

321321
// The context is now cancelled, so we expect an error.
322-
err = sender.Table(testTable).StringField("bar", "baz").AtNow(ctx)
322+
err = sender.Table(testTable).StringColumn("bar", "baz").AtNow(ctx)
323323
assert.NoError(t, err)
324324
err = sender.Flush(ctx)
325325
assert.Error(t, err)
@@ -339,7 +339,7 @@ func TestErrorOnContextDeadline(t *testing.T) {
339339

340340
// Keep writing until we get an error due to the context deadline.
341341
for i := 0; i < 100_000; i++ {
342-
err = sender.Table(testTable).StringField("bar", "baz").AtNow(ctx)
342+
err = sender.Table(testTable).StringColumn("bar", "baz").AtNow(ctx)
343343
if err != nil {
344344
return
345345
}
@@ -369,10 +369,10 @@ func BenchmarkLineSender(b *testing.B) {
369369
sender.
370370
Table(testTable).
371371
Symbol("sym_col", "test_ilp1").
372-
FloatField("double_col", float64(i)+0.42).
373-
IntField("long_col", int64(i)).
374-
StringField("str_col", "foobar").
375-
BoolField("bool_col", true).
372+
FloatColumn("double_col", float64(i)+0.42).
373+
IntColumn("long_col", int64(i)).
374+
StringColumn("str_col", "foobar").
375+
BoolColumn("bool_col", true).
376376
At(ctx, int64(1000*i))
377377
}
378378
sender.Flush(ctx)

0 commit comments

Comments
 (0)