Jq Internals: Backtracking (2017)
github.com
github.com
I wish there was something for querying json that had more of a xpath or even a sql-like syntax, or GraphQL with the addition of wildcards.
Ah, I wondered if they rolled their own SQL parser, but no, I now see the sqlite.go in the repo and all is made clear
No. Occasionally: "at infrequent or irregular intervals; now and then."
You can have your input JSON terminal left, the output post jq terminal right and interactively edit your jq script elements above.
( based upon the Go implementation of jq )
Clojure really excels at data querying/manipulation, so `jet` is very ergonomic to use.
One example:
$ echo '{"anApple": 1}' | jet -i json -k '#(-> % csk/->kebab-case keyword)' -o edn
{:an-apple 1}
Since starting to use jet, I haven't found anything jq could do that jet couldn't also do but with the additional feature of actually being able to read what I've done with it days later.[1]: https://github.com/01mf02/jaq
$ echo '{"alpha":"beta"}' | jq -r '"hello \(.alpha\)"'
jq: error: syntax error, unexpected INVALID_CHARACTER (Unix shell quoting issues?) at <top-level>, line 1:
"hello \(.alpha\)"
jq: 1 compile error
$ echo '{"alpha":"beta"}' | gojq -r '"hello \(.alpha\)"'
gojq: invalid query: "hello \(.alpha\)"
"hello \(.alpha\)"
^ unexpected token "\\"
because (a) muscle memory (b) sure, it's easy to spot that mistake in an 18 character expression, but for bigger ones, getouttahereI'm not a big fan of the language, but it works
"It's complicated, you know"
Though it's funny because I do agree that in the past that jq wasn't having its committed code being released often enough. There was a popular Github issue[1] with arguments and 70+ reactions about a confusing feature in jq that turned out to have already been fixed and committed in 2015, before the Github issue was even opened, but the fix didn't actually make it into a released version until 2018. Definitely one of the more frustrating cases of investigating a software issue I ran into. Everyone should make sure their project's release process can promptly release updates!
That said, I'm trying to bring on a new maintainer, and I'll try to find energy during the holidays, which is when I usually find energy for jq. Also, I can't reach Stephen, which means the only way to add new maintainers is to fork the project, which I don't want to do without Stephen's approval. I've created a `jqlang` org in GitHub just to squat on the name, but before I ever fork it, I want Stephen's approval, and I want him to accept ownership in the org -- it's his baby!
When I saw the comment "why is the latest release so old" my thought was "because it's perfect".
It's such a powerful tool at surface level in this api/k8s interfacing world that looking under the hood and seeing all the work just knocked me over.
You all have done something so powerful for the community regardless of the hiatus.
THANK YOU!
Very inspiring read :)
Although the case they use is almost perversely simple. Imagine in a 'real' sudoku that each number might need to be backtracked multiple times, such that the algorithm is regularly going almost back to the start.
Edit: here's a classic one trying to solve the 8 queens problem: https://commons.wikimedia.org/wiki/File:Eight-queens-animati...
https://miro.medium.com/max/786/1*Q-DyKa25eozOeMdN5YQONA.png
https://alopatindev.github.io/2018/01/14/how-to-take-notes-l...
Image: https://alopatindev.github.io/pictures/how-to-take-notes-lik...
The number of permutations of n items is n!, because at every position you can place one item from all the items that haven't already been placed. Backtracking basically recursively produces all n! solutions (where every recursion depth is one position) similar to DFS brute force enumeration with the only difference that it also continuously evaluates partial solutions and short-circuits if it detects a partial solution that is guaranteed to make any complete solution containing it invalid.
E.g. if you want to enumerate the permutations of 4 people standing in a row, there are 4!=24 ways to do it. However, if you add the condition that Alice can't stand next to Bob, you can short-circuit the enumeration early as soon as you detect that Alice and Bob have been placed together (such as Alice-Bob-?-?)
You could also have more complex scenarios where every position has its own disjoint set of items to choose from.
What you do with the enumeration is up to you. Maybe you just want to enumerate and display all possible permutations. Maybe you just want to produce the best or k best as determined by some fitness function.
Isn't the adage to only build a framework after the 3rd or 4th implementation? That seems to apply to writing a RFC, also