aboutsummaryrefslogtreecommitdiff
path: root/tests/sql_db.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2025-02-04 22:30:34 +0100
committerSébastien Dailly <sebastien@dailly.me>2025-02-13 18:30:43 +0100
commitd3e0821b9c1551177afb34220d951b087acdea22 (patch)
treeba23b2916c7cb0336cb42793e4bee931053cacf5 /tests/sql_db.ml
parent37556ab070abcbf87a1a822c95aeccf19dade687 (diff)
Fixed a bug when a group function did not partition in the same way as the uniq parameter
Diffstat (limited to 'tests/sql_db.ml')
-rw-r--r--tests/sql_db.ml153
1 files changed, 90 insertions, 63 deletions
diff --git a/tests/sql_db.ml b/tests/sql_db.ml
index 28666b2..75b8293 100644
--- a/tests/sql_db.ml
+++ b/tests/sql_db.ml
@@ -57,9 +57,7 @@ let run_test ~configuration ~input ~expected name =
let simple_extraction =
run_test "simple_extraction"
~configuration:
- {|version = 1
-
-[source]
+ {|[source]
name = "source_name"
file = "source_file"
@@ -69,31 +67,17 @@ columns = [
":B",
":E"]|}
~input:
- [
- [
- (0, ImportCSV.DataType.Integer 123);
- (1, ImportCSV.DataType.Integer 2);
- (4, ImportCSV.DataType.Integer 5);
- ];
- ]
+ ImportCSV.DataType.
+ [ [ (0, Integer 123); (1, Integer 2); (4, Integer 5) ] ]
~expected:
- (Ok
- [
- [|
- ImportCSV.DataType.Content "123_";
- ImportCSV.DataType.Integer 2;
- ImportCSV.DataType.Integer 5;
- |];
- ])
+ (Ok ImportCSV.DataType.[ [| Content "123_"; Integer 2; Integer 5 |] ])
(** Ensure the behavior of the sum function when a filter is given. It is
expected to accumulate the values over each line *)
let sum_sort =
run_test "sum_sort"
~configuration:
- {|version = 1
-
-[source]
+ {|[source]
name = "source_name"
file = "source_file"
@@ -103,37 +87,25 @@ columns = [
"sum(:C, [:B], [:A])",
]|}
~input:
- [
- [
- (0, ImportCSV.DataType.Integer 1);
- (1, ImportCSV.DataType.Content "A");
- (2, ImportCSV.DataType.Integer 100);
- ];
+ ImportCSV.DataType.
[
- (0, ImportCSV.DataType.Integer 2);
- (1, ImportCSV.DataType.Content "A");
- (2, ImportCSV.DataType.Integer 100);
- ];
- [
- (0, ImportCSV.DataType.Integer 3);
- (1, ImportCSV.DataType.Content "A");
- (2, ImportCSV.DataType.Integer 100);
- ];
- ]
+ [ (0, Integer 1); (1, Content "A"); (2, Integer 100) ];
+ [ (0, Integer 2); (1, Content "A"); (2, Integer 100) ];
+ [ (0, Integer 3); (1, Content "A"); (2, Integer 100) ];
+ ]
~expected:
(Ok
- [
- [| ImportCSV.DataType.Integer 1; ImportCSV.DataType.Integer 100 |];
- [| ImportCSV.DataType.Integer 2; ImportCSV.DataType.Integer 200 |];
- [| ImportCSV.DataType.Integer 3; ImportCSV.DataType.Integer 300 |];
- ])
+ ImportCSV.DataType.
+ [
+ [| Integer 1; Integer 100 |];
+ [| Integer 2; Integer 200 |];
+ [| Integer 3; Integer 300 |];
+ ])
let sum_total =
run_test "sum_total"
~configuration:
- {|version = 1
-
-[source]
+ {|[source]
name = "source_name"
file = "source_file"
@@ -143,14 +115,11 @@ columns = [
"sum(:C, [], [])",
]|}
~input:
- [
+ ImportCSV.DataType.
[
- (0, ImportCSV.DataType.Integer 1); (2, ImportCSV.DataType.Integer 100);
- ];
- [
- (0, ImportCSV.DataType.Integer 2); (2, ImportCSV.DataType.Integer 100);
- ];
- ]
+ [ (0, Integer 1); (2, Integer 100) ];
+ [ (0, Integer 2); (2, Integer 100) ];
+ ]
~expected:
(Ok [ [| ImportCSV.DataType.Integer 1; ImportCSV.DataType.Integer 200 |] ])
@@ -159,9 +128,7 @@ columns = [
let sum_unfiltered =
run_test "sum_unfiltered"
~configuration:
- {|version = 1
-
-[source]
+ {|[source]
name = "source_name"
file = "source_file"
@@ -171,16 +138,76 @@ columns = [
"sum(:C, [], [:A])",
]|}
~input:
- [
+ ImportCSV.DataType.
[
- (0, ImportCSV.DataType.Integer 1); (2, ImportCSV.DataType.Integer 100);
- ];
- [
- (0, ImportCSV.DataType.Integer 2); (2, ImportCSV.DataType.Integer 100);
- ];
- ]
+ [ (0, Integer 1); (2, Integer 100) ];
+ [ (0, Integer 2); (2, Integer 100) ];
+ ]
~expected:
(Ok [ [| ImportCSV.DataType.Integer 1; ImportCSV.DataType.Integer 200 |] ])
-let test_suit = [ simple_extraction; sum_sort; sum_total; sum_unfiltered ]
+let sum_group =
+ run_test "sum_group"
+ ~configuration:
+ {|[source]
+name = "source_name"
+file = "source_file"
+
+[sheet]
+columns = [
+ ":A",
+ "sum(:C, [:A], [])",
+]|}
+ ~input:
+ ImportCSV.DataType.
+ [
+ [ (0, Integer 1); (2, Integer 100) ];
+ [ (0, Integer 1); (2, Integer 100) ];
+ [ (0, Integer 2); (2, Integer 100) ];
+ ]
+ ~expected:
+ (Ok
+ ImportCSV.DataType.
+ [
+ [| Integer 1; Integer 200 |];
+ [| Integer 1; Integer 200 |];
+ [| Integer 2; Integer 100 |];
+ ])
+
+(** Adding a uniq filter on column A does not change the sum of the values *)
+let sum_group_uniq =
+ run_test "sum_group_uniq"
+ ~configuration:
+ {|[source]
+name = "source_name"
+file = "source_file"
+
+[sheet]
+uniq = [":A"]
+columns = [
+ ":A",
+ "sum(:C, [:A], [])",
+]|}
+ ~input:
+ ImportCSV.DataType.
+ [
+ [ (0, Integer 1); (2, Integer 100) ];
+ [ (0, Integer 1); (2, Integer 100) ];
+ [ (0, Integer 2); (2, Integer 100) ];
+ ]
+ ~expected:
+ (Ok
+ ImportCSV.DataType.
+ [ [| Integer 1; Integer 200 |]; [| Integer 2; Integer 100 |] ])
+
+let test_suit =
+ [
+ simple_extraction;
+ sum_sort;
+ sum_total;
+ sum_unfiltered;
+ sum_group;
+ sum_group_uniq;
+ ]
+
let tests = "sql_db" >::: test_suit