Skip to content

Commit

Permalink
Merge pull request #5712 from caskdata/feature/CDAP-5862-fix-enum-schema
Browse files Browse the repository at this point in the history
(CDAP-5862) The enum Schema representation was wrong.
  • Loading branch information
chtyim committed Apr 29, 2016
2 parents c002251 + 0b46db9 commit cc471cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,8 @@ private <V> Map.Entry<Map<V, Integer>, Map<Integer, V>> createIndex(Set<V> value
return new ImmutableEntry<>(null, null);
}

Map<V, Integer> forwardMap = new HashMap<>();
Map<Integer, V> reverseMap = new HashMap<>();
Map<V, Integer> forwardMap = new LinkedHashMap<>();
Map<Integer, V> reverseMap = new LinkedHashMap<>();
int idx = 0;
for (V value : values) {
forwardMap.put(value, idx);
Expand Down
11 changes: 6 additions & 5 deletions cdap-common/src/test/java/co/cask/cdap/io/DatumCodecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public void testReduceProjection() throws IOException, UnsupportedTypeException
/**
*
*/
public static enum TestEnum {
public enum TestEnum {
VALUE1, VALUE2, VALUE3
}

Expand All @@ -303,11 +303,12 @@ public void testEnum() throws IOException, UnsupportedTypeException {
writer.encode(TestEnum.VALUE2, encoder);

BinaryDecoder decoder = new BinaryDecoder(input);
ReflectionDatumReader<TestEnum> reader = new ReflectionDatumReader<>(schema, TypeToken.of(TestEnum.class));
Schema readSchema = Schema.parseJson(schema.toString());
ReflectionDatumReader<TestEnum> reader = new ReflectionDatumReader<>(readSchema, TypeToken.of(TestEnum.class));

Assert.assertEquals(TestEnum.VALUE1, reader.read(decoder, schema));
Assert.assertEquals(TestEnum.VALUE3, reader.read(decoder, schema));
Assert.assertEquals(TestEnum.VALUE2, reader.read(decoder, schema));
Assert.assertEquals(TestEnum.VALUE1, reader.read(decoder, readSchema));
Assert.assertEquals(TestEnum.VALUE3, reader.read(decoder, readSchema));
Assert.assertEquals(TestEnum.VALUE2, reader.read(decoder, readSchema));
}

// this tests that the datum reader treats empty fields correctly. It reproduces the issue in ENG-2404.
Expand Down

0 comments on commit cc471cc

Please sign in to comment.