Skip to content

Commit

Permalink
Fix transfer of SIValue ownership in DISTINCT function (#2176)
Browse files Browse the repository at this point in the history
Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com>
  • Loading branch information
2 people authored and AviAvni committed Mar 2, 2022
1 parent ea5d968 commit c5504ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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)

0 comments on commit c5504ab

Please sign in to comment.