AWS Glue 未在 CSV 中检测到 header

AWS Glue not detecting header in CSV

你好,我在 S3 中有一堆 CSV,这是一个通过 AWS Glue 设置的爬虫,这个爬虫构建了大约 10 个表,因为它扫描了 10 个文件夹,其中只有 1 个未检测到 headers . csv 的结构与所有其他结构相同。请指教?

您可以自己创建 table,而不是抓取指向 s3 路径的点,您可以基于现有的 table 进行抓取。这是爬虫未检测架构(尤其是列标题)时使用的概念。

同时检查 skip.header.line.count=1 是否被自动添加,如果没有,您可以手动添加,并将架构更新为您需要的正确架构。在随后的爬虫运行中,您可以更改属性,以便它忽略架构更新并仅对 table.

执行分区更新

AWs 胶水爬虫根据多个规则解释 header。如果您文件中的第一行不满足这些规则,则爬虫不会将第一行检测为 header,您将需要手动执行此操作。这是一个非常常见的问题,我们在我们的代码中集成了一个修复程序来解决这个问题,这是我们数据管道的一部分。

aws doco 摘录

To be classified as CSV, the table schema must have at least two columns and two rows of data. The CSV classifier uses a number of heuristics to determine whether a header is present in a given file. If the classifier can't determine a header from the first row of data, column headers are displayed as col1, col2, col3, and so on. The built-in CSV classifier determines whether to infer a header by evaluating the following characteristics of the file:

Every column in a potential header parses as a STRING data type.

Except for the last column, every column in a potential header has content that is fewer than 150 characters. To allow for a trailing delimiter, the last column can be empty throughout the file.

Every column in a potential header must meet the AWS Glue regex requirements for a column name.

The header row must be sufficiently different from the data rows. To determine this, one or more of the rows must parse as other than STRING type. If all columns are of type STRING, then the first row of data is not sufficiently different from subsequent rows to be used as the header.

您可以在您的爬虫上使用自定义分类器来解决这个问题:https://docs.aws.amazon.com/glue/latest/dg/custom-classifier.html

通常在分类选项Column Headings部分选择Has headings即可,如果没有,可能需要输入为此,在文本框中的标题列表中。

因为你的列都归类为字符串,所以这些列很可能违反了规则。在我的例子中,我有一个超过 150 个字符的列名,所以 Glue 读取第一行作为数据,而不是 header,然后假设所有列都是字符串。