gpt4 book ai didi

amazon-web-services - 如何确保我编写的 AWS Glue 爬网程序使用的是 OpenCSV SerDe 而不是 LazySimpleSerDe?

转载 作者:行者123 更新时间:2023-12-03 17:31:08 25 4
gpt4 key购买 nike

上下文:我略读了 this previous question但对答案不满意有两个原因:

  • 我没有用 Python 写任何东西;事实上,我根本没有为此编写任何自定义脚本,因为我依赖于 crawler而不是胶水脚本。
  • 答案没有我要求的那么完整,因为它只是指向某个库的链接。


  • 我希望利用 AWS Glue 将一些 CSV 接受到架构中,并使用 Athena 将该 CSV 表转换为多个 Parquet 格式的表以用于 ETL 目的。我正在处理的数据中嵌入了引号,除了我拥有的一条记录的值是:
    "blablabla","1","Freeman,Morgan","bla bla bla"

    当遇到 "Freeman,Morgan" 时,Glue 似乎被自己绊倒了。一段数据。

    如果我使用标准的 Glue 爬虫,我会得到一个使用 LazySimpleSerDe 创建的表,它将上面列中的记录截断为:
    "Freeman,

    ……这显然是不可取的。

    如何强制爬虫用正确的 SerDe 输出文件?

    [不愉快] 限制:
  • 希望不使用 Glue 脚本完成此操作,因为要使其正常工作,我相信我必须事先有一个表,而爬网程序将代表我创建该表。

  • 如果我必须通过 Amazon Athena 来完成这一切,我会觉得这在很大程度上会违背目的,但这是一个站得住脚的解决方案。

    最佳答案

    这将变成一个非常乏味的答案,但显然 AWS 提供了 its own set of rules用于分类文件是否为 CSV。

    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.



    我相信我已经满足了所有这些要求,因为列名与 CSV 中的实际数据大相径庭,理想情况下应该不会有太大问题。

    然而,尽管我相信它会满足 AWS Glue 正则表达式(我在任何地方都找不到定义),我还是选择从逗号转向管道。数据现在按照我的预期加载。

    关于amazon-web-services - 如何确保我编写的 AWS Glue 爬网程序使用的是 OpenCSV SerDe 而不是 LazySimpleSerDe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53841027/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com