-
Notifications
You must be signed in to change notification settings - Fork 28
/
clickhouse_query.go
72 lines (59 loc) · 1.86 KB
/
clickhouse_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package aiven
import "context"
type (
// ClickhouseQueryHandler aiven go-client handler for Clickhouse Queries
ClickhouseQueryHandler struct {
client *Client
}
ClickhouseQueryRequest struct {
Database string `json:"database"`
Query string `json:"query"`
}
ClickhouseQueryColumnMeta struct {
Name string `json:"name"`
Type string `json:"type"`
}
// ClickhouseQueryResponse aiven go-client clickhouse query response
ClickhouseQueryResponse struct {
APIResponse
Meta []ClickhouseQueryColumnMeta
Data []interface{}
}
ClickhouseCurrentQuery struct {
ClientName string `json:"client_name"`
Database string `json:"database"`
Elapsed float64 `json:"elapsed"`
Query string `json:"query"`
User string `json:"user"`
}
// ClickhouseCurrentQueriesResponse aiven go-client clickhouse current queries response
ClickhouseCurrentQueriesResponse struct {
APIResponse
Queries []ClickhouseCurrentQuery
}
)
// CurrentQueries list current queries
func (h *ClickhouseQueryHandler) CurrentQueries(ctx context.Context, project, service string) (*ClickhouseCurrentQueriesResponse, error) {
path := buildPath("project", project, "service", service, "clickhouse", "query")
bts, err := h.client.doGetRequest(ctx, path, nil)
if err != nil {
return nil, err
}
var r ClickhouseCurrentQueriesResponse
errR := checkAPIResponse(bts, &r)
return &r, errR
}
// Query creates a ClickHouse job
func (h *ClickhouseQueryHandler) Query(ctx context.Context, project, service, database, query string) (*ClickhouseQueryResponse, error) {
path := buildPath("project", project, "service", service, "clickhouse", "query")
bts, err := h.client.doPostRequest(ctx, path, ClickhouseQueryRequest{
Database: database,
Query: query,
})
if err != nil {
return nil, err
}
var r ClickhouseQueryResponse
errR := checkAPIResponse(bts, &r)
return &r, errR
}