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
8 changes: 5 additions & 3 deletions cpp/src/arrow/json/from_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -868,11 +868,13 @@ class UnionConverter final : public ConcreteConverter<UnionConverter> {
array, "[type_id, value] pair",
{[this, &id, &child_converter](sj::value& id_elem) {
ARROW_ASSIGN_OR_RAISE(auto id_value, internal::GetJsonAs<int64_t>(id_elem));
if (id_value < 0 ||
id_value >= static_cast<int64_t>(type_id_to_child_num_.size()) ||
type_id_to_child_num_[id_value] == -1) {
return Status::Invalid("type_id ", id_value, " not found in ", *type_);
}
id = static_cast<int8_t>(id_value);
auto child_num = type_id_to_child_num_[id];
if (child_num == -1) {
return Status::Invalid("type_id ", id, " not found in ", *type_);
}
child_converter = child_converters_[child_num];

if (mode_ == UnionMode::SPARSE) {
Expand Down
7 changes: 7 additions & 0 deletions cpp/src/arrow/json/from_string_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,10 @@ TEST(TestDenseUnionFromString, Errors) {
ASSERT_RAISES(Invalid, ArrayFromJSONString(type, "[\"not a valid type_id\"]"));
ASSERT_RAISES(Invalid,
ArrayFromJSONString(type, "[[0, 99]]")); // 0 is not one of {4, 8}
// Out of range type_ids, including one that truncates to 4 as int8
ASSERT_RAISES(Invalid, ArrayFromJSONString(type, "[[-1, 99]]"));
ASSERT_RAISES(Invalid, ArrayFromJSONString(type, "[[100, 99]]"));
ASSERT_RAISES(Invalid, ArrayFromJSONString(type, "[[260, 99]]"));
ASSERT_RAISES(Invalid,
ArrayFromJSONString(type, "[[4, \"\"]]")); // "" is not a valid int8()

Expand All @@ -1464,6 +1468,9 @@ TEST(TestSparseUnionFromString, Errors) {

ASSERT_RAISES(Invalid, ArrayFromJSONString(type, "[\"not a valid type_id\"]"));
ASSERT_RAISES(Invalid, ArrayFromJSONString(type, "[[0, 99]]"));
ASSERT_RAISES(Invalid, ArrayFromJSONString(type, "[[-1, 99]]"));
ASSERT_RAISES(Invalid, ArrayFromJSONString(type, "[[100, 99]]"));
ASSERT_RAISES(Invalid, ArrayFromJSONString(type, "[[260, 99]]"));
ASSERT_RAISES(Invalid, ArrayFromJSONString(type, "[[4, \"\"]]"));

ASSERT_RAISES(Invalid, ArrayFromJSONString(type, "[\"not a pair\"]"));
Expand Down
Loading