Skip to content

ARROW-3982: [C++] Allow "binary" input in simple JSON format - #3222

Closed
pitrou wants to merge 1 commit into
apache:masterfrom
pitrou:ARROW-3982-json-simple-binary
Closed

ARROW-3982: [C++] Allow "binary" input in simple JSON format#3222
pitrou wants to merge 1 commit into
apache:masterfrom
pitrou:ARROW-3982-json-simple-binary

Conversation

@pitrou

@pitrou pitrou commented Dec 19, 2018

Copy link
Copy Markdown
Member

Since rapidjson doesn't validate UTF8 by default, we can represent arbitrary binary bytes in the JSON input (bytes < 0x20 have to be represented as unicode escapes).

@codecov-io

codecov-io commented Dec 19, 2018

Copy link
Copy Markdown

Codecov Report

Merging #3222 into master will increase coverage by 1.14%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3222      +/-   ##
==========================================
+ Coverage   88.52%   89.67%   +1.14%     
==========================================
  Files         536      478      -58     
  Lines       72407    68438    -3969     
==========================================
- Hits        64099    61371    -2728     
+ Misses       8203     7067    -1136     
+ Partials      105        0     -105
Impacted Files Coverage Δ
cpp/src/arrow/pretty_print-test.cc 100% <100%> (ø) ⬆️
cpp/src/arrow/ipc/json-simple-test.cc 100% <100%> (ø) ⬆️
cpp/src/arrow/ipc/json-simple.cc 99.15% <100%> (+0.08%) ⬆️
cpp/src/arrow/csv/column-builder.cc 95.45% <0%> (-1.95%) ⬇️
cpp/src/plasma/thirdparty/ae/ae.c 71.09% <0%> (-0.95%) ⬇️
go/arrow/array/table.go
go/arrow/math/uint64_amd64.go
go/arrow/internal/testing/tools/bool.go
go/arrow/internal/bitutil/bitutil.go
... and 55 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2ab97bc...5aaa5ed. Read the comment docs.

@fsaintjacques fsaintjacques left a comment

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.

LGTM, minor style refactor proposed.

Comment thread cpp/src/arrow/ipc/json-simple.cc Outdated

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.

I'd refactor this function with a simple switch (if possible?) on Json type and hide the string_view parsing in a static inline function.

switch(json_type) {
  case Json::NULL: return AppendNull();
  case Json::STRING: {
    util::string_view view;
    ARROW_RETURN_NOT_OK(JsonStringToViewOfFixedSize(json_obj, fixed_size, &view));
    return builder_->Append(view);
  }
  default: return Status::Invalid(...);
}

This is a style preference, but I think it improves reading since there's less control flow involved.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The current idiom (a chain of ifs) is used elsewhere in the module, though. So we'd have to change other occurrences as well. IMHO there's not much benefit.

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.

I think it's OK to leave the code as is since it's similar to the rest of the file. If future refactoring is needed then whoever is working on it is free to do this code scrubbing

@wesm wesm left a comment

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.

+1

Comment thread cpp/src/arrow/ipc/json-simple.cc Outdated

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.

I think it's OK to leave the code as is since it's similar to the rest of the file. If future refactoring is needed then whoever is working on it is free to do this code scrubbing

@wesm

wesm commented Dec 20, 2018

Copy link
Copy Markdown
Member

Hm looks like this got touched by ce9c6e3. I will rebase quickly

Since rapidjson doesn't validate UTF8 by default, we can represent many
arbitrary binary bytes (except control characters < 0x20) in the JSON input.
@wesm
wesm force-pushed the ARROW-3982-json-simple-binary branch from de36a89 to 5aaa5ed Compare December 20, 2018 19:37
if (json_obj.IsString()) {
auto view = util::string_view(json_obj.GetString(), json_obj.GetStringLength());
if (view.length() != static_cast<size_t>(builder_->byte_width())) {
std::stringstream ss;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This can be simplified now :-)

@wesm wesm closed this in 1a86ab5 Dec 20, 2018
@pitrou
pitrou deleted the ARROW-3982-json-simple-binary branch December 21, 2018 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants