forked from chdb-io/chdb-go
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstreaming.go
More file actions
75 lines (63 loc) · 1.54 KB
/
Copy pathstreaming.go
File metadata and controls
75 lines (63 loc) · 1.54 KB
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
73
74
75
package chdbpurego
import "errors"
type streamingResult struct {
curConn *chdb_connection
stream *chdb_result
curChunk ChdbResult
}
func newStreamingResult(conn *chdb_connection, cRes *chdb_result) ChdbStreamResult {
// nextChunk := streamingResultNext(conn, cRes)
// if nextChunk == nil {
// return nil
// }
res := &streamingResult{
curConn: conn,
stream: cRes,
// curChunk: newChdbResult(nextChunk),
}
// runtime.SetFinalizer(res, res.Free)
return res
}
// Error implements ChdbStreamResult.
func (c *streamingResult) Error() error {
if s := chdbResultError(c.stream); s != "" {
return errors.New(s)
}
return nil
}
// Free implements ChdbStreamResult.
func (c *streamingResult) Free() {
if c.curConn != nil && c.stream != nil {
chdbStreamCancelQuery(c.curConn, c.stream)
chdbDestroyQueryResult(c.stream)
}
c.stream = nil
if c.curChunk != nil {
c.curChunk.Free()
c.curChunk = nil
}
}
// Cancel implements ChdbStreamResult.
func (c *streamingResult) Cancel() {
c.Free()
}
// GetNext implements ChdbStreamResult.
func (c *streamingResult) GetNext() ChdbResult {
if c.curChunk == nil {
nextChunk := chdbStreamFetchResult(c.curConn.internal_data, c.stream)
if nextChunk == nil {
return nil
}
c.curChunk = newChdbResult(nextChunk)
return c.curChunk
}
// free the current chunk before getting the next one
c.curChunk.Free()
c.curChunk = nil
nextChunk := chdbStreamFetchResult(c.curConn.internal_data, c.stream)
if nextChunk == nil {
return nil
}
c.curChunk = newChdbResult(nextChunk)
return c.curChunk
}