【发布时间】:2018-09-28 08:58:59
【问题描述】:
我有一个 AWS Glue 作业将数据从 RDS 表移动到 Redshift。
两个表具有相同的架构:
-- RDS
CREATE TABLE my_table (
id varchar(256) not null primary key
col1 varchar(256) not null
)
-- Redshift
CREATE TABLE my_table (
id varchar(256) not null
col1 varchar(256) not null
) sortkey(id)
我爬取了这两个模式并编写了一个简单的工作来将 DynamicFrame 从 RDS 源写入 Redshift 接收器。
val datasource = glueContext.getCatalogSource(
database = "my_rds",
tableName = "my_table",
redshiftTmpDir = ""
).getDynamicFrame()
glueContext.getCatalogSink(
database = "my_redshift",
tableName = "my_table",
redshiftTmpDir = "s3://some-bucket/some-path"
).writeDynamicFrame(datasource)
但是对于空字符串值为col1 的行,该作业会失败:
java.sql.SQLException:
Error (code 1213) while loading data into Redshift: "Missing data for not-null field"
Table name: my_table
Column name: col1
Column type: varchar(254)
Raw line: 3027616797,@NULL@
Raw field value: @NULL@
当我使用glue-spark-shell 进行调试时,我可以验证该值是一个空字符串""。
scala> datasource.toDF().filter("id = '3027616797'").select("col1").collect().head.getString(0)
res23: String = ""
如何让胶水区分空字符串"" 和NULLs?
【问题讨论】:
标签: amazon-redshift amazon-rds aws-glue