...

Source file src/cloud.google.com/go/bigquery/storage/apiv1beta2/big_query_write_client_example_test.go

Documentation: cloud.google.com/go/bigquery/storage/apiv1beta2

     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/apiv1beta2"
    24  	storagepb "cloud.google.com/go/bigquery/storage/apiv1beta2/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 ExampleNewBigQueryWriteRESTClient() {
    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.NewBigQueryWriteRESTClient(ctx)
    52  	if err != nil {
    53  		// TODO: Handle error.
    54  	}
    55  	defer c.Close()
    56  
    57  	// TODO: Use client.
    58  	_ = c
    59  }
    60  
    61  func ExampleBigQueryWriteClient_AppendRows() {
    62  	ctx := context.Background()
    63  	// This snippet has been automatically generated and should be regarded as a code template only.
    64  	// It will require modifications to work:
    65  	// - It may require correct/in-range values for request initialization.
    66  	// - It may require specifying regional endpoints when creating the service client as shown in:
    67  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
    68  	c, err := storage.NewBigQueryWriteClient(ctx)
    69  	if err != nil {
    70  		// TODO: Handle error.
    71  	}
    72  	defer c.Close()
    73  	stream, err := c.AppendRows(ctx)
    74  	if err != nil {
    75  		// TODO: Handle error.
    76  	}
    77  	go func() {
    78  		reqs := []*storagepb.AppendRowsRequest{
    79  			// TODO: Create requests.
    80  		}
    81  		for _, req := range reqs {
    82  			if err := stream.Send(req); err != nil {
    83  				// TODO: Handle error.
    84  			}
    85  		}
    86  		stream.CloseSend()
    87  	}()
    88  	for {
    89  		resp, err := stream.Recv()
    90  		if err == io.EOF {
    91  			break
    92  		}
    93  		if err != nil {
    94  			// TODO: handle error.
    95  		}
    96  		// TODO: Use resp.
    97  		_ = resp
    98  	}
    99  }
   100  
   101  func ExampleBigQueryWriteClient_BatchCommitWriteStreams() {
   102  	ctx := context.Background()
   103  	// This snippet has been automatically generated and should be regarded as a code template only.
   104  	// It will require modifications to work:
   105  	// - It may require correct/in-range values for request initialization.
   106  	// - It may require specifying regional endpoints when creating the service client as shown in:
   107  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   108  	c, err := storage.NewBigQueryWriteClient(ctx)
   109  	if err != nil {
   110  		// TODO: Handle error.
   111  	}
   112  	defer c.Close()
   113  
   114  	req := &storagepb.BatchCommitWriteStreamsRequest{
   115  		// TODO: Fill request struct fields.
   116  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/storage/apiv1beta2/storagepb#BatchCommitWriteStreamsRequest.
   117  	}
   118  	resp, err := c.BatchCommitWriteStreams(ctx, req)
   119  	if err != nil {
   120  		// TODO: Handle error.
   121  	}
   122  	// TODO: Use resp.
   123  	_ = resp
   124  }
   125  
   126  func ExampleBigQueryWriteClient_CreateWriteStream() {
   127  	ctx := context.Background()
   128  	// This snippet has been automatically generated and should be regarded as a code template only.
   129  	// It will require modifications to work:
   130  	// - It may require correct/in-range values for request initialization.
   131  	// - It may require specifying regional endpoints when creating the service client as shown in:
   132  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   133  	c, err := storage.NewBigQueryWriteClient(ctx)
   134  	if err != nil {
   135  		// TODO: Handle error.
   136  	}
   137  	defer c.Close()
   138  
   139  	req := &storagepb.CreateWriteStreamRequest{
   140  		// TODO: Fill request struct fields.
   141  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/storage/apiv1beta2/storagepb#CreateWriteStreamRequest.
   142  	}
   143  	resp, err := c.CreateWriteStream(ctx, req)
   144  	if err != nil {
   145  		// TODO: Handle error.
   146  	}
   147  	// TODO: Use resp.
   148  	_ = resp
   149  }
   150  
   151  func ExampleBigQueryWriteClient_FinalizeWriteStream() {
   152  	ctx := context.Background()
   153  	// This snippet has been automatically generated and should be regarded as a code template only.
   154  	// It will require modifications to work:
   155  	// - It may require correct/in-range values for request initialization.
   156  	// - It may require specifying regional endpoints when creating the service client as shown in:
   157  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   158  	c, err := storage.NewBigQueryWriteClient(ctx)
   159  	if err != nil {
   160  		// TODO: Handle error.
   161  	}
   162  	defer c.Close()
   163  
   164  	req := &storagepb.FinalizeWriteStreamRequest{
   165  		// TODO: Fill request struct fields.
   166  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/storage/apiv1beta2/storagepb#FinalizeWriteStreamRequest.
   167  	}
   168  	resp, err := c.FinalizeWriteStream(ctx, req)
   169  	if err != nil {
   170  		// TODO: Handle error.
   171  	}
   172  	// TODO: Use resp.
   173  	_ = resp
   174  }
   175  
   176  func ExampleBigQueryWriteClient_FlushRows() {
   177  	ctx := context.Background()
   178  	// This snippet has been automatically generated and should be regarded as a code template only.
   179  	// It will require modifications to work:
   180  	// - It may require correct/in-range values for request initialization.
   181  	// - It may require specifying regional endpoints when creating the service client as shown in:
   182  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   183  	c, err := storage.NewBigQueryWriteClient(ctx)
   184  	if err != nil {
   185  		// TODO: Handle error.
   186  	}
   187  	defer c.Close()
   188  
   189  	req := &storagepb.FlushRowsRequest{
   190  		// TODO: Fill request struct fields.
   191  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/storage/apiv1beta2/storagepb#FlushRowsRequest.
   192  	}
   193  	resp, err := c.FlushRows(ctx, req)
   194  	if err != nil {
   195  		// TODO: Handle error.
   196  	}
   197  	// TODO: Use resp.
   198  	_ = resp
   199  }
   200  
   201  func ExampleBigQueryWriteClient_GetWriteStream() {
   202  	ctx := context.Background()
   203  	// This snippet has been automatically generated and should be regarded as a code template only.
   204  	// It will require modifications to work:
   205  	// - It may require correct/in-range values for request initialization.
   206  	// - It may require specifying regional endpoints when creating the service client as shown in:
   207  	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
   208  	c, err := storage.NewBigQueryWriteClient(ctx)
   209  	if err != nil {
   210  		// TODO: Handle error.
   211  	}
   212  	defer c.Close()
   213  
   214  	req := &storagepb.GetWriteStreamRequest{
   215  		// TODO: Fill request struct fields.
   216  		// See https://pkg.go.dev/cloud.google.com/go/bigquery/storage/apiv1beta2/storagepb#GetWriteStreamRequest.
   217  	}
   218  	resp, err := c.GetWriteStream(ctx, req)
   219  	if err != nil {
   220  		// TODO: Handle error.
   221  	}
   222  	// TODO: Use resp.
   223  	_ = resp
   224  }
   225  

View as plain text