查詢在 AWS Glue Data Catalog 中註冊的目錄 - Amazon Redshift

Amazon Redshift 自 2025 年 11 月 1 日起不再支援建立新的 Python UDF。如果您想要使用 Python UDF,請在該日期之前建立 UDF。現有 Python UDF 將繼續正常運作。如需詳細資訊,請參閱部落格文章

查詢在 AWS Glue Data Catalog 中註冊的目錄

您在 AWS Glue Data Catalog 中註冊 Amazon Redshift 資料倉儲並在 AWS Lake Formation 中設定產生目錄的許可後,目錄就會自動掛載到所有可存取相同帳戶和 AWS 區域 中來源資料倉儲的 Amazon Redshift 執行個體。然後您可以如同在本機叢集或工作群組上一樣查詢該目錄。您也可以使用任何支援 Apache Iceberg REST Open API 的 SQL 引擎,來查詢 AWS Glue Data Catalog 中註冊的目錄。如需使用 Apache Iceberg REST API 在 AWS Glue Data Catalog 中查詢目錄的詳細資訊,請參閱《AWS Glue 開發人員指南》中的存取 Data Catalog。如需 Apache Iceberg REST API 的相關資訊,請參閱 Apache Iceberg REST Open API 規格

若要查詢目錄,您必須先使用 AWS Lake Formation 設定目錄的許可。如需在 AWS Lake Formation 中設定目錄許可的詳細資訊,請參閱《AWS Lake Formation 開發人員指南》中的設定 Amazon Redshift 資料共用的許可。您也需要已連接 AmazonRedshiftServiceLinkedRolePolicy 受管政策的 IAM 角色。如需服務連結角色的相關資訊,請參閱《Amazon Redshift 管理指南》中的使用 Amazon Redshift 的服務連結角色

請注意,對目錄進行的查詢必須遵循下列三部分語法來存取資料表:

database@namespace.schema.table

如需查詢 Amazon Redshift 資料倉儲的一般資訊,請參閱《Amazon Redshift 管理指南》中的查詢資料庫

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 Data API 查詢受管工作群組,方法與查詢內部 Amazon Redshift 佈建叢集或無伺服器工作群組相同,就是將目錄的 Amazon Resource Name (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