Skip to content

[C++][IPC] Schema deserialization does not preserve metadata of map field #35297

Closed

Description

@wgtmac

Describe the bug, including details regarding any error messages, version, and platform.

The code below does not deal with field metadata like nullable and metadata of key and item sub-fields of map type.

Status ConcreteTypeFromFlatbuffer(flatbuf::Type type, const void* type_data,
                                  FieldVector children, std::shared_ptr<DataType>* out) {
  switch (type) {
    case flatbuf::Type::NONE:
      return Status::Invalid("Type metadata cannot be none");
    ...
    case flatbuf::Type::Map:
      if (children.size() != 1) {
        return Status::Invalid("Map must have exactly 1 child field");
      }
      if (children[0]->nullable() || children[0]->type()->id() != Type::STRUCT ||
          children[0]->type()->num_fields() != 2) {
        return Status::Invalid("Map's key-item pairs must be non-nullable structs");
      }
      if (children[0]->type()->field(0)->nullable()) {
        return Status::Invalid("Map's keys must be non-nullable");
      } else {
        auto map = static_cast<const flatbuf::Map*>(type_data);
        *out = std::make_shared<MapType>(children[0]->type()->field(0)->type(),
                                         children[0]->type()->field(1)->type(),
                                         map->keysSorted());
      }
      return Status::OK();
    ...
    default:
      return Status::Invalid("Unrecognized type: " + ToChars(static_cast<int>(type)));
  }
}

The issue can be easily reproduced by a roundtrip test of schema serialization with a non-null map item field.

Component(s)

C++

Activity

  1. added a commit that references this issue on Apr 24, 2023
  2. added a commit that references this issue on Apr 28, 2023
  3. added this to the 13.0.0 milestone on Apr 28, 2023
  4. added a commit that references this issue on May 11, 2023
  5. added a commit that references this issue on May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions