Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

fix postgres error \u0000 not allowed - removes \u0000 from json enco… #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/main/java/com/citusdata/migration/DynamoDBTableReplicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -580,32 +580,35 @@ public static TableColumnValue columnValueFromDynamoValue(AttributeValue typedVa
return new TableColumnValue(TableColumnType.bool, value);
} else if (typedValue.getBS() != null) {
List<ByteBuffer> value = typedValue.getBS();
return new TableColumnValue(TableColumnType.jsonb, Jackson.toJsonString(value));
return new TableColumnValue(TableColumnType.jsonb, cleanupJson(Jackson.toJsonString(value)));
} else if (typedValue.getL() != null) {
List<AttributeValue> value = typedValue.getL();
List<Object> simpleList = InternalUtils.toSimpleList(value);
return new TableColumnValue(TableColumnType.jsonb, Jackson.toJsonString(simpleList));
return new TableColumnValue(TableColumnType.jsonb, cleanupJson(Jackson.toJsonString(simpleList)));
} else if (typedValue.getM() != null) {
Map<String,AttributeValue> value = typedValue.getM();
Map<String, AttributeValue> value = typedValue.getM();
Item simpleMap = Item.fromMap(InternalUtils.toSimpleMapValue(value));
return new TableColumnValue(TableColumnType.jsonb, simpleMap.toJSON());
return new TableColumnValue(TableColumnType.jsonb, cleanupJson(simpleMap.toJSON()));
} else if (typedValue.getN() != null) {
String value = typedValue.getN();
return new TableColumnValue(TableColumnType.numeric, value);
} else if (typedValue.getNS() != null) {
List<String> value = typedValue.getNS();
return new TableColumnValue(TableColumnType.jsonb, Jackson.toJsonString(value));
} else if (typedValue.getS() != null) {
String value = typedValue.getS();
return new TableColumnValue(TableColumnType.text, value);
return new TableColumnValue(TableColumnType.text, cleanupJson(typedValue.getS()));
} else if (typedValue.getSS() != null) {
List<String> value = typedValue.getSS();
return new TableColumnValue(TableColumnType.jsonb, Jackson.toJsonString(value));
return new TableColumnValue(TableColumnType.jsonb, cleanupJson(Jackson.toJsonString(value)));
} else {
return null;
}
}

private static String cleanupJson(String value) {
return value.replaceAll("\\\\u0000", "").replaceAll("\u0000", "");
}

public static TableColumnType columnTypeFromDynamoValue(AttributeValue typedValue) {
if(typedValue.getB() != null) {
return TableColumnType.bytea;
Expand Down