Skip to content

Commit 675dc7e

Browse files
committed
doc: move trees-algo to tech-spec
1 parent 82311cb commit 675dc7e

File tree

2 files changed

+51
-50
lines changed

2 files changed

+51
-50
lines changed

docs/spec/tech-spec.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,57 @@ Example rules with its generated tree:
365365
(select, "all")
366366
```
367367

368+
#### Algorithm
369+
370+
- Each rule in a sharing CSV sheet can only reference rules defined in a
371+
previous row.
372+
- a node has a type/kind, a value, and a list of children
373+
- the children of a node is called 'sons' since it's shorter
374+
- nodes are first added to ctx and then later added to parent nodes with O(1)
375+
lookup, this way the tree is constructed incrementally while parsing each
376+
rule
377+
- share nodes are made to be children of a single root-node, since each org
378+
gets its own node, there may be multiple share-rules, and the tree
379+
can only have a single root node
380+
- the root-node is updated every time a new share-node is added
381+
- tables of each rule are cached for O(1) lookup
382+
383+
```
384+
for each rule:
385+
for each table in rule, or just once if no table:
386+
init node, depending on rule mode:
387+
select:
388+
kind = select
389+
value = empty if sons are specified, otherwise 'all'
390+
sons = a value node for each column name
391+
filter:
392+
kind = filter
393+
value = operator
394+
sons =
395+
1. a key node for the field name
396+
2. a value node for each filter value
397+
group:
398+
kind = group
399+
value = operator
400+
sons = nodes matching the rule's list of ids
401+
share:
402+
kind = root
403+
sons =
404+
for each organization:
405+
kind = share
406+
value = org
407+
sons =
408+
for each select-node referenced in share-rule:
409+
for each table in select-node's rule:
410+
kind = "table"
411+
value = table
412+
sons =
413+
1. select node
414+
2. filter/group node referenced in
415+
share-node. Multiple nodes are
416+
implicitly grouped with an AND-node.
417+
```
418+
368419
### SQL query generation
369420

370421
SQL queries are (recursively) generated from each table-node of the AST. Values

docs/spec/trees-algo.md

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)