Tree-to-Tree Queries
Process nested structures (JSON, Tensors) as input, produce nested structures as result.
An Expressive Data-Centric Query Language
Query nested data, produce nested data as result
A Rhyme query is compiled through an intermediate representation (IR) that makes data dependencies explicit, optimized, and finally translated to efficient JavaScript (or C).
// share of total population, per country
rh`{
data.*A.country:
sum(data.*A.population)
/ sum(data.*B.population)
}`inp => {
let tmp = {}
tmp.t1 ??= {}
tmp.t2 ??= 0
for (let xB in inp.data) {
tmp.t2 += inp.data[xB].population
}
tmp.t0 ??= {}
for (let xA in inp.data) {
let k = inp.data[xA].country
tmp.t1[k] ??= 0
tmp.t1[k] += inp.data[xA].population
tmp.t0[k] = tmp.t1[k] / tmp.t2
}
return tmp.t0
}