Skip to content

Commit

Permalink
TestTupleVectorFromTable for fixed-size list
Browse files Browse the repository at this point in the history
  • Loading branch information
mroz45 committed Dec 12, 2024
1 parent 9996bc9 commit edeada5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cpp/src/arrow/stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ struct ConversionTraits<std::array<CType_, N>>
::arrow::internal::checked_cast<const ElementArrayType&>(*array.values());

std::array<CType_, N> arr;
for (int64_t i = 0; i < N; i++) {
for (size_t i = 0; i < N; i++) {
arr[i] =
stl::ConversionTraits<CType_>::GetEntry(value_array, array.value_offset(j) + i);
}
Expand Down
24 changes: 22 additions & 2 deletions cpp/src/arrow/stl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,16 @@ TEST(TestTableFromTupleVector, FixedSizeListType) {
std::shared_ptr<Array> expected_array =
ArrayFromJSON(fixed_size_list(int64(), 4), "[[1, 1, 2, 34], [2, -4, 1, 1]]");
std::shared_ptr<Table> expected_table = Table::Make(expected_schema, {expected_array});
std::cout << expected_table->ToString() << std::endl;

std::vector<tuple_type> rows{tuple_type(std::array<int64_t, 4>{1, 1, 2, 34}),
tuple_type(std::array<int64_t, 4>{2, -4, 1, 1})};
std::vector<std::string> names{"column1"};

std::shared_ptr<Table> table;
ASSERT_OK(TableFromTupleRange(default_memory_pool(), rows, names, &table));
ASSERT_OK(table->ValidateFull());

ASSERT_TRUE(expected_table->Equals(*table));
AssertTablesEqual(*expected_table, *table);
}

TEST(TestTableFromTupleVector, ReferenceTuple) {
Expand Down Expand Up @@ -488,6 +488,26 @@ TEST(TestTupleVectorFromTable, ListType) {
ASSERT_EQ(rows, expected_rows);
}

TEST(TestTupleVectorFromTable, FixedSizeListType) {
using tuple_type = std::tuple<std::array<int64_t, 4>>;

compute::ExecContext ctx;
compute::CastOptions cast_options;
auto expected_schema = std::make_shared<Schema>(
FieldVector{field("column1", fixed_size_list(int64(), 4), false)});
std::shared_ptr<Array> expected_array =
ArrayFromJSON(fixed_size_list(int64(), 4), "[[1, 1, 2, 34], [2, -4, 1, 1]]");
std::shared_ptr<Table> table = Table::Make(expected_schema, {expected_array});
ASSERT_OK(table->ValidateFull());

std::vector<tuple_type> expected_rows{tuple_type(std::array<int64_t, 4>{1, 1, 2, 34}),
tuple_type(std::array<int64_t, 4>{2, -4, 1, 1})};

std::vector<tuple_type> rows(2);
ASSERT_OK(TupleRangeFromTable(*table, cast_options, &ctx, &rows));
ASSERT_EQ(rows, expected_rows);
}

TEST(TestTupleVectorFromTable, CastingNeeded) {
using tuple_type = std::tuple<std::vector<int64_t>>;

Expand Down
1 change: 1 addition & 0 deletions cpp/src/arrow/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ struct CTypeTraits<std::vector<CType>> : public TypeTraits<ListType> {
}
};

/// \addtogroup c-type-traits
template <typename CType, std::size_t N>
struct CTypeTraits<std::array<CType, N>> : public TypeTraits<FixedSizeListType> {
using ArrowType = FixedSizeListType;
Expand Down

0 comments on commit edeada5

Please sign in to comment.