Hacker News new | past | comments | ask | show | jobs | submit login

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

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...



Here 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@PZJ8jkkD84Rh...


The difference might be that Brackit uses sophisticated join algorithms for these kinds of implicit joins as known from relational query processing.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: