

# 指定允许爬网程序创建的最大表数
<a name="crawler-maximum-number-of-tables"></a>

您可以选择指定允许爬网程序创建的最大表数，方法是通过 AWS Glue 控制台或 AWS CLI 指定 `TableThreshold`。如果爬网程序在其爬取过程中检测到的表数大于此输入值，则爬取失败且不会向 Data Catalog 写入任何数据。

当爬网程序检测和创建的表数比预期表数要大得多时，此参数非常有用。这可能有多种原因，例如：
+ 使用 AWS Glue 作业填充 Amazon S3 位置时，您最终可能会得到与文件夹相同级别的空文件。在这种情况下，当您在此 Amazon S3 位置运行爬网程序时，由于文件和文件夹位于同一级别，爬网程序会创建多个表。
+ 如果没有配置 `"TableGroupingPolicy": "CombineCompatibleSchemas"`，您最终得到的表数可能比预期数量多。

您可以将 `TableThreshold` 指定为一个大于 0 的整数值。该值根据每个爬网程序进行配置。也就是说，每次爬取都会考虑该值。例如：爬网程序的 `TableThreshold` 值设置为 5。每次爬取时，AWS Glue 会将检测到的表数与此表阈值（5）进行比较。如果检测到的表数小于 5，AWS Glue 将表写入 Data Catalog；否则，爬取失败，将不会写入 Data Catalog。

------
#### [ AWS 管理控制台 ]

**使用 AWS 管理控制台 设置 `TableThreshold`：**

1. 登录 AWS 管理控制台，然后打开 AWS Glue 控制台，网址为：[https://console.aws.amazon.com/glue/](https://console.aws.amazon.com/glue/)。

1. 配置爬网程序时，在**输出和计划**中，将**最大表阈值**设置为爬网程序允许生成的表数。  
![\[AWS 控制台的“Output and scheduling”（输出和计划）部分显示最大表阈值参数。\]](http://docs.aws.amazon.com/zh_cn/glue/latest/dg/images/crawler-max-tables.png)

------
#### [ 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.
```