adding functions

This commit is contained in:
Simon Petit 2024-12-10 18:00:47 +01:00
parent 4d62ebe2a3
commit 319f2f9b43
2 changed files with 28 additions and 8 deletions

View File

@ -1,9 +1,12 @@
type query = Query of select_stmt type query = Query of select_stmt
and select_stmt = and select_stmt =
| Select of column list * table list * filter option | Select of column list * table list option * filter option
and column = and column =
| Asterisk | Asterisk
| Column of string (* | Column of string *)
| Column of expression * as_clause option
and as_clause =
| As of string
and table = and table =
| Table of string | Table of string
| Join of table * join_type * table * condition option | Join of table * join_type * table * condition option
@ -20,8 +23,7 @@ and condition =
| And of condition * condition | And of condition * condition
| Or of condition * condition | Or of condition * condition
| Not of condition | Not of condition
and predicand = and predicand = expression
| Ref of string
and predicate = and predicate =
| Comparison of operator * predicand | Comparison of operator * predicand
| Between of predicand * predicand | Between of predicand * predicand
@ -39,8 +41,24 @@ and operator =
| GreaterEquals | GreaterEquals
and filter = and filter =
| Filter of condition | Filter of condition
and search_condition = and aggregate =
| Search of string | 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 = let rec pp_query fmt ast =
match ast with match ast with
@ -58,8 +76,9 @@ and pp_columns cols =
and pp_column col = and pp_column col =
match col with match col with
| Column(name) -> name | Column(Ref(name),_) -> name
| Asterisk -> "*" | Asterisk -> "*"
| _ -> failwith "not supported"
and pp_tables tables = and pp_tables tables =
match tables with match tables with

View File

@ -19,9 +19,10 @@ let rec generate_from_clause tables =
let generate_logical_plan ast = let generate_logical_plan ast =
match ast with match ast with
| Ast.Query(Select(_, tables, _)) -> | Ast.Query(Select(_, Some(tables), _)) ->
let base_plan = generate_from_clause tables in let base_plan = generate_from_clause tables in
base_plan base_plan
| Ast.Query(Select(_, None, _)) -> failwith "not supported"
(*let evaluate_plan plan = (*let evaluate_plan plan =
match plan with match plan with