Add SQL-style operators (#1322)

This commit is contained in:
Nicolas Williams committed 2017-01-30 14:11:05 -06:00
1 parent 396543191c
commit 7bdf3a39ad
4 files changed
+125

No files matched your search

+17
View File
@@ -287,3 +287,20 @@ def walk(f):
elif type == "array" then map( walk(f) ) | f
else f
end;
# SQL-ish operators here:
def INDEX(stream; idx_expr):
reduce stream as $row ({};
.[$row|idx_expr|
if type != "string" then tojson
else .
end] |= $row);
def INDEX(idx_expr): INDEX(.[]; idx_expr);
def JOIN($idx; idx_expr):
[.[] | [., $idx[idx_expr]]];
def JOIN($idx; stream; idx_expr):
stream | [., $idx[idx_expr]];
def JOIN($idx; stream; idx_expr; join_expr):
stream | [., $idx[idx_expr]] | join_expr;
def IN(s): reduce (first(select(. == s)) | true) as $v (false; if . or $v then true else false end);
def IN(src; s): reduce (src|IN(s)) as $v (false; if . or $v then true else false end);