|
21 | 21 |
|
22 | 22 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
23 | 23 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 24 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
24 | 25 | import static org.junit.jupiter.api.Assertions.assertTrue; |
25 | 26 |
|
26 | 27 | import org.apache.arrow.memory.BufferAllocator; |
@@ -115,4 +116,49 @@ void chainFilterSelectCount() { |
115 | 116 | assertEquals(1L, chained.count()); |
116 | 117 | } |
117 | 118 | } |
| 119 | + |
| 120 | + @Test |
| 121 | + void methodsThrowAfterClose() { |
| 122 | + try (SessionContext ctx = new SessionContext()) { |
| 123 | + DataFrame df = ctx.sql("SELECT 1 AS x"); |
| 124 | + df.close(); |
| 125 | + assertThrows(IllegalStateException.class, () -> df.select("x")); |
| 126 | + assertThrows(IllegalStateException.class, () -> df.filter("x > 0")); |
| 127 | + assertThrows(IllegalStateException.class, df::count); |
| 128 | + assertThrows(IllegalStateException.class, df::show); |
| 129 | + assertThrows(IllegalStateException.class, () -> df.show(5)); |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + @Test |
| 134 | + void methodsThrowAfterCollect() throws Exception { |
| 135 | + try (BufferAllocator allocator = new RootAllocator(); |
| 136 | + SessionContext ctx = new SessionContext(); |
| 137 | + DataFrame df = ctx.sql("SELECT 1 AS x")) { |
| 138 | + try (ArrowReader reader = df.collect(allocator)) { |
| 139 | + assertTrue(reader.loadNextBatch()); |
| 140 | + } |
| 141 | + assertThrows(IllegalStateException.class, () -> df.select("x")); |
| 142 | + assertThrows(IllegalStateException.class, () -> df.filter("x > 0")); |
| 143 | + assertThrows(IllegalStateException.class, df::count); |
| 144 | + assertThrows(IllegalStateException.class, df::show); |
| 145 | + assertThrows(IllegalStateException.class, () -> df.show(5)); |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + @Test |
| 150 | + void selectInvalidColumnThrows() { |
| 151 | + try (SessionContext ctx = new SessionContext(); |
| 152 | + DataFrame df = ctx.sql("SELECT 1 AS x")) { |
| 153 | + assertThrows(RuntimeException.class, () -> df.select("not_a_column")); |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + @Test |
| 158 | + void filterMalformedPredicateThrows() { |
| 159 | + try (SessionContext ctx = new SessionContext(); |
| 160 | + DataFrame df = ctx.sql("SELECT 1 AS x")) { |
| 161 | + assertThrows(RuntimeException.class, () -> df.filter("this is not sql")); |
| 162 | + } |
| 163 | + } |
118 | 164 | } |
0 commit comments