

 从补丁 198 开始，Amazon Redshift 将不再支持创建新的 Python UDF。现有的 Python UDF 将继续正常运行至 2026 年 6 月 30 日。有关更多信息，请参阅[博客文章](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)。

# 查询在 AWS Glue Data Catalog 中注册的目录
<a name="iceberg-integration-querying"></a>

在将 Amazon Redshift 数据仓库注册到 AWS Glue Data Catalog 并在 AWS Lake Formation 中为生成的目录设置权限后，该目录会自动挂载到所有 Amazon Redshift 实例中，而这些实例可以访问同一账户和 AWS 区域中的源数据仓库。然后，您可以像查询本地集群或工作组一样查询该目录。还可以使用任何支持 Apache Iceberg REST Open API 的 SQL 引擎查询注册到 AWS Glue Data Catalog 的目录。有关使用 Apache Iceberg REST API 查询 AWS Glue Data Catalog 中的目录的更多信息，请参阅《AWS Glue 开发人员指南》**中的[访问 Data Catalog](https://docs.aws.amazon.com/glue/latest/dg/access_catalog.html)。有关 Apache Iceberg REST API 的信息，请参阅 [Apache Iceberg REST Open API specification](https://github.com/apache/iceberg/blob/main/open-api/rest-catalog-open-api.yaml)。

要查询目录，必须先使用 AWS Lake Formation 设置目录的权限。有关在 AWS Lake Formation 中设置目录权限的更多信息，请参阅《AWS Lake Formation 开发人员指南》**中的[设置 Amazon Redshift 数据共享权限](https://docs.aws.amazon.com/lake-formation/latest/dg/setup-ds-perms.html)。您还需要一个附加了 `AmazonRedshiftServiceLinkedRolePolicy` 托管式策略的 IAM 角色。有关服务相关角色的信息，请参阅《Amazon Redshift 管理指南》**中的[对 Amazon Redshift 使用服务相关角色](https://docs.aws.amazon.com/redshift/latest/mgmt/using-service-linked-roles.html)。

 请注意，对目录的查询必须遵循以下由三部分组成的语法才能访问表：

```
database@namespace.schema.table
```

有关查询 Amazon Redshift 数据仓库的一般信息，请参阅《Amazon Redshift 管理指南》**中的[查询数据库](https://docs.aws.amazon.com//redshift/latest/mgmt/query-databases.html)。

------
#### [ Querying using the query editor v2 ]

为账户设置访问托管式工作组的权限后，该托管式工作组将出现在无服务器数据库的外部数据库部分下的树视图面板中。使用由三部分组成的语法格式 `database@namespace/cluster.schema.table`，您可以像查询内部 Amazon Redshift 预置集群或无服务器工作组一样查询托管式工作组。请查看以下示例语句：

```
SELECT price FROM sales_db@mynamespace.sales_schema.inventory_table
```

------
#### [ Querying using the Data API ]

可以使用 Amazon Redshift 数据 API 查询托管式工作组，查询方式与查询内部 Amazon Redshift 预置集群或无服务器工作组相同，同时将目录的 Amazon 资源名称（ARN）传递到相关 `database` 属性中。考虑以下在目录中创建表的示例。

```
aws redshift-data execute-statement —sql 'CREATE TABLE IF NOT EXISTS "dev@test-rms-catalog".public.t1 (c1 INT, c2 VARCHAR(10));' —database arn:aws:glue:us-east-1:550022730026:catalog/test-rms-catalog
```

------