forked from grafadruid/go-druid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.go
51 lines (43 loc) · 1.02 KB
/
query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package druid
import (
"net/http"
"github.com/grafadruid/go-druid/builder"
"github.com/grafadruid/go-druid/builder/query"
)
const (
NativeQueryEndpoint = "druid/v2"
SQLQueryEndpoint = "druid/v2/sql"
)
type QueryService struct {
client *Client
}
func (q *QueryService) Execute(qry builder.Query, result interface{}, headers ...http.Header) (*Response, error) {
var path string
switch qry.Type() {
case "sql":
path = SQLQueryEndpoint
default:
path = NativeQueryEndpoint
}
r, err := q.client.NewRequest("POST", path, qry)
if err != nil {
return nil, err
}
if len(headers) >= 1 {
for k, v := range headers[0] {
for _, vv := range v {
r.Header.Set(k, vv)
}
}
}
resp, err := q.client.Do(r, result)
if err != nil {
return nil, err
}
return resp, nil
}
//func (q *QueryService) Cancel(query builder.Query) () {}
//func (q *QueryService) Candidates(query builder.Query, result interface{}) (*Response, error) {}
func (q *QueryService) Load(data []byte) (builder.Query, error) {
return query.Load(data)
}