Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Compiling queries into WebAssembly #4983

vanillajonathan started this conversation in Ideas
Discussion options

I don't know how feasible this is. It is a pretty wild idea, maybe it wouldn't be possible.

PRQL could ship a prql.wit (Wasm Interface Type) file or prqlc could provide a command to output it. Perhaps it would look something like this:

interface prql {
 resource query {
 constructor(table: string);
 
 /// Summarize many rows into one row
 aggregate: func(partition: list<u64>, compute: list<u64>) -> query;
 append: func(table: table-ref) -> query;
 /// Compute new columns
 derive: func(assigns: expr) -> query;
 /// Pick rows based on their values
 filter: func(filter: expr) -> query;
 from: func(table: table-ref) -> query;
 /// Partition rows into groups and applies a pipeline to each of them
 group: func(by: expr, pipeline: expr) -> query;
 /// Add columns from another table, matching rows based on a condition
 join: func(side: join-side, with: table-ref, filter: expr) -> query;
 /// Iteratively apply a function to a relation until it’s empty
 loop: func(expr: expr) -> query;
 /// Pick & compute columns
 select: func(columns: list<u64>) -> query;
 /// Order rows based on the values of columns
 sort: func(by: list<u64>) -> query;
 
 /// Pick rows based on their position
 take: func(range: range) -> query;
 /// Apply a pipeline to overlapping segments of rows
 window: func(kind: window-kind, range: range, pipeline: expr) -> query;
 }
 
 record expr {
 }
 record table-ref {
 }
 record range {
 range: Range,
 partition: list<u64>,
 sort: list<u64>,
 }
 enum join-side {
 inner,
 left,
 right,
 full,
 }
 enum window-kind {
 rows,
 range,
 }
}

A implementer could provide an implementation of that interface and insert it into a WASI host environment.

prqlc could have a --format=wat option for the compile command which would transform the PL AST into WebAssembly text format (a .wat file) which a tool such as as wat2wasm could translate into a binary .wasm file.

Example:

echo "from pets" | prqlc compile --format=wat > query.wat
(module
 (@producers
 (processed-by "prqlc" "1.0.0 (f6e511eec 2024年10月23日)")
 )
 (func $i (import "prql" "query") (param i32))
 (func (export "main")
 i32.const 42
 call $i
 )
)
wat2wasm query.wat -o query.wasm
You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /