【问题标题】:How would chaning the read in AWS Glue change a column's data type?更改 AWS Glue 中的读取会如何更改列的数据类型?
【发布时间】:2021-06-10 00:45:37
【问题描述】:

我有一个稍作修改的 AWS Glue 作业,仅更改了读取,作业运行良好,但我的列上的数据类型已更改。我以前有 BigInt,现在我只有 Ints。这会导致依赖于这些文件的 EMR 作业由于架构不匹配而出错。我不确定是什么导致了这个问题,因为映射没有改变,所以如果有人有洞察力,那就是旧代码和新代码:

///OLD
val inputsourceDF = spark.read.format("json").load(inputFilePath)
val inputsource = DynamicFrame(inputsourceDF, glueContext)
///NEW
val inputsource = glueContext.getSourceWithFormat(connectionType = "s3",  options = JsonOptions(Map("paths" -> Set(inputFilePath))), format = "json", transformationContext = "inputsource").getDynamicFrame()

///WRITE which did not change
val inputsink = glueContext.getSinkWithFormat(connectionType = "s3", options = JsonOptions(s"""{"path": "$inputOutputFilePath"}"""), transformationContext = "inputdatasink", format = "parquet").writeDynamicFrame(inputdropnullfields.coalesce(inputPartitionCount))

这些是在粘合作业之后爬取文件时创建的表

CREATE EXTERNAL TABLE `input_new`(`id` int)

CREATE EXTERNAL TABLE `input_old`(`id` bigint)

我们添加了此更改,以便我们可以使用书签,我们将不胜感激。

【问题讨论】:

    标签: scala aws-glue aws-glue-spark


    【解决方案1】:

    spark DataFrame 和glue DynamicFrame 在从json 读取数据时都会推断模式,但显然,它们的做法不同:sparks 将所有数值视为bigint,而glue 试图变得聪明,并且(我猜)实时查看值的实际范围。

    有关DynamicFrame 架构推断的更多信息可以在here 找到。

    如果您最终还是要编写 parquet,并且希望架构稳定且一致,那么您最简单的解决方法就是恢复您的更改并返回 spark DataFrame。 您还可以在读取数据后使用apply_mapping 显式更改类型,但这似乎违背了首先拥有 动态 框架的目的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-09
      • 1970-01-01
      • 2022-01-23
      • 2016-02-10
      • 1970-01-01
      • 2010-11-24
      • 2020-07-27
      • 1970-01-01
      相关资源
      最近更新 更多