[ https://issues.apache.org/jira/browse/ARROW-2328?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16429294#comment-16429294 ]
ASF GitHub Bot commented on ARROW-2328: --------------------------------------- pitrou commented on a change in pull request #1784: ARROW-2328: [C++] Fixed and unit tested feather writing with slice URL: https://github.com/apache/arrow/pull/1784#discussion_r179913230 ########## File path: cpp/src/arrow/ipc/feather-test.cc ########## @@ -406,6 +406,89 @@ TEST_F(TestTableWriter, PrimitiveNullRoundTrip) { } } +class TestTableWriterSlice : public TestTableWriter, + public ::testing::WithParamInterface<std::tuple<int, int>> { +}; + +TEST_P(TestTableWriterSlice, SliceRoundTrip) { + auto p = GetParam(); + auto start = std::get<0>(p); + auto size = std::get<1>(p); + + std::shared_ptr<RecordBatch> batch; + ASSERT_OK(MakeIntBatchSized(start * 2, &batch)); + batch = batch->Slice(start, size); + + ASSERT_OK(writer_->Append("f0", *batch->column(0))); + ASSERT_OK(writer_->Append("f1", *batch->column(1))); + Finish(); + + std::shared_ptr<Column> col; + ASSERT_OK(reader_->GetColumn(0, &col)); + ASSERT_TRUE(col->data()->chunk(0)->Equals(batch->column(0))); + ASSERT_EQ("f0", col->name()); + + ASSERT_OK(reader_->GetColumn(1, &col)); + ASSERT_TRUE(col->data()->chunk(0)->Equals(batch->column(1))); + ASSERT_EQ("f1", col->name()); +} + +TEST_P(TestTableWriterSlice, SliceStringsRoundTrip) { + auto p = GetParam(); + auto start = std::get<0>(p); + auto size = std::get<1>(p); + auto with_nulls = start % 2 == 0; + std::shared_ptr<RecordBatch> batch; + ASSERT_OK(MakeStringTypesRecordBatch(&batch, with_nulls)); + batch = batch->Slice(start, size); + + ASSERT_OK(writer_->Append("f0", *batch->column(0))); + ASSERT_OK(writer_->Append("f1", *batch->column(1))); + Finish(); + + std::shared_ptr<Column> col; + ASSERT_OK(reader_->GetColumn(0, &col)); + SCOPED_TRACE(col->data()->chunk(0)->ToString() + "\n" + batch->column(0)->ToString()); + ASSERT_TRUE(col->data()->chunk(0)->Equals(batch->column(0))); + ASSERT_EQ("f0", col->name()); + + ASSERT_OK(reader_->GetColumn(1, &col)); + ASSERT_TRUE(col->data()->chunk(0)->Equals(batch->column(1))); + ASSERT_EQ("f1", col->name()); +} + +TEST_P(TestTableWriterSlice, SliceBooleanRoundTrip) { + auto p = GetParam(); + auto start = std::get<0>(p); + auto size = std::get<1>(p); + std::shared_ptr<RecordBatch> batch; + ASSERT_OK(MakeBooleanBatchSized(600, &batch)); + batch = batch->Slice(start, size); + + ASSERT_OK(writer_->Append("f0", *batch->column(0))); + ASSERT_OK(writer_->Append("f1", *batch->column(1))); + Finish(); + + std::shared_ptr<Column> col; + ASSERT_OK(reader_->GetColumn(0, &col)); + SCOPED_TRACE(col->data()->chunk(0)->ToString() + "\n" + batch->column(0)->ToString()); + ASSERT_TRUE(col->data()->chunk(0)->Equals(batch->column(0))); + ASSERT_EQ("f0", col->name()); + + ASSERT_OK(reader_->GetColumn(1, &col)); + ASSERT_TRUE(col->data()->chunk(0)->Equals(batch->column(1))); + ASSERT_EQ("f1", col->name()); +} + +INSTANTIATE_TEST_CASE_P( + TestTableWriterSliceOffsets, TestTableWriterSlice, + ::testing::Values(std::make_tuple(300, 30), std::make_tuple(301, 30), Review comment: Hmm... Does gtest allow making a Cartesian product here? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Writing a slice with feather ignores the offset > ----------------------------------------------- > > Key: ARROW-2328 > URL: https://issues.apache.org/jira/browse/ARROW-2328 > Project: Apache Arrow > Issue Type: Bug > Components: C++ > Affects Versions: 0.8.0 > Reporter: Adrian > Priority: Major > Labels: pull-request-available > Fix For: 0.10.0 > > Original Estimate: 0.5h > Remaining Estimate: 0.5h > > Writing a slice from row n of length m of an array to feather would write the > first m rows, instead of the rows starting at n. > The null bitmap also ends up misaligned. Also tested and fixed in the pull > request below. > I've created a pull request with tests and fix here: > [Pullrequest#1766|https://github.com/apache/arrow/pull/1766] > > -- This message was sent by Atlassian JIRA (v7.6.3#76005)