31 lines
756 B
OCaml
31 lines
756 B
OCaml
type logical_plan =
|
|
| Scan of string (* Table name *)
|
|
| Filter of logical_plan * condition
|
|
| Join of logical_plan * Ast.join_type * logical_plan
|
|
and condition =
|
|
| Condition of string
|
|
|
|
let rec generate_from_clause tables =
|
|
match tables with
|
|
| [Ast.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 generate_logical_plan ast =
|
|
match ast with
|
|
| Ast.Query(Select(_, tables, _)) ->
|
|
let base_plan = generate_from_clause tables in
|
|
base_plan
|
|
|
|
(*let evaluate_plan plan =
|
|
match plan with
|
|
| Scan(table) ->
|
|
| _ -> failwith "Unsupported plan"
|
|
*)
|