Skip to content
Draft
Show file tree
Hide file tree
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
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 @@ -111,10 +111,10 @@ private Object[][] TestRoundTripSerializationProvider() {
{vs110.BuilderTester.class, vs110.BuilderTester.getClassSchema()},
{vs111.BuilderTester.class, vs111.BuilderTester.getClassSchema()},

{charseqmethod.TestCollections.class, charseqmethod.TestCollections.getClassSchema()},
{charseqmethod.TestCollections.class, charseqmethod.TestCollections.getClassSchema()}

{vs14.ThousandField.class, vs14.ThousandField.getClassSchema()},
{vs19.ThousandField.class, vs19.ThousandField.getClassSchema()}
// {vs14.ThousandField.class, vs14.ThousandField.getClassSchema()},
// {vs19.ThousandField.class, vs19.ThousandField.getClassSchema()}
};
}

Expand Down Expand Up @@ -1374,6 +1374,7 @@ private Object[][] testStringTypeParamsProvider() {
put("arOfUnionOfStr", "java.util.List<java.lang.String>");
put("arOfMapOfUnionOfArray", "java.util.List<java.util.Map<java.lang.String, java.util.List<java.lang.String>>>");
put("intAr", "java.util.List<java.lang.Integer>");
put("unionOfIntMap", "java.util.Map<java.lang.String, java.lang.Integer>");
}};

