Skip to content

Commit 17f5851

Browse files
committed
test(dataframe): cover closed-handle and invalid-arg error paths
1 parent 5b4689e commit 17f5851

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

‎src/test/java/org/apache/datafusion/DataFrameTransformationsTest.java‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
2323
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertThrows;
2425
import static org.junit.jupiter.api.Assertions.assertTrue;
2526

2627
import org.apache.arrow.memory.BufferAllocator;
@@ -115,4 +116,49 @@ void chainFilterSelectCount() {
115116
assertEquals(1L, chained.count());
116117
}
117118
}
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+
}
118164
}

0 commit comments

Comments
 (0)