forked from bippio/go-impala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.go
68 lines (59 loc) · 1.68 KB
/
session.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
package hive
import (
"context"
"github.com/n0dev/go-impala/services/cli_service"
)
// Session represents hive session
type Session struct {
hive *Client
h *cli_service.TSessionHandle
}
// Ping checks the connection
func (s *Session) Ping(ctx context.Context) error {
req := cli_service.TGetInfoReq{
SessionHandle: s.h,
InfoType: cli_service.TGetInfoType_CLI_SERVER_NAME,
}
resp, err := s.hive.client.GetInfo(ctx, &req)
if err != nil {
return err
}
if err := checkStatus(resp); err != nil {
return err
}
s.hive.log.Printf("ping. server name: %s", resp.InfoValue.GetStringValue())
return nil
}
// ExecuteStatement returns hive operation
func (s *Session) ExecuteStatement(ctx context.Context, stmt string) (*Operation, error) {
req := cli_service.TExecuteStatementReq{
SessionHandle: s.h,
Statement: stmt,
}
resp, err := s.hive.client.ExecuteStatement(ctx, &req)
if err != nil {
return nil, err
}
if err := checkStatus(resp); err != nil {
return nil, err
}
s.hive.log.Printf("execute operation: %s", guid(resp.OperationHandle.OperationId.GUID))
s.hive.log.Printf("operation. has resultset: %v", resp.OperationHandle.GetHasResultSet())
s.hive.log.Printf("operation. modified row count: %f", resp.OperationHandle.GetModifiedRowCount())
return &Operation{h: resp.OperationHandle, hive: s.hive}, nil
}
// Close session
func (s *Session) Close(ctx context.Context) error {
s.hive.log.Printf("close session: %v", guid(s.h.GetSessionId().GUID))
req := cli_service.TCloseSessionReq{
SessionHandle: s.h,
}
resp, err := s.hive.client.CloseSession(ctx, &req)
if err != nil {
return err
}
if err := checkStatus(resp); err != nil {
return err
}
return nil
}