This repository has been archived by the owner on Feb 2, 2019. It is now read-only.
forked from kikinteractive/go-bqstreamer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
error_row.go
54 lines (46 loc) · 1.75 KB
/
error_row.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
package bqstreamer
import bigquery "google.golang.org/api/bigquery/v2"
// RowErrors contains errors relating to a single row.
// Each row can have multiple errors associated with it.
type RowErrors struct {
// A table insert operation can be split into multiple requests
// if too many rows have been queued. This means that rows
// containing errors cannot be identified by their table index.
// Therefore, each row can be identified by its insert ID instead.
InsertID string
tableDataInsertAllResponseInsertErrors bigquery.TableDataInsertAllResponseInsertErrors
}
// Next iterates over all row errors once,
// returning a single row error every call.
// Calling Next() multiple times will consequently return more row errors,
// until all row errors have been returned.
//
// The function returns true if a non-nil value was fetched.
// Once the iterator has been exhausted, (nil, false) will be returned
// on every subsequent call.
func (row *RowErrors) Next() (*bigquery.ErrorProto, bool) {
errs := row.tableDataInsertAllResponseInsertErrors.Errors
if len(errs) == 0 {
return nil, false
}
// Return elements in reverse order for memory efficiency.
var err *bigquery.ErrorProto
err, row.tableDataInsertAllResponseInsertErrors.Errors = errs[len(row.tableDataInsertAllResponseInsertErrors.Errors)-1], errs[:len(row.tableDataInsertAllResponseInsertErrors.Errors)-1]
return err, true
}
// All returns all remaining row errors (those that have not been iterated over using
// Next()).
//
// Calling Next() or All() again afterwards will yield a failed (empty)
// result.
func (row *RowErrors) All() []*bigquery.ErrorProto {
var errors []*bigquery.ErrorProto
for {
err, ok := row.Next()
if !ok {
break
}
errors = append(errors, err)
}
return errors
}