Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions cpp/src/arrow/array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,9 @@ std::shared_ptr<Array> StringArray::Slice(int64_t offset, int64_t length) const
FixedWidthBinaryArray::FixedWidthBinaryArray(const std::shared_ptr<DataType>& type,
int64_t length, const std::shared_ptr<Buffer>& data,
const std::shared_ptr<Buffer>& null_bitmap, int64_t null_count, int64_t offset)
: Array(type, length, null_bitmap, null_count, offset),
data_(data),
raw_data_(nullptr) {
: PrimitiveArray(type, length, data, null_bitmap, null_count, offset) {
DCHECK(type->type == Type::FIXED_WIDTH_BINARY);
byte_width_ = static_cast<const FixedWidthBinaryType&>(*type).byte_width();
if (data) { raw_data_ = data->data(); }
}

std::shared_ptr<Array> FixedWidthBinaryArray::Slice(
Expand Down
7 changes: 1 addition & 6 deletions cpp/src/arrow/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class ARROW_EXPORT StringArray : public BinaryArray {
// ----------------------------------------------------------------------
// Fixed width binary

class ARROW_EXPORT FixedWidthBinaryArray : public Array {
class ARROW_EXPORT FixedWidthBinaryArray : public PrimitiveArray {
public:
using TypeClass = FixedWidthBinaryType;

Expand All @@ -360,9 +360,6 @@ class ARROW_EXPORT FixedWidthBinaryArray : public Array {
return raw_data_ + (i + offset_) * byte_width_;
}

/// Note that this buffer does not account for any slice offset
std::shared_ptr<Buffer> data() const { return data_; }

int32_t byte_width() const { return byte_width_; }

const uint8_t* raw_data() const { return raw_data_; }
Expand All @@ -371,8 +368,6 @@ class ARROW_EXPORT FixedWidthBinaryArray : public Array {

protected:
int32_t byte_width_;
std::shared_ptr<Buffer> data_;
const uint8_t* raw_data_;
};

// ----------------------------------------------------------------------
Expand Down
14 changes: 6 additions & 8 deletions cpp/src/arrow/compare.cc
Original file line number Diff line number Diff line change
Expand Up @@ -666,14 +666,12 @@ class TypeEqualsVisitor {
return Status::OK();
}

Status Visit(const Time32Type& left) {
const auto& right = static_cast<const Time32Type&>(right_);
result_ = left.unit == right.unit;
return Status::OK();
}

Status Visit(const Time64Type& left) {
const auto& right = static_cast<const Time64Type&>(right_);
template <typename T>
typename std::enable_if<std::is_base_of<TimeType, T>::value ||
std::is_base_of<DateType, T>::value,
Status>::type
Visit(const T& left) {
const auto& right = static_cast<const T&>(right_);
result_ = left.unit == right.unit;
return Status::OK();
}
Expand Down
43 changes: 42 additions & 1 deletion cpp/src/arrow/ipc/ipc-json-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ void TestArrayRoundTrip(const Array& array) {
std::shared_ptr<Array> out;
ASSERT_OK(ReadJsonArray(default_memory_pool(), d, array.type(), &out));

ASSERT_TRUE(array.Equals(out)) << array_as_json;
// std::cout << array_as_json << std::endl;
CompareArraysDetailed(0, *out, array);
}

template <typename T, typename ValueType>
Expand Down Expand Up @@ -351,5 +352,45 @@ TEST(TestJsonFileReadWrite, MinimalFormatExample) {
ASSERT_TRUE(batch->column(1)->Equals(bar));
}

#define BATCH_CASES() \
::testing::Values(&MakeIntRecordBatch, &MakeListRecordBatch, &MakeNonNullRecordBatch, \
&MakeZeroLengthRecordBatch, &MakeDeeplyNestedList, &MakeStringTypesRecordBatch, \
&MakeStruct, &MakeUnion, &MakeDates, &MakeTimestamps, &MakeTimes, &MakeFWBinary);

class TestJsonRoundTrip : public ::testing::TestWithParam<MakeRecordBatch*> {
public:
void SetUp() {}
void TearDown() {}
};

void CheckRoundtrip(const RecordBatch& batch) {
std::unique_ptr<JsonWriter> writer;
ASSERT_OK(JsonWriter::Open(batch.schema(), &writer));
ASSERT_OK(writer->WriteRecordBatch(batch));

std::string result;
ASSERT_OK(writer->Finish(&result));

auto buffer = std::make_shared<Buffer>(reinterpret_cast<const uint8_t*>(result.c_str()),
static_cast<int64_t>(result.size()));

std::unique_ptr<JsonReader> reader;
ASSERT_OK(JsonReader::Open(buffer, &reader));

std::shared_ptr<RecordBatch> result_batch;
ASSERT_OK(reader->GetRecordBatch(0, &result_batch));

CompareBatch(batch, *result_batch);
}

TEST_P(TestJsonRoundTrip, RoundTrip) {
std::shared_ptr<RecordBatch> batch;
ASSERT_OK((*GetParam())(&batch)); // NOLINT clang-tidy gtest issue

CheckRoundtrip(*batch);
}

INSTANTIATE_TEST_CASE_P(TestJsonRoundTrip, TestJsonRoundTrip, BATCH_CASES());

} // namespace ipc
} // namespace arrow
63 changes: 19 additions & 44 deletions cpp/src/arrow/ipc/ipc-read-write-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,6 @@
namespace arrow {
namespace ipc {

void CompareBatch(const RecordBatch& left, const RecordBatch& right) {
if (!left.schema()->Equals(right.schema())) {
FAIL() << "Left schema: " << left.schema()->ToString()
<< "\nRight schema: " << right.schema()->ToString();
}
ASSERT_EQ(left.num_columns(), right.num_columns())
<< left.schema()->ToString() << " result: " << right.schema()->ToString();
EXPECT_EQ(left.num_rows(), right.num_rows());
for (int i = 0; i < left.num_columns(); ++i) {
EXPECT_TRUE(left.column(i)->Equals(right.column(i)))
<< "Idx: " << i << " Name: " << left.column_name(i);
}
}

using BatchVector = std::vector<std::shared_ptr<RecordBatch>>;

class TestSchemaMetadata : public ::testing::Test {
Expand Down Expand Up @@ -85,17 +71,17 @@ class TestSchemaMetadata : public ::testing::Test {
const std::shared_ptr<DataType> INT32 = std::make_shared<Int32Type>();

TEST_F(TestSchemaMetadata, PrimitiveFields) {
auto f0 = std::make_shared<Field>("f0", std::make_shared<Int8Type>());
auto f1 = std::make_shared<Field>("f1", std::make_shared<Int16Type>(), false);
auto f2 = std::make_shared<Field>("f2", std::make_shared<Int32Type>());
auto f3 = std::make_shared<Field>("f3", std::make_shared<Int64Type>());
auto f4 = std::make_shared<Field>("f4", std::make_shared<UInt8Type>());
auto f5 = std::make_shared<Field>("f5", std::make_shared<UInt16Type>());
auto f6 = std::make_shared<Field>("f6", std::make_shared<UInt32Type>());
auto f7 = std::make_shared<Field>("f7", std::make_shared<UInt64Type>());
auto f8 = std::make_shared<Field>("f8", std::make_shared<FloatType>());
auto f9 = std::make_shared<Field>("f9", std::make_shared<DoubleType>(), false);
auto f10 = std::make_shared<Field>("f10", std::make_shared<BooleanType>());
auto f0 = field("f0", std::make_shared<Int8Type>());
auto f1 = field("f1", std::make_shared<Int16Type>(), false);
auto f2 = field("f2", std::make_shared<Int32Type>());
auto f3 = field("f3", std::make_shared<Int64Type>());
auto f4 = field("f4", std::make_shared<UInt8Type>());
auto f5 = field("f5", std::make_shared<UInt16Type>());
auto f6 = field("f6", std::make_shared<UInt32Type>());
auto f7 = field("f7", std::make_shared<UInt64Type>());
auto f8 = field("f8", std::make_shared<FloatType>());
auto f9 = field("f9", std::make_shared<DoubleType>(), false);
auto f10 = field("f10", std::make_shared<BooleanType>());

Schema schema({f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10});
DictionaryMemo memo;
Expand All @@ -105,11 +91,11 @@ TEST_F(TestSchemaMetadata, PrimitiveFields) {

TEST_F(TestSchemaMetadata, NestedFields) {
auto type = std::make_shared<ListType>(std::make_shared<Int32Type>());
auto f0 = std::make_shared<Field>("f0", type);
auto f0 = field("f0", type);

std::shared_ptr<StructType> type2(new StructType({std::make_shared<Field>("k1", INT32),
std::make_shared<Field>("k2", INT32), std::make_shared<Field>("k3", INT32)}));
auto f1 = std::make_shared<Field>("f1", type2);
std::shared_ptr<StructType> type2(
new StructType({field("k1", INT32), field("k2", INT32), field("k3", INT32)}));
auto f1 = field("f1", type2);

Schema schema({f0, f1});
DictionaryMemo memo;
Expand Down Expand Up @@ -172,20 +158,7 @@ class IpcTestFixture : public io::MemoryMapFixture {
ASSERT_EQ(expected.num_columns(), result.num_columns())
<< expected.schema()->ToString() << " result: " << result.schema()->ToString();

for (int i = 0; i < expected.num_columns(); ++i) {
const auto& left = *expected.column(i);
const auto& right = *result.column(i);
if (!left.Equals(right)) {
std::stringstream pp_result;
std::stringstream pp_expected;

ASSERT_OK(PrettyPrint(left, 0, &pp_expected));
ASSERT_OK(PrettyPrint(right, 0, &pp_result));

FAIL() << "Index: " << i << " Expected: " << pp_expected.str()
<< "\nGot: " << pp_result.str();
}
}
CompareBatchColumnsDetailed(result, expected);
}

void CheckRoundtrip(const RecordBatch& batch, int64_t buffer_size) {
Expand Down Expand Up @@ -549,7 +522,7 @@ TEST_F(TestIpcRoundTrip, LargeRecordBatch) {
std::vector<std::shared_ptr<Field>> fields = {f0};
auto schema = std::make_shared<Schema>(fields);

RecordBatch batch(schema, 0, {array});
RecordBatch batch(schema, length, {array});

std::string path = "test-write-large-record_batch";

Expand All @@ -562,6 +535,8 @@ TEST_F(TestIpcRoundTrip, LargeRecordBatch) {
ASSERT_OK(DoLargeRoundTrip(batch, false, &result));
CheckReadResult(*result, batch);

ASSERT_EQ(length, result->num_rows());

// Fails if we try to write this with the normal code path
ASSERT_RAISES(Invalid, DoStandardRoundTrip(batch, false, &result));
}
Expand Down
Loading