-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpr.ml
48 lines (44 loc) · 1.06 KB
/
expr.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
type joinType =
| Inner
| Full
| Left
| Right
type props =
Props of
ColumnsPerTable.t Columns.t option
type op =
| SELECT of
t Cnf.t
* t
| PROJECT of
ColumnsPerTable.t Columns.t
* t
| JOIN of
joinType
* t Cnf.t
* t
* t
| SCAN of
Table.t
| CONST
and t =
| Expr of op * props
let fromOp op =
Expr(op, Props(None))
let rec columns expr =
let Expr(node, (Props(columnProp) as props)) = expr in
match columnProp with
(* Columns already memoized, return *)
| Some(cols) -> cols
(* Column prop hasn't been updated, recursively update it *)
| None ->
begin match node with
(* Filter columns from expr' by taking the intersect with the projection *)
| PROJECT(cols, expr') -> Columns.intersect cols (columns expr')
(* Selection doesn't restrict columns *)
| SELECT(_, expr') -> columns expr'
(* union the columns from left and right *)
| JOIN(_, _, l, r) -> Columns.union (columns l) (columns r)
| SCAN(table) -> Columns.all table
| CONST -> Columns.empty
end