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

Fix transfer of SIValue ownership in DISTINCT function #2176

Merged
merged 2 commits into from Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/arithmetic/conditional_funcs/conditional_funcs.c
Expand Up @@ -80,7 +80,7 @@ SIValue AR_COALESCE(SIValue *argv, int argc) {
// otherwise `X` is returned and added to to the set.
SIValue AR_DISTINCT(SIValue *argv, int argc) {
set *set = argv[1].ptrval;
if(Set_Add(set, argv[0])) return SI_ConstValue(argv);
if(Set_Add(set, argv[0])) return SI_TransferOwnership(argv);
return SI_NullVal();
}

Expand Down
7 changes: 7 additions & 0 deletions tests/flow/test_function_calls.py
Expand Up @@ -474,3 +474,10 @@ def test20_keys(self):
# Test trying to retrieve keys of an invalid type
query = """WITH 10 AS map RETURN keys(map)"""
self.expect_type_error(query)

def test21_distinct_memory_management(self):
# validate behavior of the DISTINCT function with allocated values
query = """MATCH (a {val: 0}) RETURN collect(DISTINCT a { .name })"""
actual_result = graph.query(query)
expected_result = [[[{'name': 'Roi'}]]]
self.env.assertEquals(actual_result.result_set, expected_result)