@@ -176,15 +176,17 @@ TEST(TestSchemaFromTuple, PrimitiveTypesTuple) {
176176}
177177
178178TEST (TestSchemaFromTuple, SimpleList) {
179- Schema expected_schema ({field (" column1" , list (utf8 ()), false )});
179+ Schema expected_schema ({field (" column1" , list (field ( " item " , utf8 (), false )), false )});
180180 std::shared_ptr<Schema> schema =
181181 SchemaFromTuple<std::tuple<std::vector<std::string>>>::MakeSchema ({" column1" });
182182
183183 ASSERT_TRUE (expected_schema.Equals (*schema));
184184}
185185
186186TEST (TestSchemaFromTuple, NestedList) {
187- Schema expected_schema ({field (" column1" , list (list (boolean ())), false )});
187+ Schema expected_schema (
188+ {field (" column1" , list (field (" item" , list (field (" item" , boolean (), false )), false )),
189+ false )});
188190 std::shared_ptr<Schema> schema =
189191 SchemaFromTuple<std::tuple<std::vector<std::vector<bool >>>>::MakeSchema (
190192 {" column1" });
@@ -230,10 +232,10 @@ TEST(TestTableFromTupleVector, PrimitiveTypes) {
230232TEST (TestTableFromTupleVector, ListType) {
231233 using tuple_type = std::tuple<std::vector<int64_t >>;
232234
233- auto expected_schema =
234- std::make_shared<Schema>( FieldVector{field (" column1" , list (int64 ()), false )});
235+ auto expected_schema = std::make_shared<Schema>(
236+ FieldVector{field (" column1" , list (field ( " item " , int64 (), false )), false )});
235237 std::shared_ptr<Array> expected_array =
236- ArrayFromJSON (list (int64 ()), " [[1, 1, 2, 34], [2, -4]]" );
238+ ArrayFromJSON (list (field ( " item " , int64 (), false )), " [[1, 1, 2, 34], [2, -4]]" );
237239 std::shared_ptr<Table> expected_table = Table::Make (expected_schema, {expected_array});
238240
239241 std::vector<tuple_type> rows{tuple_type (std::vector<int64_t >{1 , 1 , 2 , 34 }),
@@ -248,10 +250,11 @@ TEST(TestTableFromTupleVector, ListType) {
248250TEST (TestTableFromTupleVector, FixedSizeListType) {
249251 using tuple_type = std::tuple<std::array<int64_t , 4 >>;
250252
251- auto expected_schema = std::make_shared<Schema>(
252- FieldVector{ field (" column1" , fixed_size_list (int64 (), 4 ), false )});
253+ auto expected_schema = std::make_shared<Schema>(FieldVector{
254+ field (" column1" , fixed_size_list (field ( " item " , int64 (), false ), 4 ), false )});
253255 std::shared_ptr<Array> expected_array =
254- ArrayFromJSON (fixed_size_list (int64 (), 4 ), " [[1, 1, 2, 34], [2, -4, 1, 1]]" );
256+ ArrayFromJSON (fixed_size_list (field (" item" , int64 (), false ), 4 ),
257+ " [[1, 1, 2, 34], [2, -4, 1, 1]]" );
255258 std::shared_ptr<Table> expected_table = Table::Make (expected_schema, {expected_array});
256259
257260 std::vector<tuple_type> rows{tuple_type (std::array<int64_t , 4 >{1 , 1 , 2 , 34 }),
@@ -418,9 +421,9 @@ TEST(TestTableFromTupleVector, AppendingMultipleRows) {
418421 ASSERT_OK (TableFromTupleRange (default_memory_pool (), rows, names, &table));
419422
420423 std::shared_ptr<Schema> expected_schema =
421- schema ({field (" column1" , list (int32 ()), false )});
424+ schema ({field (" column1" , list (field ( " item " , int32 (), false )), false )});
422425 std::shared_ptr<Array> int_array =
423- ArrayFromJSON (list (int32 ()), " [[1, 2, 3], [10, 20, 30]]" );
426+ ArrayFromJSON (list (field ( " item " , int32 (), false )), " [[1, 2, 3], [10, 20, 30]]" );
424427 auto expected_table = Table::Make (expected_schema, {int_array});
425428
426429 ASSERT_TRUE (expected_table->Equals (*table));
@@ -488,6 +491,26 @@ TEST(TestTupleVectorFromTable, ListType) {
488491 ASSERT_EQ (rows, expected_rows);
489492}
490493
494+ TEST (TestTupleVectorFromTable, ListOptionalType) {
495+ using tuple_type = std::tuple<std::vector<std::optional<int64_t >>>;
496+
497+ compute::ExecContext ctx;
498+ compute::CastOptions cast_options;
499+ auto expected_schema =
500+ std::make_shared<Schema>(FieldVector{field (" column1" , list (int64 ()), false )});
501+ std::shared_ptr<Array> expected_array =
502+ ArrayFromJSON (list (int64 ()), " [[1, null, 2, null], [null, -4]]" );
503+ std::shared_ptr<Table> table = Table::Make (expected_schema, {expected_array});
504+
505+ std::vector<tuple_type> expected_rows{
506+ tuple_type (std::vector<std::optional<int64_t >>{1 , std::nullopt , 2 , std::nullopt }),
507+ tuple_type (std::vector<std::optional<int64_t >>{std::nullopt , -4 })};
508+
509+ std::vector<tuple_type> rows (2 );
510+ ASSERT_OK (TupleRangeFromTable (*table, cast_options, &ctx, &rows));
511+ ASSERT_EQ (rows, expected_rows);
512+ }
513+
491514TEST (TestTupleVectorFromTable, FixedSizeListType) {
492515 using tuple_type = std::tuple<std::array<int64_t , 4 >>;
493516
@@ -508,6 +531,27 @@ TEST(TestTupleVectorFromTable, FixedSizeListType) {
508531 ASSERT_EQ (rows, expected_rows);
509532}
510533
534+ TEST (TestTupleVectorFromTable, FixedSizeListOptionalType) {
535+ using tuple_type = std::tuple<std::array<std::optional<int64_t >, 4 >>;
536+
537+ compute::ExecContext ctx;
538+ compute::CastOptions cast_options;
539+ auto expected_schema = std::make_shared<Schema>(
540+ FieldVector{field (" column1" , fixed_size_list (int64 (), 4 ), false )});
541+ std::shared_ptr<Array> expected_array =
542+ ArrayFromJSON (fixed_size_list (int64 (), 4 ), " [[1, null, 2, 34], [2, -4, null, 1]]" );
543+ std::shared_ptr<Table> table = Table::Make (expected_schema, {expected_array});
544+ ASSERT_OK (table->ValidateFull ());
545+
546+ std::vector<tuple_type> expected_rows{
547+ tuple_type (std::array<std::optional<int64_t >, 4 >{1 , std::nullopt , 2 , 34 }),
548+ tuple_type (std::array<std::optional<int64_t >, 4 >{2 , -4 , std::nullopt , 1 })};
549+
550+ std::vector<tuple_type> rows (2 );
551+ ASSERT_OK (TupleRangeFromTable (*table, cast_options, &ctx, &rows));
552+ ASSERT_EQ (rows, expected_rows);
553+ }
554+
511555TEST (TestTupleVectorFromTable, CastingNeeded) {
512556 using tuple_type = std::tuple<std::vector<int64_t >>;
513557
0 commit comments