WIP
This commit is contained in:
parent
bfc6e531cb
commit
d32580b143
@ -22,6 +22,8 @@ rule read_token = parse
|
||||
| "UNION" { UNION }
|
||||
| "JOIN" { JOIN }
|
||||
| "ON" { ON }
|
||||
| "WHERE" { WHERE }
|
||||
| "HAVING" { HAVING }
|
||||
| "GROUP" { GROUP }
|
||||
| "BY" { BY }
|
||||
| "*" { ASTERISK }
|
||||
@ -31,6 +33,5 @@ rule read_token = parse
|
||||
| ")" { RIGHT_PAREN }
|
||||
| "," { COMMA }
|
||||
| whitespace { read_token lexbuf }
|
||||
| "WHERE" { WHERE }
|
||||
| alpha alphanumeric* as ident { IDENT ident }
|
||||
| eof { EOF }
|
||||
|
@ -16,12 +16,13 @@ and join_type =
|
||||
| Union
|
||||
| Natural
|
||||
and condition =
|
||||
| Condition of string * comparison
|
||||
| Condition of string * predicate
|
||||
| And of condition * condition
|
||||
| Or of condition * condition
|
||||
| Not of condition
|
||||
and comparison =
|
||||
and predicate =
|
||||
| Comparison of operator * string
|
||||
| Between of string * string
|
||||
and operator =
|
||||
| Equals
|
||||
| NotEquals
|
||||
@ -29,5 +30,7 @@ and operator =
|
||||
| GreaterThan
|
||||
| LessEquals
|
||||
| GreaterEquals
|
||||
and filter =
|
||||
| Filter of string
|
||||
and search_condition =
|
||||
| Search of string
|
||||
|
@ -1,17 +1,13 @@
|
||||
type logical_plan =
|
||||
| Scan of string (* Table name *)
|
||||
(*| Filter of logical_plan * condition*)
|
||||
| Filter of logical_plan * condition
|
||||
| Join of logical_plan * Ast.join_type * logical_plan
|
||||
and condition =
|
||||
| Condition of string
|
||||
|
||||
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 =
|
||||
let rec generate_from_clause tables =
|
||||
match tables with
|
||||
| [Table(name)] -> Scan(name)
|
||||
| [Ast.Table(name)] -> Scan(name)
|
||||
| [Ast.Join(left, j_type, right, _)] ->
|
||||
Join(
|
||||
generate_from_clause [left],
|
||||
@ -21,6 +17,12 @@ and generate_from_clause tables =
|
||||
| _ -> 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) ->
|
||||
|
@ -3,11 +3,12 @@
|
||||
open Ast
|
||||
%}
|
||||
|
||||
%token SELECT ALL DISTINCT FROM WHERE
|
||||
%token SELECT ALL DISTINCT FROM WHERE HAVING BETWEEN
|
||||
%token LEFT RIGHT FULL INNER OUTER
|
||||
%token CROSS NATURAL UNION JOIN
|
||||
%token GREATER_THAN_OPERATOR LESS_THAN_OPERATOR EQUALS_OPERATOR
|
||||
%token MAX MIN SUM COUNT AVG
|
||||
%token ASYMMETRIC SYMMETRIC
|
||||
%token <string> IDENT
|
||||
%token COMMA DOT
|
||||
%token LEFT_PAREN RIGHT_PAREN
|
||||
@ -130,10 +131,12 @@ outer_join_type:
|
||||
| RIGHT { Right }
|
||||
| FULL { Full }
|
||||
|
||||
|
||||
where_clause :
|
||||
| WHERE search_condition { }
|
||||
|
||||
having_clause :
|
||||
| HAVING search_condition {}
|
||||
|
||||
search_condition:
|
||||
(*| IDENT EQUALS_OPERATOR IDENT {}*)
|
||||
| boolean_value_expression { $1 }
|
||||
@ -159,6 +162,7 @@ boolean_primary :
|
||||
|
||||
predicate :
|
||||
| comparison_predicate { $1 }
|
||||
(* | between_predicate { $1 }*)
|
||||
|
||||
comparison_predicate :
|
||||
| row_value_predicand comparison_predicate_part2 { Condition($1, $2) }
|
||||
@ -166,6 +170,18 @@ comparison_predicate :
|
||||
comparison_predicate_part2:
|
||||
| comp_op row_value_predicand { Comparison($1, $2) }
|
||||
|
||||
between_predicate :
|
||||
| row_value_predicand between_predicate_part2 { }
|
||||
|
||||
between_predicate_part2 :
|
||||
| BETWEEN between_symetry row_value_predicand AND row_value_predicand {}
|
||||
| NOT BETWEEN between_symetry row_value_predicand AND row_value_predicand {}
|
||||
|
||||
between_symetry :
|
||||
| {}
|
||||
| ASYMMETRIC {}
|
||||
| SYMMETRIC {}
|
||||
|
||||
comp_op :
|
||||
| EQUALS_OPERATOR { Equals }
|
||||
| not_equals_operator { NotEquals }
|
||||
|
@ -11,4 +11,3 @@ let () =
|
||||
Logical_plan.Scan("t2")
|
||||
)
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user