Skip to content

Commit 3193b0a

Browse files
committed
Refine SQL query language specification
1 parent 60f2c6f commit 3193b0a

2 files changed

Lines changed: 81 additions & 14 deletions

File tree

ROADMAP.md

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

4747
This stage will implement the query language of ArgusDB.
4848

49-
- [] Refine the specification of the query language in specs/query-language.md
49+
- [x] Refine the specification of the query language in specs/query-language.md
5050
- [] Implement a grammar for parsing the query language
5151
- [] Create query plans with the internal API from the parsed SQL
5252

specs/query-language.md

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,90 @@
1-
The syntax used by ArgusDB is an extension of SQL and inspired by [XTDB](https://xtdb.com/).
2-
Examples of syntax for different use cases are given below.
1+
# Query Language Specification
32

4-
## Insertion
3+
ArgusDB supports a SQL-like query language optimized for manipulating and retrieving JSON documents.
4+
5+
## Data Model
6+
7+
The database consists of collections of JSON documents. Each document is a semi-structured object with nested fields, arrays, and values.
8+
9+
## Statements
10+
11+
### INSERT
12+
13+
The `INSERT` statement is used to add new documents to a collection.
14+
15+
**Syntax:**
16+
17+
```sql
18+
INSERT INTO <collection_name>
19+
RECORDS <json_object> [, <json_object> ...]
20+
```
21+
22+
**Parameters:**
23+
24+
* `collection_name`: The name of the collection to insert into.
25+
* `json_object`: A standard JSON object literal representing the document. Keys in the JSON object usually do not require quotes if they are simple identifiers, but standard JSON requires quotes. The parser should support standard JSON syntax.
26+
27+
**Example:**
528

629
```sql
730
INSERT INTO people
8-
RECORDS {_id: 6,
9-
name: 'fred',
10-
info: {contact: [{loc: 'home',
11-
tel: '123'},
12-
{loc: 'work',
13-
tel: '456',
14-
registered: DATE '2024-01-01'}]}}
31+
RECORDS {
32+
"name": "Alice",
33+
"age": 30,
34+
"address": {"city": "Paris", "zip": "75001"}
35+
}
1536
```
1637

17-
## Querying
38+
### SELECT
39+
40+
The `SELECT` statement retrieves data from a collection, allowing for filtering, projection, and pagination.
41+
42+
**Syntax:**
43+
44+
```sql
45+
SELECT <expression_list>
46+
FROM <collection_name>
47+
[WHERE <predicate>]
48+
[LIMIT <integer>]
49+
[OFFSET <integer>]
50+
```
51+
52+
#### Clauses
53+
54+
* **SELECT**: Specifies the fields or expressions to return in the result set.
55+
* **FROM**: Specifies the source collection to query.
56+
* **WHERE**: Filters documents based on a boolean predicate. Only documents for which the predicate evaluates to `TRUE` are included in the result.
57+
* **LIMIT**: Restricts the maximum number of documents returned.
58+
* **OFFSET**: Skips a specified number of documents before returning results.
59+
60+
#### Expressions and Operators
61+
62+
The language supports various expressions to interact with JSON data:
63+
64+
* **Field Access**:
65+
* Dot notation: `info.contact` accesses the `contact` field within the `info` object.
66+
* Array Indexing: `contact[0]` accesses the first element of the `contact` array.
67+
* **Literals**:
68+
* Strings: `'value'` (single quotes) or `"value"` (double quotes)
69+
* Numbers: `123`, `45.67`
70+
* Booleans: `TRUE`, `FALSE`
71+
* Null: `NULL`
72+
* **Comparison Operators**:
73+
* `=`: Equality
74+
* `!=` or `<>`: Inequality
75+
* `<`, `<=`: Less than, Less than or equal
76+
* `>`, `>=`: Greater than, Greater than or equal
77+
* **Logical Operators**:
78+
* `AND`: Logical conjunction
79+
* `OR`: Logical disjunction
80+
* `NOT`: Logical negation
81+
82+
**Example:**
1883

1984
```sql
20-
SELECT (people.info).contact[2].tel
85+
SELECT name, info.contact[0].tel
2186
FROM people
22-
WHERE people.name = 'fred'
87+
WHERE age >= 21 AND active = TRUE
88+
LIMIT 10
89+
OFFSET 5
2390
```

0 commit comments

Comments
 (0)