aboutsummaryrefslogtreecommitdiff
path: root/tests/sql_db.ml
diff options
context:
space:
mode:
Diffstat (limited to 'tests/sql_db.ml')
-rw-r--r--tests/sql_db.ml119
1 files changed, 119 insertions, 0 deletions
diff --git a/tests/sql_db.ml b/tests/sql_db.ml
index 75b8293..65a93ce 100644
--- a/tests/sql_db.ml
+++ b/tests/sql_db.ml
@@ -200,6 +200,121 @@ columns = [
ImportCSV.DataType.
[ [| Integer 1; Integer 200 |]; [| Integer 2; Integer 100 |] ])
+let filter_group =
+ run_test "filter_group"
+ ~configuration:
+ {|[source]
+name = "source_name"
+file = "source_file"
+
+[sheet]
+columns = [
+ ":A",
+]
+
+filters = [
+ "max(:B, [:C], [:B]) = :B",
+]
+
+|}
+ ~input:
+ ImportCSV.DataType.
+ [
+ [ (0, Integer 1); (1, Integer 100); (2, Integer 0) ];
+ [ (0, Integer 2); (1, Integer 150); (2, Integer 0) ];
+ [ (0, Integer 3); (1, Integer 200); (2, Integer 0) ];
+ ]
+ ~expected:(Ok ImportCSV.DataType.[ [| Integer 3 |] ])
+
+(** The first filter will prevent the max value to pop, and only the second one
+ will be reported *)
+let filter_expression_and_group =
+ run_test "filter expression then group"
+ ~configuration:
+ {|[source]
+name = "source_name"
+file = "source_file"
+
+[sheet]
+columns = [
+ ":A",
+]
+
+filters = [
+ ":B <> 200",
+ "max(:B, [:C], [:B]) = :B",
+]
+
+|}
+ ~input:
+ ImportCSV.DataType.
+ [
+ [ (0, Integer 1); (1, Integer 100); (2, Integer 0) ];
+ [ (0, Integer 2); (1, Integer 150); (2, Integer 0) ];
+ [ (0, Integer 3); (1, Integer 200); (2, Integer 0) ];
+ ]
+ ~expected:(Ok ImportCSV.DataType.[ [| Integer 2 |] ])
+
+(** In this case, we first filter the line and keep only the max value, but the
+ second filter will match the result and will produce an empty list *)
+let filter_group_and_expression =
+ run_test "filter group then expression"
+ ~configuration:
+ {|[source]
+name = "source_name"
+file = "source_file"
+
+[sheet]
+columns = [
+ ":A",
+]
+
+filters = [
+ "max(:B, [:C], [:B]) = :B",
+ ":B <> 200",
+]
+
+|}
+ ~input:
+ ImportCSV.DataType.
+ [
+ [ (0, Integer 1); (1, Integer 100); (2, Integer 0) ];
+ [ (0, Integer 2); (1, Integer 150); (2, Integer 0) ];
+ [ (0, Integer 3); (1, Integer 200); (2, Integer 0) ];
+ ]
+ ~expected:(Ok [])
+
+(** In this case, each filter remove the line with the higher value in B.
+
+ After the application of the two filters, the only remaining result is the
+ first line. *)
+let filter_group_and_group =
+ run_test "filter group then group"
+ ~configuration:
+ {|[source]
+name = "source_name"
+file = "source_file"
+
+[sheet]
+columns = [
+ ":A",
+]
+
+filters = [
+ "max(:B, [:C], [:B]) <> :B",
+ "max(:B, [:C], [:B]) <> :B",
+]
+
+|}
+ ~input:
+ ImportCSV.DataType.
+ [
+ [ (0, Integer 1); (1, Integer 100); (2, Integer 0) ];
+ [ (0, Integer 2); (1, Integer 150); (2, Integer 0) ];
+ [ (0, Integer 3); (1, Integer 200); (2, Integer 0) ];
+ ]
+ ~expected:(Ok [ [| ImportCSV.DataType.Integer 1 |] ])
+
let test_suit =
[
simple_extraction;
@@ -208,6 +323,10 @@ let test_suit =
sum_unfiltered;
sum_group;
sum_group_uniq;
+ filter_group;
+ filter_expression_and_group;
+ filter_group_and_expression;
+ filter_group_and_group;
]
let tests = "sql_db" >::: test_suit