Skip to content

Commit

Permalink
disable modifiable collection transformer for Maps
Browse files Browse the repository at this point in the history
  • Loading branch information
li-ukumar committed Mar 13, 2024
1 parent 2fd93ac commit 6b03955
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@
"type": "array",
"items": "int"
}
},
{
"name": "unionOfIntMap",
"type": [
"null",
{
"type": "map",
"values": "int"
}
]
}
],
"type": "record"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@
"type": "array",
"items": "int"
}
},
{
"name": "unionOfIntMap",
"type": [
"null",
{
"type": "map",
"values": "int"
}
]
}
],
"type": "record"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@
"type": "array",
"items": "int"
}
},
{
"name": "unionOfIntMap",
"type": [
"null",
{
"type": "map",
"values": "int"
}
]
}
],
"type": "record"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@
"type": "array",
"items": "int"
}
},
{
"name": "unionOfIntMap",
"type": [
"null",
{
"type": "map",
"values": "int"
}
]
}
],
"type": "record"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@
"type": "array",
"items": "int"
}
},
{
"name": "unionOfIntMap",
"type": [
"null",
{
"type": "map",
"values": "int"
}
]
}
],
"type": "record"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@
"type": "array",
"items": "int"
}
},
{
"name": "unionOfIntMap",
"type": [
"null",
{
"type": "map",
"values": "int"
}
]
}
],
"type": "record"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@
"type": "array",
"items": "int"
}
},
{
"name": "unionOfIntMap",
"type": [
"null",
{
"type": "map",
"values": "int"
}
]
}
],
"type": "record"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@
"type": "array",
"items": "int"
}
},
{
"name": "unionOfIntMap",
"type": [
"null",
{
"type": "map",
"values": "int"
}
]
}
],
"type": "record"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@
"type": "array",
"items": "int"
}
},
{
"name": "unionOfIntMap",
"type": [
"null",
{
"type": "map",
"values": "int"
}
]
}
],
"type": "record"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@
"type": "array",
"items": "int"
}
},
{
"name": "unionOfIntMap",
"type": [
"null",
{
"type": "map",
"values": "int"
}
]
}
],
"type": "record"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,11 @@ public void testRecordWithCharSeqStringTypeForMethods() throws Exception {
put("key1", Arrays.asList("val1", "val2"));
put("key2", Arrays.asList("val10", "val20"));
}};

