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
2 changes: 2 additions & 0 deletions cpp/cmake_modules/ThirdpartyToolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2823,6 +2823,8 @@ function(build_simdjson)

fetchcontent_makeavailable(simdjson)

target_compile_definitions(simdjson PUBLIC SIMDJSON_EXCEPTIONS=0)

# The macOS 11.3 SDK has incomplete C++20 concepts support, which prevents
# simdjson headers from compiling. Disable simdjson concepts for this SDK.
if(CMAKE_OSX_SYSROOT AND CMAKE_OSX_SYSROOT MATCHES "MacOSX11\\.3\\.sdk$")
Expand Down
38 changes: 27 additions & 11 deletions cpp/src/arrow/json/object_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class ObjectParser::Impl {
padded_json_ = simdjson::padded_string(json);

// Store parsed document
document_ = parser_.iterate(padded_json_);
if (auto error = parser_.iterate(padded_json_).get(document_)) {
return Status::Invalid("JSON parse error: ", simdjson::error_message(error));
}

// Validate root is an object
auto object = document_.get_object();
Expand Down Expand Up @@ -69,7 +71,12 @@ class ObjectParser::Impl {
"': ", simdjson::error_message(str_result.error()));
}

return std::string(str_result.value());
std::string_view str;
if (auto error = std::move(str_result).get(str)) {
return Status::Invalid("Error getting string for key '", key,
"': ", simdjson::error_message(error));
}
return std::string(str);
Comment on lines +74 to +79

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#50653 adds

template <typename SimdjsonValueType>
Result<SimdjsonValueType> GetJsonAs(sj::value& value) {

that already returns arrow::Results instead of error codes. This might simplify these type-casts

@Reranko05 Reranko05 Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestions! I opened #50693 to track this cleanup after #50672 is merged.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, #50653 is merged now :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to write after this PR is merged. Referenced the wrong PR. Fixed it.

}

Result<std::unordered_map<std::string, std::string>> GetStringMap() {
Expand All @@ -80,13 +87,10 @@ class ObjectParser::Impl {
auto object = document_.get_object();

for (auto field : object) {
auto key_result = field.unescaped_key();

auto key = key_result.value();

if (key_result.error()) {
return Status::Invalid("Error getting value for key '", std::string(key),
"': ", simdjson::error_message(key_result.error()));
std::string_view key;
if (auto error = field.unescaped_key().get(key)) {
return Status::Invalid("Error getting object key: ",
simdjson::error_message(error));
}

auto value = field.value();
Expand All @@ -102,7 +106,13 @@ class ObjectParser::Impl {
"': (code=", static_cast<int>(str_result.error()), ")");
}

map.emplace(std::string(key), std::string(str_result.value()));
std::string_view str;
if (auto error = std::move(str_result).get(str)) {
return Status::Invalid("Error getting value for key '", std::string(key),
"': ", simdjson::error_message(error));
}

map.emplace(std::string(key), std::string(str));
Comment on lines 90 to +115

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto field has type simdjson_result<sj::field>. If we first resolve this to a sj::field, we do not need duplicated value checks for the unescaped_key and value.

Also, first asserting the value (L110), then type-checking the value (L98), is cleaner IMO. (It also works the other way around because simdjson provides overloads for many methods on its result type)

Note that for asserting the value and type-checking the value #50653 adds helper methods we might want to reuse

}

return map;
Expand Down Expand Up @@ -132,7 +142,13 @@ class ObjectParser::Impl {
"': ", simdjson::error_message(bool_result.error()));
}

return bool_result.value();
bool value;
if (auto error = std::move(bool_result).get(value)) {
return Status::Invalid("Error getting bool for key '", key,
"': ", simdjson::error_message(error));
}
Comment on lines +145 to +149

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#50653 adds

template <typename SimdjsonValueType>
Result<SimdjsonValueType> GetJsonAs(sj::value& value) {

that already returns arrow::Results instead of error codes. This might simplify these type-casts


return value;
}

private:
Expand Down
Loading