Lakehouse 客户端库

本页面介绍了如何开始使用 Lakehouse API 的 Cloud 客户端库。通过客户端库,您可以更轻松地使用支持的语言访问Google Cloud API。虽然您可以通过向服务器发出原始请求来直接使用Google Cloud API,但客户端库可实现简化,从而显著减少您需要编写的代码量。

请参阅客户端库说明,详细了解 Cloud 客户端库和旧版 Google API 客户端库。

安装客户端库

Go

go get cloud.google.com/go/biglake/apiv1

如需了解详情,请参阅设置 Go 开发环境。

Java

如果您使用的是 Maven,请将以下代码添加到您的 pom.xml 文件中:

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-biglake</artifactId>
  <version>VERSION</version>
</dependency>

如果您使用的是 Gradle,请将以下代码添加到您的依赖项中:

implementation 'com.google.cloud:google-cloud-biglake:VERSION'

如需了解详情,请参阅设置 Java 开发环境。

Python

pip install --upgrade google-cloud-biglake

如需了解详情,请参阅设置 Python 开发环境。

Rust

cargo add google-cloud-biglake-v1

如需了解详情,请参阅 Rust 使用入门。

设置身份验证

为了对 Google Cloud API 的调用进行身份验证,客户端库支持应用默认凭证 (ADC);这些库会在一组指定的位置查找凭证,并使用这些凭证对发送到 API 的请求进行身份验证。借助 ADC,您可以在各种环境(例如本地开发或生产环境)中为您的应用提供凭据,而无需修改应用代码。

对于生产环境,设置 ADC 的方式取决于服务和上下文。如需了解详情,请参阅设置应用默认凭证。

对于本地开发环境,您可以使用与您的 Google 账号关联的凭据设置 ADC:

  1. 安装 Google Cloud CLI,然后使用联合身份登录 gcloud CLI。 登录后,运行以下命令来初始化 Google Cloud CLI:

    gcloud init
  2. 为您的用户账号创建本地身份验证凭证:

    gcloud auth application-default login

    如果返回身份验证错误,请确认您已使用联合身份登录 gcloud CLI。

    登录屏幕随即出现。在您登录后,您的凭据会存储在 ADC 使用的本地凭据文件中。

使用客户端库

以下示例展示了如何使用客户端库。

Go


func ExampleIcebergCatalogClient_ListIcebergCatalogs() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := biglake.NewIcebergCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &biglakepb.ListIcebergCatalogsRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/biglake/apiv1/biglakepb#ListIcebergCatalogsRequest.
	}
	it := c.ListIcebergCatalogs(ctx, req)
	for {
		resp, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			// TODO: Handle error.
		}
		// TODO: Use resp.
		_ = resp

		// If you need to access the underlying RPC response,
		// you can do so by casting the `Response` as below.
		// Otherwise, remove this line. Only populated after
		// first call to Next(). Not safe for concurrent access.
		_ = it.Response.(*biglakepb.ListIcebergCatalogsResponse)
	}
}

Java

import com.google.cloud.biglake.v1.IcebergCatalog;
import com.google.cloud.biglake.v1.IcebergCatalogServiceClient;
import com.google.cloud.biglake.v1.ListIcebergCatalogsRequest;
import com.google.cloud.biglake.v1.ProjectName;

public class SyncListIcebergCatalogs {

  public static void main(String[] args) throws Exception {
    syncListIcebergCatalogs();
  }

  public static void syncListIcebergCatalogs() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (IcebergCatalogServiceClient icebergCatalogServiceClient =
        IcebergCatalogServiceClient.create()) {
      ListIcebergCatalogsRequest request =
          ListIcebergCatalogsRequest.newBuilder()
              .setParent(ProjectName.of("[PROJECT]").toString())
              .setPageSize(883849137)
              .setPageToken("pageToken873572522")
              .setFilter("filter-1274492040")
              .build();
      for (IcebergCatalog element :
          icebergCatalogServiceClient.listIcebergCatalogs(request).iterateAll()) {
        // doThingsWith(element);
      }
    }
  }
}

Python

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import biglake_v1


def sample_list_iceberg_catalogs():
    # Create a client
    client = biglake_v1.IcebergCatalogServiceClient()

    # Initialize request argument(s)
    request = biglake_v1.ListIcebergCatalogsRequest(
        parent="parent_value",
    )

    # Make the request
    page_result = client.list_iceberg_catalogs(request=request)

    # Handle the response
    for response in page_result:
        print(response)

其他资源

Go

以下列表包含与 Go 版客户端库相关的更多资源的链接:

Java

以下列表包含与 Java 版客户端库相关的更多资源的链接:

Python

以下列表包含与 Python 版客户端库相关的更多资源的链接:

Rust

以下列表包含与 Rust 版客户端库相关的更多资源的链接: