From c67ed574a7a95db73d9349d58727452850bd47b9 Mon Sep 17 00:00:00 2001 From: Marcos Magueta Date: Sun, 8 Dec 2024 15:00:31 -0300 Subject: planner seq scan assuming ordering of results --- lib/planner.ml | 12 +++++++++++- lib/schema.ml | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/planner.ml b/lib/planner.ml index ceaf815..b88090d 100644 --- a/lib/planner.ml +++ b/lib/planner.ml @@ -1,7 +1,17 @@ module Scan = struct open Disk let execute commit locations (entity: string) = - Executor.read commit locations ~filename:entity + let binary = Executor.read commit locations ~filename:("schema~" ^ entity) in + let relation = + Result.map_error (fun _ -> "Failed to deserialize relation from binary format.") + @@ Data_encoding.Binary.of_bytes Schema.Protocol.relation_encoding (Bytes.concat Bytes.empty binary) in + match relation with + | Ok relation -> + begin + let attrs = List.map (fun (a: Schema.Protocol.attribute) -> relation.name ^ "/" ^ a.name) relation.attributes in + Executor.read commit locations ~filename:("schema~" ^ entity) + end + | Error err -> failwith err end module Join = struct diff --git a/lib/schema.ml b/lib/schema.ml index 74ce720..81632b4 100644 --- a/lib/schema.ml +++ b/lib/schema.ml @@ -38,7 +38,7 @@ let test_schema_write_and_retrieve() = let locations: Executor.locations = Executor.StringMap.empty in let open Extensions.Result in let+ user_relation = - let relation: Protocol.relation = { name = "user"; attributes = [{name = "first-name"; attr_type = "string"}; {name = "last-name"; attr_type = "string"}] } in + let relation: Protocol.relation = { name = "schema~user"; attributes = [{name = "first-name"; attr_type = "string"}; {name = "last-name"; attr_type = "string"}] } in Result.map_error (fun _ -> "Failed to serialize relation to binary format.") @@ Binary.to_bytes Protocol.relation_encoding relation in @@ -46,7 +46,7 @@ let test_schema_write_and_retrieve() = {kind = Command.WRITE; timestamp = 10.0; hash = ""; content = Bytes.to_string user_relation; filename = "user"; references = []} in let+ ((stream, locations), Command.ComputedHash handle) = Command.commit_and_perform stream locations command_write in let command_read: Command.t = - {kind = Command.READ; timestamp = 10.0; hash = handle; content = ""; filename = "user"; references = []} in + {kind = Command.READ; timestamp = 10.0; hash = handle; content = ""; filename = "schema~user"; references = []} in let+ ((stream, locations), Command.Read content) = Command.commit_and_perform stream locations command_read in let+ user_relation = Result.map_error (fun _ -> "Failed to deserialize relation from binary format.") -- cgit v1.2.3