Skip to content
Myr

Simplify and optimize SQLish builtins

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Muh Muhten · committed by Nico Williams · parent a1626ad · Browse files · 2 files+14 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+14 added−7 removed

  • tests:+11 added−0 removed
  • other:+3 added−7 removed

2 files+14 added−7 removed

modified:src/builtin.jq+3 added-7 removed
261 unmodified lines
262 end;263264# SQL-ish operators here:265def INDEX(stream; idx_expr):266 reduce stream as $row ({};267 .[$row|idx_expr|268 if type != "string" then tojson269 else .270 end] |= $row);266 reduce stream as $row ({}; .[$row|idx_expr|tostring] = $row);267def INDEX(idx_expr): INDEX(.[]; idx_expr);268def JOIN($idx; idx_expr):269 [.[] | [., $idx[idx_expr]]];270def JOIN($idx; stream; idx_expr):271 stream | [., $idx[idx_expr]];272def JOIN($idx; stream; idx_expr; join_expr):273 stream | [., $idx[idx_expr]] | join_expr;278def IN(s): reduce (first(select(. == s)) | true) as $v (false; if . or $v then true else false end);279def IN(src; s): reduce (src|IN(s)) as $v (false; if . or $v then true else false end);274def IN(s): any(s == .; .);275def IN(src; s): any(src == s; .);
modified:tests/jq.test+11 added
1573 unmodified lines
1574true1575true1576true15771578range(5;13)|IN(range(0;10;3))1579null1580false1581true1582false1583false1584true1585false1586false1587false15881589range(10;12)|IN(range(10))1590null1591false1592false
37 unmodified lines