Skip to content

Commit 2d17f1b

Browse files
author
Megan Foss
committed
Added Serialization/Deserialization test, added blank row test file, cleaned up compressed file test
1 parent 2262cb1 commit 2d17f1b

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

contrib/format-fixedwidth/src/test/java/org/apache/drill/exec/store/fixedwidth/TestFixedwidthRecordReader.java

+65-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.time.LocalTime;
4040

4141
import static org.apache.drill.test.QueryTestUtil.generateCompressedFile;
42+
import static org.junit.Assert.assertEquals;
4243

4344
@Category(RowSetTests.class)
4445
public class TestFixedwidthRecordReader extends ClusterTest {
@@ -98,20 +99,82 @@ public void testExplicitQuery() throws Exception {
9899
}
99100

100101
//Test Serialization/Deserialization
102+
@Test
103+
public void testSerDe() throws Exception {
104+
String sql = "SELECT COUNT(*) FROM dfs.`fwf/test.fwf`";
105+
String plan = queryBuilder().sql(sql).explainJson();
106+
long cnt = queryBuilder().physical(plan).singletonLong();
107+
assertEquals(5L, cnt);
108+
}
101109

102-
//Test Compressed File
103110
@Test
104111
public void testStarQueryWithCompressedFile() throws Exception {
105112
generateCompressedFile("fwf/test.fwf", "zip", "fwf/test.fwf.zip" );
106113

107114
String sql = "SELECT * FROM dfs.`fwf/test.fwf.zip`";
108-
System.out.println("Compressed file generated");
109115
RowSet results = client.queryBuilder().sql(sql).rowSet();
110116
RowSet expected = setupTestData();
111117
new RowSetComparison(expected).verifyAndClearAll(results);
112118
}
113119

114120
// Test Entering invalid schemata - incorrect limits
121+
// Undefined field, what happens
122+
// Parse invalid file, make sure correct error
123+
124+
125+
@Test
126+
public void testOutOfOrder() throws Exception{
127+
String sql = "SELECT Address, DateTime, `Date`, Letter FROM cp.`fwf/test.fwf`";
128+
QueryBuilder q = client.queryBuilder().sql(sql);
129+
RowSet results = q.rowSet();
130+
131+
TupleMetadata expectedSchema = new SchemaBuilder()
132+
.addNullable("Address", TypeProtos.MinorType.INT)
133+
.addNullable("DateTime", TypeProtos.MinorType.TIMESTAMP)
134+
.addNullable("Date", TypeProtos.MinorType.DATE)
135+
.addNullable("Letter", TypeProtos.MinorType.VARCHAR)
136+
.buildSchema();
137+
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema)
138+
.addRow(567, Instant.parse("2021-02-10T15:30:27.00Z"), LocalDate.parse("2021-02-10"), "test")
139+
.addRow(890, Instant.parse("2021-07-27T16:40:15.00Z"), LocalDate.parse("2021-07-27"), "TEST")
140+
.addRow(111, Instant.parse("1111-11-11T16:28:43.11Z"), LocalDate.parse("1111-11-11"), "abcd")
141+
.addRow(222, Instant.parse("2222-01-23T03:22:22.22Z"), LocalDate.parse("2222-01-22"), "efgh")
142+
.addRow(333, Instant.parse("3333-02-01T06:33:33.33Z"), LocalDate.parse("3333-02-01"), "ijkl")
143+
.addRow(444, Instant.parse("4444-03-02T07:44:44.44Z"), LocalDate.parse("4444-03-02"), "mnop")
144+
.addRow(555, Instant.parse("5555-04-03T07:55:55.55Z"), LocalDate.parse("5555-04-03"), "qrst")
145+
.addRow(666, Instant.parse("6666-05-04T08:01:01.01Z"), LocalDate.parse("6666-05-04"), "uvwx")
146+
.addRow(777, Instant.parse("7777-06-05T09:11:11.11Z"), LocalDate.parse("7777-06-05"), "yzzz")
147+
.addRow(888, Instant.parse("8888-07-07T10:22:22.22Z"), LocalDate.parse("8888-07-06"), "aabb")
148+
.addRow(888, Instant.parse("8888-07-07T10:22:22.22Z"), LocalDate.parse("8888-07-06"), "aabb")
149+
.addRow(888, Instant.parse("8888-07-07T10:22:22.22Z"), LocalDate.parse("8888-07-06"), "aabb")
150+
.addRow(888, Instant.parse("8888-07-07T10:22:22.22Z"), LocalDate.parse("8888-07-06"), "aabb")
151+
.addRow(888, Instant.parse("8888-07-07T10:22:22.22Z"), LocalDate.parse("8888-07-06"), "aabb")
152+
.addRow(888, Instant.parse("8888-07-07T10:22:22.22Z"), LocalDate.parse("8888-07-06"), "aabb")
153+
.addRow(888, Instant.parse("8888-07-07T10:22:22.22Z"), LocalDate.parse("8888-07-06"), "aabb")
154+
.addRow(888, Instant.parse("8888-07-07T10:22:22.22Z"), LocalDate.parse("8888-07-06"), "aabb")
155+
.addRow(888, Instant.parse("8888-07-07T10:22:22.22Z"), LocalDate.parse("8888-07-06"), "aabb")
156+
.addRow(888, Instant.parse("8888-07-07T10:22:22.22Z"), LocalDate.parse("8888-07-06"), "aabb")
157+
.addRow(888, Instant.parse("8888-07-07T10:22:22.22Z"), LocalDate.parse("8888-07-06"), "aabb")
158+
.addRow(888, Instant.parse("8888-07-07T10:22:22.22Z"), LocalDate.parse("8888-07-06"), "aabb")
159+
.addRow(888, Instant.parse("8888-07-07T10:22:22.22Z"), LocalDate.parse("8888-07-06"), "aabb")
160+
.addRow(888, Instant.parse("8888-07-07T10:22:22.22Z"), LocalDate.parse("8888-07-06"), "aabb")
161+
.addRow(888, Instant.parse("8888-07-07T10:22:22.22Z"), LocalDate.parse("8888-07-06"), "aabb")
162+
.addRow(888, Instant.parse("8888-07-07T10:22:22.22Z"), LocalDate.parse("8888-07-06"), "aabb")
163+
.build();
164+
165+
new RowSetComparison(expected).verifyAndClearAll(results);
166+
}
167+
168+
// How should we be handling an empty/blank row?
169+
@Test
170+
public void testEmptyRow() throws Exception {
171+
String sql = "SELECT * FROM cp.`fwf/test_blankrow.fwf`";
172+
RowSet results = client.queryBuilder().sql(sql).rowSet();
173+
RowSet expected = setupTestData();
174+
new RowSetComparison(expected).verifyAndClearAll(results);
175+
}
176+
177+
//
115178

