-
Notifications
You must be signed in to change notification settings - Fork 17
Adds jq command
#193
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
Adds jq command
#193
Conversation
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.
Amazing! Thanks for laying the groundwork here. What an excellent library jaq is. This is a great starter, and we can incrementally fill in the todos.
It is reading the whole stream into memory though, isn't it?
| let mut reader = Reader::new(AnyEncoding, input.into_source())?; | ||
| let input_elements = reader.read_all_elements()?; | ||
| let ion_stream_as_element = List::from(input_elements).into(); | ||
|
|
||
| let inputs = RcIter::new(core::iter::empty()); | ||
| // iterator over the output values | ||
| let out = filter.run((jaq_core::Ctx::new([], &inputs), ion_stream_as_element)); |
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.
This could use some commentary as to what is happening. It's slurping the entire stream into memory and then feeding it through the filter, yeah?
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.
It is, yeah. I followed one of (or the only?) example in their repo for the sake of getting this PR out. I think we can do something more efficient, but I don't know enough about filters' contract yet to be sure.
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.
It looks like there is not presently a better way, see: 01mf02/jaq#276
| .ok_or_else(|| jaq_err("index out of bounds"))?; | ||
| Ok(JaqElement::from(element.to_owned())) | ||
| } | ||
| // TODO: Should we allow indexing into a struct by integer? |
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.
Nope!
❯ echo '{"foo": "bar"}' | jq '.[0]'
jq: error (at <stdin>:1): Cannot index object with numberThere 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.
Thanks for checking! I'm only somewhat familiar with jq's behavior, so there are lots of things left to double-check.
|
Fixes: #41 |
Lays the groundwork for an
ion jqcommand.This PR adds a dependency on the
jaqcrate, which provides ajqengine, and implements the necessary traits for theElementtype.There are many
todo!()s left to implement to supportjqfeatures like math operations. However, many basic commands work:There are plenty of open questions around which
jqflags to support, what the default expression should be, etc.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.