Skip to content

Commit 62d08a9

Browse files
Factor out repeated code in RT schema test
1 parent 9aaf5cf commit 62d08a9

File tree

1 file changed

+26
-112
lines changed

1 file changed

+26
-112
lines changed

adapter/avro/src/test/java/org/apache/arrow/adapter/avro/RoundTripSchemaTest.java

Lines changed: 26 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -32,40 +32,38 @@
3232

3333
public class RoundTripSchemaTest {
3434

35+
private void doRoundTripTest(List<Field> fields) {
36+
37+
AvroToArrowConfig config = new AvroToArrowConfig(null, 1, null, Collections.emptySet(), false);
38+
39+
Schema avroSchema = ArrowToAvroUtils.createAvroSchema(fields, "TestRecord");
40+
org.apache.arrow.vector.types.pojo.Schema arrowSchema =
41+
AvroToArrowUtils.createArrowSchema(avroSchema, config);
42+
43+
// Compare string representations - equality not defined for logical types
44+
assertEquals(fields, arrowSchema.getFields());
45+
}
46+
3547
// Schema round trip for primitive types, nullable and non-nullable
3648

3749
@Test
3850
public void testRoundTripNullType() {
3951

40-
AvroToArrowConfig config = new AvroToArrowConfig(null, 1, null, Collections.emptySet(), true);
41-
4252
List<Field> fields =
4353
Arrays.asList(new Field("nullType", FieldType.notNullable(new ArrowType.Null()), null));
4454

45-
Schema avroSchema = ArrowToAvroUtils.createAvroSchema(fields, "TestRecord");
46-
org.apache.arrow.vector.types.pojo.Schema arrowSchema =
47-
AvroToArrowUtils.createArrowSchema(avroSchema, config);
48-
49-
// Exact match on fields after round trip
50-
assertEquals(fields, arrowSchema.getFields());
55+
doRoundTripTest(fields);
5156
}
5257

5358
@Test
5459
public void testRoundTripBooleanType() {
5560

56-
AvroToArrowConfig config = new AvroToArrowConfig(null, 1, null, Collections.emptySet(), false);
57-
5861
List<Field> fields =
5962
Arrays.asList(
6063
new Field("nullableBool", FieldType.nullable(new ArrowType.Bool()), null),
6164
new Field("nonNullableBool", FieldType.notNullable(new ArrowType.Bool()), null));
6265

63-
Schema avroSchema = ArrowToAvroUtils.createAvroSchema(fields, "TestRecord");
64-
org.apache.arrow.vector.types.pojo.Schema arrowSchema =
65-
AvroToArrowUtils.createArrowSchema(avroSchema, config);
66-
67-
// Exact match on fields after round trip
68-
assertEquals(fields, arrowSchema.getFields());
66+
doRoundTripTest(fields);
6967
}
7068

7169
@Test
@@ -94,8 +92,6 @@ public void testRoundTripIntegerTypes() {
9492
@Test
9593
public void testRoundTripFloatingPointTypes() {
9694

97-
AvroToArrowConfig config = new AvroToArrowConfig(null, 1, null, Collections.emptySet(), false);
98-
9995
// Only round trip types with direct equivalent in Avro
10096

10197
List<Field> fields =
@@ -117,55 +113,34 @@ public void testRoundTripFloatingPointTypes() {
117113
FieldType.notNullable(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)),
118114
null));
119115

120-
Schema avroSchema = ArrowToAvroUtils.createAvroSchema(fields, "TestRecord");
121-
org.apache.arrow.vector.types.pojo.Schema arrowSchema =
122-
AvroToArrowUtils.createArrowSchema(avroSchema, config);
123-
124-
// Exact match on fields after round trip
125-
assertEquals(fields, arrowSchema.getFields());
116+
doRoundTripTest(fields);
126117
}
127118

128119
@Test
129120
public void testRoundTripStringTypes() {
130121

131-
AvroToArrowConfig config = new AvroToArrowConfig(null, 1, null, Collections.emptySet(), false);
132-
133122
List<Field> fields =
134123
Arrays.asList(
135124
new Field("nullableUtf8", FieldType.nullable(new ArrowType.Utf8()), null),
136125
new Field("nonNullableUtf8", FieldType.notNullable(new ArrowType.Utf8()), null));
137126

138-
Schema avroSchema = ArrowToAvroUtils.createAvroSchema(fields, "TestRecord");
139-
org.apache.arrow.vector.types.pojo.Schema arrowSchema =
140-
AvroToArrowUtils.createArrowSchema(avroSchema, config);
141-
142-
// Exact match on fields after round trip
143-
assertEquals(fields, arrowSchema.getFields());
127+
doRoundTripTest(fields);
144128
}
145129

