|
22 | 22 | import static org.junit.jupiter.api.Assertions.assertEquals; |
23 | 23 | import static org.junit.jupiter.api.Assertions.assertTrue; |
24 | 24 |
|
| 25 | +import java.nio.file.Files; |
| 26 | +import java.nio.file.Path; |
| 27 | + |
25 | 28 | import org.apache.arrow.memory.BufferAllocator; |
26 | 29 | import org.apache.arrow.memory.RootAllocator; |
27 | 30 | import org.apache.arrow.vector.IntVector; |
28 | 31 | import org.apache.arrow.vector.VectorSchemaRoot; |
29 | 32 | import org.apache.arrow.vector.ipc.ArrowReader; |
| 33 | +import org.apache.arrow.vector.types.DateUnit; |
| 34 | +import org.apache.arrow.vector.types.pojo.ArrowType; |
| 35 | +import org.apache.arrow.vector.types.pojo.Schema; |
30 | 36 | import org.apache.datafusion.DataFrame; |
31 | 37 | import org.apache.datafusion.SessionContext; |
32 | 38 | import org.apache.datafusion.protobuf.EmptyRelationNode; |
33 | 39 | import org.apache.datafusion.protobuf.LogicalExprNode; |
34 | 40 | import org.apache.datafusion.protobuf.LogicalPlanNode; |
35 | 41 | import org.apache.datafusion.protobuf.ProjectionNode; |
| 42 | +import org.junit.jupiter.api.Assumptions; |
36 | 43 | import org.junit.jupiter.api.Test; |
37 | 44 |
|
38 | 45 | import datafusion_common.DatafusionCommon; |
@@ -69,4 +76,29 @@ void fromProtoExecutesProjectionOverEmptyRelation() throws Exception { |
69 | 76 | assertEquals(1, col.get(0)); |
70 | 77 | } |
71 | 78 | } |
| 79 | + |
| 80 | + @Test |
| 81 | + void tableSchemaReturnsExpectedLineitemFields() { |
| 82 | + Path lineitem = Path.of("tpch-data/sf1/lineitem.parquet"); |
| 83 | + Assumptions.assumeTrue( |
| 84 | + Files.exists(lineitem), "TPC-H SF1 data not found; run `make tpch-data` first"); |
| 85 | + |
| 86 | + try (SessionContext ctx = new SessionContext()) { |
| 87 | + ctx.registerParquet("lineitem", lineitem.toAbsolutePath().toString()); |
| 88 | + Schema schema = ctx.tableSchema("lineitem"); |
| 89 | + |
| 90 | + assertEquals(16, schema.getFields().size()); |
| 91 | + assertEquals("l_orderkey", schema.getFields().get(0).getName()); |
| 92 | + assertTrue(schema.getFields().get(0).getType() instanceof ArrowType.Int); |
| 93 | + |
| 94 | + // l_extendedprice = Decimal128(12, 2) |
| 95 | + ArrowType.Decimal price = (ArrowType.Decimal) schema.findField("l_extendedprice").getType(); |
| 96 | + assertEquals(12, price.getPrecision()); |
| 97 | + assertEquals(2, price.getScale()); |
| 98 | + |
| 99 | + // l_shipdate = Date(DAY) |
| 100 | + ArrowType.Date ship = (ArrowType.Date) schema.findField("l_shipdate").getType(); |
| 101 | + assertEquals(DateUnit.DAY, ship.getUnit()); |
| 102 | + } |
| 103 | + } |
72 | 104 | } |
0 commit comments