protoc_gen_bq_schema

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

README

protoc-gen-bq-schema

protoc-gen-bq-schema is a plugin for ProtocolBuffer compiler. It converts messages written in .proto format into schema files in JSON for BigQuery. So you can reuse existing data definitions in .proto for BigQuery with this plugin.

Installation

go get github.com/GoogleCloudPlatform/protoc-gen-bq-schema

Usage

protoc --bq-schema_out=path/to/outdir [--bq-schema_opt=single-message] foo.proto

protoc and protoc-gen-bq-schema commands must be found in $PATH.

The generated JSON schema files are suffixed with .schema and their base names are named after their package names and bq_table_name options.

If you do not already have the standard google protobuf libraries in your proto_path, you'll need to specify them directly on the command line (and potentially need to copy bq_schema.proto into a proto_path directory as well), like this:

protoc --bq-schema_out=path/to/out/dir foo.proto --proto_path=. --proto_path=<path_to_google_proto_folder>/src
Example

Suppose that we have the following foo.proto.

syntax = "proto2";
package foo;
import "bq_table.proto";
import "bq_field.proto";

message Bar {
  option (gen_bq_schema.bigquery_opts).table_name = "bar_table";

  message Nested {
    repeated int32 a = 1;
  }

  // Description of field a -- this is an int32
  required int32 a = 1;

  // Nested b structure
  optional Nested b = 2;

  // Repeated c string
  repeated string c = 3;

  optional bool d = 4 [(gen_bq_schema.bigquery).ignore = true];

  // TIMESTAMP (uint64 in proto) - required in BigQuery
  optional uint64 e = 5 [
    (gen_bq_schema.bigquery) = {
      require: true
      type_override: 'TIMESTAMP'
    }
  ];
}

message Baz {
  required int32 a = 1;
}

protoc --bq-schema_out=. foo.proto will generate a file named foo/bar_table.schema. The message foo.Baz is ignored because it doesn't have option gen_bq_schema.bigquery_opts.

protoc --bq-schema_out=. --bq-schema_opt=single-message single_message.proto will generate a file named foo/single_message.schema. The message foo.Baz is also ignored because it is not the first message in the file.

License

protoc-gen-bq-schema is licensed under the Apache License version 2.0. This is not an official Google product.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

Types

type Comments added in v1.1.0

type Comments map[string]string

Comments is a map between path in FileDescriptorProto and leading/trailing comments for each field.

func ParseComments added in v1.1.0

func ParseComments(fd *descriptor.FileDescriptorProto) Comments

ParseComments reads FileDescriptorProto and parses comments into a map.

func (Comments) Get added in v1.1.0

func (c Comments) Get(path string) string

Get returns comment for path or empty string if path has no comment.

type Field

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"`
}

Field describes the schema of a field in BigQuery.

type ProtoPackage

type ProtoPackage struct {
	// contains filtered or unexported fields
}

ProtoPackage describes a package of Protobuf, which is an container of message types.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL