Skip to content
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: jq support #1801

Closed
wants to merge 19 commits into from
Closed

feat: jq support #1801

wants to merge 19 commits into from

Conversation

ssddOnTop
Copy link
Member

@ssddOnTop ssddOnTop commented Apr 27, 2024

Issue Reference(s):
Fixes #1321
/claim #1321

Summary by CodeRabbit

  • New Features

    • Enhanced the GraphQL schema to simplify the user query argument structure.
    • Introduced new evaluation methods across various modules to enhance processing capabilities.
    • Updated mustache template syntax for improved clarity and consistency in variable references.
  • Bug Fixes

    • Adjusted key-value pair transformations to ensure correct string conversion in headers management.
  • Documentation

    • Updated internal test cases to align with the new mustache syntax and evaluation methods.

@github-actions github-actions bot added the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label Apr 27, 2024
Copy link
Contributor

coderabbitai bot commented Apr 27, 2024

Warning

Rate Limit Exceeded

@ssddOnTop has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 18 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 36c4e48 and 4f7122d.

Walkthrough

The updates primarily focus on integrating JAQ, a JSON transformation DSL, as an alternative to mustache templates across various modules. This involves adding new methods for evaluating JAQ filters, modifying mustache syntax, and updating related functionalities in structs and methods to support more complex JSON manipulations.

Changes

Files Summary
benches/request_template_bench.rs, src/grpc/request_template.rs, src/http/request_template.rs Added evaluate method to handle JAQ filters.
examples/jsonplaceholder.graphql, src/serde_value_ext.rs Updated mustache template syntax to include a leading dot.
src/config/reader_context.rs, src/path.rs Added imports and methods for JAQ filter evaluation.
src/helpers/... Adjustments in functions and test cases to support string transformations and validations.
src/mustache.rs Comprehensive restructuring to incorporate JAQ filters and update methods accordingly.

Assessment against linked issues

