3 ms·
I'm working on a JSONiq based implementation to jointly process JSON data and XML. The compiler uses set-oriented processing (and thus uses hash joins for insta
by lichtenberger 4y ago
I'm working on a JSONiq based implementation to jointly process JSON data and XML. The compiler uses set-oriented processing (and thus uses hash joins for instance wherever applicable) and is meant to provide a base for JSON based database systems with shared common optimizations (but can also be used as a standalone in-memory query processor):
http://brackit.io http://brackit.io
The language itself borrows a lot of concepts from functional languages as higher order functions, closures... you can also develop modules with functions for easy reuse...
A simple join for instance looks like this:
let $stores :=
[
{ "store number" : 1, "state" : "MA" },
{ "store number" : 2, "state" : "MA" },
{ "store number" : 3, "state" : "CA" },
{ "store number" : 4, "state" : "CA" }
]
let $sales := [
{ "product" : "broiler", "store number" : 1, "quantity" : 20 },
{ "product" : "toaster", "store number" : 2, "quantity" : 100 },
{ "product" : "toaster", "store number" : 2, "quantity" : 50 },
{ "product" : "toaster", "store number" : 3, "quantity" : 50 },
{ "product" : "blender", "store number" : 3, "quantity" : 100 },
{ "product" : "blender", "store number" : 3, "quantity" : 150 },
{ "product" : "socks", "store number" : 1, "quantity" : 500 },
{ "product" : "socks", "store number" : 2, "quantity" : 10 },
{ "product" : "shirt", "store number" : 3, "quantity" : 10 }
]
let $join :=
for $store in $stores, $sale in $sales
where $store=>"store number" = $sale=>"store number"
return {
"nb" : $store=>"store number",
"state" : $store=>state,
"sold" : $sale=>product
}
return [$join]
Of course you can also group by, count, order by, nest FLWOR clauses...
- preferjq 4y agoHere is a straightforward jq translation def stores: [ { "store number" : 1, "state" : "MA" }, { "store number" : 2, "state" : "MA" }, { "store number" : 3, "state" : "CA" }, { "store number" : 4, "state" : "CA" } ]; def sales: [ { "product" : "broiler", "store number" : 1, "quantity" : 20 }, { "product" : "toaster", "store number" : 2, "quantity" : 100 }, { "product" : "toaster", "store number" : 2, "quantity" : 50 }, { "product" : "toaster", "store number" : 3, "quantity" : 50 }, { "product" : "blender", "store number" : 3, "quantity" : 100 }, { "product" : "blender", "store number" : 3, "quantity" : 150 }, { "product" : "socks", "store number" : 1, "quantity" : 500 }, { "product" : "socks", "store number" : 2, "quantity" : 10 }, { "product" : "shirt", "store number" : 3, "quantity" : 10 } ]; [ {store: stores[], sale: sales[]} | select(.store."store number" == .sale."store number") | { nb: .store."store number", state: .store.state, sold: .sale.product } ] Try it online - https://tio.run/##rZPPUsMgEMbP5Sl2ctIZmklbe6HTg@PZJ8jkkD84RhEsbA5O9dkxobQqjTHpyIWw@fbHfrA87ayFdlT8AQwqzQ0j4EbqZ4A9RO4XyOal4DoCBgvaxXLk3SK6v43ggw7plxP1qx/6uz/1N@d6L8825OQvF7/Ye9Wqakp0yYVWtWiptN/1rskl1vjmXCUQ1PUdhCo32A9aBqBFkvwPaH0hZzWFUwguq3GcYWNTQIMVGVU@mzE3tk4uwpzf1xDlsdY47nDCLiVBZzoC8w8zzahrYXZo5DQ7Jr@D4YKXeBU7YRxsvN1C3GUE8etT9h5kwbrP3vwvnwDuibGjzq0ombVxJSrmd/FHQWaH8jJirZ3L8hM https://tio.run/##rZPPUsMgEMbP5Sl2ctIZmklbe6HTg@PZJ8jkkD84Rh...
- lichtenberger 4y agoThe difference might be that Brackit uses sophisticated join algorithms for these kinds of implicit joins as known from relational query processing.