| 12 | ) |
| 13 | |
| 14 | func (c *Client) WriteTable(ctx context.Context, msgs <-chan *message.WriteInsert) error { |
| 15 | var s *filetypes.Stream |
| 16 | |
| 17 | for msg := range msgs { |
| 18 | if s == nil { |
| 19 | table := msg.GetTable() |
| 20 | |
| 21 | name := fmt.Sprintf("%s/%s.%s%s", c.spec.Path, table.Name, c.spec.Format, c.spec.FileSpec.Compression.Extension()) |
| 22 | if !c.spec.NoRotate { |
| 23 | name += "." + uuid.NewString() |
| 24 | } |
| 25 | |
| 26 | var err error |
| 27 | s, err = c.Client.StartStream(table, func(r io.Reader) error { |
| 28 | _, err := c.storageClient.UploadStream(ctx, c.spec.Container, name, r, nil) |
| 29 | return err |
| 30 | }) |
| 31 | if err != nil { |
| 32 | return err |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | if err := s.Write([]arrow.RecordBatch{msg.Record}); err != nil { |
| 37 | _ = s.FinishWithError(err) |
| 38 | return err |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | return s.Finish() |
| 43 | } |
| 44 | |
| 45 | func (c *Client) Write(ctx context.Context, msgs <-chan message.WriteMessage) error { |
| 46 | return c.writer.Write(ctx, msgs) |