我正在运行 AWS Glue 作业,使用 Glue 自动生成的 PySpark 脚本将 S3 上的管道分隔文件加载到 RDS Postgres 实例中。
最初,它抱怨某些列中的 NULL 值:
pyspark.sql.utils.IllegalArgumentException: u"Can't get JDBC type for null"
在对 SO 进行一些谷歌搜索和阅读之后,我尝试通过将我的 AWS Glue 动态数据帧转换为 Spark 数据帧、执行函数fillna()并重新转换回动态数据帧来替换文件中的 NULL。
datasource0 = glueContext.create_dynamic_frame.from_catalog(database =
"xyz_catalog", table_name = "xyz_staging_files", transformation_ctx =
"datasource0")
custom_df = datasource0.toDF()
custom_df2 = custom_df.fillna(-1)
custom_df3 = custom_df2.fromDF()
applymapping1 = ApplyMapping.apply(frame = custom_df3, mappings = [("id",
"string", "id", "int"),........more code
参考:
http://spark.apache.org/docs/latest/api/python/pyspark.sql.html#pyspark.sql.DataFrame.fillna
现在,当我运行我的工作时,它会引发以下错误:
Log Contents:
Traceback (most recent call last):
File "script_2017-12-20-22-02-13.py", line 23, in <module>
custom_df3 = custom_df2.fromDF()
AttributeError: 'DataFrame' object has no attribute 'fromDF'
End of LogType:stdout
我是 Python 和 Spark 的新手,已经尝试了很多,但无法理解这一点。感谢一些专家的帮助。
我尝试将我的 reconvert 命令更改为:
custom_df3 = glueContext.create_dynamic_frame.fromDF(frame = custom_df2)
但仍然得到错误:
AttributeError: 'DynamicFrameReader' object has no attribute 'fromDF'
更新:我怀疑这与 NULL 值无关。消息“Can't get JDBC type for null”似乎不是指 NULL 值,而是 JDBC 无法破译的某些数据/类型。
我创建了一个只有 1 条记录的文件,没有 NULL 值,将所有布尔类型更改为 INT(并将值替换为 0 和 1),但仍然得到相同的错误:
pyspark.sql.utils.IllegalArgumentException: u"Can't get JDBC type for null"
更新:确保导入 DynamicFrame(从 awsglue.context import DynamicFrame),因为 fromDF / toDF 是 DynamicFrame 的一部分。