Skip to content

Commit

Permalink
Add default value expression option
Browse files Browse the repository at this point in the history
  • Loading branch information
vckamanga committed Apr 4, 2024
1 parent 100bba8 commit 05a770d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 21 deletions.
6 changes: 6 additions & 0 deletions bq_field.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ message BigQueryFieldOptions {

// Optionally add PolicyTag for a field in BigQuery schema.
string policy_tags = 6;

// Optional default value.
//
// See https://cloud.google.com/bigquery/docs/default-values for possible
// values.
string default_value_expression = 7;
}


Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/GoogleCloudPlatform/protoc-gen-bq-schema
go 1.16

require (
github.com/golang/glog v1.2.0
github.com/golang/glog v1.2.1
google.golang.org/protobuf v1.33.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68=
github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/golang/glog v1.2.1 h1:OptwRhECazUx5ix5TTWC3EZhsZEHWcYWY4FQHTIubm4=
github.com/golang/glog v1.2.1/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
Expand Down
17 changes: 11 additions & 6 deletions pkg/converter/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ var (

// Field describes the schema of a field in BigQuery.
type Field struct {
Name string `json:"name"`
Type string `json:"type"`
Mode string `json:"mode"`
Description string `json:"description,omitempty"`
Fields []*Field `json:"fields,omitempty"`
PolicyTags *PolicyTags `json:"policyTags,omitempty"`
Name string `json:"name"`
Type string `json:"type"`
Mode string `json:"mode"`
Description string `json:"description,omitempty"`
Fields []*Field `json:"fields,omitempty"`
PolicyTags *PolicyTags `json:"policyTags,omitempty"`
DefaultValueExpression string `json:"defaultValueExpression,omitempty"`
}

// PolicyTags describes the structure of a Policy Tag
Expand Down Expand Up @@ -166,6 +167,10 @@ func convertField(
Names: []string{opt.PolicyTags},
}
}

if len(opt.DefaultValueExpression) > 0 {
field.DefaultValueExpression = opt.DefaultValueExpression
}
}

if len(field.Description) > 1024 {
Expand Down
42 changes: 29 additions & 13 deletions protos/bq_field.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion protos/bq_table.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 05a770d

Please sign in to comment.