Compare commits
7 Commits
master
...
fix-valuet
Author | SHA1 | Date | |
---|---|---|---|
|
769f7cca03 | ||
|
1657f77562 | ||
|
3c4faa8663 | ||
|
2cc310703e | ||
|
97a3747905 | ||
|
a4f2035943 | ||
|
62624a39c8 |
@ -104,6 +104,7 @@ struct Date {};
|
||||
struct LocalTime {};
|
||||
struct LocalDateTime {};
|
||||
struct Duration {};
|
||||
struct Graph {};
|
||||
|
||||
template <class ArgType>
|
||||
bool ArgIsType(const TypedValue &arg) {
|
||||
@ -143,6 +144,8 @@ bool ArgIsType(const TypedValue &arg) {
|
||||
return arg.IsLocalDateTime();
|
||||
} else if constexpr (std::is_same_v<ArgType, Duration>) {
|
||||
return arg.IsDuration();
|
||||
} else if constexpr (std::is_same_v<ArgType, Graph>) {
|
||||
return arg.IsGraph();
|
||||
} else if constexpr (std::is_same_v<ArgType, void>) {
|
||||
return true;
|
||||
} else {
|
||||
@ -193,6 +196,8 @@ constexpr const char *ArgTypeName() {
|
||||
return "LocalDateTime";
|
||||
} else if constexpr (std::is_same_v<ArgType, Duration>) {
|
||||
return "Duration";
|
||||
} else if constexpr (std::is_same_v<ArgType, Graph>) {
|
||||
return "graph";
|
||||
} else {
|
||||
static_assert(std::is_same_v<ArgType, Null>, "Unknown ArgType");
|
||||
}
|
||||
@ -583,7 +588,8 @@ TypedValue Type(const TypedValue *args, int64_t nargs, const FunctionContext &ct
|
||||
}
|
||||
|
||||
TypedValue ValueType(const TypedValue *args, int64_t nargs, const FunctionContext &ctx) {
|
||||
FType<Or<Null, Bool, Integer, Double, String, List, Map, Vertex, Edge, Path>>("type", args, nargs);
|
||||
FType<Or<Null, Bool, Integer, Double, String, List, Map, Vertex, Edge, Path, Date, LocalTime, LocalDateTime, Duration,
|
||||
Graph>>("type", args, nargs);
|
||||
// The type names returned should be standardized openCypher type names.
|
||||
// https://github.com/opencypher/openCypher/blob/master/docs/openCypher9.pdf
|
||||
switch (args[0].type()) {
|
||||
@ -616,8 +622,9 @@ TypedValue ValueType(const TypedValue *args, int64_t nargs, const FunctionContex
|
||||
case TypedValue::Type::Duration:
|
||||
return TypedValue("DURATION", ctx.memory);
|
||||
case TypedValue::Type::Graph:
|
||||
return TypedValue("GRAPH", ctx.memory);
|
||||
case TypedValue::Type::Function:
|
||||
throw QueryRuntimeException("Cannot fetch graph as it is not standardized openCypher type name");
|
||||
throw QueryRuntimeException("Unknown value type! Please report an issue!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,4 +3,5 @@ function(copy_awesome_functions_e2e_python_files FILE_NAME)
|
||||
endfunction()
|
||||
|
||||
copy_awesome_functions_e2e_python_files(common.py)
|
||||
copy_awesome_functions_e2e_python_files(awesome_functions.py)
|
||||
copy_awesome_functions_e2e_python_files(property_size.py)
|
||||
copy_awesome_functions_e2e_python_files(value_type.py)
|
||||
|
102
tests/e2e/awesome_functions/value_type.py
Normal file
102
tests/e2e/awesome_functions/value_type.py
Normal file
@ -0,0 +1,102 @@
|
||||
# Copyright 2023 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
|
||||
# License, and you may not use this file except in compliance with the Business Source License.
|
||||
#
|
||||
# As of the Change Date specified in that file, in accordance with
|
||||
# the Business Source License, use of this software will be governed
|
||||
# by the Apache License, Version 2.0, included in the file
|
||||
# licenses/APL.txt.
|
||||
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
from common import get_bytes, memgraph
|
||||
|
||||
TYPE = "type"
|
||||
|
||||
|
||||
def test_value_type_on_null_type(memgraph):
|
||||
result = next(memgraph.execute_and_fetch("RETURN valuetype(null) AS type"))[TYPE]
|
||||
assert result == "NULL"
|
||||
|
||||
|
||||
def test_value_type_on_bool_type(memgraph):
|
||||
result = next(memgraph.execute_and_fetch("RETURN valuetype(true) AS type"))[TYPE]
|
||||
assert result == "BOOLEAN"
|
||||
|
||||
|
||||
def test_value_type_on_int_type(memgraph):
|
||||
result = next(memgraph.execute_and_fetch("RETURN valuetype(1) AS type"))[TYPE]
|
||||
assert result == "INTEGER"
|
||||
|
||||
|
||||
def test_value_type_on_float_type(memgraph):
|
||||
result = next(memgraph.execute_and_fetch("RETURN valuetype(1.1) AS type"))[TYPE]
|
||||
assert result == "FLOAT"
|
||||
|
||||
|
||||
def test_value_type_on_string_type(memgraph):
|
||||
result = next(memgraph.execute_and_fetch("RETURN valuetype('string_type') AS type"))[TYPE]
|
||||
assert result == "STRING"
|
||||
|
||||
|
||||
def test_value_type_on_list_type(memgraph):
|
||||
result = next(memgraph.execute_and_fetch("RETURN valuetype([1, 2, 3]) AS type"))[TYPE]
|
||||
assert result == "LIST"
|
||||
|
||||
|
||||
def test_value_type_on_map_type(memgraph):
|
||||
result = next(memgraph.execute_and_fetch("RETURN valuetype({key: 'value'}) AS type"))[TYPE]
|
||||
assert result == "MAP"
|
||||
|
||||
|
||||
def test_value_type_on_date_type(memgraph):
|
||||
result = next(memgraph.execute_and_fetch("RETURN valuetype(date('2023-01-01')) AS type"))[TYPE]
|
||||
assert result == "DATE"
|
||||
|
||||
|
||||
def test_value_type_on_local_time_type(memgraph):
|
||||
result = next(memgraph.execute_and_fetch("RETURN valuetype(localtime('23:00:00')) AS type"))[TYPE]
|
||||
assert result == "LOCAL_TIME"
|
||||
|
||||
|
||||
def test_value_type_on_local_date_time_type(memgraph):
|
||||
result = next(memgraph.execute_and_fetch("RETURN valuetype(localdatetime('2022-01-01T23:00:00')) AS type"))[TYPE]
|
||||
assert result == "LOCAL_DATE_TIME"
|
||||
|
||||
|
||||
def test_value_type_on_duration_type(memgraph):
|
||||
result = next(memgraph.execute_and_fetch("RETURN valuetype(duration('P5DT2M2.33S')) AS type"))[TYPE]
|
||||
assert result == "DURATION"
|
||||
|
||||
|
||||
def test_value_type_on_node_type(memgraph):
|
||||
result = next(memgraph.execute_and_fetch("CREATE (n) WITH n RETURN valuetype(n) AS type"))[TYPE]
|
||||
assert result == "NODE"
|
||||
|
||||
|
||||
def test_value_type_on_relationship_type(memgraph):
|
||||
result = next(memgraph.execute_and_fetch("CREATE (n)-[r:TYPE]->(m) WITH r RETURN valuetype(r) AS type"))[TYPE]
|
||||
assert result == "RELATIONSHIP"
|
||||
|
||||
|
||||
def test_value_type_on_path_type(memgraph):
|
||||
result = next(
|
||||
memgraph.execute_and_fetch(
|
||||
"CREATE (n)-[r:TYPE]->(m) WITH 1 AS x MATCH p=(n)-[r]->(m) RETURN valuetype(p) AS type"
|
||||
)
|
||||
)[TYPE]
|
||||
assert result == "PATH"
|
||||
|
||||
|
||||
def test_value_type_on_graph_type(memgraph):
|
||||
result = next(memgraph.execute_and_fetch("MATCH p=(n)-[r]->(m) WITH project(p) AS g RETURN valuetype(g) AS type"))[
|
||||
TYPE
|
||||
]
|
||||
assert result == "GRAPH"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(pytest.main([__file__, "-rA"]))
|
@ -8,7 +8,11 @@ awesome_functions_cluster: &awesome_functions_cluster
|
||||
|
||||
|
||||
workloads:
|
||||
- name: "Awesome Functions"
|
||||
- name: "Property size awesome function"
|
||||
binary: "tests/e2e/pytest_runner.sh"
|
||||
args: ["awesome_functions/awesome_functions.py"]
|
||||
args: ["awesome_functions/property_size.py"]
|
||||
<<: *awesome_functions_cluster
|
||||
- name: "Value type awesome function"
|
||||
binary: "tests/e2e/pytest_runner.sh"
|
||||
args: ["awesome_functions/value_type.py"]
|
||||
<<: *awesome_functions_cluster
|
||||
|
Loading…
Reference in New Issue
Block a user