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

on list insert [null]==[null] #2927

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/arithmetic/entity_funcs/entity_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static SIValue _AR_NodeDegree
// validate signature function(NODE, STR_0, STR_1, ... STR_N)
for(int i = 1; i < argc; i++) {
if(SI_TYPE(argv[i]) == T_STRING) {
if(SIArray_ContainsValue(labels, argv[i], NULL) == false) {
if(SIArray_ContainsValue(labels, argv[i], NULL, false) == false) {
SIArray_Append(&labels, argv[i]);
}
} else {
Expand All @@ -182,7 +182,7 @@ static SIValue _AR_NodeDegree
Error_SITypeMismatch(elem, T_STRING);
return SI_NullVal();
}
if(SIArray_ContainsValue(labels, elem, NULL) == false) {
if(SIArray_ContainsValue(labels, elem, NULL, false) == false) {
SIArray_Append(&labels, elem);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/arithmetic/list_funcs/list_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ SIValue AR_IN(SIValue *argv, int argc, void *private_data) {
SIValue lookupList = argv[1];
// indicate if there was a null comparison during the array scan
bool comparedNull = false;
if(SIArray_ContainsValue(lookupList, lookupValue, &comparedNull)) {
if(SIArray_ContainsValue(lookupList, lookupValue, &comparedNull, false)) {
return SI_BoolVal(true);
}
// if there was a null comparison return null, other wise return false as the lookup item did not found
Expand Down Expand Up @@ -531,7 +531,7 @@ SIValue AR_INSERT(SIValue *argv, int argc, void *private_data) {
allow_dups = SIValue_IsTrue(argv[3]);
}

if(!allow_dups && SIArray_ContainsValue(list, val, NULL)) {
if(!allow_dups && SIArray_ContainsValue(list, val, NULL, true)) {
// caller requested no duplicates
// if value already exists in list return the original list
return SIArray_Clone(list);
Expand Down
4 changes: 4 additions & 0 deletions src/arithmetic/string_funcs/string_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ SIValue AR_JOIN(SIValue *argv, int argc, void *private_data) {

uint32_t count = SIArray_Length(list);

if(count == 0) {
return SI_ConstStringVal("");
}

size_t delimeter_len = strlen(delimiter);
uint str_len = delimeter_len * (count - 1);
for(uint i = 0; i < count; i++) {
Expand Down
5 changes: 4 additions & 1 deletion src/datatypes/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool SIArray_ContainsType(SIValue siarray, SIType t) {
* @param comparedNull: indicate if there was a null comparison during the array scan
* @retval a boolean indicating whether value was found in siarray
*/
bool SIArray_ContainsValue(SIValue siarray, SIValue value, bool *comparedNull) {
bool SIArray_ContainsValue(SIValue siarray, SIValue value, bool *comparedNull, bool nullEqualsNull) {
// indicate if there was a null comparison during the array scan
if(comparedNull) *comparedNull = false;
uint array_len = SIArray_Length(siarray);
Expand All @@ -74,6 +74,9 @@ bool SIArray_ContainsValue(SIValue siarray, SIValue value, bool *comparedNull) {
int compareValue = SIValue_Compare(elem, value, &disjointOrNull);
if(disjointOrNull == COMPARED_NULL) {
if(comparedNull) *comparedNull = true;
if(nullEqualsNull && compareValue == 0) {
return true;
}
continue;
}
if(compareValue == 0) return true;
Expand Down
2 changes: 1 addition & 1 deletion src/datatypes/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool SIArray_ContainsType(SIValue siarray, SIType t);
* @param comparedNull: indicate if there was a null comparison during the array scan
* @retval a boolean indicating whether value was found in siarray
*/
bool SIArray_ContainsValue(SIValue siarray, SIValue value, bool *comparedNull);
bool SIArray_ContainsValue(SIValue siarray, SIValue value, bool *comparedNull, bool nullEqualsNull);

/**
* @brief Returns true if all of the elements in the array are of type 't'
Expand Down
5 changes: 5 additions & 0 deletions tests/flow/test_function_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2483,6 +2483,11 @@ def test89_JOIN(self):
query = """RETURN string.join(['HELL','OW', 'NOW'], ' ')"""
actual_result = graph.query(query)
self.env.assertEquals(actual_result.result_set[0], expected_result)

expected_result = ['']
query = """RETURN string.join([])"""
actual_result = graph.query(query)
self.env.assertEquals(actual_result.result_set[0], expected_result)

def test90_size(self):
query_to_expected_result = {
Expand Down
6 changes: 6 additions & 0 deletions tests/flow/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,12 @@ def test11_insert(self):
actual_result = redis_graph.query(query)
self.env.assertEquals(actual_result.result_set[0], expected_result)

# test val of type [NULL]
expected_result = [[1, [None], 2, 3]]
query = """RETURN list.insert([1,[null],2,3], -1, [null], false)"""
actual_result = redis_graph.query(query)
self.env.assertEquals(actual_result.result_set[0], expected_result)

# test dup=true
expected_result = [[1,2,3]]
query = """RETURN list.insert([1,2,3], 0, 2, false)"""
Expand Down