我创建了一个AWS glue作业,将数据从CSV文件加载到Mysql RDS数据库。数据已成功加载,但所有空值都作为字符串插入到MySQL表中,而不是作为NULL插入。
因此,如果我像select * from myTable where myCol is null这样查询我表,结果为0
但当我在这里执行select * from myTable where myCol where = 'NULL'时,我会得到结果。
有问题的字段的数据类型是字符串。
你知道怎么解决这个问题吗?
发布于 2021-10-30 17:10:33
对于任何感兴趣的人,我最终修改了我的pyspark脚本。
我将AWS glue作为字符串处理的所有NULL列转换为null (在Python中为None)。
import pyspark.sql.functions as f
## ...
def convertToNull(dfa):
for i in dfa.columns:
dfa = dfa.withColumn(i , f.when((f.col(i) == 'NULL') | (f.col(i) == 'null'), None).otherwise(f.col(i)))
return dfa
## .........https://stackoverflow.com/questions/69774750
复制相似问题