forked from bippio/go-impala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
59 lines (49 loc) · 1.3 KB
/
client.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
package hive
import (
"context"
"log"
"strconv"
"github.com/apache/thrift/lib/go/thrift"
"github.com/bippio/go-impala/services/cli_service"
)
// Client represents Hive Client
type Client struct {
client *cli_service.TCLIServiceClient
opts *Options
log *log.Logger
}
// Options for Hive Client
type Options struct {
MaxRows int64
MemLimit string
QueryTimeout int
}
// NewClient creates Hive Client
func NewClient(client thrift.TClient, log *log.Logger, opts *Options) *Client {
return &Client{
client: cli_service.NewTCLIServiceClient(client),
log: log,
opts: opts,
}
}
// OpenSession creates new hive session
func (c *Client) OpenSession(ctx context.Context) (*Session, error) {
cfg := map[string]string{
"MEM_LIMIT": c.opts.MemLimit,
"QUERY_TIMEOUT_S": strconv.Itoa(c.opts.QueryTimeout),
}
req := cli_service.TOpenSessionReq{
ClientProtocol: cli_service.TProtocolVersion_HIVE_CLI_SERVICE_PROTOCOL_V7,
Configuration: cfg,
}
resp, err := c.client.OpenSession(ctx, &req)
if err != nil {
return nil, err
}
if err := checkStatus(resp); err != nil {
return nil, err
}
c.log.Printf("open session: %s", guid(resp.SessionHandle.GetSessionId().GUID))
c.log.Printf("session config: %v", resp.Configuration)
return &Session{h: resp.SessionHandle, hive: c}, nil
}