-
Notifications
You must be signed in to change notification settings - Fork 501
/
write.go
47 lines (38 loc) · 1.04 KB
/
write.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
package client
import (
"context"
"fmt"
"io"
"github.com/apache/arrow/go/v16/arrow"
"github.com/cloudquery/filetypes/v4"
"github.com/cloudquery/plugin-sdk/v4/message"
"github.com/google/uuid"
)
func (c *Client) WriteTable(ctx context.Context, msgs <-chan *message.WriteInsert) error {
var s *filetypes.Stream
for msg := range msgs {
if s == nil {
table := msg.GetTable()
name := fmt.Sprintf("%s/%s.%s%s", c.spec.Path, table.Name, c.spec.Format, c.spec.FileSpec.Compression.Extension())
if !c.spec.NoRotate {
name += "." + uuid.NewString()
}
var err error
s, err = c.Client.StartStream(table, func(r io.Reader) error {
_, err := c.storageClient.UploadStream(ctx, c.spec.Container, name, r, nil)
return err
})
if err != nil {
return err
}
}
if err := s.Write([]arrow.Record{msg.Record}); err != nil {
_ = s.FinishWithError(err)
return err
}
}
return s.Finish()
}
func (c *Client) Write(ctx context.Context, msgs <-chan message.WriteMessage) error {
return c.writer.Write(ctx, msgs)
}