Extend ToBoolean function (#1620)

This commit is contained in:
DavIvek 2024-01-08 13:17:55 +01:00 committed by GitHub
parent 57e40a2b18
commit bd11266f82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 3 deletions

View File

@ -1,4 +1,4 @@
// Copyright 2023 Memgraph Ltd.
// Copyright 2024 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
@ -504,8 +504,8 @@ TypedValue ToBoolean(const TypedValue *args, int64_t nargs, const FunctionContex
return TypedValue(value.ValueInt() != 0L, ctx.memory);
} else {
auto s = utils::ToUpperCase(utils::Trim(value.ValueString()));
if (s == "TRUE") return TypedValue(true, ctx.memory);
if (s == "FALSE") return TypedValue(false, ctx.memory);
if (s == "TRUE" || s == "T") return TypedValue(true, ctx.memory);
if (s == "FALSE" || s == "F") return TypedValue(false, ctx.memory);
// I think this is just stupid and that exception should be thrown, but
// neo4j does it this way...
return TypedValue(ctx.memory);

View File

@ -60,6 +60,34 @@ Feature: Functions
| false |
| true |
Scenario: ToBoolean test 03:
Given an empty graph
And having executed
"""
CREATE (:Node {prop: ToBoolean("t")});
"""
When executing query:
"""
MATCH (n:Node) RETURN n.prop;
"""
Then the result should be:
| n.prop |
| true |
Scenario: ToBoolean test 03:
Given an empty graph
And having executed
"""
CREATE (:Node {prop: ToBoolean("f")});
"""
When executing query:
"""
MATCH (n:Node) RETURN n.prop;
"""
Then the result should be:
| n.prop |
| false |
Scenario: ToInteger test 01:
Given an empty graph
And having executed