Skip to content

Commit

Permalink
Fix tests arrow tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ktf committed Apr 20, 2020
1 parent 6580d49 commit 582af8b
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions tree/dataframe/test/datasource_arrow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ std::shared_ptr<Schema> exampleSchema()
field("Married", arrow::boolean()), field("Babies", arrow::uint32())});
}

template <typename T>
std::shared_ptr<T> makeColumn(std::shared_ptr<Field>, std::shared_ptr<arrow::Array> array) {
return std::make_shared<T>(field, array);
}

template <>
std::shared_ptr<arrow::ChunkedArray> makeColumn<arrow::ChunkedArray>(std::shared_ptr<Field>, std::shared_ptr<arrow::Array> array) {
return std::make_shared<arrow::ChunkedArray>(array);
}

std::shared_ptr<Table> createTestTable()
{
auto schema_ = exampleSchema();
Expand All @@ -49,10 +59,14 @@ std::shared_ptr<Table> createTestTable()
arrow::ArrayFromVector<BooleanType, bool>(marriageStatus, &arrays_[3]);
arrow::ArrayFromVector<UInt32Type, unsigned int>(babies, &arrays_[4]);

std::vector<std::shared_ptr<Column>> columns_ = {
std::make_shared<Column>(schema_->field(0), arrays_[0]), std::make_shared<Column>(schema_->field(1), arrays_[1]),
std::make_shared<Column>(schema_->field(2), arrays_[2]), std::make_shared<Column>(schema_->field(3), arrays_[3]),
std::make_shared<Column>(schema_->field(4), arrays_[4])};
using ColumnType = typename decltype(std::declval<arrow::Table>().column(0))::element_type;

std::vector<std::shared_ptr<ColumnType>> columns_ = {
makeColumn<ColumnType>(schema_->field(0), arrays_[0]),
makeColumn<ColumnType>(schema_->field(1), arrays_[1]),
makeColumn<ColumnType>(schema_->field(2), arrays_[2]),
makeColumn<ColumnType>(schema_->field(3), arrays_[3]),
makeColumn<ColumnType>(schema_->field(4), arrays_[4])};

auto table_ = Table::Make(schema_, columns_);
return table_;
Expand Down

0 comments on commit 582af8b

Please sign in to comment.