Skip to content
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

support nested containers as attribute type #658

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

swilly22
Copy link
Contributor

@swilly22 swilly22 commented Apr 21, 2024

Resolves #657, #31

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added functionality to check for a specific type in nested maps within arrays.
    • Introduced new functions to create maps from keys and values arrays, from a binary stream, and to check if a map contains a key with a specific type.
    • Added functions to handle writing map data to effects buffers and saving maps in a specific format within serializers.
  • Bug Fixes

    • Updated error message related to property values, specifying valid types as primitive types, arrays, or maps.
    • Updated handling of NULL values in property maps.
    • Refined validation for array and map property values to exclude invalid types.
  • Documentation

    • Enhanced comments for clarity and consistency in various files.
  • Tests

    • Added and adjusted test cases to reflect new features and changes in handling properties and map types.

@swilly22 swilly22 requested a review from AviAvni April 21, 2024 10:53
Copy link

coderabbitai bot commented Apr 21, 2024

Walkthrough

The recent updates introduce enhanced support for nested data structures within graph entities, specifically focusing on nested arrays and maps. This includes new functionalities for creating, updating, and serializing maps, as well as improved error handling and validation for entity attributes that utilize these complex types.

Changes

Files Change Summary
src/datatypes/map.c, src/datatypes/map.h Added functions to create maps from arrays, binary streams, and check for specific key types.
src/errors/error_msgs.h Updated error messages related to shortestPath traversals and SET expressions to mention FalkorDB.
tests/flow/test_all_shortest_paths.py Updated error messages related to shortest paths to mention FalkorDB.
tests/flow/test_entity_update.py Adjusted property assignments in Cypher queries and updated error messages and test method names.
tests/flow/test_graph_create.py Modified queries for creating invalid complex types in arrays, added a test for creating entities with arrays and maps as attributes.
tests/flow/test_persistency.py Added a test to verify the persistence of nested containers in a graph database.
tests/flow/test_shortest_path.py Updated assertion message related to shortest paths to mention FalkorDB.

Assessment against linked issues

Objective Addressed Explanation
Add support for nested datatypes, specifically maps, in properties. (#657)
Enable the usage of maps as property values within the system. (#657)
Maintain backward compatibility with existing property structures. (#657)
Ensure that the system can handle nested data structures for properties. (#657)
Provide clear documentation and examples for utilizing nested map datatypes in properties. (#657) Documentation and examples are not covered in the PR changes.

Possibly related issues

🐇🎉
A map and array nested deep,
In code where data structures sleep.
Now they stir, in graph's embrace,
Crafted with elegance and grace.
Cheers to the coders, their wisdom we reap!
🎉🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Actionable comments outside the diff hunks (1)
tests/flow/test_effects.py (1)

Line range hint 36-36: Avoid using a bare except statement.

- except:
+ except Exception as e:
+     # Handle or log the exception e appropriately

Using a bare except can catch unexpected events such as memory errors, interrupts, system exit, and so on. It's better to catch specific exceptions to avoid masking other errors.

Comment on lines +520 to +522
v: vecf32([-1.1, 2.2, -3.3]),
m: {a:1, b:{c:'string_val'}}
}"""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

Several files in the codebase still use the old function signature.

  • The search did not reveal specific handling for the attributes v and m in serialization or deserialization processes.
  • The only related mention was a generic comment in tests/flow/test_persistency.py about property handling, which does not confirm specific management for v and m.
Analysis chain

Ensure the new attributes v and m are correctly handled in the test.

Check the serialization and deserialization processes for the updated attributes in edge updates using map overwrite.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the attributes 'v' and 'm' are being correctly serialized and deserialized.
rg --type py "serialize_v_attribute"
rg --type py "serialize_m_attribute"
rg --type py "deserialize_v_attribute"
rg --type py "deserialize_m_attribute"

Length of output: 151



Script:

#!/bin/bash
# Broaden the search to check for any serialization or deserialization related to 'v' and 'm' in Python files
rg --type py -A 3 -B 3 "v" | grep -i "serialize\|deserialize"
rg --type py -A 3 -B 3 "m" | grep -i "serialize\|deserialize"

Length of output: 397

Copy link
Contributor Author

@swilly22 swilly22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

"CREATE ({v: []})", # empty array
"CREATE ({v: [[]]})", # nested array
"CREATE ({v: [{}]})", # map within array
"CREATE ({v: {x:{}}})", # nested map
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add additional values to nested maps.


for query in queries:
try:
self.graph.query(query)
self.env.assertTrue(False)
except redis.exceptions.ResponseError as e:
self.env.assertContains("Property values can only be of primitive types or arrays of primitive types", str(e))
self.env.assertContains("Property values can only be of primitive types arrays or maps", str(e))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rephrase,
e.g. "properties can't contain Graph entities nor Paths."

("CREATE (a {v: {s:1}}) RETURN a.v", {'s': 1}),

# map with NULL element
("CREATE (a {v: {s: null}}) RETURN a.v", {'s': None}),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include a scenario which tests map containing strings


try:
self.graph.query("MERGE (n:N) ON MATCH SET n = {v: 1}, n.a.b=3 RETURN n")
self.env.assertTrue(False)
except ResponseError as e:
self.env.assertContains("RedisGraph does not currently support non-alias references on the left-hand side of SET expressions", str(e))
self.env.assertContains("FalkorDB does not currently support non-alias references on the left-hand side of SET expressions", str(e))

# Fail when a property is a complex type nested within an array type
def test13_invalid_complex_type_in_array(self):
# Test combinations of invalid types with nested and top-level arrays
# Invalid types are NULL, maps, nodes, edges, and paths
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update comment

try:
res = self.graph.query(q)
except ResponseError as e:
self.env.assertContains("", str(e))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fill in exception error message

@@ -60,6 +60,29 @@ static void _RdbSaveSIVector
SerializerIO_WriteFloat(rdb, values[i]);
}
}
static void _RdBSaveMap
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talk to Dudi regarding update procedure.

@@ -9,6 +9,7 @@
// forward declarations
static SIValue _RdbLoadPoint(SerializerIO rdb);
static SIValue _RdbLoadSIArray(SerializerIO rdb);
static SIValue _RdbLoadMap (SerializerIO rdb, SIType t);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra space!

// a map containing an invalid type
if(SI_TYPE(val) == T_MAP) {
SIType invalid_types = ~SI_VALID_PROPERTY_VALUE & ~T_NULL;
bool res = SIArray_ContainsType(val, invalid_types);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong function call, should be SIMap_ContainsType!

@swilly22
Copy link
Contributor Author

swilly22 commented May 2, 2024

Performance test for Saving / Loading graphs with plenty of maps, some of which are small others might be quite large.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support nested arrays and nested maps as entity attribute
1 participant