28 lines
707 B
OCaml
28 lines
707 B
OCaml
type logical_plan =
|
|
| Scan of string (* Table name *)
|
|
(*| Filter of logical_plan * condition*)
|
|
| Join of logical_plan * Ast.join_type * logical_plan
|
|
|
|
let rec generate_logical_plan ast =
|
|
match ast with
|
|
| Ast.Query(Select(_, tables)) ->
|
|
let base_plan = generate_from_clause tables in
|
|
base_plan
|
|
|
|
and generate_from_clause tables =
|
|
match tables with
|
|
| [Table(name)] -> Scan(name)
|
|
| [Ast.Join(left, j_type, right, _)] ->
|
|
Join(
|
|
generate_from_clause [left],
|
|
j_type,
|
|
generate_from_clause [right]
|
|
)
|
|
| _ -> failwith "Unsupported table structure"
|
|
|
|
|
|
let evaluate_plan plan =
|
|
match plan with
|
|
| Scan(table) ->
|
|
| _ -> failwith "Unsupported plan"
|