【问题标题】:aws glue dropping mostly null fieldsaws 胶水主要丢弃空字段
【发布时间】:2019-08-29 21:48:49
【问题描述】:

我有一个数据框 df。它有几列大多为空。我正在使用下面的代码将其写入 s3 存储桶。然后我爬取 s3 存储桶以获取数据目录中的表模式。我发现当我抓取数据时,大部分为空的字段都会被删除。我检查了输出的 json,发现有些记录有该字段,而另一些则没有。有谁知道问题可能是什么?我想包含这些字段,即使它们大多为空。

代码:

# importing libraries

import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job

glueContext = GlueContext(SparkContext.getOrCreate())

from pyspark.sql.functions import col
from pyspark.sql.functions import first
from pyspark.sql.functions  import date_format
from pyspark.sql.functions import lit,StringType
from pyspark.sql.types import *
from pyspark.sql.functions import to_date,format_number,dayofmonth,hour,dayofyear,month,year,weekofyear,date_format,unix_timestamp
from pyspark.sql.functions import *


# write to table
df.write.json('s3://path/table')

【问题讨论】:

  • Spark 会出现这种行为。参考stackoverflow.com/a/44283055/4326922
  • @bdcloud 感谢您就此事回复我。那么当它们完全为空时,spark 会丢弃这些字段吗?我正在使用的字段大多为空,但不完全。其中一个字段的缺失值比另一个字段略少,显示在导出的数据中。写函数有空阈值可以调整吗?

标签: python-3.x pyspark aws-glue aws-glue-data-catalog


【解决方案1】:

为什么不使用 AWS Glue 写入方法而不是 spark DF?

glueContext.write_dynamic_frame.from_options

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-23
    • 2019-01-15
    • 2019-05-18
    相关资源
    最近更新 更多