Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mbuczko/metaql

PromQL alike query language
https://github.com/mbuczko/metaql

Last synced: 15 days ago
JSON representation

PromQL alike query language

Awesome Lists containing this project

README

        

This crate is to parse a simple query language, similar to one used by [Prometheus](https://prometheus.io/docs/prometheus/latest/querying/basics/).

Grammar considered here comes down to:

``` antlr
query -> filter range?
filter -> CURLY_OPEN group (OR group)* CURLY_CLOSE
group -> matcher (COMMA matcher)*
matcher -> PATH op value
op -> '!'? ( EQ | CONTAINS )
value -> scalar | array
scalar -> STRING | BOOL | numeric
numeric -> INTEGER | FLOAT
array -> SQARE_OPEN value ( COMMA value )* SQARE_CLOSE
range -> SQARE_OPEN duration SQUARE_CLOSE
duration -> INTEGER unit
unit -> "ms" | "s" | "m" | "h" | "d" | "w" | "mo" | "y"
```

which allows to define queries, as simple as:

```
{ meta.tags ~ "vacation" }
```

or more complicated, like:

```
{ meta.tags ~ "vacation", status = "completed" }
{ meta.tags ~ "vacation", status ~ ["completed", "in-progress"] }
{ meta.focal_length = "35mm" } [10d]
{ meta.focal_length = "35mm" | meta.camera = "pentax" }
{ meta.tags ~ "vacation", nickname = "alice", meta.focal_length = 18.5 | meta.camera = "pentax"} [10d]
```

Futhermore, AST can be auto-transformed into corresponding WHERE conditions of SQL query.

Note, conditions are tightly coupled with Postgres notation for now. For example, nested paths like `meta.focal_length` are assumed to be a valid paths within JSON objects, and as such are turned into postgres-specific JSON queries (`meta->>'focal_length` in this case).

WIP.