【问题标题】:AWS Glue DynamicFrame tries to write empty string as nullAWS Glue DynamicFrame 尝试将空字符串写入 null
【发布时间】: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


    【解决方案1】:

    看起来这是Databricks Datasource for Redshift (docs) 中的问题(显然AWS Glue 在内部使用它)。有关于这个问题的公开票,但他们已经一年多没有碰过:

    我试过那个代码,但结果完全一样:

    datasource
      .toDF()
      .write
      .format("com.databricks.spark.redshift")
      .option("url", "<RS_JDBC_URL>?user=<USER>&password=<PASSWORD>")
      .option("dbtable", "my_table")
      .option("tempdir", "s3://S_PATH")
      .option("forward_spark_s3_credentials", "true")
      .save
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 2021-12-09
      • 2019-08-22
      • 1970-01-01
      • 1970-01-01
      • 2021-10-06
      相关资源
      最近更新 更多