Skip to content

Commit 0898b8a

Browse files
committed
test(proto): add failing test for SessionContext.tableSchema
1 parent 7ca79a6 commit 0898b8a

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

‎src/test/java/org/apache/datafusion/proto/SessionContextProtoTest.java‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,24 @@
2222
import static org.junit.jupiter.api.Assertions.assertEquals;
2323
import static org.junit.jupiter.api.Assertions.assertTrue;
2424

25+
import java.nio.file.Files;
26+
import java.nio.file.Path;
27+
2528
import org.apache.arrow.memory.BufferAllocator;
2629
import org.apache.arrow.memory.RootAllocator;
2730
import org.apache.arrow.vector.IntVector;
2831
import org.apache.arrow.vector.VectorSchemaRoot;
2932
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;
3036
import org.apache.datafusion.DataFrame;
3137
import org.apache.datafusion.SessionContext;
3238
import org.apache.datafusion.protobuf.EmptyRelationNode;
3339
import org.apache.datafusion.protobuf.LogicalExprNode;
3440
import org.apache.datafusion.protobuf.LogicalPlanNode;
3541
import org.apache.datafusion.protobuf.ProjectionNode;
42+
import org.junit.jupiter.api.Assumptions;
3643
import org.junit.jupiter.api.Test;
3744

3845
import datafusion_common.DatafusionCommon;
@@ -69,4 +76,29 @@ void fromProtoExecutesProjectionOverEmptyRelation() throws Exception {
6976
assertEquals(1, col.get(0));
7077
}
7178
}
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+
}
72104
}

0 commit comments

Comments
 (0)