我正在尝试在我的一个DDB表中更改属性的数据类型,但是由于这些数据已从并写入并写入到属性的数据类型时会导致读取旧记录时随后的读取失败,看起来像这样:
could not unconvert attribute
DynamoDBMappingException: expected M in value {N: 1000,}
我的问题是如何更改表中属性的数据类型,并构建更改,以便我仍然可以阅读以前记录中存在的双重值。这是所讨论的课程:
@DynamoDBTable(tableName = "Sections")
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SectionRecord {
@DynamoDBHashKey
private String id;
private Map<String, Double> sectionTarget; //previous definition: private Double sectionTarget;
public void setSectionTarget(Double sectionTarget, String key) {
if (this.sectionTarget == null) {
this.sectionTarget = new HashMap<Double, String>();
}
this.sectionTarget.put(key, sectionTarget);
}
public void getSectionTarget(String key) {
return this.sectionTarget.get(key);
}
}
最终,我尝试阅读这样的唱片:
mapper.load(SectionRecord.class, id);
大概是问题所在的地方 - 我试图阅读双重(当前存在于DDB中)作为地图(更改我已经对属性做出了)。
我很想听听如何最好地构建这种变化的指导,以便可以缓解这些向后兼容的问题。
I am attempting to change the data type of an attribute in one of my DDB tables, but because this data is read from and written to, altering the data type of the attribute causes subsequent read failures when reading old records, which look like this:
could not unconvert attribute
DynamoDBMappingException: expected M in value {N: 1000,}
My question is about how I can change the data type of an attribute in my table, and architect the change such that I can still read the Double value that exists in previous records. Here is the class in question:
@DynamoDBTable(tableName = "Sections")
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SectionRecord {
@DynamoDBHashKey
private String id;
private Map<String, Double> sectionTarget; //previous definition: private Double sectionTarget;
public void setSectionTarget(Double sectionTarget, String key) {
if (this.sectionTarget == null) {
this.sectionTarget = new HashMap<Double, String>();
}
this.sectionTarget.put(key, sectionTarget);
}
public void getSectionTarget(String key) {
return this.sectionTarget.get(key);
}
}
And eventually, I try to read a record like this:
mapper.load(SectionRecord.class, id);
Which is presumably where the issue comes from - I'm trying to read a Double (which exists in the ddb currently) as a map (the changes I've made to the attribute).
I'd love to hear some guidance on how best to architect such a change such that these backwards compatibility issues could be mitigated.
发布评论
评论(1)
必须
欢迎来到您没有数据库迁移的Dynamo :(
You have to
Welcome to dynamo where you don't have DB migrations :(