pitrou commented on code in PR #51014:
URL: https://github.com/apache/arrow/pull/51014#discussion_r3871670890
##########
cpp/src/arrow/util/simdjson_internal.h:
##########
@@ -294,6 +295,118 @@ Status VisitJsonValue(simdjson::ondemand::value value,
ObjectFn&& object_fn,
return Status::Invalid("Unreachable");
}
+inline Status PrettyPrintJsonValue(simdjson::ondemand::value value,
std::string* out,
Review Comment:
Can we please move this to `simdjson_internal.cc`? There's no reason to
inline the implement in the `.h` file.
Also, can this return `Result<std::string>`? It would be more idiomatic than
an out-pointer parameter.
##########
cpp/src/arrow/json/parser_test.cc:
##########
@@ -321,5 +321,17 @@ TEST(BlockParser, AdHoc) {
R"([{"c":true, "d": "1991-02-03"}, {"c":false, "d":"2019-04-01"}])"});
}
+TEST(JsonTest, PrettyPrintEscapesObjectKeys) {
Review Comment:
This doesn't seem like a great place for this test but I can't think of
anything better.
##########
cpp/src/arrow/json/reader_test.cc:
##########
@@ -550,10 +551,14 @@ class StreamingReaderTestBase {
auto options = GenerateOptions::Defaults();
options.null_probability = 0;
for (int i = 0; i < num_rows; ++i) {
- StringBuffer string_buffer;
- Writer writer(string_buffer);
+ Writer writer;
ABORT_NOT_OK(Generate(data_fields, engine, &writer, options));
- std::string json = string_buffer.GetString();
+
+ auto json_result = writer.GetString();
+ ABORT_NOT_OK(json_result.status());
+ auto json_view = std::move(json_result).ValueOrDie();
+ std::string json(json_view);
Review Comment:
I think you can write this more concisely as:
```suggestion
std::string json = writer.GetString().As<std::string>();
```
##########
cpp/src/arrow/util/simdjson_internal.h:
##########
@@ -27,6 +27,7 @@
#include <simdjson.h>
+#include "arrow/json/json_writer_internal.h"
Review Comment:
We shouldn't be including `arrow/json` IMHO. Let's wait for
https://github.com/apache/arrow/pull/50990 to be merged perhaps?
##########
cpp/src/arrow/json/test_common.h:
##########
@@ -258,14 +261,26 @@ inline static Status ParseFromString(ParseOptions
options, string_view src_str,
}
static inline std::string PrettyPrint(string_view one_line) {
- rj::Document document;
+ simdjson::ondemand::parser parser;
// Must pass size to avoid ASAN issues.
- document.Parse(one_line.data(), one_line.size());
- rj::StringBuffer sb;
- rj::PrettyWriter<rj::StringBuffer> writer(sb);
- document.Accept(writer);
- return sb.GetString();
+ simdjson::padded_string json(one_line.data(), one_line.size());
Review Comment:
Why not use
[`fractured_json_string`](https://simdjson.github.io/simdjson/namespacesimdjson.html#a64861b6d9d98dc3c85683b50cc6d224a)?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]