Skip to content

Commit d92f70e

Browse files
Add unit test
1 parent e4cd545 commit d92f70e

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

parquet-tools/src/main/java/org/apache/parquet/tools/read/SimpleMapRecord.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ protected Object toJsonObject() {
4545
return result;
4646
}
4747

48-
private String keyToString(Object kvValue) {
48+
String keyToString(Object kvValue) {
49+
if (kvValue == null) {
50+
return "null";
51+
}
52+
4953
Class<?> type = kvValue.getClass();
5054
if (type.isArray()) {
51-
5255
if (type.getComponentType() == boolean.class) {
5356
return Arrays.toString((boolean[]) kvValue);
5457
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.apache.parquet.tools.read;
2+
3+
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
public class TestSimpleMapRecord {
8+
9+
class TestRecord {
10+
private int x;
11+
private int y;
12+
13+
public TestRecord(int x, int y) {
14+
this.x = x;
15+
this.y = y;
16+
}
17+
18+
@Override
19+
public String toString() {
20+
return "TestRecord {" + x + "," + y + "}";
21+
}
22+
}
23+
24+
@Test
25+
public void testBinary() {
26+
SimpleMapRecord r = new SimpleMapRecord();
27+
Assert.assertEquals("null", r.keyToString(null));
28+
Assert.assertEquals("[true, false, true]", r.keyToString(new boolean[]{true, false, true}));
29+
Assert.assertEquals("[a, z]", r.keyToString(new char[] { 'a', 'z' }));
30+
Assert.assertEquals("[1.0, 3.0]", r.keyToString(new double[]{1.0, 3.0 }));
31+
Assert.assertEquals("[2.0, 4.0]", r.keyToString(new double[]{2.0f, 4.0f }));
32+
Assert.assertEquals("[100.0, 999.0]", r.keyToString(new double[]{100, 999 }));
33+
Assert.assertEquals("[23.0, 37.0]", r.keyToString(new double[] { 23l, 37l }));
34+
Assert.assertEquals("[-1.0, -2.0]", r.keyToString(new double[]{(short) -1, (short) -2}));
35+
Assert.assertEquals("dGVzdA==", r.keyToString("test".getBytes()));
36+
Assert.assertEquals("TestRecord {222,333}", r.keyToString(new TestRecord(222, 333)));
37+
}
38+
}

0 commit comments

Comments
 (0)