|
24 | 24 | import static org.junit.jupiter.api.Assertions.assertThrows; |
25 | 25 | import static org.junit.jupiter.api.Assertions.assertTrue; |
26 | 26 |
|
| 27 | +import java.nio.file.Files; |
| 28 | +import java.nio.file.Path; |
| 29 | + |
27 | 30 | import org.apache.arrow.memory.BufferAllocator; |
28 | 31 | import org.apache.arrow.memory.RootAllocator; |
| 32 | +import org.apache.arrow.vector.BigIntVector; |
29 | 33 | import org.apache.arrow.vector.VectorSchemaRoot; |
30 | 34 | import org.apache.arrow.vector.ipc.ArrowReader; |
| 35 | +import org.junit.jupiter.api.Assumptions; |
31 | 36 | import org.junit.jupiter.api.Test; |
32 | 37 |
|
33 | 38 | class DataFrameTransformationsTest { |
@@ -161,4 +166,32 @@ void filterMalformedPredicateThrows() { |
161 | 166 | assertThrows(RuntimeException.class, () -> df.filter("this is not sql")); |
162 | 167 | } |
163 | 168 | } |
| 169 | + |
| 170 | + @Test |
| 171 | + void lineitemFilterCountAgainstSqlBaseline() throws Exception { |
| 172 | + Path lineitem = Path.of("tpch-data/sf1/lineitem.parquet"); |
| 173 | + Assumptions.assumeTrue( |
| 174 | + Files.exists(lineitem), "TPC-H SF1 data not found; run `make tpch-data` first"); |
| 175 | + |
| 176 | + try (SessionContext ctx = new SessionContext()) { |
| 177 | + ctx.registerParquet("lineitem", lineitem.toAbsolutePath().toString()); |
| 178 | + |
| 179 | + long viaDataFrame; |
| 180 | + try (DataFrame df = ctx.sql("SELECT * FROM lineitem"); |
| 181 | + DataFrame filtered = df.filter("l_orderkey < 100")) { |
| 182 | + viaDataFrame = filtered.count(); |
| 183 | + } |
| 184 | + |
| 185 | + long viaSql; |
| 186 | + try (BufferAllocator allocator = new RootAllocator(); |
| 187 | + DataFrame df = ctx.sql("SELECT COUNT(*) FROM lineitem WHERE l_orderkey < 100"); |
| 188 | + ArrowReader reader = df.collect(allocator)) { |
| 189 | + assertTrue(reader.loadNextBatch()); |
| 190 | + VectorSchemaRoot root = reader.getVectorSchemaRoot(); |
| 191 | + viaSql = ((BigIntVector) root.getVector(0)).get(0); |
| 192 | + } |
| 193 | + |
| 194 | + assertEquals(viaSql, viaDataFrame); |
| 195 | + } |
| 196 | + } |
164 | 197 | } |
0 commit comments