Objective Addressed Explanation
Using JAQ as an alternative to mustache templates (#1321)
Implement an evaluator for JSON-like objects using JAQ (#1321)
Parse and store JAQ templates at compile time (#1321) It's unclear if JAQ templates are compiled and stored at compile time as the changes primarily focus on runtime evaluations.
Write benchmarks comparing existing and new implementations (#1321) Benchmarks comparing the performance of mustache and JAQ implementations are not included in the changes.

The changes make significant strides towards integrating JAQ for JSON transformations, enhancing the flexibility and capabilities of the template system. However, some aspects like benchmarking and compile-time processing of JAQ templates need further clarification or implementation.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ssddOnTop ssddOnTop changed the title Feat/jq support1 feat: jacques support Apr 27, 2024
src/path.rs Outdated Show resolved Hide resolved
Copy link

codecov bot commented Apr 27, 2024

Codecov Report

Attention: Patch coverage is 81.25000% with 84 lines in your changes are missing coverage. Please review.

Project coverage is 86.60%. Comparing base (c7a25cb) to head (4f7122d).
Report is 2 commits behind head on main.

Files Patch % Lines
src/mustache.rs 72.33% 57 Missing ⚠️
src/path.rs 0.00% 9 Missing ⚠️
src/config/reader_context.rs 0.00% 6 Missing ⚠️
src/grpc/request_template.rs 0.00% 6 Missing ⚠️
src/http/request_template.rs 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1801      +/-   ##
==========================================
- Coverage   86.89%   86.60%   -0.29%     
==========================================
  Files         156      156              
  Lines       15829    16078     +249     
==========================================
+ Hits        13754    13924     +170     
- Misses       2075     2154      +79     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

src/mustache.rs Outdated Show resolved Hide resolved
src/mustache.rs Outdated Show resolved Hide resolved
src/http/request_template.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Out of diff range and nitpick comments (1)
src/mustache.rs (1)

51-66: Clarify the behavior when the rendered value is empty.

Consider adding documentation or unit tests to explain that evaluate is used as a fallback when the rendered value is empty. This helps maintain clarity and ensures that future maintainers or users of this method understand its behavior.

src/path.rs Outdated Show resolved Hide resolved
src/path.rs Outdated Show resolved Hide resolved
src/mustache.rs Outdated Show resolved Hide resolved
src/mustache.rs Outdated Show resolved Hide resolved
@ssddOnTop ssddOnTop mentioned this pull request Apr 27, 2024
@ssddOnTop ssddOnTop added the ci: benchmark Runs benchmarks label Apr 27, 2024
Copy link

github-actions bot commented Apr 27, 2024

🐰Bencher

ReportWed, May 1, 2024 at 13:52:15 UTC
Projecttailcall
Branch1801/merge
Testbedbenchmarking-runner
Click to view all benchmark results
BenchmarkLatencyLatency Results
nanoseconds (ns) | (Δ%)
Latency Upper Boundary
nanoseconds (ns) | (%)
group_by✅ (view plot)607.20 (-0.45%)635.42 (95.56%)
input/args.missing✅ (view plot)24.93 (-1.60%)26.23 (95.01%)
input/args.nested.existing✅ (view plot)56.13 (-0.18%)58.28 (96.31%)
input/args.nested.missing✅ (view plot)38.55 (-1.43%)39.98 (96.43%)
input/args.root✅ (view plot)53.22 (+0.66%)55.00 (96.76%)
input/headers.existing✅ (view plot)31.39 (-0.44%)31.81 (98.67%)
input/headers.missing✅ (view plot)30.05 (-1.39%)31.23 (96.21%)
input/value.missing✅ (view plot)23.09 (-2.26%)25.08 (92.04%)
input/value.nested.existing✅ (view plot)40.22 (-1.94%)42.78 (94.02%)
input/value.nested.missing✅ (view plot)35.25 (-1.45%)37.36 (94.36%)
input/value.root✅ (view plot)38.73 (+0.29%)39.85 (97.19%)
input/vars.existing✅ (view plot)8.36 (-1.15%)8.86 (94.33%)
input/vars.missing✅ (view plot)8.06 (-0.86%)8.95 (90.06%)
jq_bench✅ (view plot)2,302.80
mustache_bench✅ (view plot)279.30
test_batched_body✅ (view plot)1,776,700.00 (+2.71%)1,808,671.46 (98.23%)
test_data_loader✅ (view plot)473,150.00 (+0.16%)489,698.58 (96.62%)
with_mustache_expressions✅ (view plot)1,144.40 (-1.74%)1,217.95 (93.96%)
with_mustache_literal✅ (view plot)729.32 (+0.72%)760.15 (95.94%)

Bencher - Continuous Benchmarking
View Public Perf Page
Docs | Repo | Chat | Help

@tusharmath tusharmath changed the title feat: jacques support feat: jq support Apr 27, 2024
src/path.rs Outdated Show resolved Hide resolved
@tusharmath tusharmath marked this pull request as draft April 27, 2024 11:49
@ssddOnTop ssddOnTop marked this pull request as ready for review May 1, 2024 10:57
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

src/mustache.rs Outdated Show resolved Hide resolved
src/mustache.rs Outdated Show resolved Hide resolved
src/grpc/request_template.rs Show resolved Hide resolved
src/mustache.rs Outdated Show resolved Hide resolved
@tusharmath tusharmath marked this pull request as draft May 1, 2024 12:20
@ssddOnTop ssddOnTop marked this pull request as ready for review May 1, 2024 13:13
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

benches/bench_jq_and_mustache.rs Show resolved Hide resolved
src/mustache.rs Show resolved Hide resolved
src/mustache.rs Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Out of diff range and nitpick comments (1)
src/mustache.rs (1)

Line range hint 44-53: The parse method's fallback mechanism to treat the input as a literal if parsing fails is a good safeguard. However, consider logging the error for debugging purposes.

+            Err(e) => {
+                log::error!("Failed to parse mustache template: {}", e);
+                Ok(Mustache::from(vec![Segment::Literal(str.to_string())]))
+            },

src/mustache.rs Show resolved Hide resolved
src/mustache.rs Show resolved Hide resolved
Comment on lines +221 to +246
fn parse_jq(input: &str) -> IResult<&str, Option<jaq_interpret::Filter>> {
let (input, _) = nom::character::complete::multispace0(input)?;
let (input, _) = tag("{{")(input)?;
let (input, _) = nom::character::complete::multispace0(input)?;
let (input, _) = tag("jq:")(input)?;
let (input, _) = nom::character::complete::multispace0(input)?;
let (input, filter) = take_until("}}")(input)?;
let filter = filter.trim();
let mut defs = jaq_interpret::ParseCtx::new(vec![]);
defs.insert_natives(jaq_core::core());
defs.insert_defs(jaq_std::std());

let (filter, errs) = jaq_parse::parse(filter, jaq_parse::main());
let _err_str = errs
.iter()
.map(|v| v.to_string())
.collect::<Vec<String>>()
.join("\n");
if !errs.is_empty() || filter.is_none() {
return Err(nom::Err::Error(nom::error::Error::new(
"failed to parse jq", // TODO: fix ownership issue and return _err_str
nom::error::ErrorKind::Tag,
)));
}
let filter = defs.compile(filter.unwrap());
Ok((input, Some(filter)))
Copy link
Contributor

Choose a reason for hiding this comment

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

The parse_jq function's error handling could be improved by including the actual error messages collected, which would aid in diagnosing parse failures.

+            "failed to parse jq", // TODO: fix ownership issue and return _err_str
+            _err_str,

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
fn parse_jq(input: &str) -> IResult<&str, Option<jaq_interpret::Filter>> {
let (input, _) = nom::character::complete::multispace0(input)?;
let (input, _) = tag("{{")(input)?;
let (input, _) = nom::character::complete::multispace0(input)?;
let (input, _) = tag("jq:")(input)?;
let (input, _) = nom::character::complete::multispace0(input)?;
let (input, filter) = take_until("}}")(input)?;
let filter = filter.trim();
let mut defs = jaq_interpret::ParseCtx::new(vec![]);
defs.insert_natives(jaq_core::core());
defs.insert_defs(jaq_std::std());
let (filter, errs) = jaq_parse::parse(filter, jaq_parse::main());
let _err_str = errs
.iter()
.map(|v| v.to_string())
.collect::<Vec<String>>()
.join("\n");
if !errs.is_empty() || filter.is_none() {
return Err(nom::Err::Error(nom::error::Error::new(
"failed to parse jq", // TODO: fix ownership issue and return _err_str
nom::error::ErrorKind::Tag,
)));
}
let filter = defs.compile(filter.unwrap());
Ok((input, Some(filter)))
fn parse_jq(input: &str) -> IResult<&str, Option<jaq_interpret::Filter>> {
let (input, _) = nom::character::complete::multispace0(input)?;
let (input, _) = tag("{{")(input)?;
let (input, _) = nom::character::complete::multispace0(input)?;
let (input, _) = tag("jq:")(input)?;
let (input, _) = nom::character::complete::multispace0(input)?;
let (input, filter) = take_until("}}")(input)?;
let filter = filter.trim();
let mut defs = jaq_interpret::ParseCtx::new(vec![]);
defs.insert_natives(jaq_core::core());
defs.insert_defs(jaq_std::std());
let (filter, errs) = jaq_parse::parse(filter, jaq_parse::main());
let _err_str = errs
.iter()
.map(|v| v.to_string())
.collect::<Vec<String>>()
.join("\n");
if !errs.is_empty() || filter.is_none() {
return Err(nom::Err::Error(nom::error::Error::new(
"failed to parse jq", // TODO: fix ownership issue and return _err_str
_err_str,
nom::error::ErrorKind::Tag,
)));
}
let filter = defs.compile(filter.unwrap());
Ok((input, Some(filter)))

@ssddOnTop ssddOnTop closed this May 2, 2024
@ssddOnTop ssddOnTop deleted the feat/jq-support1 branch May 2, 2024 15:18
@tusharmath
Copy link
Contributor

/tip 300$

Copy link

algora-pbc bot commented May 24, 2024

🎉🎈 @ssddOnTop has been awarded $300! 🎈🎊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 Bounty claim ci: benchmark Runs benchmarks 💰 Rewarded type: feature Brand new functionality, features, pages, workflows, endpoints, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using JAQ as an alternative to mustache templates
3 participants