Implementation of all JSONLogic operators#65
Conversation
Signed-off-by: Marcin Olko <molko@google.com>
Signed-off-by: Marcin Olko <molko@google.com>
Signed-off-by: Marcin Olko <molko@google.com>
Signed-off-by: Marcin Olko <molko@google.com>
Signed-off-by: Marcin Olko <molko@google.com>
Signed-off-by: Marcin Olko <molko@google.com>
Signed-off-by: Marcin Olko <molko@google.com>
|
/gemini review |
Summary of ChangesHello @m-olko, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the JSON logic evaluation capabilities by integrating a wide array of new operators across logical, numeric, string, and array categories. It also introduces a more robust error handling mechanism using Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a significant enhancement to the JSON logic evaluator, adding a wide range of operators for data access, logic, numeric computations, and string manipulations. The transition to using absl::StatusOr for error handling is a great improvement for robustness.
My review focuses on a few areas to further improve consistency and correctness:
- Error Handling: There's an inconsistency in how errors are propagated. In some cases, they are swallowed and converted to
null, while in others, the status is passed up. Consistently propagating the status, as highlighted by the rule regardingabsl::StatusOrpropagation, would make debugging easier. - Code Clarity: Some small improvements can be made for code clarity, such as replacing a generic
catch(...)and using more idiomatic C++ for loops. - API Contract: A comment regarding the API for operator functions seems to be out of sync with the implementation, which could lead to confusion.
Overall, this is a very solid contribution with well-structured code, especially the Number class for handling numeric operations. The suggested changes are aimed at making the implementation even more robust and maintainable.
There was a problem hiding this comment.
Code Review
This pull request implements a wide range of operators for the JsonLogic evaluator, including data access, logic, numeric, string, and array operations. The implementation correctly transitions to using absl::StatusOr for robust error handling throughout the operator functions. My review focuses on ensuring correct error propagation, improving code clarity, and addressing potential issues. I've identified several critical compilation errors related to incorrect absl::StatusOr return types and a high-severity issue where error statuses are being suppressed, which directly align with the rule regarding absl::StatusOr error propagation. Additionally, I've provided suggestions to improve code conciseness and adhere to best practices like avoiding catch(...).
Signed-off-by: Marcin Olko <molko@google.com>
Signed-off-by: Marcin Olko <molko@google.com>
Signed-off-by: Marcin Olko <molko@google.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request is a significant feature addition, implementing a wide range of operators for the JsonLogic evaluator, including data access, logical, numeric, string, and array operations. The code is well-structured, with new operators organized into separate files and a robust Number class for handling various numeric types. My review identifies a few areas for improvement: a potential bug in large unsigned number arithmetic, a suggestion to enhance error handling robustness by using more specific exception catches, and recommendations to align the behavior of equality operators with the reference implementation for certain edge cases to ensure predictability.
Signed-off-by: Marcin Olko <molko@google.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive set of JsonLogic operators. The implementation is extensive and aligns well with the standard json-logic specification. The code is well-structured. My review includes suggestions to enhance robustness and correctness, particularly regarding absl::StatusOr error propagation and numeric operations.
| if (rhs_val == 0) { | ||
| return absl::InvalidArgumentError("Modulo by zero"); | ||
| } | ||
| return Number(lhs_val % rhs_val); |
There was a problem hiding this comment.
The current implementation of integer modulo using the % operator can produce incorrect results for mixed signed and unsigned integer types due to C++'s integer promotion rules. For instance, an operation like -1 % 5u would evaluate incorrectly because the signed -1 is promoted to a large unsigned value before the modulo operation.
To ensure correct behavior across all integer types, it's safer to handle mixed-sign cases by promoting to floating-point numbers and using std::fmod. This prevents unexpected outcomes from implicit type promotions.
if (rhs_val == 0) {
return absl::InvalidArgumentError("Modulo by zero");
}
if constexpr (std::is_signed_v<decltype(lhs_val)> !=
std::is_signed_v<decltype(rhs_val)>) {
return Number(std::fmod(static_cast<double>(lhs_val),
static_cast<double>(rhs_val)));
} else {
return Number(lhs_val % rhs_val);
}|
The PR is still marked as a draft - is it ready for review? |
Sorry, I missed that. Yes, it is ready for review. |
Signed-off-by: Marcin Olko <molko@google.com>
Signed-off-by: Marcin Olko <molko@google.com>
|
FYI, This is the information from |
Signed-off-by: Marcin Olko <molko@google.com>
Signed-off-by: Marcin Olko <molko@google.com>
Signed-off-by: Marcin Olko <molko@google.com>
Signed-off-by: Marcin Olko <molko@google.com>
| const nlohmann::json& data, | ||
| std::string_view op_name) { | ||
| auto resolved_res = eval.Apply(values, data); | ||
| if (!resolved_res.ok()) return resolved_res.status(); |
There was a problem hiding this comment.
I removed as much as possible now, but in the Number object, those auto allow for easily templating lambdas. In C++20 you can have Explicit template paramter list for lambdas, but in C++17 you either need to use auto, or create code with much more boilerplate, so I chose the first option. I think in this Number setup, it is quite readable what the code is trying to accomplish.
Signed-off-by: Marcin Olko <molko@google.com>
This PR
Sorry for such huge commit, I experimented with antigravity and still need to learn.
Implements all of the operators for JSONLogic engine, co-authored by antigravity. All of the operators were then checked manually by me and improved for better integration with our codebase and introperability.
Additionally after @tangenti suggestion, added json_logic cli for easier testing and validation.
Related Issues
Fixes #32
Fixes #33
Fixes #34
Fixes #35
Fixes #36
Notes
Result for
./check_progress:How to test