2828import org .apache .arrow .vector .types .IntervalUnit ;
2929import org .apache .arrow .vector .types .TimeUnit ;
3030import org .apache .arrow .vector .types .UnionMode ;
31+ import org .apache .arrow .vector .types .pojo .ArrowType .Binary ;
32+ import org .apache .arrow .vector .types .pojo .ArrowType .Bool ;
33+ import org .apache .arrow .vector .types .pojo .ArrowType .Date ;
34+ import org .apache .arrow .vector .types .pojo .ArrowType .Decimal ;
35+ import org .apache .arrow .vector .types .pojo .ArrowType .FloatingPoint ;
36+ import org .apache .arrow .vector .types .pojo .ArrowType .Int ;
37+ import org .apache .arrow .vector .types .pojo .ArrowType .Interval ;
38+ import org .apache .arrow .vector .types .pojo .ArrowType .List ;
39+ import org .apache .arrow .vector .types .pojo .ArrowType .Null ;
40+ import org .apache .arrow .vector .types .pojo .ArrowType .Struct ;
41+ import org .apache .arrow .vector .types .pojo .ArrowType .Time ;
42+ import org .apache .arrow .vector .types .pojo .ArrowType .Timestamp ;
43+ import org .apache .arrow .vector .types .pojo .ArrowType .Union ;
44+ import org .apache .arrow .vector .types .pojo .ArrowType .Utf8 ;
3145import org .junit .Test ;
3246
3347public class TestSchema {
@@ -43,46 +57,48 @@ private static Field field(String name, ArrowType type, Field... children) {
4357 @ Test
4458 public void testComplex () throws IOException {
4559 Schema schema = new Schema (asList (
46- field ("a" , false , new ArrowType .Int (8 , true )),
47- field ("b" , new ArrowType .Struct (),
48- field ("c" , new ArrowType .Int (16 , true )),
49- field ("d" , new ArrowType .Utf8 ())),
50- field ("e" , new ArrowType .List (), field (null , new ArrowType .Date ())),
51- field ("f" , new ArrowType .FloatingPoint (FloatingPointPrecision .SINGLE )),
52- field ("g" , new ArrowType .Timestamp (TimeUnit .MILLISECOND )),
53- field ("h" , new ArrowType .Interval (IntervalUnit .DAY_TIME ))
60+ field ("a" , false , new Int (8 , true )),
61+ field ("b" , new Struct (),
62+ field ("c" , new Int (16 , true )),
63+ field ("d" , new Utf8 ())),
64+ field ("e" , new List (), field (null , new Date ())),
65+ field ("f" , new FloatingPoint (FloatingPointPrecision .SINGLE )),
66+ field ("g" , new Timestamp (TimeUnit .MILLISECOND , "UTC" )),
67+ field ("h" , new Timestamp (TimeUnit .MICROSECOND , null )),
68+ field ("i" , new Interval (IntervalUnit .DAY_TIME ))
5469 ));
5570 roundTrip (schema );
5671 assertEquals (
57- "Schema<a: Int(8, true) not null, b: Struct<c: Int(16, true), d: Utf8>, e: List<Date>, f: FloatingPoint(SINGLE), g: Timestamp(MILLISECOND), h: Interval(DAY_TIME)>" ,
72+ "Schema<a: Int(8, true) not null, b: Struct<c: Int(16, true), d: Utf8>, e: List<Date>, f: FloatingPoint(SINGLE), g: Timestamp(MILLISECOND, UTC ), h: Timestamp(MICROSECOND, null), i : Interval(DAY_TIME)>" ,
5873 schema .toString ());
5974 }
6075
6176 @ Test
6277 public void testAll () throws IOException {
6378 Schema schema = new Schema (asList (
64- field ("a" , false , new ArrowType .Null ()),
65- field ("b" , new ArrowType .Struct (), field ("ba" , new ArrowType .Null ())),
66- field ("c" , new ArrowType .List (), field ("ca" , new ArrowType .Null ())),
67- field ("d" , new ArrowType .Union (UnionMode .Sparse , new int [] {1 , 2 , 3 }), field ("da" , new ArrowType .Null ())),
68- field ("e" , new ArrowType .Int (8 , true )),
69- field ("f" , new ArrowType .FloatingPoint (FloatingPointPrecision .SINGLE )),
70- field ("g" , new ArrowType .Utf8 ()),
71- field ("h" , new ArrowType .Binary ()),
72- field ("i" , new ArrowType .Bool ()),
73- field ("j" , new ArrowType .Decimal (5 , 5 )),
74- field ("k" , new ArrowType .Date ()),
75- field ("l" , new ArrowType .Time (TimeUnit .MILLISECOND , 32 )),
76- field ("m" , new ArrowType .Timestamp (TimeUnit .MILLISECOND )),
77- field ("n" , new ArrowType .Interval (IntervalUnit .DAY_TIME ))
79+ field ("a" , false , new Null ()),
80+ field ("b" , new Struct (), field ("ba" , new Null ())),
81+ field ("c" , new List (), field ("ca" , new Null ())),
82+ field ("d" , new Union (UnionMode .Sparse , new int [] {1 , 2 , 3 }), field ("da" , new Null ())),
83+ field ("e" , new Int (8 , true )),
84+ field ("f" , new FloatingPoint (FloatingPointPrecision .SINGLE )),
85+ field ("g" , new Utf8 ()),
86+ field ("h" , new Binary ()),
87+ field ("i" , new Bool ()),
88+ field ("j" , new Decimal (5 , 5 )),
89+ field ("k" , new Date ()),
90+ field ("l" , new Time (TimeUnit .MILLISECOND , 32 )),
91+ field ("m" , new Timestamp (TimeUnit .MILLISECOND , "UTC" )),
92+ field ("n" , new Timestamp (TimeUnit .MICROSECOND , null )),
93+ field ("o" , new Interval (IntervalUnit .DAY_TIME ))
7894 ));
7995 roundTrip (schema );
8096 }
8197
8298 @ Test
8399 public void testUnion () throws IOException {
84100 Schema schema = new Schema (asList (
85- field ("d" , new ArrowType . Union (UnionMode .Sparse , new int [] {1 , 2 , 3 }), field ("da" , new ArrowType . Null ()))
101+ field ("d" , new Union (UnionMode .Sparse , new int [] {1 , 2 , 3 }), field ("da" , new Null ()))
86102 ));
87103 roundTrip (schema );
88104 contains (schema , "Sparse" );
@@ -91,20 +107,26 @@ public void testUnion() throws IOException {
91107 @ Test
92108 public void testTS () throws IOException {
93109 Schema schema = new Schema (asList (
94- field ("a" , new ArrowType .Timestamp (TimeUnit .SECOND )),
95- field ("b" , new ArrowType .Timestamp (TimeUnit .MILLISECOND )),
96- field ("c" , new ArrowType .Timestamp (TimeUnit .MICROSECOND )),
97- field ("d" , new ArrowType .Timestamp (TimeUnit .NANOSECOND ))
110+ field ("a" , new Timestamp (TimeUnit .SECOND , "UTC" )),
111+ field ("b" , new Timestamp (TimeUnit .MILLISECOND , "UTC" )),
112+ field ("c" , new Timestamp (TimeUnit .MICROSECOND , "UTC" )),
113+ field ("d" , new Timestamp (TimeUnit .NANOSECOND , "UTC" )),
114+ field ("e" , new Timestamp (TimeUnit .SECOND , null )),
115+ field ("f" , new Timestamp (TimeUnit .MILLISECOND , null )),
116+ field ("g" , new Timestamp (TimeUnit .MICROSECOND , null )),
117+ field ("h" , new Timestamp (TimeUnit .NANOSECOND , null ))
98118 ));
99119 roundTrip (schema );
100- contains (schema , "SECOND" , "MILLISECOND" , "MICROSECOND" , "NANOSECOND" );
120+ assertEquals (
121+ "Schema<a: Timestamp(SECOND, UTC), b: Timestamp(MILLISECOND, UTC), c: Timestamp(MICROSECOND, UTC), d: Timestamp(NANOSECOND, UTC), e: Timestamp(SECOND, null), f: Timestamp(MILLISECOND, null), g: Timestamp(MICROSECOND, null), h: Timestamp(NANOSECOND, null)>" ,
122+ schema .toString ());
101123 }
102124
103125 @ Test
104126 public void testInterval () throws IOException {
105127 Schema schema = new Schema (asList (
106- field ("a" , new ArrowType . Interval (IntervalUnit .YEAR_MONTH )),
107- field ("b" , new ArrowType . Interval (IntervalUnit .DAY_TIME ))
128+ field ("a" , new Interval (IntervalUnit .YEAR_MONTH )),
129+ field ("b" , new Interval (IntervalUnit .DAY_TIME ))
108130 ));
109131 roundTrip (schema );
110132 contains (schema , "YEAR_MONTH" , "DAY_TIME" );
@@ -113,9 +135,9 @@ public void testInterval() throws IOException {
113135 @ Test
114136 public void testFP () throws IOException {
115137 Schema schema = new Schema (asList (
116- field ("a" , new ArrowType . FloatingPoint (FloatingPointPrecision .HALF )),
117- field ("b" , new ArrowType . FloatingPoint (FloatingPointPrecision .SINGLE )),
118- field ("c" , new ArrowType . FloatingPoint (FloatingPointPrecision .DOUBLE ))
138+ field ("a" , new FloatingPoint (FloatingPointPrecision .HALF )),
139+ field ("b" , new FloatingPoint (FloatingPointPrecision .SINGLE )),
140+ field ("c" , new FloatingPoint (FloatingPointPrecision .DOUBLE ))
119141 ));
120142 roundTrip (schema );
121143 contains (schema , "HALF" , "SINGLE" , "DOUBLE" );
0 commit comments