@@ -177,34 +177,36 @@ func TestClient_ShowTagValues(t *testing.T) {
177
177
}
178
178
time .Sleep (time .Second * 5 )
179
179
180
- // SHOW TAG VALUES FROM measurement WITH KEY = location
180
+ // SHOW TAG VALUES FROM measurement WITH KEY = location ORDER BY location ASC
181
181
tagValueResult , err := c .ShowTagValues (NewShowTagValuesBuilder ().Database (databaseName ).Measurement (measurement ).
182
- With ("location" ))
182
+ With ("location" ). OrderBy ( "location" , Asc ) )
183
183
assert .Nil (t , err )
184
184
assert .Equal (t , 4 , len (tagValueResult ))
185
185
expValues := []string {"c1" , "c2" , "u1" , "u2" }
186
- sort .Strings (expValues )
187
- sort .Strings (tagValueResult )
186
+ assert .EqualValues (t , expValues , tagValueResult )
187
+
188
+ // SHOW TAG VALUES FROM measurement WITH KEY = location ORDER BY location DESC
189
+ tagValueResult , err = c .ShowTagValues (NewShowTagValuesBuilder ().Database (databaseName ).Measurement (measurement ).
190
+ With ("location" ).OrderBy ("location" , Desc ))
191
+ assert .Nil (t , err )
192
+ assert .Equal (t , 4 , len (tagValueResult ))
193
+ expValues = []string {"u2" , "u1" , "c2" , "c1" }
188
194
assert .EqualValues (t , expValues , tagValueResult )
189
195
190
196
// SHOW TAG VALUES FROM measurement WITH KEY = location LIMIT 2 OFFSET 0
191
197
tagValueResult , err = c .ShowTagValues (NewShowTagValuesBuilder ().Database (databaseName ).Measurement (measurement ).
192
- With ("location" ).Limit (2 ).Offset (0 ))
198
+ With ("location" ).Limit (2 ).Offset (0 ). OrderBy ( "location" , Asc ) )
193
199
assert .Nil (t , err )
194
200
assert .Equal (t , 2 , len (tagValueResult ))
195
201
expValues = []string {"c1" , "c2" }
196
- sort .Strings (expValues )
197
- sort .Strings (tagValueResult )
198
202
assert .EqualValues (t , expValues , tagValueResult )
199
203
200
204
// SHOW TAG VALUES FROM measurement WITH KEY = location LIMIT 2 OFFSET 2
201
205
tagValueResult , err = c .ShowTagValues (NewShowTagValuesBuilder ().Database (databaseName ).Measurement (measurement ).
202
- With ("location" ).Limit (2 ).Offset (2 ))
206
+ With ("location" ).Limit (2 ).Offset (2 ). OrderBy ( "location" , Asc ) )
203
207
assert .Nil (t , err )
204
208
assert .Equal (t , 2 , len (tagValueResult ))
205
209
expValues = []string {"u1" , "u2" }
206
- sort .Strings (expValues )
207
- sort .Strings (tagValueResult )
208
210
assert .EqualValues (t , expValues , tagValueResult )
209
211
210
212
// SHOW TAG VALUES FROM measurement WITH KEY = location LIMIT 2 OFFSET 2 WHERE country = cn
@@ -281,34 +283,36 @@ func TestClient_ShowTagValues_WithRegexp(t *testing.T) {
281
283
}
282
284
time .Sleep (time .Second * 5 )
283
285
284
- // SHOW TAG VALUES FROM measurement WITH KEY = /loc.*/
286
+ // SHOW TAG VALUES FROM measurement WITH KEY = /loc.*/ order by location ASC
285
287
tagValueResult , err := c .ShowTagValues (NewShowTagValuesBuilder ().Database (databaseName ).Measurement (measurement ).
286
- With ("/loc.*/" ))
288
+ With ("/loc.*/" ). OrderBy ( "location" , Asc ) )
287
289
assert .Nil (t , err )
288
290
assert .Equal (t , 4 , len (tagValueResult ))
289
291
expValues := []string {"c1" , "c2" , "u1" , "u2" }
290
- sort .Strings (expValues )
291
- sort .Strings (tagValueResult )
292
+ assert .EqualValues (t , expValues , tagValueResult )
293
+
294
+ // SHOW TAG VALUES FROM measurement WITH KEY = /loc.*/ order by location ASC
295
+ tagValueResult , err = c .ShowTagValues (NewShowTagValuesBuilder ().Database (databaseName ).Measurement (measurement ).
296
+ With ("/loc.*/" ).OrderBy ("location" , Desc ))
297
+ assert .Nil (t , err )
298
+ assert .Equal (t , 4 , len (tagValueResult ))
299
+ expValues = []string {"u2" , "u1" , "c2" , "c1" }
292
300
assert .EqualValues (t , expValues , tagValueResult )
293
301
294
302
// SHOW TAG VALUES FROM measurement WITH KEY = /loc./ LIMIT 2 OFFSET 0
295
303
tagValueResult , err = c .ShowTagValues (NewShowTagValuesBuilder ().Database (databaseName ).Measurement (measurement ).
296
- With ("/loc.*/" ).Limit (2 ).Offset (0 ))
304
+ With ("/loc.*/" ).Limit (2 ).Offset (0 ). OrderBy ( "location" , Asc ) )
297
305
assert .Nil (t , err )
298
306
assert .Equal (t , 2 , len (tagValueResult ))
299
307
expValues = []string {"c1" , "c2" }
300
- sort .Strings (expValues )
301
- sort .Strings (tagValueResult )
302
308
assert .EqualValues (t , expValues , tagValueResult )
303
309
304
310
// SHOW TAG VALUES FROM measurement WITH KEY = /loc./ LIMIT 2 OFFSET 2
305
311
tagValueResult , err = c .ShowTagValues (NewShowTagValuesBuilder ().Database (databaseName ).Measurement (measurement ).
306
- With ("/loc.*/" ).Limit (2 ).Offset (2 ))
312
+ With ("/loc.*/" ).Limit (2 ).Offset (2 ). OrderBy ( "location" , Asc ) )
307
313
assert .Nil (t , err )
308
314
assert .Equal (t , 2 , len (tagValueResult ))
309
315
expValues = []string {"u1" , "u2" }
310
- sort .Strings (expValues )
311
- sort .Strings (tagValueResult )
312
316
assert .EqualValues (t , expValues , tagValueResult )
313
317
314
318
// SHOW TAG VALUES FROM measurement WITH KEY = /loc./ LIMIT 2 OFFSET 2 WHERE country = cn
@@ -387,7 +391,7 @@ func TestClient_ShowTagValues_WithIn(t *testing.T) {
387
391
388
392
// SHOW TAG VALUES FROM measurement WITH KEY IN (location, country)
389
393
tagValueResult , err := c .ShowTagValues (NewShowTagValuesBuilder ().Database (databaseName ).Measurement (measurement ).
390
- With ("location" , "country" ))
394
+ With ("location" , "country" ). OrderBy ( "location" , Asc ). OrderBy ( "country" , Asc ) )
391
395
assert .Nil (t , err )
392
396
assert .Equal (t , 6 , len (tagValueResult ))
393
397
expValues := []string {"c1" , "c2" , "u1" , "u2" , "cn" , "us" }
@@ -397,13 +401,13 @@ func TestClient_ShowTagValues_WithIn(t *testing.T) {
397
401
398
402
// SHOW TAG VALUES FROM measurement WITH KEY IN (location, country) LIMIT 2 OFFSET 0
399
403
tagValueResult , err = c .ShowTagValues (NewShowTagValuesBuilder ().Database (databaseName ).Measurement (measurement ).
400
- With ("location" , "country" ).Limit (2 ).Offset (0 ))
404
+ With ("location" , "country" ).Limit (2 ).Offset (0 ). OrderBy ( "location" , Asc ) )
401
405
assert .Nil (t , err )
402
406
assert .Equal (t , 2 , len (tagValueResult ))
403
407
404
408
// SHOW TAG VALUES FROM measurement WITH KEY IN (location, country) LIMIT 2 OFFSET 2
405
409
tagValueResult , err = c .ShowTagValues (NewShowTagValuesBuilder ().Database (databaseName ).Measurement (measurement ).
406
- With ("location" , "country" ).Limit (2 ).Offset (2 ))
410
+ With ("location" , "country" ).Limit (2 ).Offset (2 ). OrderBy ( "location" , Asc ) )
407
411
assert .Nil (t , err )
408
412
assert .Equal (t , 2 , len (tagValueResult ))
409
413
@@ -421,6 +425,90 @@ func TestClient_ShowTagValues_Error_NoWithKey(t *testing.T) {
421
425
assert .Equal (t , ErrEmptyTagKey , err )
422
426
}
423
427
428
+ func TestClient_ShowTagValues_OrderBy (t * testing.T ) {
429
+ c := testDefaultClient (t )
430
+ databaseName := randomDatabaseName ()
431
+ err := c .CreateDatabase (databaseName )
432
+ require .Nil (t , err )
433
+ measurement := randomMeasurement ()
434
+ defer func () {
435
+ err := c .DropDatabase (databaseName )
436
+ assert .Nil (t , err )
437
+ }()
438
+ callback := func (err error ) {
439
+ assert .Nil (t , err )
440
+ }
441
+
442
+ points := []* Point {
443
+ {
444
+ Measurement : measurement ,
445
+ Tags : map [string ]string {
446
+ "location" : "c1" ,
447
+ "country" : "cn" ,
448
+ },
449
+ Fields : map [string ]interface {}{
450
+ "weather" : "sun" ,
451
+ "temperature" : 25.0 ,
452
+ },
453
+ },
454
+ {
455
+ Measurement : measurement ,
456
+ Tags : map [string ]string {
457
+ "location" : "c2" ,
458
+ "country" : "cn" ,
459
+ },
460
+ Fields : map [string ]interface {}{
461
+ "weather" : "sun" ,
462
+ "temperature" : 26.0 ,
463
+ },
464
+ },
465
+ {
466
+ Measurement : measurement ,
467
+ Tags : map [string ]string {
468
+ "location" : "u1" ,
469
+ "country" : "us" ,
470
+ },
471
+ Fields : map [string ]interface {}{
472
+ "weather" : "sun" ,
473
+ "temperature" : 35.0 ,
474
+ },
475
+ },
476
+ {
477
+ Measurement : measurement ,
478
+ Tags : map [string ]string {
479
+ "location" : "u2" ,
480
+ "country" : "us" ,
481
+ },
482
+ Fields : map [string ]interface {}{
483
+ "weather" : "sun" ,
484
+ "temperature" : 36.0 ,
485
+ },
486
+ },
487
+ }
488
+
489
+ for _ , point := range points {
490
+ err := c .WritePoint (databaseName , point , callback )
491
+ assert .Nil (t , err )
492
+ }
493
+ time .Sleep (time .Second * 5 )
494
+
495
+ // SHOW TAG VALUES FROM measurement WITH KEY = location order by location asc
496
+ tagValueResult , err := c .ShowTagValues (NewShowTagValuesBuilder ().Database (databaseName ).Measurement (measurement ).
497
+ With ("location" ).OrderBy ("location" , Asc ))
498
+ assert .Nil (t , err )
499
+ assert .Equal (t , 4 , len (tagValueResult ))
500
+ expValues := []string {"c1" , "c2" , "u1" , "u2" }
501
+ assert .EqualValues (t , expValues , tagValueResult )
502
+
503
+ // SHOW TAG VALUES FROM measurement WITH KEY = location order by location desc
504
+ tagValueResult , err = c .ShowTagValues (NewShowTagValuesBuilder ().Database (databaseName ).Measurement (measurement ).
505
+ With ("location" ).OrderBy ("location" , Desc ))
506
+ assert .Nil (t , err )
507
+ assert .Equal (t , 4 , len (tagValueResult ))
508
+ expValues = []string {"u2" , "u1" , "c2" , "c1" }
509
+ assert .EqualValues (t , expValues , tagValueResult )
510
+ }
511
+
424
512
func TestClient_ShowSeries (t * testing.T ) {
425
513
c := testDefaultClient (t )
426
514
databaseName := randomDatabaseName ()
0 commit comments