-
Notifications
You must be signed in to change notification settings - Fork 5
/
messagesaver.go
40 lines (34 loc) · 1.09 KB
/
messagesaver.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
package protobq
import (
"cloud.google.com/go/bigquery"
"google.golang.org/protobuf/proto"
)
// MessageSaver implements bigquery.ValueSaver for a proto.Message.
// The message is converted to a BigQuery row using the provided MarshalOptions.
type MessageSaver struct {
// Options to use for marshaling the Message.
Options MarshalOptions
// InsertID governs the best-effort deduplication feature of
// BigQuery streaming inserts.
//
// If the InsertID is empty, a random InsertID will be generated by
// this library to facilitate deduplication.
//
// If the InsertID is set to the sentinel value bigquery.NoDedupeID, an InsertID
// is not sent.
//
// For all other non-empty values, BigQuery will use the provided
// value for best-effort deduplication.
InsertID string
// Message to save.
Message proto.Message
}
var _ bigquery.ValueSaver = &MessageSaver{}
// Save implements bigquery.ValueSaver.
func (m *MessageSaver) Save() (map[string]bigquery.Value, string, error) {
row, err := m.Options.Marshal(m.Message)
if err != nil {
return nil, "", err
}
return row, m.InsertID, nil
}