-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/reduce mapping layers #403
Conversation
Warning Rate Limit Exceeded@amimart has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 6 minutes and 6 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the @coderabbitai review command. Alternatively, push new commits to this PR. We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per repository. WalkthroughThe changes primarily focus on enhancing the functionality of the query engine and refactoring the code for better organization and readability. Key modifications include the introduction of new structs and methods, changes to function parameters and return types, and the removal of unused code. The updates aim to improve the handling of triples and atoms, namespace resolution, and error handling. Changes
Poem
TipsChat with CodeRabbit Bot (
|
size-limit report 📦
|
Codecov Report
@@ Coverage Diff @@
## main #403 +/- ##
==========================================
- Coverage 97.76% 96.93% -0.83%
==========================================
Files 42 48 +6
Lines 10243 9858 -385
==========================================
- Hits 10014 9556 -458
- Misses 229 302 +73
... and 5 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
fa085ff
to
6ebbf83
Compare
@ccamel I've open to PR to review to take benefits from your eventual remarks and those from @coderabbitai while I'm adding some tests 😎 |
bdc737a
to
cc94b6d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to filter (2)
- Cargo.lock
- contracts/okp4-cognitarium/Cargo.toml
Files selected for processing (9)
- contracts/okp4-cognitarium/src/contract.rs (6 hunks)
- contracts/okp4-cognitarium/src/querier/engine.rs (10 hunks)
- contracts/okp4-cognitarium/src/querier/mapper.rs (1 hunks)
- contracts/okp4-cognitarium/src/querier/mod.rs (1 hunks)
- contracts/okp4-cognitarium/src/querier/plan_builder.rs (5 hunks)
- contracts/okp4-cognitarium/src/rdf/atom.rs (3 hunks)
- contracts/okp4-cognitarium/src/rdf/mapper.rs (2 hunks)
- contracts/okp4-cognitarium/src/state/namespaces.rs (3 hunks)
- contracts/okp4-cognitarium/src/storer/engine.rs (5 hunks)
Files skipped from review due to trivial changes (3)
- contracts/okp4-cognitarium/src/querier/mod.rs
- contracts/okp4-cognitarium/src/rdf/atom.rs
- contracts/okp4-cognitarium/src/rdf/mapper.rs
Additional comments: 33
contracts/okp4-cognitarium/src/querier/mapper.rs (1)
- 1-84: The changes in this hunk are mostly about adding a new parameter
prefixes
to the functionsnode_as_subject
,node_as_predicate
,node_as_object
,literal_as_object
, andiri_as_node
. This parameter is used to resolve namespaces and handle prefixed IRIs. The functioniri_as_node
now returns aStdResult<state::Node>
instead ofstate::Node
, which allows for better error handling. The changes seem to be consistent and logical. However, ensure that all calls to these functions throughout the codebase have been updated to match the new signatures.contracts/okp4-cognitarium/src/contract.rs (7)
99-115: The
delete_all
method is used here to delete all triples. Ensure that this is the intended behavior and that it won't accidentally delete necessary data. Also, make sure that thedelete_all
method handles errors properly and doesn't fail silently if it encounters an issue.140-147: The
query
module has been modified. Ensure that all changes are compatible with the rest of the codebase and that all necessary updates have been made.173-176: The
select
function now uses themap_select_solutions
function. Ensure that this function is correctly implemented and that it handles errors properly.222-231: The
describe
function now uses theresolve_atoms
method. Ensure that this method is correctly implemented and that it handles errors properly.276-285: The
construct
function now uses theresolve_atoms
method. Ensure that this method is correctly implemented and that it handles errors properly.321-322: The
as_select_variables
function is used here. Ensure that this function is correctly implemented and that it handles errors properly.341-370: The
map_select_solutions
function is used here. Ensure that this function is correctly implemented and that it handles errors properly.contracts/okp4-cognitarium/src/storer/engine.rs (5)
4-9: The import of
blake3::Hash
has been removed. Ensure that it is not used elsewhere in the code.52-63: The
triple_size
function now returns aStdResult<usize>
instead ofusize
. This change is likely due to the fact that the function now performs operations that can fail and return an error. This is a good practice as it allows for better error handling.108-111: The
delete_all
function now takes a slice ofTriple
structs instead ofrdf::Atom
. This change is likely due to the fact that the function now operates directly onTriple
structs instead ofrdf::Atom
. This is a good practice as it simplifies the function's implementation and makes it more efficient.115-149: The
delete_triple
function has been modified to use thetriples().may_load
andtriples().replace
functions instead oftriples().remove
. This change is likely due to the fact that the function now needs to check if the triple exists before deleting it and replace it withNone
if it does. This is a good practice as it prevents the function from attempting to delete non-existing triples and allows for better error handling.241-276: The
triple_size
,subject_size
,node_size
, andobject_size
functions now take a mutable reference toself
. This change is likely due to the fact that these functions now modify theStoreEngine
struct's state. This is a good practice as it allows these functions to modify the struct's state and ensures that the struct's state is always up-to-date.contracts/okp4-cognitarium/src/state/namespaces.rs (3)
194-205: The
resolve_from_key
method is a good addition to theNamespaceBatchService
struct. It provides a way to resolve aNamespace
from its internal key, which can be useful in various scenarios. The implementation looks correct and it uses theresolve_from_key
method from theNamespaceResolver
struct, which is the correct way to do it.238-261: The
free_ref
method has been updated to take akey
parameter instead of astorage
parameter. This is a good change as it simplifies the method signature and makes it more intuitive to use. The implementation of the method has also been updated to decrement the reference count of the namespace and update thens_count_diff
field accordingly. This is a logical change and it seems to be implemented correctly. However, it's important to ensure that thefree_ref
method is called correctly throughout the codebase with the new signature.286-288: The
allocate
method is a private method used to allocate a newNamespace
with a given value. The implementation looks correct and it properly updates thens_key_inc
andns_count_diff
fields. However, it's important to note that theallocate
method does not check if aNamespace
with the same value already exists. If this is a possibility, it might be a good idea to add a check for this to avoid creating duplicateNamespace
instances.fn allocate(&mut self, value: String) -> Namespace { if self.ns_resolver.by_val.contains_key(&value) { panic!("Namespace with the same value already exists"); } let ns = Namespace { value, key: self.ns_key_inc, counter: 0u128, }; self.ns_key_inc += 1; self.ns_count_diff += 1; self.ns_resolver.insert(ns).borrow().clone() }contracts/okp4-cognitarium/src/querier/engine.rs (11)
1-24: The
QueryEngine
andSelectResults
structs are defined. TheQueryEngine
struct has astorage
field, and theSelectResults
struct hashead
andsolutions
fields. TheQueryEngine
struct has anew
method that takes astorage
argument and returns a newQueryEngine
instance.47-55: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [34-52]
The
select
method of theQueryEngine
struct is defined. It takes aQueryPlan
and a vector ofSelectItem
as arguments, and returns aSelectResults
instance. Thehead
field of theSelectResults
instance is a vector of the keys of thebindings
map, and thesolutions
field is aSolutionsIterator
instance.
- 372-418: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [375-439]
The
SolutionsIterator
struct and its methods are defined. TheSolutionsIterator
struct hasiter
andbindings
fields. Thenew
method takes aResolvedVariablesIterator
and aBTreeMap
of bindings as arguments, and returns a newSolutionsIterator
instance. Theresolve_triples
andresolve_atoms
methods take several arguments and return a vector ofTriple
andAtom
instances, respectively.
441-535: The
ResolvedTripleIterator
struct and its methods are defined. TheResolvedTripleIterator
struct hasiter
,templates
, andbuffer
fields. Thetry_new
method takes several arguments and returns a newResolvedTripleIterator
instance. Thenext
method returns the nextTriple
instance from the buffer.502-631: The
TripleTemplate
struct and its methods are defined. TheTripleTemplate
struct hassubject
,predicate
, andobject
fields. Thetry_new
method takes several arguments and returns a newTripleTemplate
instance. Theresolve
method takes aBTreeMap
of variables as an argument and returns aTriple
instance.633-856: The
ResolvedAtomIterator
struct and its methods are defined. TheResolvedAtomIterator
struct hasns_resolver
,storage
,iter
,templates
, andbuffer
fields. Thetry_new
method takes several arguments and returns a newResolvedAtomIterator
instance. Thenext
method returns the nextAtom
instance from the buffer.986-1082: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [858-1079]
The test module is defined. It contains several test cases for the
select
method of theQueryEngine
struct.
- 926-937: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [918-934]
This test case expects an error because the selected variable is not found in the query.
- 946-966: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [935-963]
This test case expects a successful result with a single variable in the result set.
- 986-1082: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [964-1066]
This test case expects a successful result with multiple variables in the result set.
- 1068-1079: The test cases are executed and the results are asserted.
contracts/okp4-cognitarium/src/querier/plan_builder.rs (6)
1-11: Imports have been updated to reflect the changes in the codebase. Ensure that these changes do not break any functionality.
1-11: > Note: This review was outside of the patch, but no patch was found that overlapped with it. Original lines [12-80]
The
PlanBuilder
struct and its methods have been updated. The changes seem to be mostly refactoring and reorganizing the code. Ensure that these changes do not break any functionality.
115-138: The
build_subject_pattern
andbuild_predicate_pattern
methods have been updated to use the newnode_as_subject
andnode_as_predicate
functions. Ensure that these changes do not break any functionality.142-159: The
build_object_pattern
method has been updated to use the newnode_as_object
andliteral_as_object
functions. Ensure that these changes do not break any functionality.180-188: The test imports have been updated to reflect the changes in the codebase. Ensure that these changes do not break any functionality.
264-335: The
build_named_node
test has been commented out. If this test is no longer relevant due to the changes in the codebase, consider removing it entirely. If it is still relevant, consider updating it to reflect the changes in the codebase.337-End:
Thebuild_triple_pattern
andbuild_plan
tests have been updated to reflect the changes in the codebase. Ensure that these changes do not break any functionality.
cc94b6d
to
f08f7d2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's awesome! Great job. 👍
Closes #404
Proposed solution
To avoid unnecessary mapping layers, it is mandatory that the
QueryEngine
doesn't return already mapped data, its design is thus altered to provide a solutions iterator by exposing the resolved variables from the state directly.As a common usage of the
QueryEngine::select
in the processing ofDeleteData
,Describe
andConstruct
messages is to recompose triples or atoms from a set of patterns applied on resolved variables, I propose to introduce new iterator implementations (i.e.ResolvedTripleIterator
&ResolvedAtomIterator
) which based on a set of patterns and a solutions iterator offer those recomposition.The
StoreEngine
has been in consequence updated to manage triple deletion directly fromstate::Triple
, this way there is no mapping layer between the select query and the actual deletion.Bug fixes
StoreEngine
now doesn't decrease counters (i.e. triple count & total byte size) when deleting non existing triples.DeleteData
,Describe
andConstruct
when a resolved triple pattern leads to an impossible triple construction (e.g. a variable from the object term representing a simple literal used as a predicate) it doesn't fail anymore, the solution is ignored.Summary by CodeRabbit
Refactor:
execute
andquery
modules incontract.rs
for better code readability and efficiency.QueryEngine
struct and related functions inengine.rs
.PlanBuilder
struct and its methods inplan_builder.rs
for better code structure.TriplePattern
struct fromatom.rs
to clean up the codebase.New Features:
mapper
module inmod.rs
for better code organization.resolve_from_key
method innamespaces.rs
to resolve aNamespace
from its internal key.Bug Fixes:
contract.rs
for correct program execution.mapper.rs
to handle prefixed IRIs and resolve namespaces.Chores:
StoreEngine
struct inengine.rs
to use more appropriate data types and methods.