116179
private RowSet setupTestData(){
117180
TupleMetadata expectedSchema = new SchemaBuilder()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
12.34 test 567 02-10-2021 10:30:27 02-10-2021T10:30:27.00Z
2+
56.78 TEST 890 07-27-2021 12:40:15 07-27-2021T12:40:15.00Z
3+
11.11 abcd 111 11-11-1111 11:11:11 11-11-1111T11:11:11.11Z
4+
22.22 efgh 222 01-22-2222 22:22:22 01-22-2222T22:22:22.22Z
5+
33.33 ijkl 333 02-01-3333 01:33:33 02-01-3333T01:33:33.33Z
6+
44.44 mnop 444 03-02-4444 02:44:44 03-02-4444T02:44:44.44Z
7+
55.55 qrst 555 04-03-5555 03:55:55 04-03-5555T03:55:55.55Z
8+
66.66 uvwx 666 05-04-6666 04:01:01 05-04-6666T04:01:01.01Z
9+
77.77 yzzz 777 06-05-7777 05:11:11 06-05-7777T05:11:11.11Z
10+
88.88 aabb 888 07-06-8888 06:22:22 07-07-8888T06:22:22.22Z
11+
88.88 aabb 888 07-06-8888 06:22:22 07-07-8888T06:22:22.22Z
12+
13+
88.88 aabb 888 07-06-8888 06:22:22 07-07-8888T06:22:22.22Z
14+
88.88 aabb 888 07-06-8888 06:22:22 07-07-8888T06:22:22.22Z
15+
88.88 aabb 888 07-06-8888 06:22:22 07-07-8888T06:22:22.22Z
16+
88.88 aabb 888 07-06-8888 06:22:22 07-07-8888T06:22:22.22Z
17+
88.88 aabb 888 07-06-8888 06:22:22 07-07-8888T06:22:22.22Z
18+
88.88 aabb 888 07-06-8888 06:22:22 07-07-8888T06:22:22.22Z
19+
88.88 aabb 888 07-06-8888 06:22:22 07-07-8888T06:22:22.22Z
20+
88.88 aabb 888 07-06-8888 06:22:22 07-07-8888T06:22:22.22Z
21+
88.88 aabb 888 07-06-8888 06:22:22 07-07-8888T06:22:22.22Z
22+
88.88 aabb 888 07-06-8888 06:22:22 07-07-8888T06:22:22.22Z
23+
88.88 aabb 888 07-06-8888 06:22:22 07-07-8888T06:22:22.22Z
24+
88.88 aabb 888 07-06-8888 06:22:22 07-07-8888T06:22:22.22Z
25+
88.88 aabb 888 07-06-8888 06:22:22 07-07-8888T06:22:22.22Z
26+
88.88 aabb 888 07-06-8888 06:22:22 07-07-8888T06:22:22.22Z

0 commit comments

Comments
 (0)