@@ -22,6 +22,7 @@ import (
22
22
"reflect"
23
23
"sort"
24
24
"strings"
25
+ "sync"
25
26
"time"
26
27
27
28
"github.com/gocql/gocql"
@@ -44,32 +45,50 @@ func (s *dbserver) Query(ctx context.Context, query *server.DataQuery) (result *
44
45
Meta : & server.DataMeta {},
45
46
}
46
47
47
- // query database and tables
48
- if result .Meta .Databases , err = dbQuery .GetDatabases (ctx ); err != nil {
49
- log .Printf ("failed to query databases: %v\n " , err )
50
- }
48
+ wg := sync.WaitGroup {}
51
49
52
- if result .Meta .CurrentDatabase = query .Key ; query .Key == "" {
53
- if result .Meta .CurrentDatabase , err = dbQuery .GetCurrentDatabase (); err != nil {
54
- log .Printf ("failed to query current database: %v\n " , err )
50
+ wg .Add (1 )
51
+ go func () {
52
+ defer wg .Done ()
53
+ // query database and tables
54
+ if result .Meta .Databases , err = dbQuery .GetDatabases (ctx ); err != nil {
55
+ log .Printf ("failed to query databases: %v\n " , err )
55
56
}
56
- }
57
+ }()
57
58
58
- if result .Meta .Tables , err = dbQuery .GetTables (ctx , result .Meta .CurrentDatabase ); err != nil {
59
- log .Printf ("failed to query tables: %v\n " , err )
60
- }
59
+ wg .Add (1 )
60
+ go func () {
61
+ defer wg .Done ()
62
+
63
+ if result .Meta .CurrentDatabase = query .Key ; query .Key == "" {
64
+ if result .Meta .CurrentDatabase , err = dbQuery .GetCurrentDatabase (); err != nil {
65
+ log .Printf ("failed to query current database: %v\n " , err )
66
+ }
67
+ }
61
68
69
+ if result .Meta .Tables , err = dbQuery .GetTables (ctx , result .Meta .CurrentDatabase ); err != nil {
70
+ log .Printf ("failed to query tables: %v\n " , err )
71
+ }
72
+ }()
73
+
74
+ defer wg .Wait ()
62
75
// query data
63
76
if query .Sql == "" {
64
77
return
65
78
}
66
79
67
80
query .Sql = dbQuery .GetInnerSQL ().ToNativeSQL (query .Sql )
68
- result .Meta .Labels = dbQuery .GetLabels (ctx , query .Sql )
69
- result .Meta .Labels = append (result .Meta .Labels , & server.Pair {
70
- Key : "_native_sql" ,
71
- Value : query .Sql ,
72
- })
81
+
82
+ wg .Add (1 )
83
+ go func () {
84
+ defer wg .Done ()
85
+
86
+ result .Meta .Labels = dbQuery .GetLabels (ctx , query .Sql )
87
+ result .Meta .Labels = append (result .Meta .Labels , & server.Pair {
88
+ Key : "_native_sql" ,
89
+ Value : query .Sql ,
90
+ })
91
+ }()
73
92
74
93
var dataResult * server.DataQueryResult
75
94
now := time .Now ()
@@ -222,10 +241,7 @@ func (q *commonDataQuery) GetCurrentDatabase() (current string, err error) {
222
241
223
242
func (q * commonDataQuery ) GetLabels (ctx context.Context , sql string ) (metadata []* server.Pair ) {
224
243
metadata = make ([]* server.Pair , 0 )
225
- if databaseResult , err := sqlQuery (ctx , fmt .Sprintf ("explain %s" , sql ), q .session ); err == nil {
226
- if len (databaseResult .Items ) != 1 {
227
- return
228
- }
244
+ if databaseResult , err := sqlQuery (ctx , fmt .Sprintf ("explain %s" , sql ), q .session ); err == nil && len (databaseResult .Items ) == 1 {
229
245
for _ , data := range databaseResult .Items [0 ].Data {
230
246
switch data .Key {
231
247
case "type" :
@@ -236,6 +252,18 @@ func (q *commonDataQuery) GetLabels(ctx context.Context, sql string) (metadata [
236
252
}
237
253
}
238
254
}
255
+
256
+ if databaseResult , err := sqlQuery (ctx , "SELECT release_version FROM system.local" , q .session ); err == nil && len (databaseResult .Items ) >= 1 {
257
+ for _ , data := range databaseResult .Items [0 ].Data {
258
+ switch data .Key {
259
+ case "release_version" :
260
+ metadata = append (metadata , & server.Pair {
261
+ Key : "version" ,
262
+ Value : data .Value ,
263
+ })
264
+ }
265
+ }
266
+ }
239
267
return
240
268
}
241
269
0 commit comments