146130
@Test
147131
public void testRoundTripBinaryTypes() {
148132

149-
AvroToArrowConfig config = new AvroToArrowConfig(null, 1, null, Collections.emptySet(), false);
150-
151133
List<Field> fields =
152134
Arrays.asList(
153135
new Field("nullableBinary", FieldType.nullable(new ArrowType.Binary()), null),
154136
new Field("nonNullableBinary", FieldType.notNullable(new ArrowType.Binary()), null));
155137

156-
Schema avroSchema = ArrowToAvroUtils.createAvroSchema(fields, "TestRecord");
157-
org.apache.arrow.vector.types.pojo.Schema arrowSchema =
158-
AvroToArrowUtils.createArrowSchema(avroSchema, config);
159-
160-
// Exact match on fields after round trip
161-
assertEquals(fields, arrowSchema.getFields());
138+
doRoundTripTest(fields);
162139
}
163140

164141
@Test
165142
public void testRoundTripFixedSizeBinaryTypes() {
166143

167-
AvroToArrowConfig config = new AvroToArrowConfig(null, 1, null, Collections.emptySet(), false);
168-
169144
List<Field> fields =
170145
Arrays.asList(
171146
new Field(
@@ -177,21 +152,14 @@ public void testRoundTripFixedSizeBinaryTypes() {
177152
FieldType.notNullable(new ArrowType.FixedSizeBinary(10)),
178153
null));
179154

180-
Schema avroSchema = ArrowToAvroUtils.createAvroSchema(fields, "TestRecord");
181-
org.apache.arrow.vector.types.pojo.Schema arrowSchema =
182-
AvroToArrowUtils.createArrowSchema(avroSchema, config);
183-
184-
// Exact match on fields after round trip
185-
assertEquals(fields, arrowSchema.getFields());
155+
doRoundTripTest(fields);
186156
}
187157

188158
// Schema round trip for logical types, nullable and non-nullable
189159

190160
@Test
191161
public void testRoundTripDecimalTypes() {
192162

193-
AvroToArrowConfig config = new AvroToArrowConfig(null, 1, null, Collections.emptySet(), false);
194-
195163
List<Field> fields =
196164
Arrays.asList(
197165
new Field(
@@ -223,19 +191,12 @@ public void testRoundTripDecimalTypes() {
223191
FieldType.notNullable(new ArrowType.Decimal(60, 50, 256)),
224192
null));
225193

226-
Schema avroSchema = ArrowToAvroUtils.createAvroSchema(fields, "TestRecord");
227-
org.apache.arrow.vector.types.pojo.Schema arrowSchema =
228-
AvroToArrowUtils.createArrowSchema(avroSchema, config);
229-
230-
// Compare string representations - equality not defined for logical types
231-
assertEquals(fields.toString(), arrowSchema.getFields().toString());
194+
doRoundTripTest(fields);
232195
}
233196

234197
@Test
235198
public void testRoundTripDateTypes() {
236199

237-
AvroToArrowConfig config = new AvroToArrowConfig(null, 1, null, Collections.emptySet(), false);
238-
239200
List<Field> fields =
240201
Arrays.asList(
241202
new Field(
@@ -245,19 +206,12 @@ public void testRoundTripDateTypes() {
245206
FieldType.notNullable(new ArrowType.Date(DateUnit.DAY)),
246207
null));
247208

248-
Schema avroSchema = ArrowToAvroUtils.createAvroSchema(fields, "TestRecord");
249-
org.apache.arrow.vector.types.pojo.Schema arrowSchema =
250-
AvroToArrowUtils.createArrowSchema(avroSchema, config);
251-
252-
// Compare string representations - equality not defined for logical types
253-
assertEquals(fields.toString(), arrowSchema.getFields().toString());
209+
doRoundTripTest(fields);
254210
}
255211

256212
@Test
257213
public void testRoundTripTimeTypes() {
258214

259-
AvroToArrowConfig config = new AvroToArrowConfig(null, 1, null, Collections.emptySet(), false);
260-
261215
List<Field> fields =
262216
Arrays.asList(
263217
new Field(
@@ -277,19 +231,12 @@ public void testRoundTripTimeTypes() {
277231
FieldType.notNullable(new ArrowType.Time(TimeUnit.MICROSECOND, 64)),
278232
null));
279233

280-
Schema avroSchema = ArrowToAvroUtils.createAvroSchema(fields, "TestRecord");
281-
org.apache.arrow.vector.types.pojo.Schema arrowSchema =
282-
AvroToArrowUtils.createArrowSchema(avroSchema, config);
283-
284-
// Compare string representations - equality not defined for logical types
285-
assertEquals(fields.toString(), arrowSchema.getFields().toString());
234+
doRoundTripTest(fields);
286235
}
287236

288237
@Test
289238
public void testRoundTripZoneAwareTimestampTypes() {
290239

291-
AvroToArrowConfig config = new AvroToArrowConfig(null, 1, null, Collections.emptySet(), false);
292-
293240
List<Field> fields =
294241
Arrays.asList(
295242
new Field(
@@ -317,19 +264,12 @@ public void testRoundTripZoneAwareTimestampTypes() {
317264
FieldType.notNullable(new ArrowType.Timestamp(TimeUnit.NANOSECOND, "UTC")),
318265
null));
319266

320-
Schema avroSchema = ArrowToAvroUtils.createAvroSchema(fields, "TestRecord");
321-
org.apache.arrow.vector.types.pojo.Schema arrowSchema =
322-
AvroToArrowUtils.createArrowSchema(avroSchema, config);
323-
324-
// Compare string representations - equality not defined for logical types
325-
assertEquals(fields.toString(), arrowSchema.getFields().toString());
267+
doRoundTripTest(fields);
326268
}
327269

328270
@Test
329271
public void testRoundTripLocalTimestampTypes() {
330272

331-
AvroToArrowConfig config = new AvroToArrowConfig(null, 1, null, Collections.emptySet(), false);
332-
333273
List<Field> fields =
334274
Arrays.asList(
335275
new Field(
@@ -357,21 +297,14 @@ public void testRoundTripLocalTimestampTypes() {
357297
FieldType.notNullable(new ArrowType.Timestamp(TimeUnit.NANOSECOND, null)),
358298
null));
359299

360-
Schema avroSchema = ArrowToAvroUtils.createAvroSchema(fields, "TestRecord");
361-
org.apache.arrow.vector.types.pojo.Schema arrowSchema =
362-
AvroToArrowUtils.createArrowSchema(avroSchema, config);
363-
364-
// Compare string representations - equality not defined for logical types
365-
assertEquals(fields.toString(), arrowSchema.getFields().toString());
300+
doRoundTripTest(fields);
366301
}
367302

368303
// Schema round trip for complex types, where the contents are primitive and logical types
369304

370305
@Test
371306
public void testRoundTripListType() {
372307

373-
AvroToArrowConfig config = new AvroToArrowConfig(null, 1, null, Collections.emptySet(), false);
374-
375308
List<Field> fields =
376309
Arrays.asList(
377310
new Field(
@@ -403,19 +336,12 @@ public void testRoundTripListType() {
403336
FieldType.notNullable(new ArrowType.Timestamp(TimeUnit.MILLISECOND, "UTC")),
404337
null))));
405338

406-
Schema avroSchema = ArrowToAvroUtils.createAvroSchema(fields, "TestRecord");
407-
org.apache.arrow.vector.types.pojo.Schema arrowSchema =
408-
AvroToArrowUtils.createArrowSchema(avroSchema, config);
409-
410-
// Compare string representations - equality not defined for logical types
411-
assertEquals(fields.toString(), arrowSchema.getFields().toString());
339+
doRoundTripTest(fields);
412340
}
413341

414342
@Test
415343
public void testRoundTripMapType() {
416344

417-
AvroToArrowConfig config = new AvroToArrowConfig(null, 1, null, Collections.emptySet(), false);
418-
419345
List<Field> fields =
420346
Arrays.asList(
421347
new Field(
@@ -471,19 +397,12 @@ public void testRoundTripMapType() {
471397
new ArrowType.Timestamp(TimeUnit.MILLISECOND, "UTC")),
472398
null))))));
473399

474-
Schema avroSchema = ArrowToAvroUtils.createAvroSchema(fields, "TestRecord");
475-
org.apache.arrow.vector.types.pojo.Schema arrowSchema =
476-
AvroToArrowUtils.createArrowSchema(avroSchema, config);
477-
478-
// Compare string representations - equality not defined for logical types
479-
assertEquals(fields.toString(), arrowSchema.getFields().toString());
400+
doRoundTripTest(fields);
480401
}
481402

482403
@Test
483404
public void testRoundTripStructType() {
484405

485-
AvroToArrowConfig config = new AvroToArrowConfig(null, 1, null, Collections.emptySet(), false);
486-
487406
List<Field> fields =
488407
Arrays.asList(
489408
new Field(
@@ -519,11 +438,6 @@ public void testRoundTripStructType() {
519438
FieldType.notNullable(new ArrowType.Timestamp(TimeUnit.MILLISECOND, "UTC")),
520439
null))));
521440

522-
Schema avroSchema = ArrowToAvroUtils.createAvroSchema(fields, "TestRecord");
523-
org.apache.arrow.vector.types.pojo.Schema arrowSchema =
524-
AvroToArrowUtils.createArrowSchema(avroSchema, config);
525-
526-
// Compare string representations - equality not defined for logical types
527-
assertEquals(fields.toString(), arrowSchema.getFields().toString());
441+
doRoundTripTest(fields);
528442
}
529443
}

0 commit comments

Comments
 (0)