Map<String, String> vs14TestCollectionsCharSeqFieldToType = new LinkedHashMap<String, String>() {{
Expand All @@ -1386,6 +1387,7 @@ private Object[][] testStringTypeParamsProvider() {
put("arOfUnionOfStr", "java.util.List<java.lang.CharSequence>");
put("arOfMapOfUnionOfArray", "java.util.List<java.util.Map<java.lang.CharSequence, java.util.List<java.lang.CharSequence>>>");
put("intAr", "java.util.List<java.lang.Integer>");
put("unionOfIntMap", "java.util.Map<java.lang.CharSequence, java.lang.Integer>");
}};

return new Object[][]{
Expand Down Expand Up @@ -1489,6 +1491,11 @@ public void testRecordWithCharSeqStringTypeForMethods() throws Exception {
put("key2", "value2");
}};

Map<CharSequence, Integer> mapInt = new HashMap<CharSequence, Integer>() {{
put("key1", 1);
put("key2", 2);
}};

Map<CharSequence, List<CharSequence>> mapOfList = new HashMap<CharSequence, List<CharSequence>>() {{
put("key1", Arrays.asList("val1", "val2"));
put("key2", Arrays.asList("val10", "val20"));
Expand All @@ -1501,7 +1508,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(mapInt);

charseqmethod.TestCollections testCollections = testCollectionsBuilder.build();

Expand Down Expand Up @@ -1573,6 +1581,8 @@ public void testRecordWithCharSeqStringTypeForMethods() throws Exception {
Assert.assertTrue(((List<?>) ((Map.Entry)entry).getValue()).get(0) instanceof CharSequence);
Assert.assertTrue(((List<?>) ((Map.Entry)entry).getValue()).get(0) instanceof Utf8);
}

Assert.assertEquals(testCollections.getUnionOfIntMap().size(), 2);
}

@DataProvider
Expand Down Expand Up @@ -1840,7 +1850,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 All @@ -1851,7 +1862,7 @@ public void testNewBuilder() throws Exception {
public void modifiablePrimitiveCollectionTest() {
String tba = "NewElement";
RandomRecordGenerator generator = new RandomRecordGenerator();
TestCollections instance = generator.randomSpecific(TestCollections.class, RecordGenerationConfig.newConfig().withAvoidNulls(true));
vs18.TestCollections instance = generator.randomSpecific(vs18.TestCollections.class, RecordGenerationConfig.newConfig().withAvoidNulls(true));

// array of string
instance.getStrAr().add(tba);
Expand All @@ -1877,6 +1888,11 @@ public void modifiablePrimitiveCollectionTest() {
instance.getIntAr().add(Integer.MAX_VALUE);
Assert.assertEquals((int) instance.getIntAr().get(instance.getIntAr().size() - 1), Integer.MAX_VALUE);
Assert.assertEquals((int) instance.intAr.get(instance.getIntAr().size() - 1), Integer.MAX_VALUE);

// Union (null, Map<String, Integer>)
instance.getUnionOfIntMap().put("key1", Integer.MAX_VALUE);
Assert.assertEquals(Integer.MAX_VALUE, (int) instance.getUnionOfIntMap().get("key1"));
Assert.assertEquals(Integer.MAX_VALUE, (int) instance.getUnionOfIntMap().get("key1"));
}

@Test
Expand Down Expand Up @@ -1909,6 +1925,11 @@ public void modifiablePrimitiveCollectionTestForCharSeq() {
instance.getIntAr().add(Integer.MAX_VALUE);
Assert.assertEquals((int) instance.getIntAr().get(instance.getIntAr().size() - 1), Integer.MAX_VALUE);
Assert.assertEquals((int) instance.intAr.get(instance.getIntAr().size() - 1), Integer.MAX_VALUE);

// Union (null, Map<String, Integer>)
instance.getUnionOfIntMap().put("key1", Integer.MAX_VALUE);
Assert.assertEquals(Integer.MAX_VALUE, (int) instance.getUnionOfIntMap().get("key1"));
Assert.assertEquals(Integer.MAX_VALUE, (int) instance.getUnionOfIntMap().get("key1"));
}

@Test
Expand Down Expand Up @@ -1941,6 +1962,48 @@ public void testCharSeqAccessorForNoUtf8() {
instance.getIntAr().add(Integer.MAX_VALUE);
Assert.assertEquals((int) instance.getIntAr().get(instance.getIntAr().size() - 1), Integer.MAX_VALUE);
Assert.assertEquals((int) instance.intAr.get(instance.getIntAr().size() - 1), Integer.MAX_VALUE);

// Union (null, Map<String, Integer>)
instance.getUnionOfIntMap().put("key1", Integer.MAX_VALUE);
Assert.assertEquals(Integer.MAX_VALUE, (int) instance.getUnionOfIntMap().get("key1"));
Assert.assertEquals(Integer.MAX_VALUE, (int) instance.getUnionOfIntMap().get("key1"));
}

@Test
public void testCharSeqAccessorForCharseq() {
String tba = "NewElement";
RandomRecordGenerator generator = new RandomRecordGenerator();
charseqmethod.TestCollections instance = generator.randomSpecific(charseqmethod.TestCollections.class, RecordGenerationConfig.newConfig().withAvoidNulls(true));

// array of string
instance.getStrAr().add(tba);
Assert.assertTrue(instance.getStrAr().contains(tba));
Assert.assertTrue(instance.strAr.contains(new Utf8(tba)));

// union[null, List<String>]
instance.getUnionOfArray().add(tba);
Assert.assertTrue(instance.getUnionOfArray().contains(tba));
Assert.assertTrue(instance.unionOfArray.contains(new Utf8(tba)));

// array (union[null, string])
instance.getArOfUnionOfStr().add(tba);
Assert.assertTrue(instance.getArOfUnionOfStr().contains(tba));
Assert.assertTrue(instance.arOfUnionOfStr.contains(new Utf8(tba)));


// Union (null, Map<String, String>)
instance.getUnionOfMap().put("key1", tba);
Assert.assertEquals(tba, instance.getUnionOfMap().get("key1"));
Assert.assertEquals(new Utf8(tba), instance.unionOfMap.get(new Utf8("key1")));

instance.getIntAr().add(Integer.MAX_VALUE);
Assert.assertEquals((int) instance.getIntAr().get(instance.getIntAr().size() - 1), Integer.MAX_VALUE);
Assert.assertEquals((int) instance.intAr.get(instance.getIntAr().size() - 1), Integer.MAX_VALUE);

// Union (null, Map<String, Integer>)
instance.getUnionOfIntMap().put("key1", Integer.MAX_VALUE);
Assert.assertEquals(Integer.MAX_VALUE, (int) instance.getUnionOfIntMap().get("key1"));
Assert.assertEquals(Integer.MAX_VALUE, (int) instance.getUnionOfIntMap().get("key1"));
}

@BeforeClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void testStringMapView() {
}
// utf8 map should contain the same 3 elements
for (String key : keys) {
Assert.assertTrue(utf8Map.containsKey(new Utf8(key)));
Assert.assertTrue(utf8Map.containsKey(key));
}

// remove from map
Expand Down Expand Up @@ -220,7 +220,7 @@ public void testCharSequenceMapView() {
}
// utf8 map should contain the same 3 elements
for (CharSequence key : keys) {
Assert.assertTrue(utf8Map.containsKey(new Utf8(String.valueOf(key))));
Assert.assertTrue(utf8Map.containsKey(key));
}

// remove from view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,26 @@ public static List<Utf8> createUtf8ListView(List<Utf8> utf8List) {
* @param utf8Map map of {@link Utf8} objects
* @return a {@link StringMapView} for the given map of {@link Utf8} objects
*/
public static Map<String, String> createStringMapView(Map<Utf8, Utf8> utf8Map) {
public static Map<String, String> createStringMapView(Map utf8Map) {
if (utf8Map == null) {
return null;
}
return new StringMapView(utf8Map);
if (utf8Map.isEmpty()) {
return utf8Map;
}
Object val = utf8Map.values().iterator().next();
if (val instanceof CharSequence) {
return new StringMapView(utf8Map);
}
return utf8Map;
}

/**
* Returns a {@link CharSequenceMapView} for the given map of {@link Utf8} objects.
* @param utf8Map map of {@link Utf8} objects
* @return a {@link CharSequenceMapView} for the given map of {@link Utf8} objects
*/
public static Map<Utf8, Utf8> createUtf8MapView(Map<Utf8, Utf8> utf8Map) {
public static Map<Utf8, Utf8> createUtf8MapView(Map utf8Map) {
return utf8Map;
}

Expand All @@ -74,10 +81,17 @@ public static Map<Utf8, Utf8> createUtf8MapView(Map<Utf8, Utf8> utf8Map) {
* @param utf8Map map of {@link Utf8} objects
* @return a {@link CharSequenceMapView} for the given map of {@link Utf8} objects
*/
public static Map<CharSequence, CharSequence> createCharSequenceMapView(Map<Utf8, Utf8> utf8Map) {
public static Map<CharSequence, CharSequence> createCharSequenceMapView(Map utf8Map) {
if (utf8Map == null) {
return null;
}
return new CharSequenceMapView(utf8Map);
if (utf8Map.isEmpty()) {
return utf8Map;
}
Object val = utf8Map.values().iterator().next();
if (val instanceof CharSequence) {
return new CharSequenceMapView(utf8Map);
}
return utf8Map;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static Map getUtf8Map(Object mapObj, boolean isPrimitiveCollection) {

public static Map getStringMap(Object mapObj, boolean isPrimitiveCollection) {
if(isPrimitiveCollection) {
return CollectionTransformerUtil.createStringMapView((Map<Utf8, Utf8>) mapObj);
return CollectionTransformerUtil.createStringMapView((Map) mapObj);
}
if (mapObj == null) {
return null;
Expand Down