Compare commits

...

2 Commits

Author SHA1 Message Date
827a7fd1d3 ading tests 2024-12-11 08:32:28 +01:00
0206e0be00 enabling in_predicate 2024-12-11 08:31:55 +01:00
3 changed files with 43 additions and 24 deletions

View File

@ -28,8 +28,8 @@ and predicate =
| Comparison of operator * predicand | Comparison of operator * predicand
| Between of predicand * predicand | Between of predicand * predicand
| NotBetween of predicand * predicand | NotBetween of predicand * predicand
| In of string list | In of predicand list
| NotIn of string list | NotIn of predicand list
| Like of string | Like of string
| NotLike of string | NotLike of string
and operator = and operator =
@ -66,7 +66,7 @@ let rec pp_query fmt ast =
and pp_select s = and pp_select s =
match s with match s with
| Select(cols, _, _) -> pp_columns cols | Select(cols, _, _) -> String.cat "SELECT " (pp_columns cols)
and pp_columns cols = and pp_columns cols =
match cols with match cols with
@ -77,8 +77,10 @@ and pp_columns cols =
and pp_column col = and pp_column col =
match col with match col with
| Column(Ref(name),_) -> name | Column(Ref(name),_) -> name
| Column(StringLiteral(name),_) -> "'"^name^"'"
| Column(DateLiteral(name),_) -> "'"^name^"'"
| Asterisk -> "*" | Asterisk -> "*"
| _ -> failwith "not supported" | _ -> failwith "Pretty parsing of Column not supported"
and pp_tables tables = and pp_tables tables =
match tables with match tables with

View File

@ -509,8 +509,8 @@ as_clause :
predicate : predicate :
| comparison_predicate { $1 } | comparison_predicate { $1 }
| in_predicate { $1 }
(* | between_predicate { $1 } *) (* | between_predicate { $1 } *)
(* | in_predicate { $1 } *)
(* | like_predicate { $1 }*) (* | like_predicate { $1 }*)
(*****************) (*****************)

View File

@ -11,11 +11,15 @@ let query_testable =
Alcotest.testable Ast.pp_query equal_ast Alcotest.testable Ast.pp_query equal_ast
let test_simple_select () = let test_simple_select () =
let query = "SELECT a FROM t" in let query = "SELECT a, b FROM t" in
let q1 = parse query in let q1 = parse query in
let ast1 = Query( let ast1 = Query(
Select( Select(
[ [
Column(
Ref("b"),
None
);
Column( Column(
Ref("a"), Ref("a"),
None None
@ -48,24 +52,9 @@ let test_simple_select () =
) in ) in
Alcotest.(check query_testable) query q2 ast2 ; Alcotest.(check query_testable) query q2 ast2 ;
let query = "SELECT 'a'" in let query = "SELECT 'b', 'a', DATE '2024-12-25' AS date" in
let q3 = parse query in let q3 = parse query in
let ast3 = Query( let ast3 = Query(
Select(
[
Column(
StringLiteral("a"),
None
)
],
None,
None
)
) in
Alcotest.(check query_testable) query q3 ast3;
let q4 = parse "SELECT DATE '2024-12-25' AS date" in
let ast4 = Query(
Select( Select(
[ [
Column( Column(
@ -73,13 +62,21 @@ let test_simple_select () =
Some( Some(
As("date") As("date")
) )
);
Column(
StringLiteral("a"),
None
);
Column(
StringLiteral("b"),
None
) )
], ],
None, None,
None None
) )
) in ) in
Alcotest.(check query_testable) "OK" q4 ast4 Alcotest.(check query_testable) query q3 ast3
let test_default_join () = let test_default_join () =
let q1 = parse "SELECT a FROM t1 JOIN t2 ON b = c" in let q1 = parse "SELECT a FROM t1 JOIN t2 ON b = c" in
@ -337,6 +334,26 @@ let test_where_equals () =
) in ) in
Alcotest.(check query_testable) "Ok" q1 ast1 Alcotest.(check query_testable) "Ok" q1 ast1
(*
let test_aggregtes () =
let query = "SELECT AVG(a) FROM t" in
let q1 = parse query in
let ast1 = Query(
Select(
[
],
Some(
[
Table("t")
]
),
None
)
) in
Alcotest.(check query_testable) query q1 ast1
*)
let simple_select_set = [ ("Equals", `Quick, test_simple_select) ] let simple_select_set = [ ("Equals", `Quick, test_simple_select) ]
let simple_join_set = [ let simple_join_set = [