Home Articles

弹性映射减少JSON导出到DynamoDB错误AttributeValue可能不包含空字符串

Asked
Viewed 1404 times
0

我正在尝试使用来自S3中包含稀疏字段的JSON文件的EMR作业来导入数据,例如一个ios_os字段和android_os但只有一个包含数据 . 有时数据为空,有时它是一个空字符串,当尝试插入DynamoDB时我收到错误(虽然我能够插入一些稀疏填充的记录):

“AttributeValue可能不包含空字符串”{“created_at_timestamp”:1358122714,...,“data”:null,“type”:“e”,“android_network_carrier”:“”}

我过滤掉了具有空字符串“”的列,但我仍然遇到了这个错误 . 我假设它是“属性”:导致此(或两者)的空值 . 我假设为了使它正常工作,这些值在进入DynamoDB时不应该存在?

有没有办法告诉Hive通过JSONSerde或Hive与DynamoDB表的交互来忽略空字符串属性值 .

以下是Hive SQL架构和插入命令的示例:

CREATE EXTERNAL TABLE IF NOT EXISTS json_events (
  -- Common
  created_at BIGINT,
  data STRING,
  type STRING,
  android_network_carrier STRING
)
PARTITIONED BY (created_at BIGINT, type STRING)
ROW FORMAT SERDE "org.apache.hadoop.hive.contrib.serde2.JsonSerde"
WITH SERDEPROPERTIES (
  -- Common
  "created_at"="$.created_at",
  "data"="$.data",
  "android_network_carrier"="$.anw",
  "type"="$.dt"
)
LOCATION s3://test.data/json_events;

CREATE EXTERNAL TABLE IF NOT EXISTS dynamo_events (
  -- Common
  created_at BIGINT,
  data STRING,
  type STRING,
  android_network_carrier STRING
)
STORED BY 'org.apache.hadoop.hive.dynamodb.DynamoDBStorageHandler' 
TBLPROPERTIES ("dynamodb.table.name" = "test-events", 
"dynamodb.column.mapping" = "created_at:created_at,data:data,type:type,android_network_carrier:android_network_carrier"); 
ALTER TABLE json_events RECOVER PARTITIONS;

INSERT OVERWRITE TABLE dynamo_events
SELECT created_at,
  data,
  android_network_carrier,
  type
FROM json_events 
WHERE created_at = 20130114 AND type = 'e';

1 Answer

  • 1

    null s不应该't be a problem as long as it'不适用于主键 .

    但是,DynamoDB不允许空字符串或空集,如the data model中所述 .

    为了解决这个问题,我认为你有几个选择:

    • 为"n/a"之类的空字符串定义常量,并确保数据提取过程处理缺失值 .

    • 您也可以过滤这些记录,但这意味着会丢失数据 . 这可以这样做:

    INSERT OVERWRITE TABLE dynamo_events
    SELECT created_at,
      data,
      android_network_carrier,
      type
    FROM json_events 
    WHERE created_at = 20130114 AND type = 'e' AND android_network_carrier != "";
    

Related