Skip to content

Commit

Permalink
Merge pull request #1 from vckamanga/enh/add-default-value
Browse files Browse the repository at this point in the history
Add default value expression
  • Loading branch information
vckamanga authored Apr 4, 2024
2 parents 100bba8 + d1b0e60 commit 1876555
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 27 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
3 changes: 2 additions & 1 deletion examples/foo/test_table.schema
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"names": [
"private"
]
}
},
"defaultValueExpression": "GENERATE_UUID()"
},
{
"name": "b",
Expand Down
13 changes: 6 additions & 7 deletions examples/test_table.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ message TestTable{

int32 a = 1 [
(gen_bq_schema.bigquery) = {
require: true
policy_tags : "private"
}
];
require: true
policy_tags : "private"
default_value_expression: "GENERATE_UUID()"
}];

string b = 2 [(gen_bq_schema.bigquery).policy_tags="public"];

message Nested {
int32 a = 1 [(gen_bq_schema.bigquery) = {
require: true
policy_tags : "private"
}
];
}];

string b = 2;
}
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
40 changes: 28 additions & 12 deletions protos/bq_field.pb.go

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

0 comments on commit 1876555

Please sign in to comment.