wip logical planning
This commit is contained in:
parent
e8bef29441
commit
656554048a
@ -1,17 +1,34 @@
|
|||||||
type logical_plan =
|
type logical_plan =
|
||||||
| Project of logical_plan * string
|
| Project of logical_plan * string list
|
||||||
| Scan of string (* Table name *)
|
| Scan of string (* Table name *)
|
||||||
| Filter of logical_plan
|
| Filter of logical_plan
|
||||||
| Join of logical_plan * Ast.join_type * logical_plan
|
| Join of logical_plan * Ast.join_type * logical_plan
|
||||||
| Group of logical_plan * string list
|
| Group of logical_plan * string list
|
||||||
|
|
||||||
let ast_to_logical ast =
|
let rec ast_to_logical ast =
|
||||||
match ast with
|
match ast with
|
||||||
| Ast.Select(_, _) -> Project(Scan("table"), "ok")
|
| Ast.Select(cols, _) -> Project(Scan("table"), (columns_to_logical cols))
|
||||||
| _ -> failwith "Query not supported yet"
|
| _ -> failwith "Query not supported yet"
|
||||||
|
|
||||||
|
and columns_to_logical columns =
|
||||||
|
let rec aux cols acc =
|
||||||
|
match cols with
|
||||||
|
| [] -> acc
|
||||||
|
| Ast.Column(col,_)::l ->
|
||||||
|
let s = expression_to_logical col in
|
||||||
|
aux l (s::acc)
|
||||||
|
| _ -> failwith "Not supported"
|
||||||
|
in
|
||||||
|
aux columns []
|
||||||
|
|
||||||
|
and expression_to_logical exp =
|
||||||
|
match exp with
|
||||||
|
| Ast.Ref(s) -> s
|
||||||
|
| _ -> failwith "Expression not supported yet"
|
||||||
|
|
||||||
|
|
||||||
let rec pp_logical_plan plan =
|
let rec pp_logical_plan plan =
|
||||||
match plan with
|
match plan with
|
||||||
| Project(plan2, name) -> pp_logical_plan plan2 ^ name
|
| Project(plan2, name) -> pp_logical_plan plan2 ^ (String.concat ";" name)
|
||||||
| _ -> "Not supported"
|
| _ -> "Not supported"
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ let test_simple_select () =
|
|||||||
in
|
in
|
||||||
let plan1 = ast_to_logical ast1 in
|
let plan1 = ast_to_logical ast1 in
|
||||||
let plan2 =
|
let plan2 =
|
||||||
Project(Scan("table"), "string")
|
Project(Scan("table"), ["string"])
|
||||||
in
|
in
|
||||||
Alcotest.(check logical_plan_testable) "ok" plan1 plan2
|
Alcotest.(check logical_plan_testable) "ok" plan1 plan2
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user