You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Reranko05 (via GitHub)" <gi...@apache.org> on 2026/08/03 10:41:12 UTC
[PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Reranko05 opened a new pull request, #50781:
URL: https://github.com/apache/arrow/pull/50781
### Rationale for this change
This PR continues the simdjson migration by replacing the remaining RapidJSON usages under `cpp/src/parquet` with simdjson and `JsonWriter`. It also removes the remaining unnecessary RapidJSON dependencies from the Parquet test target and Meson build configuration.
### What changes are included in this PR?
* Replace the remaining RapidJSON parsing logic in `reader_test.cc` with simdjson.
* Replace RapidJSON parsing and serialization in `geospatial/util_json_internal.cc` with simdjson and `JsonWriter`.
* Replace RapidJSON string escaping in `types.cc` with `JsonWriter`.
* Remove the unused `rapidjson_dep` dependency from `cpp/src/parquet/meson.build`.
* Remove the remaining RapidJSON dependency from the Parquet test target in `CMakeLists.txt`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3716274006
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -71,14 +112,26 @@ ::arrow::Result<std::string> GeospatialGeoArrowCrsToParquetCrs(
// If we could not detect a longitude/latitude CRS, just write the string to the
// LogicalType crs (being sure to unescape a JSON string into a regular string)
- if (json_crs.IsString()) {
- return json_crs.GetString();
- } else {
- rj::StringBuffer buffer;
- rj::Writer<rj::StringBuffer> writer(buffer);
- json_crs.Accept(writer);
- return buffer.GetString();
+ RETURN_NOT_OK(::arrow::internal::GetSimdjsonResult(crs_object.reset(),
+ "Failed to reset 'crs' object: ")
Review Comment:
It seems that all `GetSimdjsonResult()` messages have `: ` suffix. How about adding it automatically?
```diff
diff --git a/cpp/src/arrow/util/simdjson_internal.h b/cpp/src/arrow/util/simdjson_internal.h
index 8ffb741da4..187dd3aaa5 100644
--- a/cpp/src/arrow/util/simdjson_internal.h
+++ b/cpp/src/arrow/util/simdjson_internal.h
@@ -85,7 +85,7 @@ template <typename T>
Result<T> GetSimdjsonResult(simdjson::simdjson_result<T> result, std::string_view error) {
T value;
if (auto error_code = std::move(result).get(value); error_code != simdjson::SUCCESS) {
- return Status::Invalid(error, simdjson::error_message(error_code));
+ return Status::Invalid(error, ": ", simdjson::error_message(error_code));
}
return value;
}
```
(BTW, `GetSimdjsonResult()` name may be a bit strange because it doesn't return `simdjson::result<T>`. It gets `arrow::Result<T>` from `simdjson::result<T>`. `ResolveSimdjsonResult()`, `SimdjsonResultToArrow()` or something may be better.)
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -17,52 +17,93 @@
#include "parquet/geospatial/util_json_internal.h"
+#include <simdjson.h>
#include <string>
#include "arrow/extension_type.h"
-#include "arrow/json/rapidjson_defs.h" // IWYU pragma: keep
+#include "arrow/json/json_writer_internal.h"
#include "arrow/result.h"
+#include "arrow/util/simdjson_internal.h"
#include "arrow/util/string.h"
-#include <rapidjson/document.h>
-#include <rapidjson/writer.h>
-
#include "parquet/exception.h"
#include "parquet/types.h"
namespace parquet {
namespace {
::arrow::Result<std::string> GeospatialGeoArrowCrsToParquetCrs(
- const ::arrow::rapidjson::Document& document) {
- namespace rj = ::arrow::rapidjson;
+ simdjson::ondemand::object object) {
+ auto crs_field = object["crs"];
- if (!document.HasMember("crs") || document["crs"].IsNull()) {
+ if (crs_field.error() == simdjson::NO_SUCH_FIELD) {
// Parquet GEOMETRY/GEOGRAPHY do not have a concept of a null/missing
// CRS, but an omitted one is more likely to have meant "lon/lat" than
// a truly unspecified one (i.e., Engineering CRS with arbitrary XY units)
return "";
}
- const auto& json_crs = document["crs"];
- if (json_crs.IsString() && (json_crs == "EPSG:4326" || json_crs == "OGC:CRS84")) {
- // crs can be left empty because these cases both correspond to
- // longitude/latitude in WGS84 according to the Parquet specification
+ ARROW_ASSIGN_OR_RAISE(auto json_crs, ::arrow::internal::GetSimdjsonResult(
+ crs_field, "Failed to get 'crs' field: "));
+
+ ARROW_ASSIGN_OR_RAISE(bool is_null, ::arrow::internal::IsJsonNull(json_crs));
+ if (is_null) {
return "";
- } else if (json_crs.IsObject()) {
- // Attempt to detect common PROJJSON representations of longitude/latitude and return
- // an empty crs to maximize compatibility with readers that do not implement CRS
- // support. PROJJSON stores this in the "id" member like:
- // {..., "id": {"authority": "...", "code": "..."}}
- if (json_crs.HasMember("id")) {
- const auto& identifier = json_crs["id"];
- if (identifier.HasMember("authority") && identifier.HasMember("code")) {
- if (identifier["authority"] == "OGC" && identifier["code"] == "CRS84") {
- return "";
- } else if (identifier["authority"] == "EPSG" && identifier["code"] == "4326") {
+ }
+
+ if (auto string = ::arrow::internal::GetJsonAs<std::string_view>(json_crs);
+ string.ok()) {
+ if (*string == "EPSG:4326" || *string == "OGC:CRS84") {
+ // crs can be left empty because these cases both correspond to
+ // longitude/latitude in WGS84 according to the Parquet specification
+ return "";
+ }
+
+ // If we could not detect a longitude/latitude CRS, just write the string to the
+ // LogicalType crs (being sure to unescape a JSON string into a regular string)
+ return std::string(*string);
+ }
+
+ ARROW_ASSIGN_OR_RAISE(
+ auto crs_object,
+ ::arrow::internal::GetJsonAs<simdjson::ondemand::object>(json_crs));
+
+ // Attempt to detect common PROJJSON representations of longitude/latitude and return
+ // an empty crs to maximize compatibility with readers that do not implement CRS
+ // support. PROJJSON stores this in the "id" member like:
+ // {..., "id": {"authority": "...", "code": "..."}}
+ auto id_field = crs_object["id"];
+
+ if (id_field.error() != simdjson::NO_SUCH_FIELD) {
+ ARROW_ASSIGN_OR_RAISE(auto identifier, ::arrow::internal::GetSimdjsonResult(
+ id_field, "Failed to get 'id' field: "));
+
+ auto authority_field = identifier["authority"];
+ auto code_field = identifier["code"];
+
+ if (authority_field.error() != simdjson::NO_SUCH_FIELD &&
+ code_field.error() != simdjson::NO_SUCH_FIELD) {
+ ARROW_ASSIGN_OR_RAISE(auto authority,
+ ::arrow::internal::GetSimdjsonResult(
+ authority_field, "Failed to get 'authority' field: "));
+
+ ARROW_ASSIGN_OR_RAISE(auto code, ::arrow::internal::GetSimdjsonResult(
+ code_field, "Failed to get 'code' field: "));
+
+ ARROW_ASSIGN_OR_RAISE(auto authority_string,
+ ::arrow::internal::GetJsonAs<std::string_view>(authority));
+
+ auto code_string = ::arrow::internal::GetJsonAs<std::string_view>(code);
+
+ if (code_string.ok()) {
+ if ((authority_string == "OGC" && *code_string == "CRS84") ||
+ (authority_string == "EPSG" && *code_string == "4326")) {
Review Comment:
How about using `_result` suffix for `arrow::Result` variable for readability?
```suggestion
auto code_string_result = ::arrow::internal::GetJsonAs<std::string_view>(code);
if (code_string_result.ok()) {
auto code_string = *code_string_result;
if ((authority_string == "OGC" && code_string == "CRS84") ||
(authority_string == "EPSG" && code_string == "4326")) {
```
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -17,52 +17,93 @@
#include "parquet/geospatial/util_json_internal.h"
+#include <simdjson.h>
#include <string>
#include "arrow/extension_type.h"
-#include "arrow/json/rapidjson_defs.h" // IWYU pragma: keep
+#include "arrow/json/json_writer_internal.h"
#include "arrow/result.h"
+#include "arrow/util/simdjson_internal.h"
#include "arrow/util/string.h"
-#include <rapidjson/document.h>
-#include <rapidjson/writer.h>
-
#include "parquet/exception.h"
#include "parquet/types.h"
namespace parquet {
namespace {
::arrow::Result<std::string> GeospatialGeoArrowCrsToParquetCrs(
- const ::arrow::rapidjson::Document& document) {
- namespace rj = ::arrow::rapidjson;
+ simdjson::ondemand::object object) {
+ auto crs_field = object["crs"];
- if (!document.HasMember("crs") || document["crs"].IsNull()) {
+ if (crs_field.error() == simdjson::NO_SUCH_FIELD) {
// Parquet GEOMETRY/GEOGRAPHY do not have a concept of a null/missing
// CRS, but an omitted one is more likely to have meant "lon/lat" than
// a truly unspecified one (i.e., Engineering CRS with arbitrary XY units)
return "";
}
- const auto& json_crs = document["crs"];
- if (json_crs.IsString() && (json_crs == "EPSG:4326" || json_crs == "OGC:CRS84")) {
- // crs can be left empty because these cases both correspond to
- // longitude/latitude in WGS84 according to the Parquet specification
+ ARROW_ASSIGN_OR_RAISE(auto json_crs, ::arrow::internal::GetSimdjsonResult(
+ crs_field, "Failed to get 'crs' field: "));
+
+ ARROW_ASSIGN_OR_RAISE(bool is_null, ::arrow::internal::IsJsonNull(json_crs));
+ if (is_null) {
return "";
- } else if (json_crs.IsObject()) {
- // Attempt to detect common PROJJSON representations of longitude/latitude and return
- // an empty crs to maximize compatibility with readers that do not implement CRS
- // support. PROJJSON stores this in the "id" member like:
- // {..., "id": {"authority": "...", "code": "..."}}
- if (json_crs.HasMember("id")) {
- const auto& identifier = json_crs["id"];
- if (identifier.HasMember("authority") && identifier.HasMember("code")) {
- if (identifier["authority"] == "OGC" && identifier["code"] == "CRS84") {
- return "";
- } else if (identifier["authority"] == "EPSG" && identifier["code"] == "4326") {
+ }
+
+ if (auto string = ::arrow::internal::GetJsonAs<std::string_view>(json_crs);
+ string.ok()) {
+ if (*string == "EPSG:4326" || *string == "OGC:CRS84") {
Review Comment:
Can we avoid `if (...; ...)` for readability?
```suggestion
auto crs_string_result = ::arrow::internal::GetJsonAs<std::string_view>(json_crs);
if (crs_string_result.ok()) {
auto crs_string = *crs_string_result;
if (crs_string == "EPSG:4326" || crs_string == "OGC:CRS84") {
```
##########
cpp/src/parquet/types.cc:
##########
@@ -1785,13 +1782,9 @@ namespace {
void WriteCrsKeyAndValue(const std::string_view crs, std::ostream& json) {
// There is no restriction on the crs value here, and it may contain quotes
// or backslashes that would result in invalid JSON if unescaped.
- namespace rj = ::arrow::rapidjson;
- rj::StringBuffer buffer;
- rj::Writer<rj::StringBuffer> writer(buffer);
- rj::Value v;
- v.SetString(crs.data(), static_cast<int32_t>(crs.size()));
- v.Accept(writer);
- json << R"(, "crs": )" << buffer.GetString();
+ ::arrow::json::JsonWriter writer;
+ writer.String(crs);
+ json << R"(, "crs": )" << writer.GetString().ValueUnsafe();
Review Comment:
Can we use `JsonWriter` for all JSON build instead of mixing manual JSON build and `JsonWriter` build?
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -125,18 +178,18 @@ ::arrow::Result<std::string> MakeGeoArrowCrsMetadata(
}
std::string EscapeCrsAsJsonIfRequired(std::string_view crs) {
- namespace rj = ::arrow::rapidjson;
- rj::Document document;
- if (document.Parse(crs.data(), crs.length()).HasParseError()) {
- rj::StringBuffer buffer;
- rj::Writer<rj::StringBuffer> writer(buffer);
- rj::Value v;
- v.SetString(crs.data(), static_cast<int32_t>(crs.size()));
- v.Accept(writer);
- return std::string(buffer.GetString());
- } else {
- return std::string(crs);
+ simdjson::ondemand::parser parser;
+ simdjson::padded_string json(crs);
+
+ if (parser.iterate(json).error() != simdjson::SUCCESS) {
+ ::arrow::json::JsonWriter writer;
+ writer.String(crs);
+
+ auto escaped = writer.GetString().ValueUnsafe();
Review Comment:
Should we change the return type to `arrow::Result<std::string>` from `std::string` to propagate an error?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3720169747
##########
cpp/src/parquet/reader_test.cc:
##########
@@ -1230,14 +1223,15 @@ TEST_F(TestJSONWithLocalFile, JSONOutputSortColumns) {
namespace {
::arrow::Status CheckJsonValid(std::string_view json_string) {
- rj::Document json_doc;
- constexpr auto kParseFlags = rj::kParseFullPrecisionFlag | rj::kParseNanAndInfFlag;
- json_doc.Parse<kParseFlags>(json_string.data(), json_string.length());
- if (json_doc.HasParseError()) {
- return ::arrow::Status::Invalid("JSON parse error at offset ",
- json_doc.GetErrorOffset(), ": ",
- rj::GetParseError_En(json_doc.GetParseError()));
+ simdjson::ondemand::parser parser;
+ simdjson::ondemand::document document;
+
+ auto padded_json = simdjson::padded_string(json_string);
+
+ if (auto error = parser.iterate(padded_json).get(document)) {
Review Comment:
I did not preserve the previous `NaN`/`Inf` behavior, since simdjson doesn't currently support it. Should we preserve the previous `NaN`/`Inf` behavior here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "taepper (via GitHub)" <gi...@apache.org>.
taepper commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3718473528
##########
cpp/src/parquet/reader_test.cc:
##########
@@ -1230,14 +1223,15 @@ TEST_F(TestJSONWithLocalFile, JSONOutputSortColumns) {
namespace {
::arrow::Status CheckJsonValid(std::string_view json_string) {
- rj::Document json_doc;
- constexpr auto kParseFlags = rj::kParseFullPrecisionFlag | rj::kParseNanAndInfFlag;
- json_doc.Parse<kParseFlags>(json_string.data(), json_string.length());
- if (json_doc.HasParseError()) {
- return ::arrow::Status::Invalid("JSON parse error at offset ",
- json_doc.GetErrorOffset(), ": ",
- rj::GetParseError_En(json_doc.GetParseError()));
+ simdjson::ondemand::parser parser;
+ simdjson::ondemand::document document;
+
+ auto padded_json = simdjson::padded_string(json_string);
+
+ if (auto error = parser.iterate(padded_json).get(document)) {
Review Comment:
The `NaN`/`Inf` case is a very unfortunate one. While not being part of the official JSON RFC, it will be added to the next simdjson release: https://github.com/simdjson/simdjson/pull/2696
I added behavior preserving json parsing to our testing helpers in `from_string.cc`:
https://github.com/apache/arrow/pull/50653
Maybe that work-around is also acceptable here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on PR #50781:
URL: https://github.com/apache/arrow/pull/50781#issuecomment-5169139787
Thanks @rok, `reset()` + `raw_json()` fixed the iteration issue.
However, one test still fails because `raw_json()` preserves the original formatting (e.g. `{"key0": "value0"}`), whereas the previous RapidJSON `Writer` minified it to `{"key0":"value0"}`. `LogicalType::Equals()` compares the CRS string literally.
Would you prefer keeping the previous compact formatting or preserving the original JSON formatting?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on PR #50781:
URL: https://github.com/apache/arrow/pull/50781#issuecomment-5167834273
@rok @taepper
I'm migrating `parquet/geospatial/util_json_internal.cc` and ran into an `ondemand` question.
`GeospatialGeoArrowCrsToParquetCrs()` needs to:
1. inspect the `crs` object (e.g. check the `id.authority`/`code` fields to detect EPSG:4326/CRS84), and
2. if it isn't a recognized lon/lat CRS, serialize the same object back to JSON.
With RapidJSON this was straightforward because the DOM is reusable, but with `simdjson::ondemand` the object has already been consumed by the time I want to serialize it, leading to `OUT_OF_ORDER_ITERATION`.
Is the expected approach here to restructure the code into a single pass, or is there another way to serialize an already-inspected `ondemand::object`?
Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #50781:
URL: https://github.com/apache/arrow/pull/50781#issuecomment-5165343236
:warning: GitHub issue #50779 **has been automatically assigned in GitHub** to PR creator.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3717898418
##########
cpp/src/parquet/CMakeLists.txt:
##########
Review Comment:
Removed.
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -17,52 +17,93 @@
#include "parquet/geospatial/util_json_internal.h"
+#include <simdjson.h>
#include <string>
#include "arrow/extension_type.h"
-#include "arrow/json/rapidjson_defs.h" // IWYU pragma: keep
+#include "arrow/json/json_writer_internal.h"
#include "arrow/result.h"
+#include "arrow/util/simdjson_internal.h"
#include "arrow/util/string.h"
-#include <rapidjson/document.h>
-#include <rapidjson/writer.h>
-
#include "parquet/exception.h"
#include "parquet/types.h"
namespace parquet {
namespace {
::arrow::Result<std::string> GeospatialGeoArrowCrsToParquetCrs(
- const ::arrow::rapidjson::Document& document) {
- namespace rj = ::arrow::rapidjson;
+ simdjson::ondemand::object object) {
+ auto crs_field = object["crs"];
- if (!document.HasMember("crs") || document["crs"].IsNull()) {
+ if (crs_field.error() == simdjson::NO_SUCH_FIELD) {
// Parquet GEOMETRY/GEOGRAPHY do not have a concept of a null/missing
// CRS, but an omitted one is more likely to have meant "lon/lat" than
// a truly unspecified one (i.e., Engineering CRS with arbitrary XY units)
return "";
}
- const auto& json_crs = document["crs"];
- if (json_crs.IsString() && (json_crs == "EPSG:4326" || json_crs == "OGC:CRS84")) {
- // crs can be left empty because these cases both correspond to
- // longitude/latitude in WGS84 according to the Parquet specification
+ ARROW_ASSIGN_OR_RAISE(auto json_crs, ::arrow::internal::GetSimdjsonResult(
+ crs_field, "Failed to get 'crs' field: "));
+
+ ARROW_ASSIGN_OR_RAISE(bool is_null, ::arrow::internal::IsJsonNull(json_crs));
+ if (is_null) {
return "";
- } else if (json_crs.IsObject()) {
- // Attempt to detect common PROJJSON representations of longitude/latitude and return
- // an empty crs to maximize compatibility with readers that do not implement CRS
- // support. PROJJSON stores this in the "id" member like:
- // {..., "id": {"authority": "...", "code": "..."}}
- if (json_crs.HasMember("id")) {
- const auto& identifier = json_crs["id"];
- if (identifier.HasMember("authority") && identifier.HasMember("code")) {
- if (identifier["authority"] == "OGC" && identifier["code"] == "CRS84") {
- return "";
- } else if (identifier["authority"] == "EPSG" && identifier["code"] == "4326") {
+ }
+
+ if (auto string = ::arrow::internal::GetJsonAs<std::string_view>(json_crs);
+ string.ok()) {
+ if (*string == "EPSG:4326" || *string == "OGC:CRS84") {
Review Comment:
Addressed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3718420013
##########
cpp/src/arrow/util/simdjson_internal.h:
##########
@@ -82,10 +82,11 @@ constexpr const char* JsonTypeName() {
}
template <typename T>
-Result<T> GetSimdjsonResult(simdjson::simdjson_result<T> result, std::string_view error) {
+Result<T> ResolveSimdjsonResult(simdjson::simdjson_result<T> result,
+ std::string_view error) {
T value;
if (auto error_code = std::move(result).get(value); error_code != simdjson::SUCCESS) {
- return Status::Invalid(error, simdjson::error_message(error_code));
+ return Status::Invalid(error, ": ", simdjson::error_message(error_code));
Review Comment:
https://github.com/apache/arrow/pull/50781#discussion_r3716274006
Feedback from @kou
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3720125476
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -17,52 +17,96 @@
#include "parquet/geospatial/util_json_internal.h"
+#include <simdjson.h>
#include <string>
#include "arrow/extension_type.h"
-#include "arrow/json/rapidjson_defs.h" // IWYU pragma: keep
+#include "arrow/json/json_writer_internal.h"
#include "arrow/result.h"
+#include "arrow/util/simdjson_internal.h"
#include "arrow/util/string.h"
-#include <rapidjson/document.h>
-#include <rapidjson/writer.h>
-
#include "parquet/exception.h"
#include "parquet/types.h"
namespace parquet {
namespace {
::arrow::Result<std::string> GeospatialGeoArrowCrsToParquetCrs(
- const ::arrow::rapidjson::Document& document) {
- namespace rj = ::arrow::rapidjson;
+ simdjson::ondemand::object object) {
+ auto crs_field = object["crs"];
Review Comment:
Addressed. Added regression tests as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on PR #50781:
URL: https://github.com/apache/arrow/pull/50781#issuecomment-5187150639
> I also see many RapidJSON references in [cpp/cmake_modules/ThirdpartyToolchain.cmake](https://github.com/Reranko05/arrow/blob/777999e80bbae38a4656f7536e28825ab9140355/cpp/cmake_modules/ThirdpartyToolchain.cmake). Are we ready to remove those yet? (I don't know, hence the question)
@rok RapidJSON is no longer used by Parquet after this change, so I've removed the Parquet-specific dependency. However, there are still many RapidJSON users elsewhere in Arrow (e.g. `arrow/json`, `arrow/integration`, `arrow/extension`,` arrow/flight/sql`), so I don't think we're ready to remove the `ThirdpartyToolchain` references yet.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on PR #50781:
URL: https://github.com/apache/arrow/pull/50781#issuecomment-5216228708
@wgtmac Thanks for pointing it out, I investigated it further and found that the missing `simdjson_dep` definition was indeed the cause. I've added the Meson support for simdjson (including the fallback) and updated the relevant targets. The Meson CI is now passing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #50781:
URL: https://github.com/apache/arrow/pull/50781#issuecomment-5285419087
After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit c44eca6892364e58489fe564f910c0e1c1c6cb6b.
There were no benchmark performance regressions. 🎉
The [full Conbench report](https://github.com/apache/arrow/runs/94567569971) has more details. It also includes information about 47 possible false positives for unstable benchmarks that are known to sometimes produce them.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3720135987
##########
cpp/src/parquet/reader_test.cc:
##########
@@ -1230,14 +1223,15 @@ TEST_F(TestJSONWithLocalFile, JSONOutputSortColumns) {
namespace {
::arrow::Status CheckJsonValid(std::string_view json_string) {
- rj::Document json_doc;
- constexpr auto kParseFlags = rj::kParseFullPrecisionFlag | rj::kParseNanAndInfFlag;
- json_doc.Parse<kParseFlags>(json_string.data(), json_string.length());
- if (json_doc.HasParseError()) {
- return ::arrow::Status::Invalid("JSON parse error at offset ",
- json_doc.GetErrorOffset(), ": ",
- rj::GetParseError_En(json_doc.GetParseError()));
+ simdjson::ondemand::parser parser;
+ simdjson::ondemand::document document;
+
+ auto padded_json = simdjson::padded_string(json_string);
+
+ if (auto error = parser.iterate(padded_json).get(document)) {
Review Comment:
Addressed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3713559558
##########
cpp/src/parquet/CMakeLists.txt:
##########
Review Comment:
Can we remove this yet?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "taepper (via GitHub)" <gi...@apache.org>.
taepper commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3718502214
##########
cpp/src/parquet/reader_test.cc:
##########
@@ -1230,14 +1223,15 @@ TEST_F(TestJSONWithLocalFile, JSONOutputSortColumns) {
namespace {
::arrow::Status CheckJsonValid(std::string_view json_string) {
- rj::Document json_doc;
- constexpr auto kParseFlags = rj::kParseFullPrecisionFlag | rj::kParseNanAndInfFlag;
- json_doc.Parse<kParseFlags>(json_string.data(), json_string.length());
- if (json_doc.HasParseError()) {
- return ::arrow::Status::Invalid("JSON parse error at offset ",
- json_doc.GetErrorOffset(), ": ",
- rj::GetParseError_En(json_doc.GetParseError()));
+ simdjson::ondemand::parser parser;
+ simdjson::ondemand::document document;
+
+ auto padded_json = simdjson::padded_string(json_string);
+
+ if (auto error = parser.iterate(padded_json).get(document)) {
Review Comment:
(in the case we really want to keep supporting `NaN`/`Inf` here, the tests were using json to generate test data for our Float computations so it was required. Again, it is not part of the JSON RFC so dropping support for it here is defendable, although many JSON libraries such as RapidJSON do support it)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3718478887
##########
cpp/src/parquet/meson.build:
##########
@@ -88,7 +88,7 @@ if not thrift_dep.found()
thrift_dep = thrift_proj.dependency('thrift')
endif
-parquet_deps = [arrow_dep, rapidjson_dep, thrift_dep]
+parquet_deps = [arrow_dep, thrift_dep]
Review Comment:
I'm not sure. I removed `rapidjson_dep` because Parquet no longer uses RapidJSON, but I didn't add `simdjson_dep` since the build succeeds without it. Is there a specific reason it should be added here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #50781:
URL: https://github.com/apache/arrow/pull/50781#issuecomment-5169305015
@Reranko05 let's avoid behavior changes. Perhaps we can use [simdjson::minify](https://github.com/simdjson/simdjson/blob/v4.6.4/doc/basics.md#minifying-json-strings-without-parsing)?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3732524468
##########
cpp/src/parquet/types.cc:
##########
@@ -1785,13 +1782,9 @@ namespace {
void WriteCrsKeyAndValue(const std::string_view crs, std::ostream& json) {
// There is no restriction on the crs value here, and it may contain quotes
// or backslashes that would result in invalid JSON if unescaped.
- namespace rj = ::arrow::rapidjson;
- rj::StringBuffer buffer;
- rj::Writer<rj::StringBuffer> writer(buffer);
- rj::Value v;
- v.SetString(crs.data(), static_cast<int32_t>(crs.size()));
- v.Accept(writer);
- json << R"(, "crs": )" << buffer.GetString();
+ ::arrow::json::JsonWriter writer;
+ writer.String(crs);
+ json << R"(, "crs": )" << writer.GetString().ValueUnsafe();
Review Comment:
OK. Let's do it in a separated PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3717901796
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -71,14 +112,26 @@ ::arrow::Result<std::string> GeospatialGeoArrowCrsToParquetCrs(
// If we could not detect a longitude/latitude CRS, just write the string to the
// LogicalType crs (being sure to unescape a JSON string into a regular string)
- if (json_crs.IsString()) {
- return json_crs.GetString();
- } else {
- rj::StringBuffer buffer;
- rj::Writer<rj::StringBuffer> writer(buffer);
- json_crs.Accept(writer);
- return buffer.GetString();
+ RETURN_NOT_OK(::arrow::internal::GetSimdjsonResult(crs_object.reset(),
+ "Failed to reset 'crs' object: ")
Review Comment:
Addressed. Changed it to `ResolveSimdjsonResult()`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3720130143
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -149,24 +207,42 @@ ::arrow::Result<std::shared_ptr<const LogicalType>> LogicalTypeFromGeoArrowMetad
return LogicalType::Geometry();
}
- namespace rj = ::arrow::rapidjson;
- rj::Document document;
- if (document.Parse(serialized_data.data(), serialized_data.length()).HasParseError()) {
+ simdjson::ondemand::parser parser;
+ simdjson::padded_string json(serialized_data);
+
+ simdjson::ondemand::document document;
+ if (auto error = parser.iterate(json).get(document); error != simdjson::SUCCESS) {
Review Comment:
Addressed. Added regression tests as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3720107041
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -17,52 +17,96 @@
#include "parquet/geospatial/util_json_internal.h"
+#include <simdjson.h>
#include <string>
#include "arrow/extension_type.h"
-#include "arrow/json/rapidjson_defs.h" // IWYU pragma: keep
+#include "arrow/json/json_writer_internal.h"
#include "arrow/result.h"
+#include "arrow/util/simdjson_internal.h"
#include "arrow/util/string.h"
-#include <rapidjson/document.h>
-#include <rapidjson/writer.h>
-
#include "parquet/exception.h"
#include "parquet/types.h"
namespace parquet {
namespace {
::arrow::Result<std::string> GeospatialGeoArrowCrsToParquetCrs(
- const ::arrow::rapidjson::Document& document) {
- namespace rj = ::arrow::rapidjson;
+ simdjson::ondemand::object object) {
+ auto crs_field = object["crs"];
- if (!document.HasMember("crs") || document["crs"].IsNull()) {
+ if (crs_field.error() == simdjson::NO_SUCH_FIELD) {
// Parquet GEOMETRY/GEOGRAPHY do not have a concept of a null/missing
// CRS, but an omitted one is more likely to have meant "lon/lat" than
// a truly unspecified one (i.e., Engineering CRS with arbitrary XY units)
return "";
}
- const auto& json_crs = document["crs"];
- if (json_crs.IsString() && (json_crs == "EPSG:4326" || json_crs == "OGC:CRS84")) {
- // crs can be left empty because these cases both correspond to
Review Comment:
Addressed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3720116849
##########
cpp/src/arrow/util/simdjson_internal.h:
##########
@@ -82,10 +82,11 @@ constexpr const char* JsonTypeName() {
}
template <typename T>
-Result<T> GetSimdjsonResult(simdjson::simdjson_result<T> result, std::string_view error) {
+Result<T> ResolveSimdjsonResult(simdjson::simdjson_result<T> result,
+ std::string_view error) {
T value;
if (auto error_code = std::move(result).get(value); error_code != simdjson::SUCCESS) {
- return Status::Invalid(error, simdjson::error_message(error_code));
+ return Status::Invalid(error, ": ", simdjson::error_message(error_code));
Review Comment:
Addressed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3720121915
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -17,52 +17,96 @@
#include "parquet/geospatial/util_json_internal.h"
+#include <simdjson.h>
#include <string>
#include "arrow/extension_type.h"
-#include "arrow/json/rapidjson_defs.h" // IWYU pragma: keep
+#include "arrow/json/json_writer_internal.h"
#include "arrow/result.h"
+#include "arrow/util/simdjson_internal.h"
#include "arrow/util/string.h"
-#include <rapidjson/document.h>
-#include <rapidjson/writer.h>
-
#include "parquet/exception.h"
#include "parquet/types.h"
namespace parquet {
namespace {
::arrow::Result<std::string> GeospatialGeoArrowCrsToParquetCrs(
- const ::arrow::rapidjson::Document& document) {
- namespace rj = ::arrow::rapidjson;
+ simdjson::ondemand::object object) {
+ auto crs_field = object["crs"];
- if (!document.HasMember("crs") || document["crs"].IsNull()) {
+ if (crs_field.error() == simdjson::NO_SUCH_FIELD) {
// Parquet GEOMETRY/GEOGRAPHY do not have a concept of a null/missing
// CRS, but an omitted one is more likely to have meant "lon/lat" than
// a truly unspecified one (i.e., Engineering CRS with arbitrary XY units)
return "";
}
- const auto& json_crs = document["crs"];
- if (json_crs.IsString() && (json_crs == "EPSG:4326" || json_crs == "OGC:CRS84")) {
- // crs can be left empty because these cases both correspond to
- // longitude/latitude in WGS84 according to the Parquet specification
+ ARROW_ASSIGN_OR_RAISE(auto json_crs, ::arrow::internal::ResolveSimdjsonResult(
+ crs_field, "Failed to get 'crs' field: "));
+
+ ARROW_ASSIGN_OR_RAISE(bool is_null, ::arrow::internal::IsJsonNull(json_crs));
+ if (is_null) {
return "";
- } else if (json_crs.IsObject()) {
- // Attempt to detect common PROJJSON representations of longitude/latitude and return
- // an empty crs to maximize compatibility with readers that do not implement CRS
- // support. PROJJSON stores this in the "id" member like:
- // {..., "id": {"authority": "...", "code": "..."}}
- if (json_crs.HasMember("id")) {
- const auto& identifier = json_crs["id"];
- if (identifier.HasMember("authority") && identifier.HasMember("code")) {
- if (identifier["authority"] == "OGC" && identifier["code"] == "CRS84") {
- return "";
- } else if (identifier["authority"] == "EPSG" && identifier["code"] == "4326") {
+ }
+
+ auto crs_string_result = ::arrow::internal::GetJsonAs<std::string_view>(json_crs);
+
+ if (crs_string_result.ok()) {
+ auto crs_string = *crs_string_result;
+
+ if (crs_string == "EPSG:4326" || crs_string == "OGC:CRS84") {
+ return "";
+ }
+
+ // If we could not detect a longitude/latitude CRS, just write the string to the
+ // LogicalType crs (being sure to unescape a JSON string into a regular string)
+ return std::string(crs_string);
+ }
+
+ ARROW_ASSIGN_OR_RAISE(
+ auto crs_object,
+ ::arrow::internal::GetJsonAs<simdjson::ondemand::object>(json_crs));
+
+ // Attempt to detect common PROJJSON representations of longitude/latitude and return
+ // an empty crs to maximize compatibility with readers that do not implement CRS
+ // support. PROJJSON stores this in the "id" member like:
+ // {..., "id": {"authority": "...", "code": "..."}}
+ auto id_field = crs_object["id"];
+
+ if (id_field.error() != simdjson::NO_SUCH_FIELD) {
+ ARROW_ASSIGN_OR_RAISE(auto identifier, ::arrow::internal::ResolveSimdjsonResult(
+ id_field, "Failed to get 'id' field: "));
+
+ auto authority_field = identifier["authority"];
Review Comment:
Addressed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3734165704
##########
cpp/src/parquet/types.cc:
##########
@@ -1785,13 +1782,9 @@ namespace {
void WriteCrsKeyAndValue(const std::string_view crs, std::ostream& json) {
// There is no restriction on the crs value here, and it may contain quotes
// or backslashes that would result in invalid JSON if unescaped.
- namespace rj = ::arrow::rapidjson;
- rj::StringBuffer buffer;
- rj::Writer<rj::StringBuffer> writer(buffer);
- rj::Value v;
- v.SetString(crs.data(), static_cast<int32_t>(crs.size()));
- v.Accept(writer);
- json << R"(, "crs": )" << buffer.GetString();
+ ::arrow::json::JsonWriter writer;
+ writer.String(crs);
+ json << R"(, "crs": )" << writer.GetString().ValueUnsafe();
Review Comment:
Created an issue for this. #50830
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3718052877
##########
cpp/src/parquet/meson.build:
##########
@@ -88,7 +88,7 @@ if not thrift_dep.found()
thrift_dep = thrift_proj.dependency('thrift')
endif
-parquet_deps = [arrow_dep, rapidjson_dep, thrift_dep]
+parquet_deps = [arrow_dep, thrift_dep]
Review Comment:
Why not adding simdjson equivalent?
##########
cpp/src/arrow/util/simdjson_internal.h:
##########
@@ -82,10 +82,11 @@ constexpr const char* JsonTypeName() {
}
template <typename T>
-Result<T> GetSimdjsonResult(simdjson::simdjson_result<T> result, std::string_view error) {
+Result<T> ResolveSimdjsonResult(simdjson::simdjson_result<T> result,
Review Comment:
Why do we need this rename?
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -17,52 +17,96 @@
#include "parquet/geospatial/util_json_internal.h"
+#include <simdjson.h>
#include <string>
#include "arrow/extension_type.h"
-#include "arrow/json/rapidjson_defs.h" // IWYU pragma: keep
+#include "arrow/json/json_writer_internal.h"
#include "arrow/result.h"
+#include "arrow/util/simdjson_internal.h"
#include "arrow/util/string.h"
-#include <rapidjson/document.h>
-#include <rapidjson/writer.h>
-
#include "parquet/exception.h"
#include "parquet/types.h"
namespace parquet {
namespace {
::arrow::Result<std::string> GeospatialGeoArrowCrsToParquetCrs(
- const ::arrow::rapidjson::Document& document) {
- namespace rj = ::arrow::rapidjson;
+ simdjson::ondemand::object object) {
+ auto crs_field = object["crs"];
- if (!document.HasMember("crs") || document["crs"].IsNull()) {
+ if (crs_field.error() == simdjson::NO_SUCH_FIELD) {
// Parquet GEOMETRY/GEOGRAPHY do not have a concept of a null/missing
// CRS, but an omitted one is more likely to have meant "lon/lat" than
// a truly unspecified one (i.e., Engineering CRS with arbitrary XY units)
return "";
}
- const auto& json_crs = document["crs"];
- if (json_crs.IsString() && (json_crs == "EPSG:4326" || json_crs == "OGC:CRS84")) {
- // crs can be left empty because these cases both correspond to
Review Comment:
Can we preserve the original comments?
##########
cpp/src/arrow/util/simdjson_internal.h:
##########
@@ -82,10 +82,11 @@ constexpr const char* JsonTypeName() {
}
template <typename T>
-Result<T> GetSimdjsonResult(simdjson::simdjson_result<T> result, std::string_view error) {
+Result<T> ResolveSimdjsonResult(simdjson::simdjson_result<T> result,
+ std::string_view error) {
T value;
if (auto error_code = std::move(result).get(value); error_code != simdjson::SUCCESS) {
- return Status::Invalid(error, simdjson::error_message(error_code));
+ return Status::Invalid(error, ": ", simdjson::error_message(error_code));
Review Comment:
Why do we need this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3718452083
##########
cpp/src/arrow/util/simdjson_internal.h:
##########
@@ -82,10 +82,11 @@ constexpr const char* JsonTypeName() {
}
template <typename T>
-Result<T> GetSimdjsonResult(simdjson::simdjson_result<T> result, std::string_view error) {
+Result<T> ResolveSimdjsonResult(simdjson::simdjson_result<T> result,
+ std::string_view error) {
T value;
if (auto error_code = std::move(result).get(value); error_code != simdjson::SUCCESS) {
- return Status::Invalid(error, simdjson::error_message(error_code));
+ return Status::Invalid(error, ": ", simdjson::error_message(error_code));
Review Comment:
Oh, I missed this. Thanks for pointing it out!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on PR #50781:
URL: https://github.com/apache/arrow/pull/50781#issuecomment-5175390676
cc: @kou @rok @pitrou
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #50781:
URL: https://github.com/apache/arrow/pull/50781#issuecomment-5180707735
I also see many RapidJSON references in [cpp/cmake_modules/ThirdpartyToolchain.cmake](https://github.com/Reranko05/arrow/blob/777999e80bbae38a4656f7536e28825ab9140355/cpp/cmake_modules/ThirdpartyToolchain.cmake). Are we ready to remove those yet?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #50781:
URL: https://github.com/apache/arrow/pull/50781#issuecomment-5168160672
As per [docs here](https://github.com/simdjson/simdjson/blob/master/doc/basics.md#raw-json-string-for-objects-and-arrays) you could probably use the `.reset()` in case you don't get desired CRS fields.
```cpp
// Inspect crs_object...
// If it was not a recognized lon/lat CRS:
ARROW_ASSIGN_OR_RAISE(
auto ignored,
::arrow::internal::GetSimdjsonResult(
crs_object.reset(), "Failed to reset 'crs' object: "));
ARROW_ASSIGN_OR_RAISE(
auto raw_crs,
::arrow::internal::GetSimdjsonResult(
crs_object.raw_json(), "Failed to get raw 'crs' JSON: "));
return std::string(raw_crs);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3718415940
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -17,52 +17,96 @@
#include "parquet/geospatial/util_json_internal.h"
+#include <simdjson.h>
#include <string>
#include "arrow/extension_type.h"
-#include "arrow/json/rapidjson_defs.h" // IWYU pragma: keep
+#include "arrow/json/json_writer_internal.h"
#include "arrow/result.h"
+#include "arrow/util/simdjson_internal.h"
#include "arrow/util/string.h"
-#include <rapidjson/document.h>
-#include <rapidjson/writer.h>
-
#include "parquet/exception.h"
#include "parquet/types.h"
namespace parquet {
namespace {
::arrow::Result<std::string> GeospatialGeoArrowCrsToParquetCrs(
- const ::arrow::rapidjson::Document& document) {
- namespace rj = ::arrow::rapidjson;
+ simdjson::ondemand::object object) {
+ auto crs_field = object["crs"];
- if (!document.HasMember("crs") || document["crs"].IsNull()) {
+ if (crs_field.error() == simdjson::NO_SUCH_FIELD) {
// Parquet GEOMETRY/GEOGRAPHY do not have a concept of a null/missing
// CRS, but an omitted one is more likely to have meant "lon/lat" than
// a truly unspecified one (i.e., Engineering CRS with arbitrary XY units)
return "";
}
- const auto& json_crs = document["crs"];
- if (json_crs.IsString() && (json_crs == "EPSG:4326" || json_crs == "OGC:CRS84")) {
- // crs can be left empty because these cases both correspond to
- // longitude/latitude in WGS84 according to the Parquet specification
+ ARROW_ASSIGN_OR_RAISE(auto json_crs, ::arrow::internal::ResolveSimdjsonResult(
+ crs_field, "Failed to get 'crs' field: "));
+
+ ARROW_ASSIGN_OR_RAISE(bool is_null, ::arrow::internal::IsJsonNull(json_crs));
+ if (is_null) {
return "";
- } else if (json_crs.IsObject()) {
- // Attempt to detect common PROJJSON representations of longitude/latitude and return
- // an empty crs to maximize compatibility with readers that do not implement CRS
- // support. PROJJSON stores this in the "id" member like:
- // {..., "id": {"authority": "...", "code": "..."}}
- if (json_crs.HasMember("id")) {
- const auto& identifier = json_crs["id"];
- if (identifier.HasMember("authority") && identifier.HasMember("code")) {
- if (identifier["authority"] == "OGC" && identifier["code"] == "CRS84") {
- return "";
- } else if (identifier["authority"] == "EPSG" && identifier["code"] == "4326") {
+ }
+
+ auto crs_string_result = ::arrow::internal::GetJsonAs<std::string_view>(json_crs);
+
+ if (crs_string_result.ok()) {
+ auto crs_string = *crs_string_result;
+
+ if (crs_string == "EPSG:4326" || crs_string == "OGC:CRS84") {
+ return "";
+ }
+
+ // If we could not detect a longitude/latitude CRS, just write the string to the
+ // LogicalType crs (being sure to unescape a JSON string into a regular string)
+ return std::string(crs_string);
+ }
+
+ ARROW_ASSIGN_OR_RAISE(
+ auto crs_object,
+ ::arrow::internal::GetJsonAs<simdjson::ondemand::object>(json_crs));
+
+ // Attempt to detect common PROJJSON representations of longitude/latitude and return
+ // an empty crs to maximize compatibility with readers that do not implement CRS
+ // support. PROJJSON stores this in the "id" member like:
+ // {..., "id": {"authority": "...", "code": "..."}}
+ auto id_field = crs_object["id"];
+
+ if (id_field.error() != simdjson::NO_SUCH_FIELD) {
+ ARROW_ASSIGN_OR_RAISE(auto identifier, ::arrow::internal::ResolveSimdjsonResult(
+ id_field, "Failed to get 'id' field: "));
+
+ auto authority_field = identifier["authority"];
Review Comment:
`authority_field` is consumed only after `identifier["code"]` has been accessed. In simdjson On-Demand, a field value is valid only until the next field lookup on the same object; development checks may report `OUT_OF_ORDER_ITERATION`, and using it without those checks is unsafe. Could we consume and convert `authority` before looking up `code`, and avoid retaining multiple lazy field results?
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -113,30 +169,32 @@ ::arrow::Result<std::string> MakeGeoArrowCrsMetadata(
ARROW_ASSIGN_OR_RAISE(std::string projjson_value, metadata->Get(metadata_field));
// This value should be valid JSON, but if it is not, we escape it as a string such
// that it can be inspected by the consumer of GeoArrow.
- return R"("crs": )" + EscapeCrsAsJsonIfRequired(projjson_value) +
- R"(, "crs_type": "projjson")";
+ ARROW_ASSIGN_OR_RAISE(auto escaped, EscapeCrsAsJsonIfRequired(projjson_value));
+ return R"("crs": )" + escaped + R"(, "crs_type": "projjson")";
}
}
// Pass on the string directly to GeoArrow. If the string is already valid JSON,
// insert it directly into GeoArrow's "crs" field. Otherwise, escape it and pass it as a
// string value.
- return R"("crs": )" + EscapeCrsAsJsonIfRequired(crs);
+ ARROW_ASSIGN_OR_RAISE(auto escaped, EscapeCrsAsJsonIfRequired(crs));
+
+ return R"("crs": )" + escaped;
}
-std::string EscapeCrsAsJsonIfRequired(std::string_view crs) {
- namespace rj = ::arrow::rapidjson;
- rj::Document document;
- if (document.Parse(crs.data(), crs.length()).HasParseError()) {
- rj::StringBuffer buffer;
- rj::Writer<rj::StringBuffer> writer(buffer);
- rj::Value v;
- v.SetString(crs.data(), static_cast<int32_t>(crs.size()));
- v.Accept(writer);
- return std::string(buffer.GetString());
- } else {
- return std::string(crs);
+::arrow::Result<std::string> EscapeCrsAsJsonIfRequired(std::string_view crs) {
+ simdjson::ondemand::parser parser;
+ simdjson::padded_string json(crs);
+
+ if (parser.iterate(json).error() != simdjson::SUCCESS) {
Review Comment:
`parser.iterate(json).error()` does not mean that the whole JSON value is valid. On-Demand validates only values that are consumed, and this document is never consumed here; `simdjson::minify()` also explicitly does not validate its input. As a result, malformed CRS content can be returned unescaped and then embedded as invalid GeoArrow metadata, whereas the RapidJSON implementation escaped it as a string. Could we fully parse or consume the value before deciding to return it verbatim?
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -17,52 +17,96 @@
#include "parquet/geospatial/util_json_internal.h"
+#include <simdjson.h>
#include <string>
#include "arrow/extension_type.h"
-#include "arrow/json/rapidjson_defs.h" // IWYU pragma: keep
+#include "arrow/json/json_writer_internal.h"
#include "arrow/result.h"
+#include "arrow/util/simdjson_internal.h"
#include "arrow/util/string.h"
-#include <rapidjson/document.h>
-#include <rapidjson/writer.h>
-
#include "parquet/exception.h"
#include "parquet/types.h"
namespace parquet {
namespace {
::arrow::Result<std::string> GeospatialGeoArrowCrsToParquetCrs(
- const ::arrow::rapidjson::Document& document) {
- namespace rj = ::arrow::rapidjson;
+ simdjson::ondemand::object object) {
+ auto crs_field = object["crs"];
Review Comment:
RapidJSON matched decoded object keys, but simdjson default `object["key"]` lookup does not unescape keys. Valid metadata such as `{"cr\u0073":"EPSG:3857"}` will therefore be treated as missing `crs`, and an escaped `edges` key can silently change GEOGRAPHY to GEOMETRY. Could we preserve the previous behavior by matching `field.unescaped_key()` or using a fully parsed DOM object, and add an escaped-key regression test?
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -149,24 +207,42 @@ ::arrow::Result<std::shared_ptr<const LogicalType>> LogicalTypeFromGeoArrowMetad
return LogicalType::Geometry();
}
- namespace rj = ::arrow::rapidjson;
- rj::Document document;
- if (document.Parse(serialized_data.data(), serialized_data.length()).HasParseError()) {
+ simdjson::ondemand::parser parser;
+ simdjson::padded_string json(serialized_data);
+
+ simdjson::ondemand::document document;
+ if (auto error = parser.iterate(json).get(document); error != simdjson::SUCCESS) {
Review Comment:
This only consumes the fields needed by the selected branch, so successful `iterate()` plus `get_object()` no longer guarantees that the full extension metadata is valid JSON. For example, invalid content in an unvisited field after `edges` can be accepted even though RapidJSON rejected the document before conversion. Could we fully validate the metadata before interpreting `crs` and `edges`?
##########
cpp/src/parquet/reader_test.cc:
##########
@@ -1230,14 +1223,15 @@ TEST_F(TestJSONWithLocalFile, JSONOutputSortColumns) {
namespace {
::arrow::Status CheckJsonValid(std::string_view json_string) {
- rj::Document json_doc;
- constexpr auto kParseFlags = rj::kParseFullPrecisionFlag | rj::kParseNanAndInfFlag;
- json_doc.Parse<kParseFlags>(json_string.data(), json_string.length());
- if (json_doc.HasParseError()) {
- return ::arrow::Status::Invalid("JSON parse error at offset ",
- json_doc.GetErrorOffset(), ": ",
- rj::GetParseError_En(json_doc.GetParseError()));
+ simdjson::ondemand::parser parser;
+ simdjson::ondemand::document document;
+
+ auto padded_json = simdjson::padded_string(json_string);
+
+ if (auto error = parser.iterate(padded_json).get(document)) {
Review Comment:
`CheckJsonValid()` no longer validates the full JSON output: it creates an On-Demand document but never consumes it, so only stage-1 errors are detected. This can let malformed printer output pass the test. The previous parser also intentionally enabled full precision and NaN/Inf, so the replacement should preserve that contract while actually traversing and validating the document.
##########
cpp/src/arrow/util/simdjson_internal.h:
##########
@@ -82,10 +82,11 @@ constexpr const char* JsonTypeName() {
}
template <typename T>
-Result<T> GetSimdjsonResult(simdjson::simdjson_result<T> result, std::string_view error) {
+Result<T> ResolveSimdjsonResult(simdjson::simdjson_result<T> result,
+ std::string_view error) {
T value;
if (auto error_code = std::move(result).get(value); error_code != simdjson::SUCCESS) {
- return Status::Invalid(error, simdjson::error_message(error_code));
+ return Status::Invalid(error, ": ", simdjson::error_message(error_code));
Review Comment:
`ResolveSimdjsonResult()` now inserts `": "`, but all callers still pass prefixes ending in `": "`, so errors become `Failed ...: : <simdjson error>`. Could we either remove the suffix from every caller or keep delimiter formatting in the callers only?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on PR #50781:
URL: https://github.com/apache/arrow/pull/50781#issuecomment-5188333044
I've posted several review comments (some are posted by Codex as I'm not that familiar with simdjson). Let me know what you think.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on PR #50781:
URL: https://github.com/apache/arrow/pull/50781#issuecomment-5211962671
https://github.com/apache/arrow/actions/runs/31024222689/job/92369046910?pr=50781
We need to fix meson ci due to `../../arrow/cpp/src/arrow/integration/meson.build:26:8: ERROR: Unknown variable "simdjson_dep".`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on PR #50781:
URL: https://github.com/apache/arrow/pull/50781#issuecomment-5216260166
@wgtmac Thanks for pointing it out, I have added the Meson support for simdjson and updated the relevant targets. The Meson CI is now passing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3763028884
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -17,52 +17,110 @@
#include "parquet/geospatial/util_json_internal.h"
+#include <simdjson.h>
Review Comment:
Do we need this? We have `#include "arrow/util/simdjson_internal.h"`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3717902617
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -17,52 +17,93 @@
#include "parquet/geospatial/util_json_internal.h"
+#include <simdjson.h>
#include <string>
#include "arrow/extension_type.h"
-#include "arrow/json/rapidjson_defs.h" // IWYU pragma: keep
+#include "arrow/json/json_writer_internal.h"
#include "arrow/result.h"
+#include "arrow/util/simdjson_internal.h"
#include "arrow/util/string.h"
-#include <rapidjson/document.h>
-#include <rapidjson/writer.h>
-
#include "parquet/exception.h"
#include "parquet/types.h"
namespace parquet {
namespace {
::arrow::Result<std::string> GeospatialGeoArrowCrsToParquetCrs(
- const ::arrow::rapidjson::Document& document) {
- namespace rj = ::arrow::rapidjson;
+ simdjson::ondemand::object object) {
+ auto crs_field = object["crs"];
- if (!document.HasMember("crs") || document["crs"].IsNull()) {
+ if (crs_field.error() == simdjson::NO_SUCH_FIELD) {
// Parquet GEOMETRY/GEOGRAPHY do not have a concept of a null/missing
// CRS, but an omitted one is more likely to have meant "lon/lat" than
// a truly unspecified one (i.e., Engineering CRS with arbitrary XY units)
return "";
}
- const auto& json_crs = document["crs"];
- if (json_crs.IsString() && (json_crs == "EPSG:4326" || json_crs == "OGC:CRS84")) {
- // crs can be left empty because these cases both correspond to
- // longitude/latitude in WGS84 according to the Parquet specification
+ ARROW_ASSIGN_OR_RAISE(auto json_crs, ::arrow::internal::GetSimdjsonResult(
+ crs_field, "Failed to get 'crs' field: "));
+
+ ARROW_ASSIGN_OR_RAISE(bool is_null, ::arrow::internal::IsJsonNull(json_crs));
+ if (is_null) {
return "";
- } else if (json_crs.IsObject()) {
- // Attempt to detect common PROJJSON representations of longitude/latitude and return
- // an empty crs to maximize compatibility with readers that do not implement CRS
- // support. PROJJSON stores this in the "id" member like:
- // {..., "id": {"authority": "...", "code": "..."}}
- if (json_crs.HasMember("id")) {
- const auto& identifier = json_crs["id"];
- if (identifier.HasMember("authority") && identifier.HasMember("code")) {
- if (identifier["authority"] == "OGC" && identifier["code"] == "CRS84") {
- return "";
- } else if (identifier["authority"] == "EPSG" && identifier["code"] == "4326") {
+ }
+
+ if (auto string = ::arrow::internal::GetJsonAs<std::string_view>(json_crs);
+ string.ok()) {
+ if (*string == "EPSG:4326" || *string == "OGC:CRS84") {
+ // crs can be left empty because these cases both correspond to
+ // longitude/latitude in WGS84 according to the Parquet specification
+ return "";
+ }
+
+ // If we could not detect a longitude/latitude CRS, just write the string to the
+ // LogicalType crs (being sure to unescape a JSON string into a regular string)
+ return std::string(*string);
+ }
+
+ ARROW_ASSIGN_OR_RAISE(
+ auto crs_object,
+ ::arrow::internal::GetJsonAs<simdjson::ondemand::object>(json_crs));
+
+ // Attempt to detect common PROJJSON representations of longitude/latitude and return
+ // an empty crs to maximize compatibility with readers that do not implement CRS
+ // support. PROJJSON stores this in the "id" member like:
+ // {..., "id": {"authority": "...", "code": "..."}}
+ auto id_field = crs_object["id"];
+
+ if (id_field.error() != simdjson::NO_SUCH_FIELD) {
+ ARROW_ASSIGN_OR_RAISE(auto identifier, ::arrow::internal::GetSimdjsonResult(
+ id_field, "Failed to get 'id' field: "));
+
+ auto authority_field = identifier["authority"];
+ auto code_field = identifier["code"];
+
+ if (authority_field.error() != simdjson::NO_SUCH_FIELD &&
+ code_field.error() != simdjson::NO_SUCH_FIELD) {
+ ARROW_ASSIGN_OR_RAISE(auto authority,
+ ::arrow::internal::GetSimdjsonResult(
+ authority_field, "Failed to get 'authority' field: "));
+
+ ARROW_ASSIGN_OR_RAISE(auto code, ::arrow::internal::GetSimdjsonResult(
+ code_field, "Failed to get 'code' field: "));
+
+ ARROW_ASSIGN_OR_RAISE(auto authority_string,
+ ::arrow::internal::GetJsonAs<std::string_view>(authority));
+
+ auto code_string = ::arrow::internal::GetJsonAs<std::string_view>(code);
+
+ if (code_string.ok()) {
+ if ((authority_string == "OGC" && *code_string == "CRS84") ||
+ (authority_string == "EPSG" && *code_string == "4326")) {
Review Comment:
Addressed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3717915274
##########
cpp/src/parquet/types.cc:
##########
@@ -1785,13 +1782,9 @@ namespace {
void WriteCrsKeyAndValue(const std::string_view crs, std::ostream& json) {
// There is no restriction on the crs value here, and it may contain quotes
// or backslashes that would result in invalid JSON if unescaped.
- namespace rj = ::arrow::rapidjson;
- rj::StringBuffer buffer;
- rj::Writer<rj::StringBuffer> writer(buffer);
- rj::Value v;
- v.SetString(crs.data(), static_cast<int32_t>(crs.size()));
- v.Accept(writer);
- json << R"(, "crs": )" << buffer.GetString();
+ ::arrow::json::JsonWriter writer;
+ writer.String(crs);
+ json << R"(, "crs": )" << writer.GetString().ValueUnsafe();
Review Comment:
Good point. That would require refactoring the entire `ToJSON()` implementation instead of only the `crs` field. I wasn't sure if that was in scope for this PR. Should I include that refactoring here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3717916524
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -125,18 +178,18 @@ ::arrow::Result<std::string> MakeGeoArrowCrsMetadata(
}
std::string EscapeCrsAsJsonIfRequired(std::string_view crs) {
- namespace rj = ::arrow::rapidjson;
- rj::Document document;
- if (document.Parse(crs.data(), crs.length()).HasParseError()) {
- rj::StringBuffer buffer;
- rj::Writer<rj::StringBuffer> writer(buffer);
- rj::Value v;
- v.SetString(crs.data(), static_cast<int32_t>(crs.size()));
- v.Accept(writer);
- return std::string(buffer.GetString());
- } else {
- return std::string(crs);
+ simdjson::ondemand::parser parser;
+ simdjson::padded_string json(crs);
+
+ if (parser.iterate(json).error() != simdjson::SUCCESS) {
+ ::arrow::json::JsonWriter writer;
+ writer.String(crs);
+
+ auto escaped = writer.GetString().ValueUnsafe();
Review Comment:
Addressed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3718421247
##########
cpp/src/arrow/util/simdjson_internal.h:
##########
@@ -82,10 +82,11 @@ constexpr const char* JsonTypeName() {
}
template <typename T>
-Result<T> GetSimdjsonResult(simdjson::simdjson_result<T> result, std::string_view error) {
+Result<T> ResolveSimdjsonResult(simdjson::simdjson_result<T> result,
Review Comment:
https://github.com/apache/arrow/pull/50781#discussion_r3716274006
Feedback from @kou
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "Reranko05 (via GitHub)" <gi...@apache.org>.
Reranko05 commented on code in PR #50781:
URL: https://github.com/apache/arrow/pull/50781#discussion_r3773302853
##########
cpp/src/parquet/geospatial/util_json_internal.cc:
##########
@@ -17,52 +17,110 @@
#include "parquet/geospatial/util_json_internal.h"
+#include <simdjson.h>
Review Comment:
Removed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson [arrow]
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou merged PR #50781:
URL: https://github.com/apache/arrow/pull/50781
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org