Extend ToBoolean function (#1620)
This commit is contained in:
parent
57e40a2b18
commit
bd11266f82
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2023 Memgraph Ltd.
|
// Copyright 2024 Memgraph Ltd.
|
||||||
//
|
//
|
||||||
// Use of this software is governed by the Business Source License
|
// 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
|
// 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);
|
return TypedValue(value.ValueInt() != 0L, ctx.memory);
|
||||||
} else {
|
} else {
|
||||||
auto s = utils::ToUpperCase(utils::Trim(value.ValueString()));
|
auto s = utils::ToUpperCase(utils::Trim(value.ValueString()));
|
||||||
if (s == "TRUE") return TypedValue(true, ctx.memory);
|
if (s == "TRUE" || s == "T") return TypedValue(true, ctx.memory);
|
||||||
if (s == "FALSE") return TypedValue(false, 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
|
// I think this is just stupid and that exception should be thrown, but
|
||||||
// neo4j does it this way...
|
// neo4j does it this way...
|
||||||
return TypedValue(ctx.memory);
|
return TypedValue(ctx.memory);
|
||||||
|
@ -60,6 +60,34 @@ Feature: Functions
|
|||||||
| false |
|
| false |
|
||||||
| true |
|
| 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:
|
Scenario: ToInteger test 01:
|
||||||
Given an empty graph
|
Given an empty graph
|
||||||
And having executed
|
And having executed
|
||||||
|
Loading…
Reference in New Issue
Block a user