指定編目程式可建立的資料表數目上限 - AWS Glue

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

指定編目程式可建立的資料表數目上限

您可以透過 AWS Glue 主控台或 AWS CLI 指定 TableThreshold,來選擇指定編目程式可建立的資料表數目上限。如果爬蟲程式在其網路爬取期間偵測到的資料表大於此輸入值,網路爬取就會失敗,且不會將任何資料寫入資料型錄。

當爬蟲程式偵測並建立的資料表比您預期的要大得多時,此參數非常有用。這可能有多種原因,例如:

  • 如果使用 AWS Glue 任務填充 Amazon S3 位置,您最終可能會得到與資料夾相同層級的空檔案。在這種情況下,當您在此 Amazon S3 位置執行爬蟲程式時,由於檔案和資料夾存在於相同層級,爬蟲程式會建立多個資料表。

  • 如果未設定 "TableGroupingPolicy": "CombineCompatibleSchemas",您最終可能會得到比預期更多的資料表。

您可以指定 TableThreshold 作為大於 0 的整數值。此值的設定是以每個爬蟲程式為基礎。也就是說,對於每個網路爬取,都會考慮此值。例如:爬蟲程式具有設定為 5 的 TableThreshold 值。在每次網路爬取中,AWS Glue 會比較偵測到的資料表數目與此資料表閾值 (5),如果偵測到的資料表數目少於 5 個,AWS Glue 會將資料表寫入資料型錄,如果沒有少於 5 個,網路爬取就會失敗,而不寫入資料型錄。

AWS 管理主控台
若要使用 AWS 管理主控台 設定 TableThreshold,請執行以下操作:
  1. 登入 AWS 管理主控台,並前往 https://console.aws.amazon.com/glue/ 開啟 AWS Glue 主控台。

  2. 設定編目程式時,在輸出和排程中,將資料表閾值上限設定為允許編目程式產生的資料表數目。

    AWS 主控台的「輸出和排程」區段顯示資料表閾值參數的上限。
AWS CLI

若要使用 AWS CLI 設定 TableThreshold,請執行以下操作:

aws glue update-crawler \ --name myCrawler \ --configuration '{"Version": 1.0, "CrawlerOutput": {"Tables": { "TableThreshold": 5 }}}'
API

若要使用 API 設定 TableThreshold,請執行以下操作:

"{"Version":1.0, "CrawlerOutput": {"Tables":{"AddOrUpdateBehavior":"MergeNewColumns", "TableThreshold":5}}}";

錯誤訊息會記錄下來,以協助您識別資料表路徑並清理資料。在爬蟲程式因為資料表計數大於提供的資料表閾值而失敗的情況下,登入帳戶的範例:

Table Threshold value = 28, Tables detected - 29

在 CloudWatch 中,我們會將偵測到的所有資料表位置記錄為 INFO 訊息。將錯誤記錄為失敗原因。

ERROR com.amazonaws.services.glue.customerLogs.CustomerLogService - CustomerLogService received CustomerFacingException with message The number of tables detected by crawler: 29 is greater than the table threshold value provided: 28. Failing crawler without writing to Data Catalog. com.amazonaws.services.glue.exceptions.CustomerFacingInternalException: The number of tables detected by crawler: 29 is greater than the table threshold value provided: 28. Failing crawler without writing to Data Catalog.