ocaml_sql_parser/lib/logical_plan.ml
2024-11-28 14:28:46 +00:00

31 lines
753 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"
*)