New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add format
ReQL command
#7066
base: main
Are you sure you want to change the base?
Conversation
Is it going to be I would expect it to support non-string values and use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some bugs, and I think the treatment of format strings with unmatched curly braces is bad.
You wrote format or FORMAT the whole time in the code, which is why I'm asking. I think r.format would be fine. |
Thank you for the review, @srh . I'll go through the suggestions in the upcoming days. Also, I'll use the r.format version instead of r.fmt. That seems a bit more correct to me. |
@srh except coercing all comments are addressed. The error message wording is probably not the best, but I'm opened for any suggestions.
Although the original proposal was Regarding the coercing
datum_t field = datum.get_field(datum_string_t{param_name});
r.expr(field).coerce_to("STRING") Update: I'm going to update the PR tomorrow with the latest changes and adjusted polyglot tests |
ce3938a
to
509b19e
Compare
509b19e
to
5abe8e0
Compare
Now, this is ready for review. |
6153155
to
a30959f
Compare
d20e82d
to
a0da68b
Compare
We might also want to reserve a character for use in format strings for use in specifying how the data is formatted. C# uses We might also want to reserve |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Const reference nitpicking.
What do you think nested fields might look like? Maybe we should reserve an escape or quoting character that could be used for field names. |
I had some time today to think about it, though I couldn't come up with a better idea. I think there are two questions:
The original proposal was to have a string replacement like this: // Replace the placeholder with string representation
r.format("Simple formatting: {x}", {"x": "}) To define formatting, we could use the // Format the replacement as a floating point number v1
r.format("Temperature: {temp%f.2}", {temp: 32.123})
// Format the replacement as a floating point number v2
r.format("Temperature: {temp:f.2}", {temp: 32.123})
// Format the replacement as a floating point number v3
r.format("Temperature: {temp,f.2}", {temp: 32.123}) Out of the three the third variant, using
If I understand correctly, this would be the usage example (assuming the subfield access character is // Replace the placeholder with string representation
r.format("Simple formatting: {x.y}", {x: {y: 1}}) Well, I would not support this. It could bring too many edge cases to the table. Consider the following example: r.format("Simple formatting: {x.y}", {"x.y": 1}) In this case, the key has the access character ( r.format("Simple formatting: {x.y}", {"x.y": {y: 1}}) What would we render here? The key is I would simply say that nested field's shouldn't be allowed as of now. If someone brings a proposal for solving all issues mentioned above, we could consider that, but I don't have a good proposal for solving the issue. I went ahead and reserved the |
8e79795
to
121957d
Compare
FTR: Before we merge the Python driver must be adjusted too. |
0a3b8af
to
70654fa
Compare
779b734
to
bfcddfd
Compare
Add basic string formatting to ReQL and bump polyglot test target to newer target versions. Signed-off-by: Gabor Boros <gabor.brs@gmail.com>
Signed-off-by: Gabor Boros <gabor.brs@gmail.com>
bfcddfd
to
6746820
Compare
The PR is rebased; I'll finish the PR after the next 2.4.x release. Basically, the test-runner and related python code must be bumped to work nicely with Python3 and we are good to go. |
@srh If I would want to fix the Python tests to work with the new driver implementation and Python 3, I would at least 4x the PRs size with somewhat irrelevant changes. How about the following?
We already discussed the second one, but wanted to bring into your attention again as I've seen your plans to release a new 2.4.x version. |
@gabor-boros I am hoping to get FreeBSD-related compilation fixes merged before forking the branches. |
@srh 👌I'll wait for that to not interfere |
Just reminding myself: after we break off the Python/test code changes and merge these, we will want to
|
Description
This PR resolves #3353 by adding the mentioned
r.format
command. The command formats the template string, passed as the first parameter, using the object provided as the second parameter.Related PRs
format
ReQL command docs#1332Limitations
The object must havestring
keys andstring
values.Questions
Should we supportint
anddouble
in the object? If yes, what would be the expected way of lexical casting of doubles to strings withouth adding extra trailing zeros or truncating the doubles?Leftovers
2.4.x
branch before merging and rename the current one tomain
The drivers shouldn't release
format
support until 2.5.0.format
command rethinkdb-javascript#14format
rethinkdb-ruby#28format
in the Java driver (cc: @adriantodt)Other (maintained) drivers:
format
in the Go driver (cc: @CMogilko)format
in the Typescript driver (cc: @atassis)