Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to set a default value expression #48

Merged
merged 4 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading