הגדרת נקודת הקצה של השירות

בדוגמה הזו מוסבר איך להגדיר נקודת קצה חלופית כשמשתמשים בספריות הלקוח של BigQuery.

דוגמת קוד

Go

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Goהוראות ההגדרה שבמדריך למתחילים של BigQuery באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של BigQuery Go API.

כדי לבצע אימות ב-BigQuery, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

import (
	"context"
	"fmt"

	"cloud.google.com/go/bigquery"
	"google.golang.org/api/option"
)

// setClientEndpoint creates a bigquery.Client pointing
// to a specific endpoint.
func setClientEndpoint(endpoint, projectID string) (*bigquery.Client, error) {
	// projectID := "my-project-id"
	// endpoint := "https://bigquery.googleapis.com/bigquery/v2/
	ctx := context.Background()
	client, err := bigquery.NewClient(ctx, projectID, option.WithEndpoint(endpoint))
	if err != nil {
		return nil, fmt.Errorf("bigquery.NewClient: %w", err)
	}
	defer client.Close()

	return client, nil
}

Node.js

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Node.jsהוראות ההגדרה שבמדריך למתחילים של BigQuery באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של BigQuery Node.js API.

כדי לבצע אימות ב-BigQuery, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

// Import the Google Cloud client library
const {BigQuery} = require('@google-cloud/bigquery');

function setClientEndpoint() {
  // Create a bigquery client pointing to a specific endpoint

  /**
   * TODO(developer): Uncomment the following line of code and fill in your region before running the sample.
   */
  // const region = 'my-region';

  const bigquery = new BigQuery({
    apiEndpoint: `${region}-bigquery.googleapis.com`,
  });

  console.log('API Endpoint:');
  console.log(bigquery.apiEndpoint);
}

המאמרים הבאים

כדי לחפש ולסנן דוגמאות קוד למוצרים אחרים של Google Cloud , אפשר להיעזר בדפדפן לדוגמאות שלGoogle Cloud .