Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/mbuczko/metaql
- Owner: mbuczko
- Created: 2023-02-17T21:05:14.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-07T20:17:30.000Z (10 months ago)
- Last Synced: 2024-03-07T21:28:31.893Z (10 months ago)
- Language: Rust
- Size: 105 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.