הצגת רשימה של מאגרי הנתונים של הארגון (גרסה 1)

הצגת רשימה של כל מאגרי הנתונים של ארגון במיקום מסוים.

דוגמת קוד

Go

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

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

import (
	"context"
	"fmt"
	"io"

	analyticshub "cloud.google.com/go/bigquery/analyticshub/apiv1"
	analyticshubpb "cloud.google.com/go/bigquery/analyticshub/apiv1/analyticshubpb"
	"google.golang.org/api/iterator"
)

// listOrgDataExchanges lists organization data exchanges in a specified location.
func listOrgDataExchanges(ctx context.Context, w io.Writer, organizationID string, locationID string) error {
	organization := fmt.Sprintf("organizations/%s/locations/%s", organizationID, locationID)

	client, err := analyticshub.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("analyticshub.NewClient: %w", err)
	}
	defer client.Close()

	req := &analyticshubpb.ListOrgDataExchangesRequest{
		Organization: organization,
	}

	it := client.ListOrgDataExchanges(ctx, req)
	for {
		resp, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("it.Next: %w", err)
		}
		fmt.Fprintf(w, "Data exchange: %s\n", resp.GetName())
	}

	return nil
}

Java

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

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

import com.google.cloud.bigquery.analyticshub.v1.AnalyticsHubServiceClient;
import com.google.cloud.bigquery.analyticshub.v1.DataExchange;
import com.google.cloud.bigquery.analyticshub.v1.ListOrgDataExchangesRequest;
import java.io.IOException;

public class ListOrgDataExchanges {

  public static void main(String[] args) throws IOException {
    String organizationId = "example-organization-id";
    String locationId = "example-location-id";
    listOrgDataExchanges(organizationId, locationId);
  }

  public static void listOrgDataExchanges(String organizationId, String locationId)
      throws IOException {
    // Initialize client within try-with-resources to ensure automatic cleanup
    try (AnalyticsHubServiceClient client = AnalyticsHubServiceClient.create()) {
      String organization =
          String.format("organizations/%s/locations/%s", organizationId, locationId);

      ListOrgDataExchangesRequest request =
          ListOrgDataExchangesRequest.newBuilder()
              .setOrganization(organization)
              .build();

      for (DataExchange dataExchange : client.listOrgDataExchanges(request).iterateAll()) {
        System.out.println("Data exchange: " + dataExchange.getName());
        System.out.println("Display name: " + dataExchange.getDisplayName());
      }
    }
  }
}

Node.js

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

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

'use strict';

const {AnalyticsHubServiceClient} = require('@google-cloud/bigquery-analyticshub');
const {status} = require('@grpc/grpc-js');

const client = new AnalyticsHubServiceClient();

/**
 * Lists data exchanges from an organization in BigQuery Analytics Hub.
 */
async function listOrgDataExchanges() {
  try {
    const organization = 'example-organization';
    const location = 'example-location';
    const orgLocation = `organizations/${organization}/locations/${location}`;

    const request = {
      organization: orgLocation,
    };

    const [dataExchanges] = await client.listOrgDataExchanges(request);

    console.log(`Retrieved ${dataExchanges.length} data exchange(s)`);
    for (const dataExchange of dataExchanges) {
      console.log(`Data exchange: ${dataExchange.name}`);
    }
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error('Resource not found:', err.message);
    } else if (err.code === status.PERMISSION_DENIED) {
      console.error('Permission denied:', err.message);
    } else if (err.code !== undefined) {
      console.error(`API error (status ${err.code}):`, err.message);
    } else {
      throw err;
    }
  }
}

module.exports = { listOrgDataExchanges };

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

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