func convertProtoValueToBQType()

in tools/mc2bq/pkg/schema/schema.go [154:198]


func convertProtoValueToBQType(value protoreflect.Value, fd protoreflect.FieldDescriptor, schema *bigquery.FieldSchema) (any, error) {
	bqtype := schema.Type
	kind := fd.Kind()
	switch kind {
	case protoreflect.BoolKind:
		switch bqtype {
		case bigquery.BooleanFieldType:
			return value.Bool(), nil
		}
	case protoreflect.Int32Kind,
		protoreflect.Sint32Kind,
		protoreflect.Sfixed32Kind,
		protoreflect.Int64Kind,
		protoreflect.Sint64Kind,
		protoreflect.Sfixed64Kind:
		switch bqtype {
		case bigquery.IntegerFieldType:
			return value.Int(), nil
		}
	case protoreflect.Uint32Kind,
		protoreflect.Fixed32Kind,
		protoreflect.Uint64Kind,
		protoreflect.Fixed64Kind:
		switch bqtype {
		case bigquery.IntegerFieldType:
			return value.Uint(), nil
		}
	case protoreflect.StringKind:
		switch bqtype {
		case bigquery.StringFieldType:
			return value.String(), nil
		}
	case protoreflect.FloatKind,
		protoreflect.DoubleKind:
		return value.Float(), nil
	case protoreflect.MessageKind:
		return normalizeToSchema(value.Message(), schema)
	case protoreflect.EnumKind:
		switch bqtype {
		case bigquery.StringFieldType:
			return protoimpl.X.EnumStringOf(fd.Enum(), value.Enum()), nil
		}
	}
	return nil, fieldConversionError(kind, bqtype)
}