diff --git a/lib/logical_plan.ml b/lib/logical_plan.ml index 9fe1f4d..5ca7384 100644 --- a/lib/logical_plan.ml +++ b/lib/logical_plan.ml @@ -1,31 +1,17 @@ type logical_plan = + | Project of logical_plan * string | Scan of string (* Table name *) - | Filter of logical_plan * condition + | Filter of logical_plan | Join of logical_plan * Ast.join_type * logical_plan -and condition = - | Condition of string + | Group of logical_plan * string list -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 = +let ast_to_logical ast = match ast with - | Ast.Query(Select(_, Some(tables), _)) -> - let base_plan = generate_from_clause tables in - base_plan - | Ast.Query(Select(_, None, _)) -> failwith "not supported" + | Ast.Select(_, _) -> Project(Scan("table"), "ok") + | _ -> failwith "Query not supported yet" + +let rec pp_logical_plan plan = + match plan with + | Project(plan2, name) -> pp_logical_plan plan2 ^ name + | _ -> "Not supported" -(*let evaluate_plan plan = - match plan with - | Scan(table) -> - | _ -> failwith "Unsupported plan" -*)