-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathequal.go
45 lines (38 loc) · 1013 Bytes
/
equal.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
package bqs
import "cloud.google.com/go/bigquery"
// Equal compares two bigquery.Schema and returns true if they are equal.
// It returns false if the length of the schemas are different or the fields are different.
func Equal(a, b bigquery.Schema) bool {
if len(a) != len(b) {
return false
}
for _, p := range a {
if !contain(b, p) {
return false
}
}
return true
}
func equalFieldSchema(a, b *bigquery.FieldSchema) bool {
// TODO: check PolicyTags
// TODO: check RangeElementType
return a.Name == b.Name &&
a.Type == b.Type &&
a.Description == b.Description &&
a.Required == b.Required &&
a.Repeated == b.Repeated &&
a.MaxLength == b.MaxLength &&
a.Precision == b.Precision &&
a.Scale == b.Scale &&
a.DefaultValueExpression == b.DefaultValueExpression &&
a.Collation == b.Collation &&
Equal(a.Schema, b.Schema)
}
func contain(s bigquery.Schema, p *bigquery.FieldSchema) bool {
for _, q := range s {
if equalFieldSchema(q, p) {
return true
}
}
return false
}