Reranko05 commented on code in PR #50945:
URL: https://github.com/apache/arrow/pull/50945#discussion_r3886484120
##########
cpp/src/arrow/json/chunker.cc:
##########
@@ -124,40 +115,76 @@ namespace {
// and uses actual JSON parsing to delimit them.
class ParsingBoundaryFinder : public BoundaryFinder {
public:
- Status FindFirst(string_view partial, string_view block, int64_t* out_pos)
override {
- auto length = ConsumeWholeObject(MultiStringStream({partial, block}));
+ Status FindFirst(std::string_view partial, std::string_view block,
+ int64_t* out_pos) override {
+ std::string combined;
+ combined.reserve(partial.size() + block.size());
+ combined.append(partial);
+ combined.append(block);
+
+ const size_t start = ConsumeWhitespace(combined);
+ if (start < combined.size() && combined[start] != '{' && combined[start]
!= '[') {
+ return Status::Invalid("JSON parse error: Invalid value");
+ }
+
+ const auto length = ConsumeWholeObject(combined);
+
if (length == string_view::npos) {
*out_pos = -1;
} else if (ARROW_PREDICT_FALSE(length < partial.size())) {
- return Status::Invalid("JSON chunk error: invalid data at end of
document");
+ return Status::Invalid("JSON parse error: Invalid value");
} else {
DCHECK_LE(length, partial.size() + block.size());
*out_pos = static_cast<int64_t>(length - partial.size());
}
+
return Status::OK();
}
Status FindLast(std::string_view block, int64_t* out_pos) override {
const size_t block_length = block.size();
size_t consumed_length = 0;
+
+ if (block_length > 0) {
+ const size_t start = ConsumeWhitespace(block);
+ if (start < block.size() && block[start] != '{' && block[start] != '[') {
+ return Status::Invalid("JSON parse error: Invalid value");
+ }
+ }
+
while (consumed_length < block_length) {
- rj::MemoryStream ms(reinterpret_cast<const char*>(block.data()),
block.size());
- using InputStream = rj::EncodedInputStream<rj::UTF8<>, rj::MemoryStream>;
- auto length = ConsumeWholeObject(InputStream(ms));
+ const auto length = ConsumeWholeObject(block);
+
if (length == string_view::npos || length == 0) {
- // found incomplete object or block is empty
+ const size_t start = ConsumeWhitespace(block);
+
+ if (start < block.size()) {
+ const char first_char = block[start];
+
+ if (first_char != '{' && first_char != '[') {
+ const size_t remaining_len = block.size() - start;
+
+ if (remaining_len > 1 || (first_char != '}' && first_char != ']'))
{
+ return Status::Invalid("JSON parse error: Invalid value");
+ }
+ }
+ }
Review Comment:
Added comments.
--
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]