Skip to content
Open
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
24 changes: 24 additions & 0 deletions cpp/src/arrow/ipc/message_internal_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <iosfwd>
#include <memory>
#include <sstream>
#include <string>

#include <flatbuffers/flatbuffers.h>

Expand Down Expand Up @@ -114,6 +115,29 @@ TEST(TestMessageInternal, TestEndiannessRoundtrip) {
}
}

// GH-51779: Schema.fbs allows DictionaryEncoding.indexType to be omitted, in
// which case the indices are signed int32.
TEST(TestMessageInternal, DictionaryEncodingWithoutIndexType) {
FBB fbb;
auto name = fbb.CreateString("f0");
auto value_type = flatbuf::CreateUtf8(fbb);
auto encoding = flatbuf::CreateDictionaryEncoding(fbb, /*id=*/0, /*indexType=*/0);
auto fb_field = flatbuf::CreateField(fbb, name, /*nullable=*/true, flatbuf::Type_Utf8,
value_type.Union(), encoding);
auto fb_schema = flatbuf::CreateSchema(fbb, flatbuf::Endianness_Little,
fbb.CreateVector({fb_field}));
fbb.Finish(flatbuf::CreateMessage(fbb, flatbuf::MetadataVersion_V5,
flatbuf::MessageHeader_Schema, fb_schema.Union()));
auto metadata = Buffer::FromString(
std::string(reinterpret_cast<const char*>(fbb.GetBufferPointer()), fbb.GetSize()));

ASSERT_OK_AND_ASSIGN(auto message, Message::Open(metadata, /*body=*/nullptr));
DictionaryMemo memo;
ASSERT_OK_AND_ASSIGN(auto schema, ReadSchema(*message, &memo));
AssertSchemaEqual(*::arrow::schema({field("f0", dictionary(int32(), utf8()))}),
*schema);
}

struct SampleMessageParams {
std::shared_ptr<const KeyValueMetadata> custom_metadata = {};
int64_t body_length = 0;
Expand Down
8 changes: 6 additions & 2 deletions cpp/src/arrow/ipc/metadata_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,12 @@ Status FieldFromFlatbuffer(const flatbuf::Field* field, FieldPosition field_pos,
// dictionary_memo
std::shared_ptr<DataType> index_type;
auto int_data = encoding->indexType();
CHECK_FLATBUFFERS_NOT_NULL(int_data, "DictionaryEncoding.indexType");
RETURN_NOT_OK(IntFromFlatbuffer(int_data, &index_type));
if (int_data == nullptr) {
// Schema.fbs: "If this field is null, the indices must be signed int32."
index_type = int32();
} else {
RETURN_NOT_OK(IntFromFlatbuffer(int_data, &index_type));
}
dict_value_type = type;
ARROW_ASSIGN_OR_RAISE(type,
DictionaryType::Make(index_type, type, encoding->isOrdered()));
Expand Down
Loading