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

View File

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

View File

@ -11,11 +11,15 @@ let query_testable =
Alcotest.testable Ast.pp_query equal_ast
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 ast1 = Query(
Select(
[
Column(
Ref("b"),
None
);
Column(
Ref("a"),
None
@ -48,24 +52,9 @@ let test_simple_select () =
) in
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 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(
[
Column(
@ -73,14 +62,22 @@ let test_simple_select () =
Some(
As("date")
)
);
Column(
StringLiteral("a"),
None
);
Column(
StringLiteral("b"),
None
)
],
None,
None
)
) in
Alcotest.(check query_testable) "OK" q4 ast4
Alcotest.(check query_testable) query q3 ast3
let test_default_join () =
let q1 = parse "SELECT a FROM t1 JOIN t2 ON b = c" in
let ast1 = Query(
@ -337,6 +334,26 @@ let test_where_equals () =
) in
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_join_set = [