@@ -253,4 +253,45 @@ void distinctIsNonDestructive() {
253253 assertEquals (3L , source .count ());
254254 }
255255 }
256+
257+ @ Test
258+ void dropColumnsRemovesNamedColumns () throws Exception {
259+ try (BufferAllocator allocator = new RootAllocator ();
260+ SessionContext ctx = new SessionContext ();
261+ DataFrame source = ctx .sql ("SELECT 1 AS a, 2 AS b, 3 AS c" );
262+ DataFrame dropped = source .dropColumns ("b" );
263+ ArrowReader reader = dropped .collect (allocator )) {
264+ assertTrue (reader .loadNextBatch ());
265+ VectorSchemaRoot root = reader .getVectorSchemaRoot ();
266+ assertArrayEquals (
267+ new String [] {"a" , "c" },
268+ root .getSchema ().getFields ().stream ().map (f -> f .getName ()).toArray (String []::new ));
269+ }
270+ }
271+
272+ @ Test
273+ void dropColumnsIsNonDestructive () {
274+ try (SessionContext ctx = new SessionContext ();
275+ DataFrame source = ctx .sql ("SELECT 1 AS a, 2 AS b" )) {
276+ try (DataFrame dropped = source .dropColumns ("a" )) {
277+ assertEquals (1L , dropped .count ());
278+ }
279+ assertEquals (1L , source .count ());
280+ }
281+ }
282+
283+ @ Test
284+ void dropColumnsSilentlyIgnoresUnknownNames () throws Exception {
285+ try (BufferAllocator allocator = new RootAllocator ();
286+ SessionContext ctx = new SessionContext ();
287+ DataFrame df = ctx .sql ("SELECT 1 AS x" );
288+ DataFrame dropped = df .dropColumns ("not_a_column" );
289+ ArrowReader reader = dropped .collect (allocator )) {
290+ assertTrue (reader .loadNextBatch ());
291+ VectorSchemaRoot root = reader .getVectorSchemaRoot ();
292+ assertArrayEquals (
293+ new String [] {"x" },
294+ root .getSchema ().getFields ().stream ().map (f -> f .getName ()).toArray (String []::new ));
295+ }
296+ }
256297}
0 commit comments