Skip to content

Conversation

@rayangler
Copy link
Contributor

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Sep 16, 2020

Codecov Report

Merging #724 into master will decrease coverage by 1.65%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #724      +/-   ##
==========================================
- Coverage   94.31%   92.65%   -1.66%     
==========================================
  Files         357      357              
  Lines       18663    20052    +1389     
==========================================
+ Hits        17602    18580     +978     
- Misses       1061     1472     +411     
Impacted Files Coverage Δ
src/bsoncxx/json.cpp 91.11% <100.00%> (-0.56%) ⬇️
src/bsoncxx/test/json.cpp 100.00% <100.00%> (ø)
src/mongocxx/test/client_side_encryption.cpp 67.01% <0.00%> (-30.69%) ⬇️
src/mongocxx/test_util/client_helpers.cpp 65.23% <0.00%> (-24.15%) ⬇️
src/mongocxx/test/spec/monitoring.cpp 55.71% <0.00%> (-8.58%) ⬇️
src/mongocxx/instance.cpp 81.15% <0.00%> (-4.21%) ⬇️
src/mongocxx/private/change_stream.hh 93.65% <0.00%> (-3.97%) ⬇️
src/mongocxx/change_stream.cpp 92.30% <0.00%> (-2.82%) ⬇️
src/bsoncxx/document/value.cpp 62.50% <0.00%> (-2.50%) ⬇️
... and 35 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 7ccc2d4...641e6b3. Read the comment docs.

@rayangler rayangler marked this pull request as ready for review September 16, 2020 18:06
Copy link
Contributor

@samantharitter samantharitter left a comment

Choose a reason for hiding this comment

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

These code changes look pretty good, just a few comments!

But: I have some questions about whether this is a useful thing to add to the driver. Did a request for this feature come from the community? Maybe @bazile-clyde knows?

Since this option can't take a JSON representation mode, it's a little less useful than the to_json() method without really being much quicker or shorter to type. Also I don't think the UDL syntax is super widely known, so I'm not sure people would use this unless it was a specific community-requested feature. I'm not sure it's actually worth us committing and then supporting this.

}

document::value BSONCXX_CALL operator"" _bson(const char* str, size_t len) {
// len isn't used, but it is required for the UDL to use a char*
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can get around this by changing the signature so it does not name the len variable:
document::value BSONCXX_CALL operator"" _bson(const char* str, size_t) {...}

But also, it looks like there should be a signature possible that just takes (const char*) according to this page, did you have trouble implementing that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll try it with document::value BSONCXX_CALL operator"" _bson(const char* str, size_t) {...}! Thanks for letting me know you could do that.

I originally tried just using (const char*) but it's not an applicable literal operator. On that page, there is a list of accepted parameters and it lists (const char*) as being only used:

as fallbacks for integer and floating-point user-defined literals

BSONCXX_API document::value BSONCXX_CALL from_json(stdx::string_view json);

///
/// Constructs a new document::value from the provided JSON text
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, please add a period at the end of the sentence

R"({ "number" : { "$numberInt" : "42" }, "bin" : { "$binary" : { "base64": "ZGVhZGJlZWY=", "subType" : "04" } } })");
}

TEST_CASE("UDL _bson works like from_json()") {
Copy link
Contributor

Choose a reason for hiding this comment

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

For completeness' sake, please add a test for the empty document "{}"

@bazile-clyde
Copy link
Contributor

bazile-clyde commented Sep 17, 2020

These code changes look pretty good, just a few comments!

But: I have some questions about whether this is a useful thing to add to the driver. Did a request for this feature come from the community? Maybe @bazile-clyde knows?

Since this option can't take a JSON representation mode, it's a little less useful than the to_json() method without really being much quicker or shorter to type. Also I don't think the UDL syntax is super widely known, so I'm not sure people would use this unless it was a specific community-requested feature. I'm not sure it's actually worth us committing and then supporting this.

@samantharitter This came out of the usability requests from the engineers that worked on genny as a nice to have. There are also a few tickets that point to nlohmann/JSON as a model for easily creating documents. One of the simpler ways to generate JSON in that library is also a UDL. As far as how widely known UDLs are, I'm not sure. Strings, dates, numeric types, etc. in the standard library all have them. So they aren't hidden. Is it worth committing and supporting? I think so. It's just a wrapper function. So about 3 lines of code for quick usability improvement. With all of the complaints we've received about how difficult it is to create BSON documents, I don't see why not.

Copy link
Contributor

@samantharitter samantharitter left a comment

Choose a reason for hiding this comment

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

LGTM! @bazile-clyde thank you for clarifying the history of this ticket, sounds like people will use it!

Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

Looks good! Just a request for another test case and removal of extra string length calculation.

@rayangler rayangler requested a review from kevinAlbs September 23, 2020 21:33
Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

LGTM! The failures on travis are unrelated.

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.

5 participants