Something went wrong. Try again.
SQL frontend over the catalog engine
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152(* A hash join keys a text by the semantics' collating key and reads a text as the number the semantics says it spells. A toy semantics whose one sequence folds case and that reads no text as a number offers 'abc' and 'ABC' for an outer 'ABC' and nothing for an outer 5, where sqlite3's numeric reading offers the inner '5' too. *)
open Catalog
module Toy = struct type collation = Fold
let key Fold s = String.lowercase_ascii s let numeric _ = Noneend
module Join = Sql.Private.Join_core.Make (Toy)
(* The inner rows [c] offers where [outer] stands. *)let offered (c : Cursor.t) = let m = Register.v () in let rec go acc = c.column 0 m; let acc = Register.to_value m :: acc in if c.next () then go acc else List.rev acc in if c.rewind () then go [] else []
let value = Alcotest.testable Value.pp Value.equal
let test_semantics_decide () = let outer = Spi.list_cursor [ [ Value.Text "ABC" ]; [ Value.Int 5L ] ] in let inner = [ [ Value.Text "abc" ]; [ Value.Text "5" ]; [ Value.Text "ABC" ] ] in let c = Join.probe ~collation:Fold ~outer ~outer_key:0 ~inner ~inner_key:0 () in Alcotest.(check bool) "the outer has a first row" true (outer.rewind ()); Alcotest.(check (list value)) "'ABC' meets both spellings under the folding key" [ Value.Text "abc"; Value.Text "ABC" ] (offered c); Alcotest.(check bool) "the outer has a second row" true (outer.next ()); Alcotest.(check (list value)) "5 meets no text" [] (offered c)
let suite = ( "join_core", [ Alcotest.test_case "the semantics decide every hash key" `Quick test_semantics_decide; ] )