niyue commented on a change in pull request #11486:
URL: https://github.com/apache/arrow/pull/11486#discussion_r740215632
##########
File path: cpp/src/arrow/ipc/read_write_test.cc
##########
@@ -2410,6 +2469,160 @@ TEST(DictionaryMemo, AddDictionaryType) {
AssertMemoDictionaryType(memo, 44, utf8());
}
+TEST(IoRecordedRandomAccessFile, IoRecording) {
+ IoRecordedRandomAccessFile file(42);
+ ASSERT_TRUE(file.GetRecordedReads().empty());
+
+ ASSERT_OK(file.ReadAt(1, 2));
+ ASSERT_EQ(file.GetRecordedReads().size(), 1);
+ ASSERT_EQ(file.GetRecordedReads()[0], (io::ReadRange{1, 2}));
+
+ ASSERT_OK(file.ReadAt(5, 3));
+ ASSERT_EQ(file.GetRecordedReads().size(), 2);
+ ASSERT_EQ(file.GetRecordedReads()[1], (io::ReadRange{5, 3}));
+
+ // continuous IOs will be merged
+ ASSERT_OK(file.ReadAt(5 + 3, 6));
+ ASSERT_EQ(file.GetRecordedReads().size(), 2);
+ ASSERT_EQ(file.GetRecordedReads()[1], (io::ReadRange{5, 3 + 6}));
+
+ // this should not happen but reading out of bounds will do no harm
+ ASSERT_OK(file.ReadAt(43, 1));
+}
+
+TEST(IoRecordedRandomAccessFile, IoRecordingWithOutput) {
+ std::shared_ptr<Buffer> out;
+ IoRecordedRandomAccessFile file(42);
+ ASSERT_TRUE(file.GetRecordedReads().empty());
+ ASSERT_EQ(file.ReadAt(1, 2, &out), 2L);
+ ASSERT_EQ(file.GetRecordedReads().size(), 1);
+ ASSERT_EQ(file.GetRecordedReads()[0], (io::ReadRange{1, 2}));
+
+ ASSERT_EQ(file.ReadAt(5, 1, &out), 1);
+ ASSERT_EQ(file.GetRecordedReads().size(), 2);
+ ASSERT_EQ(file.GetRecordedReads()[1], (io::ReadRange{5, 1}));
+
+ // continuous IOs will be merged
+ ASSERT_EQ(file.ReadAt(5 + 1, 6, &out), 6);
+ ASSERT_EQ(file.GetRecordedReads().size(), 2);
+ ASSERT_EQ(file.GetRecordedReads()[1], (io::ReadRange{5, 1 + 6}));
+}
+
+Status MakeBooleanInt32Int64Batch(const int length,
std::shared_ptr<RecordBatch>* out) {
+ // Make the schema
+ auto f0 = field("f0", boolean());
+ auto f1 = field("f1", int32());
+ auto f2 = field("f2", int64());
Review comment:
A record batch with 3 fields (bool/int32/int64) are used for IO testing
below.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]