Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Seamlessly save and load protocol buffers to and from BigQuery using Go.

License

NotificationsYou must be signed in to change notification settings

ThreeDotsLabs/protobuf-bigquery-go

 
 

Repository files navigation

PkgGoDevGoReportCardCodecov

Seamlessly save and load protocol buffers to and from BigQuery using Go.

This library provides add-ons tocloud.google.com/bigquery forfirst-class protobuf support usingprotobuf reflection.

Installing

$ go get -u go.einride.tech/protobuf-bigquery

Examples

protobq.InferSchema

BigQuery schema inference for arbitrary protobuf messages.

funcExampleInferSchema() {msg:=&library.Book{}schema:=protobq.InferSchema(msg)expected:= bigquery.Schema{{Name:"name",Type:bigquery.StringFieldType},{Name:"author",Type:bigquery.StringFieldType},{Name:"title",Type:bigquery.StringFieldType},{Name:"read",Type:bigquery.BooleanFieldType},}fmt.Println(cmp.Equal(expected,schema))// Output: true}

protobq.MessageSaver

An implementation ofbigquery.ValueSaverthat saves arbitrary protobuf messages to BigQuery.

funcExampleMessageSaver() {ctx:=context.Background()// Write protobuf messages to a BigQuery table.projectID:=flag.String("project","","BigQuery project to write to.")datasetID:=flag.String("dataset","","BigQuery dataset to write to.")tableID:=flag.String("table","","BigQuery table to write to.")create:=flag.Bool("create",false,"Flag indicating whether to create the table.")flag.Parse()// Connect to BigQuery.client,err:=bigquery.NewClient(ctx,*projectID)iferr!=nil {panic(err)// TODO: Handle error.}table:=client.Dataset(*datasetID).Table(*tableID)// Create the table by inferring the BigQuery schema from the protobuf schema.if*create {iferr:=table.Create(ctx,&bigquery.TableMetadata{Schema:protobq.InferSchema(&publicv1.FilmLocation{}),});err!=nil {panic(err)// TODO: Handle error.}}// Insert the protobuf messages.inserter:=table.Inserter()fori,filmLocation:=range []*publicv1.FilmLocation{{Title:"Dark Passage",ReleaseYear:1947,Locations:"Filbert Steps"},{Title:"D.O.A",ReleaseYear:1950,Locations:"Union Square"},{Title:"Flower Drum Song",ReleaseYear:1961,Locations:"Chinatown"},} {iferr:=inserter.Put(ctx,&protobq.MessageSaver{Message:filmLocation,InsertID:strconv.Itoa(i),// include an optional insert ID});err!=nil {panic(err)// TODO: Handle error.}}}

protobq.MessageLoader

An implementation ofbigquery.ValueLoaderthat loads arbitrary protobuf messages from BigQuery.

funcExampleMessageLoader() {ctx:=context.Background()// Read from the public "film locations" BigQuery dataset into a proto message.const (project="bigquery-public-data"dataset="san_francisco_film_locations"table="film_locations")// Connect to BigQuery.client,err:=bigquery.NewClient(ctx,project)iferr!=nil {panic(err)// TODO: Handle error.}// Load BigQuery rows into a FilmLocation message.messageLoader:=&protobq.MessageLoader{Message:&publicv1.FilmLocation{},}// Iterate rows in table.rowIterator:=client.Dataset(dataset).Table(table).Read(ctx)for {// Load next row into the FilmLocation message.iferr:=rowIterator.Next(messageLoader);err!=nil {iferrors.Is(err,iterator.Done) {break}panic(err)// TODO: Handle error.}// Print the message.fmt.Println(prototext.Format(messageLoader.Message))}}

Features

Support for Well-Known Types (google.protobuf)

ProtobufBigQuery
google.protobuf.TimestampTIMESTAMP
google.protobuf.DurationFLOAT (seconds)
google.protobuf.DoubleValueFLOAT
google.protobuf.FloatValueFLOAT
google.protobuf.Int32ValueINTEGER
google.protobuf.Int64ValueINTEGER
google.protobuf.Uint32ValueINTEGER
google.protobuf.Uint64ValueINTEGER
google.protobuf.BoolValueBOOLEAN
google.protobuf.StringValueSTRING
google.protobuf.BytesValueBYTES
google.protobuf.StructValueSTRING (JSON)

Reference ≫

Support for API Common Protos (google.type)

ProtobufBigQuery
google.type.DateDATE
google.type.DateTimeRECORD (or DATETIME)
google.type.LatLngGEOGRAPHY
google.type.TimeOfDayTIME

Reference ≫

About

Seamlessly save and load protocol buffers to and from BigQuery using Go.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go97.1%
  • Makefile2.9%

[8]ページ先頭

©2009-2025 Movatter.jp