

# 将多个数据源和爬网程序结合使用
<a name="schema-crawlers-data-sources"></a>

当 Amazon Glue 爬网程序扫描 Amazon S3 并检测到多个目录时，它会使用启发法来确定表的根在目录结构中的位置，以及表的分区所在的目录。在某些情况下，如果在两个或更多目录中检测到的架构相似，则爬网程序可能将它们视为分区而不是单独的表。一种帮助爬网程序发现单个表的方法是将每个表的根目录添加为爬网程序的数据存储。

以下示例是 Amazon S3 中的分区：

```
s3://amzn-s3-demo-bucket/folder1/table1/partition1/file.txt
s3://amzn-s3-demo-bucket/folder1/table1/partition2/file.txt
s3://amzn-s3-demo-bucket/folder1/table1/partition3/file.txt
s3://amzn-s3-demo-bucket/folder1/table2/partition4/file.txt
s3://amzn-s3-demo-bucket/folder1/table2/partition5/file.txt
```

如果 `table1` 和 `table2` 的架构类似，并且单个数据源在 Amazon Glue 中设置为 `s3://amzn-s3-demo-bucket/folder1/`，则爬网程序可能创建一个具有两个分区列的表：一个分区列包含 `table1` 和 `table2`，另一个分区列包含 `partition1` 到 `partition5`。

要让 Amazon Glue 爬网程序创建两个单独的表，请将爬网程序设置为具有两个数据源 `s3://amzn-s3-demo-bucket/folder1/table1/` 和 `s3://amzn-s3-demo-bucket/folder1/table2`，如以下过程所示。

**向 Amazon Glue 中的现有爬网程序中添加 S3 数据存储**

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

1. 在导航窗格中，选择 **爬网程序**。

1. 选择指向爬网程序的链接，然后选择 **Edit**（编辑）。

1. 对于**步骤 2：选择数据源和分类器**，选择 **Edit**（编辑）。

1. 对于**数据来源和目录**，选择**添加数据来源**。

1. 在 **Add data source**（添加数据来源）对话框中，对于 **S3 path**（S3 路径），选择 **Browse**（浏览）。

1. 选择要使用的计划，然后选择 **Choose**（选择）。

   您添加的数据来源显示在 **Data sources**（数据来源）列表中。

1. 选择**下一步**。

1. 在 **Configure security settings**（配置安全设置）页面中，创建或选择爬网程序的 IAM 角色，然后选择 **Next**（下一步）。

1. 确保 S3 路径以斜杠结尾，然后选择 **Add an S3 data source**（添加 S3 数据来源）。

1. 在 **Set output and scheduling**（设置输出和计划）页面中，对于 **Output configuration**（输出配置），选择目标数据库。

1. 选择**下一步**。

1. 在 **Review and update**（审核和更新）页面中，查看您所做的选择。要编辑步骤，请选择 **Edit**（编辑）。

1.  选择**更新**。