adding functions
This commit is contained in:
parent
4d62ebe2a3
commit
319f2f9b43
33
lib/ast.ml
33
lib/ast.ml
@ -1,9 +1,12 @@
|
||||
type query = Query of select_stmt
|
||||
and select_stmt =
|
||||
| Select of column list * table list * filter option
|
||||
| Select of column list * table list option * filter option
|
||||
and column =
|
||||
| Asterisk
|
||||
| Column of string
|
||||
(* | Column of string *)
|
||||
| Column of expression * as_clause option
|
||||
and as_clause =
|
||||
| As of string
|
||||
and table =
|
||||
| Table of string
|
||||
| Join of table * join_type * table * condition option
|
||||
@ -20,8 +23,7 @@ and condition =
|
||||
| And of condition * condition
|
||||
| Or of condition * condition
|
||||
| Not of condition
|
||||
and predicand =
|
||||
| Ref of string
|
||||
and predicand = expression
|
||||
and predicate =
|
||||
| Comparison of operator * predicand
|
||||
| Between of predicand * predicand
|
||||
@ -39,8 +41,24 @@ and operator =
|
||||
| GreaterEquals
|
||||
and filter =
|
||||
| Filter of condition
|
||||
and search_condition =
|
||||
| Search of string
|
||||
and aggregate =
|
||||
| Aggregate of func * filter option
|
||||
and func =
|
||||
| Function of function_type * quantifier option * expression
|
||||
and function_type =
|
||||
| Avg
|
||||
| Max
|
||||
| Min
|
||||
| Sum
|
||||
| Count
|
||||
and quantifier =
|
||||
| All
|
||||
| Distinct
|
||||
and expression =
|
||||
| Ref of string
|
||||
| StringLiteral of string
|
||||
| DateLiteral of string
|
||||
| TimeLiteral of string
|
||||
|
||||
let rec pp_query fmt ast =
|
||||
match ast with
|
||||
@ -58,8 +76,9 @@ and pp_columns cols =
|
||||
|
||||
and pp_column col =
|
||||
match col with
|
||||
| Column(name) -> name
|
||||
| Column(Ref(name),_) -> name
|
||||
| Asterisk -> "*"
|
||||
| _ -> failwith "not supported"
|
||||
|
||||
and pp_tables tables =
|
||||
match tables with
|
||||
|
@ -19,9 +19,10 @@ let rec generate_from_clause tables =
|
||||
|
||||
let generate_logical_plan ast =
|
||||
match ast with
|
||||
| Ast.Query(Select(_, tables, _)) ->
|
||||
| Ast.Query(Select(_, Some(tables), _)) ->
|
||||
let base_plan = generate_from_clause tables in
|
||||
base_plan
|
||||
| Ast.Query(Select(_, None, _)) -> failwith "not supported"
|
||||
|
||||
(*let evaluate_plan plan =
|
||||
match plan with
|
||||
|
Loading…
Reference in New Issue
Block a user