如何指定允许爬网程序创建的最大表数 - Amazon Glue
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

如何指定允许爬网程序创建的最大表数

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

当爬网程序检测和创建的表数比预期表数要大得多时,此参数非常有用。这可能有多种原因,例如:

  • 使用 Amazon Glue 作业填充 Amazon S3 位置时,您最终可能会得到与文件夹相同级别的空文件。在这种情况下,当您在此 Amazon S3 位置运行爬网程序时,由于文件和文件夹位于同一级别,爬网程序会创建多个表。

  • 如果没有配置 "TableGroupingPolicy": "CombineCompatibleSchemas",您最终得到的表数可能比预期数量多。

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

控制台

使用 Amazon 控制台设置 TableThreshold

Amazon 控制台的“Output and scheduling”(输出和计划)部分显示最大表阈值参数。
CLI

使用 Amazon CLI 设置 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.