Skip to content

Commit bcd2af1

Browse files
committed
Define internal query algebra specifications
1 parent 77b4d5e commit bcd2af1

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

ROADMAP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ This stage will implement the compaction algorithm for the LSM tree.
3838

3939
# Stage 6 - Internal query API
4040

41-
- [] Define the operators and structures of the internal query algebra in specs/query-algebra.md
41+
- [x] Define the operators and structures of the internal query algebra in specs/query-algebra.md
4242
- [] Implement selection of attributes from document collections
4343
- [] Implement filtering based on constraints on attributes
4444

specs/query-algebra.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Internal Query Algebra
2+
3+
This document defines the operators and structures for the internal query algebra of ArgusDB. This algebra represents the intermediate representation of queries that will be executed against the database.
4+
5+
## Query Plan
6+
7+
A query plan is a tree of operators. The execution engine evaluates this tree, typically starting from the leaves (data sources) and processing data up to the root.
8+
9+
## Operators
10+
11+
The following operators are defined:
12+
13+
### 1. Scan
14+
15+
* **Description**: Scans the database for documents. It produces a stream of documents.
16+
* **Parameters**:
17+
* `collection`: (Implicitly the whole DB for now, or filtered by some criteria if we add collections later).
18+
* **Output**: A stream of `(DocumentID, Document)` pairs.
19+
20+
### 2. Project (Select)
21+
22+
* **Description**: Transforms each document in the input stream by selecting a subset of fields or computing new fields.
23+
* **Parameters**:
24+
* `projections`: A list of expressions defining the output fields.
25+
* **Input**: A stream of documents.
26+
* **Output**: A stream of modified documents.
27+
28+
### 3. Filter (Where)
29+
30+
* **Description**: Filters the input stream, passing only documents that satisfy a predicate.
31+
* **Parameters**:
32+
* `predicate`: A boolean expression that is evaluated against each document.
33+
* **Input**: A stream of documents.
34+
* **Output**: A stream of documents satisfying the predicate.
35+
36+
### 4. Limit
37+
38+
* **Description**: Limits the number of documents returned.
39+
* **Parameters**:
40+
* `limit`: The maximum number of documents to return.
41+
* **Input**: A stream of documents.
42+
* **Output**: A stream of at most `limit` documents.
43+
44+
### 5. Offset
45+
46+
* **Description**: Skips a specified number of documents from the beginning of the stream.
47+
* **Parameters**:
48+
* `offset`: The number of documents to skip.
49+
* **Input**: A stream of documents.
50+
* **Output**: The input stream minus the first `offset` documents.
51+
52+
## Expressions
53+
54+
Operators like `Project` and `Filter` rely on expressions.
55+
56+
* **FieldReference**: Refers to a field in the document (e.g., `a.b`).
57+
* **Literal**: A constant value (e.g., `1`, `"hello"`, `true`).
58+
* **BinaryExpression**: Combines two expressions with an operator (e.g., `a > 5`, `b == "test"`).
59+
* Supported operators: `=`, `!=`, `<`, `<=`, `>`, `>=`.
60+
* **LogicalExpression**: Combines boolean expressions.
61+
* Supported operators: `AND`, `OR`, `NOT`.
62+
63+
## Execution Model
64+
65+
The query engine will execute the plan by pulling data from the root operator. Each operator pulls data from its child, processes it, and returns it to its parent. This is a standard iterator (Volcano) model.

0 commit comments

Comments
 (0)