in pkg/converter/convert.go [111:200]
func convertField(
curPkg *ProtoPackage,
desc *descriptor.FieldDescriptorProto,
msgOpts *protos.BigQueryMessageOptions,
parentMessages map[*descriptor.DescriptorProto]bool,
comments Comments,
path string) (*Field, error) {
field := &Field{
Name: desc.GetName(),
}
if msgOpts.GetUseJsonNames() && desc.GetJsonName() != "" {
field.Name = desc.GetJsonName()
}
var ok bool
field.Mode, ok = modeFromFieldLabel[desc.GetLabel()]
if !ok {
return nil, fmt.Errorf("unrecognized field label: %s", desc.GetLabel().String())
}
field.Type, ok = typeFromFieldType[desc.GetType()]
if !ok {
return nil, fmt.Errorf("unrecognized field type: %s", desc.GetType().String())
}
if comment := comments.Get(path); comment != "" {
field.Description = comment
}
opts := desc.GetOptions()
if opts != nil && proto.HasExtension(opts, protos.E_Bigquery) {
opt := proto.GetExtension(opts, protos.E_Bigquery).(*protos.BigQueryFieldOptions)
if opt.Ignore {
// skip the field below
return nil, nil
}
if opt.Require {
field.Mode = "REQUIRED"
}
if len(opt.TypeOverride) > 0 {
field.Type = opt.TypeOverride
}
if len(opt.Name) > 0 {
field.Name = opt.Name
}
if len(opt.Description) > 0 {
field.Description = opt.Description
}
if len(opt.PolicyTags) > 0 {
field.PolicyTags = &PolicyTags{
Names: []string{opt.PolicyTags},
}
}
if len(opt.DefaultValueExpression) > 0 {
field.DefaultValueExpression = opt.DefaultValueExpression
}
}
if len(field.Description) > 1024 {
field.Description = field.Description[:1021] + "..."
}
if field.Type != "RECORD" {
return field, nil
}
if t, ok := typeFromWKT[desc.GetTypeName()]; ok {
field.Type = t
return field, nil
}
fields, err := convertFieldsForType(curPkg, desc.GetTypeName(), parentMessages)
if err != nil {
return nil, err
}
if len(fields) == 0 { // discard RECORDs that would have zero fields
return nil, nil
}
field.Fields = fields
return field, nil
}