1 // Copyright 2024 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT. 16 17 package storage_test 18 19 import ( 20 "context" 21 "io" 22 23 storage "cloud.google.com/go/bigquery/storage/apiv1" 24 storagepb "cloud.google.com/go/bigquery/storage/apiv1/storagepb" 25 ) 26 27 func ExampleNewBigQueryWriteClient() { 28 ctx := context.Background() 29 // This snippet has been automatically generated and should be regarded as a code template only. 30 // It will require modifications to work: 31 // - It may require correct/in-range values for request initialization. 32 // - It may require specifying regional endpoints when creating the service client as shown in: 33 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 34 c, err := storage.NewBigQueryWriteClient(ctx) 35 if err != nil { 36 // TODO: Handle error. 37 } 38 defer c.Close() 39 40 // TODO: Use client. 41 _ = c 42 } 43 44 func ExampleBigQueryWriteClient_AppendRows() { 45 ctx := context.Background() 46 // This snippet has been automatically generated and should be regarded as a code template only. 47 // It will require modifications to work: 48 // - It may require correct/in-range values for request initialization. 49 // - It may require specifying regional endpoints when creating the service client as shown in: 50 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 51 c, err := storage.NewBigQueryWriteClient(ctx) 52 if err != nil { 53 // TODO: Handle error. 54 } 55 defer c.Close() 56 stream, err := c.AppendRows(ctx) 57 if err != nil { 58 // TODO: Handle error. 59 } 60 go func() { 61 reqs := []*storagepb.AppendRowsRequest{ 62 // TODO: Create requests. 63 } 64 for _, req := range reqs { 65 if err := stream.Send(req); err != nil { 66 // TODO: Handle error. 67 } 68 } 69 stream.CloseSend() 70 }() 71 for { 72 resp, err := stream.Recv() 73 if err == io.EOF { 74 break 75 } 76 if err != nil { 77 // TODO: handle error. 78 } 79 // TODO: Use resp. 80 _ = resp 81 } 82 } 83 84 func ExampleBigQueryWriteClient_BatchCommitWriteStreams() { 85 ctx := context.Background() 86 // This snippet has been automatically generated and should be regarded as a code template only. 87 // It will require modifications to work: 88 // - It may require correct/in-range values for request initialization. 89 // - It may require specifying regional endpoints when creating the service client as shown in: 90 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 91 c, err := storage.NewBigQueryWriteClient(ctx) 92 if err != nil { 93 // TODO: Handle error. 94 } 95 defer c.Close() 96 97 req := &storagepb.BatchCommitWriteStreamsRequest{ 98 // TODO: Fill request struct fields. 99 // See https://pkg.go.dev/cloud.google.com/go/bigquery/storage/apiv1/storagepb#BatchCommitWriteStreamsRequest. 100 } 101 resp, err := c.BatchCommitWriteStreams(ctx, req) 102 if err != nil { 103 // TODO: Handle error. 104 } 105 // TODO: Use resp. 106 _ = resp 107 } 108 109 func ExampleBigQueryWriteClient_CreateWriteStream() { 110 ctx := context.Background() 111 // This snippet has been automatically generated and should be regarded as a code template only. 112 // It will require modifications to work: 113 // - It may require correct/in-range values for request initialization. 114 // - It may require specifying regional endpoints when creating the service client as shown in: 115 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 116 c, err := storage.NewBigQueryWriteClient(ctx) 117 if err != nil { 118 // TODO: Handle error. 119 } 120 defer c.Close() 121 122 req := &storagepb.CreateWriteStreamRequest{ 123 // TODO: Fill request struct fields. 124 // See https://pkg.go.dev/cloud.google.com/go/bigquery/storage/apiv1/storagepb#CreateWriteStreamRequest. 125 } 126 resp, err := c.CreateWriteStream(ctx, req) 127 if err != nil { 128 // TODO: Handle error. 129 } 130 // TODO: Use resp. 131 _ = resp 132 } 133 134 func ExampleBigQueryWriteClient_FinalizeWriteStream() { 135 ctx := context.Background() 136 // This snippet has been automatically generated and should be regarded as a code template only. 137 // It will require modifications to work: 138 // - It may require correct/in-range values for request initialization. 139 // - It may require specifying regional endpoints when creating the service client as shown in: 140 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 141 c, err := storage.NewBigQueryWriteClient(ctx) 142 if err != nil { 143 // TODO: Handle error. 144 } 145 defer c.Close() 146 147 req := &storagepb.FinalizeWriteStreamRequest{ 148 // TODO: Fill request struct fields. 149 // See https://pkg.go.dev/cloud.google.com/go/bigquery/storage/apiv1/storagepb#FinalizeWriteStreamRequest. 150 } 151 resp, err := c.FinalizeWriteStream(ctx, req) 152 if err != nil { 153 // TODO: Handle error. 154 } 155 // TODO: Use resp. 156 _ = resp 157 } 158 159 func ExampleBigQueryWriteClient_FlushRows() { 160 ctx := context.Background() 161 // This snippet has been automatically generated and should be regarded as a code template only. 162 // It will require modifications to work: 163 // - It may require correct/in-range values for request initialization. 164 // - It may require specifying regional endpoints when creating the service client as shown in: 165 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 166 c, err := storage.NewBigQueryWriteClient(ctx) 167 if err != nil { 168 // TODO: Handle error. 169 } 170 defer c.Close() 171 172 req := &storagepb.FlushRowsRequest{ 173 // TODO: Fill request struct fields. 174 // See https://pkg.go.dev/cloud.google.com/go/bigquery/storage/apiv1/storagepb#FlushRowsRequest. 175 } 176 resp, err := c.FlushRows(ctx, req) 177 if err != nil { 178 // TODO: Handle error. 179 } 180 // TODO: Use resp. 181 _ = resp 182 } 183 184 func ExampleBigQueryWriteClient_GetWriteStream() { 185 ctx := context.Background() 186 // This snippet has been automatically generated and should be regarded as a code template only. 187 // It will require modifications to work: 188 // - It may require correct/in-range values for request initialization. 189 // - It may require specifying regional endpoints when creating the service client as shown in: 190 // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options 191 c, err := storage.NewBigQueryWriteClient(ctx) 192 if err != nil { 193 // TODO: Handle error. 194 } 195 defer c.Close() 196 197 req := &storagepb.GetWriteStreamRequest{ 198 // TODO: Fill request struct fields. 199 // See https://pkg.go.dev/cloud.google.com/go/bigquery/storage/apiv1/storagepb#GetWriteStreamRequest. 200 } 201 resp, err := c.GetWriteStream(ctx, req) 202 if err != nil { 203 // TODO: Handle error. 204 } 205 // TODO: Use resp. 206 _ = resp 207 } 208