protoc-gen-bq-schema helps you to send your Protocol Buffer messages to BigQuery.
Перейти к файлу
Mark Scannell a6702960c1 updated 2020-12-12 09:28:25 +00:00
.circleci Commit to add CI and release management -- release current version prior to making potentially breaking changes. 2020-12-11 09:29:29 +00:00
.github/workflows updated 2020-12-12 09:28:25 +00:00
examples Updated generated example schema. 2020-12-11 21:03:14 +00:00
protos Updated 2020-11-16 15:12:47 +00:00
.gitignore discard RECORD fields that would have no fields 2018-02-03 16:02:37 -08:00
LICENSE Initial commit for opensourceing protoc-gen-bq-schema 2014-08-20 14:19:36 +09:00
Makefile Correct Make dependencies 2019-01-14 22:15:27 +09:00
README.md Updated example to include descriptions. 2020-12-11 12:59:00 +00:00
bq_field.proto Updated 2020-11-16 15:12:47 +00:00
bq_table.proto Merge branch 'master' into updates 2020-12-11 13:51:43 +00:00
comments.go Use comments as field description 2019-01-24 16:55:07 -05:00
comments_test.go Use comments as field description 2019-01-24 16:55:07 -05:00
field_option_test.go Fix test failures 2019-01-14 22:15:27 +09:00
go.mod Updated 2020-11-16 15:12:47 +00:00
go.sum Updated 2020-12-12 09:25:35 +00:00
main.go Updated 2020-12-12 09:25:35 +00:00
plugin_test.go Merge branch 'master' into updates 2020-12-11 13:51:43 +00:00

README.md

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 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.

License

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