|
39 | 39 | import java.time.LocalTime;
|
40 | 40 |
|
41 | 41 | import static org.apache.drill.test.QueryTestUtil.generateCompressedFile;
|
| 42 | +import static org.junit.Assert.assertEquals; |
42 | 43 |
|
43 | 44 | @Category(RowSetTests.class)
|
44 | 45 | public class TestFixedwidthRecordReader extends ClusterTest {
|
@@ -98,20 +99,82 @@ public void testExplicitQuery() throws Exception {
|
98 | 99 | }
|
99 | 100 |
|
100 | 101 | //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 | + } |
101 | 109 |
|
102 |
| - //Test Compressed File |
103 | 110 | @Test
|
104 | 111 | public void testStarQueryWithCompressedFile() throws Exception {
|
105 | 112 | generateCompressedFile("fwf/test.fwf", "zip", "fwf/test.fwf.zip" );
|
106 | 113 |
|
107 | 114 | String sql = "SELECT * FROM dfs.`fwf/test.fwf.zip`";
|
108 |
| - System.out.println("Compressed file generated"); |
109 | 115 | RowSet results = client.queryBuilder().sql(sql).rowSet();
|
110 | 116 | RowSet expected = setupTestData();
|
111 | 117 | new RowSetComparison(expected).verifyAndClearAll(results);
|
112 | 118 | }
|
113 | 119 |
|
114 | 120 | // 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 | + // |
115 | 178 |
|
116 | 179 | private RowSet setupTestData(){
|
117 | 180 | TupleMetadata expectedSchema = new SchemaBuilder()
|
|
0 commit comments