allow list in tostring (#3184) · RedisGraph/RedisGraph@beb98a0 · GitHub
Skip to content

Commit beb98a0

Browse files
authored
allow list in tostring (#3184)
* allow list in tostring * address reivew * add doc * doc
1 parent 6c0f91e commit beb98a0

5 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎docs/commands/graph.query.md‎

Lines changed: 1 addition & 1 deletion

‎src/arithmetic/string_funcs/string_funcs.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
// toString supports only integer, float, string, boolean, point, duration,
2020
// date, time, localtime, localdatetime or datetime values
21-
#define STRINGABLE (SI_NUMERIC | T_POINT | T_DURATION | T_DATETIME | T_STRING | T_BOOL)
21+
// array for backward compatibility
22+
#define STRINGABLE (SI_NUMERIC | T_ARRAY | T_POINT | T_DURATION | T_DATETIME | T_STRING | T_BOOL)
2223

2324
// returns a string containing the specified number of leftmost characters of the original string.
2425
SIValue AR_LEFT(SIValue *argv, int argc, void *private_data) {

‎tests/flow/test_function_calls.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ def test32_toStringOrNull(self):
10491049
# list
10501050
query = """RETURN toStringOrNull([1])"""
10511051
actual_result = graph.query(query)
1052-
self.env.assertEquals(actual_result.result_set[0][0], None)
1052+
self.env.assertEquals(actual_result.result_set[0][0], "[1]")
10531053

10541054
# node
10551055
query = """CREATE (n) RETURN toStringOrNull(n)"""
@@ -1105,8 +1105,12 @@ def test33_toString(self):
11051105
actual_result = graph.query(query)
11061106
self.env.assertEquals(actual_result.result_set[0][0], None)
11071107

1108+
# null
1109+
query = """RETURN toString([1])"""
1110+
actual_result = graph.query(query)
1111+
self.env.assertEquals(actual_result.result_set[0][0], "[1]")
1112+
11081113
queries = [
1109-
"""RETURN toString([1])""", # list
11101114
"""CREATE (n) RETURN toString(n)""", # node
11111115
"""CREATE ()-[r:R]->() RETURN toString(r)""" # edge
11121116
]
@@ -2218,7 +2222,7 @@ def test86_type_mismatch_message(self):
22182222
"CREATE ()-[r:R]->() RETURN hasLabels(r, ['abc', 'def'])": "Type mismatch: expected Node or Null but was Edge",
22192223
"RETURN toBoolean(1.2)": "Type mismatch: expected String, Boolean, Integer, or Null but was Float",
22202224
"RETURN isEmpty(1)": "Type mismatch: expected Map, List, String, or Null but was Integer",
2221-
"CREATE ()-[r:R]->() RETURN toString(r)": "Type mismatch: expected Datetime, Duration, String, Boolean, Integer, Float, Null, or Point but was Edge",
2225+
"CREATE ()-[r:R]->() RETURN toString(r)": "Type mismatch: expected List, Datetime, Duration, String, Boolean, Integer, Float, Null, or Point but was Edge",
22222226
}
22232227
for query, error in queries_with_errors.items():
22242228
self.expect_error(query, error)

‎tests/flow/test_list.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,8 @@ def test09_toStringList(self):
700700
self.env.assertEquals(actual_result.result_set[0], expected_result)
701701

702702
# Test list with mixed type values
703-
query = """RETURN toStringList(['abc', 7, '5.32', null, ['a','b']]) """
704-
expected_result = [['abc', '7', '5.32', None, None]]
703+
query = """RETURN toStringList(['abc', 7, '5.32', null, ['a','b', [{key:'value'}]]]) """
704+
expected_result = [['abc', '7', '5.32', None, '[a, b, [{key: value}]]']]
705705
actual_result = redis_graph.query(query)
706706
self.env.assertEquals(actual_result.result_set[0], expected_result)
707707

‎tests/tck/features/expressions/typeConversion/TypeConversion4.feature‎

Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)