Map<CharSequence, Integer> mapOfInt = new HashMap<CharSequence, Integer>() {{
put("key1", 1);
put("key2", 2);
}};
charseqmethod.TestCollections.Builder testCollectionsBuilder = charseqmethod.TestCollections.newBuilder()
.setStr(str)
.setStrAr(Arrays.asList(str))
Expand All @@ -1501,7 +1506,8 @@ public void testRecordWithCharSeqStringTypeForMethods() throws Exception {
.setArOfMap(Arrays.asList(mapCharSeq))
.setUnionOfMap(mapCharSeq)
.setArOfUnionOfStr(Arrays.asList(str))
.setArOfMapOfUnionOfArray(Arrays.asList(mapOfList)).setIntAr(Arrays.asList(1, 2, 3));
.setArOfMapOfUnionOfArray(Arrays.asList(mapOfList)).setIntAr(Arrays.asList(1, 2, 3))
.setUnionOfIntMap(mapOfInt);

charseqmethod.TestCollections testCollections = testCollectionsBuilder.build();

Expand Down Expand Up @@ -1840,7 +1846,8 @@ public void testNewBuilder() throws Exception {
.setArOfMap(instance.getArOfMap())
.setUnionOfMap(instance.getUnionOfMap())
.setArOfUnionOfStr(instance.getArOfUnionOfStr())
.setArOfMapOfUnionOfArray(instance.getArOfMapOfUnionOfArray());
.setArOfMapOfUnionOfArray(instance.getArOfMapOfUnionOfArray())
.setUnionOfIntMap(instance.getUnionOfIntMap());

TestCollections.newBuilder(builder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ private String getSerializedCustomDecodeBlock(SpecificRecordGenerationConfig con
codeBlockBuilder.addStatement("$L.add($L)", arrayVarName, arrayElementVarName)
.endControlFlow()
.endControlFlow()
.addStatement("$L = com.linkedin.avroutil1.compatibility.collectiontransformer.ListTransformer.getUtf8List($L)", fieldName, arrayVarName);
.addStatement("$L = com.linkedin.avroutil1.compatibility.collectiontransformer.ListTransformer.convertToUtf8($L)", fieldName, arrayVarName);

serializedCodeBlock = codeBlockBuilder.build().toString();

Expand Down Expand Up @@ -1165,7 +1165,7 @@ private String getSerializedCustomDecodeBlock(SpecificRecordGenerationConfig con
codeBlockBuilder.addStatement("$L.put($L,$L)", mapVarName, mapKeyVarName, mapValueVarName)
.endControlFlow()
.endControlFlow()
.addStatement("$L = com.linkedin.avroutil1.compatibility.collectiontransformer.MapTransformer.getUtf8Map($L)", fieldName, mapVarName);;
.addStatement("$L = com.linkedin.avroutil1.compatibility.collectiontransformer.MapTransformer.convertToUtf8($L)", fieldName, mapVarName);;

serializedCodeBlock = codeBlockBuilder.build().toString();

Expand Down Expand Up @@ -1581,9 +1581,8 @@ private void addGetByIndexMethod(TypeSpec.Builder classBuilder, AvroRecordSchema
SpecificRecordGeneratorUtil.isCollectionSchemaValuePrimitive(field.getSchema()));
} else if (SpecificRecordGeneratorUtil.isMapTransformerApplicable(field.getSchema())) {
switchBuilder.addStatement(
"case $L: return com.linkedin.avroutil1.compatibility.collectiontransformer.MapTransformer.get$LMap(this.$L, $L)",
fieldIndex++, config.getDefaultMethodStringRepresentation().getJsonValue(), escapedFieldName,
SpecificRecordGeneratorUtil.isCollectionSchemaValuePrimitive(field.getSchema()));
"case $L: return com.linkedin.avroutil1.compatibility.collectiontransformer.MapTransformer.get$LMap(this.$L)",
fieldIndex++, config.getDefaultMethodStringRepresentation().getJsonValue(), escapedFieldName);
} else if (field.getSchema() != null && AvroType.UNION.equals(field.getSchema().type())) {

switchBuilder.addStatement("case $L:", fieldIndex++);
Expand All @@ -1610,9 +1609,8 @@ private void addGetByIndexMethod(TypeSpec.Builder classBuilder, AvroRecordSchema
} else if (SpecificRecordGeneratorUtil.isMapTransformerApplicable(unionMemberSchema.getSchema())) {
switchBuilder.beginControlFlow("else if($1L instanceof $2T)", escapedFieldName, Map.class)
.addStatement(
"return com.linkedin.avroutil1.compatibility.collectiontransformer.MapTransformer.get$1LMap($2L, $3L)",
config.getDefaultMethodStringRepresentation().getJsonValue(), escapedFieldName,
SpecificRecordGeneratorUtil.isCollectionSchemaValuePrimitive(field.getSchema()))
"return com.linkedin.avroutil1.compatibility.collectiontransformer.MapTransformer.get$1LMap($2L)",
config.getDefaultMethodStringRepresentation().getJsonValue(), escapedFieldName)
.endControlFlow();
}
}
Expand Down Expand Up @@ -1826,9 +1824,9 @@ private MethodSpec getGetterMethodSpec(AvroSchemaField field, SpecificRecordGene
SpecificRecordGeneratorUtil.isCollectionSchemaValuePrimitive(field.getSchema()));
} else if (SpecificRecordGeneratorUtil.isMapTransformerApplicable(field.getSchema())) {
methodSpecBuilder.addStatement(
"return com.linkedin.avroutil1.compatibility.collectiontransformer.MapTransformer.get$LMap(this.$L, $L)",
"return com.linkedin.avroutil1.compatibility.collectiontransformer.MapTransformer.get$LMap(this.$L)",
config.getDefaultMethodStringRepresentation().getJsonValue(),
escapedFieldName, SpecificRecordGeneratorUtil.isCollectionSchemaValuePrimitive(field.getSchema()));
escapedFieldName);
} else if (field.getSchema() != null && AvroType.UNION.equals(field.getSchema().type())) {

methodSpecBuilder.beginControlFlow("if (this.$1L == null)", escapedFieldName)
Expand All @@ -1852,9 +1850,8 @@ private MethodSpec getGetterMethodSpec(AvroSchemaField field, SpecificRecordGene
} else if (SpecificRecordGeneratorUtil.isMapTransformerApplicable(unionMemberSchema.getSchema())) {
methodSpecBuilder.beginControlFlow("else if($1L instanceof $2T)", escapedFieldName, Map.class)
.addStatement(
"return com.linkedin.avroutil1.compatibility.collectiontransformer.MapTransformer.get$2LMap($1L, $3L)",
escapedFieldName, config.getDefaultMethodStringRepresentation().getJsonValue(),
SpecificRecordGeneratorUtil.isCollectionSchemaValuePrimitive(field.getSchema()))
"return com.linkedin.avroutil1.compatibility.collectiontransformer.MapTransformer.get$2LMap($1L)",
escapedFieldName, config.getDefaultMethodStringRepresentation().getJsonValue())
.endControlFlow();
}
}
Expand Down

This file was deleted.

Loading

0 comments on commit 6b03955

Please sign in to comment.