-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_issue.py
More file actions
173 lines (147 loc) · 5.34 KB
/
Copy pathtest_issue.py
File metadata and controls
173 lines (147 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from __future__ import annotations
import pytest
try:
from tools.python_api.test.type_aliases import ConnDB
except ImportError:
from type_aliases import ConnDB
# required by python-lint
def test_param_empty(conn_db_readwrite: ConnDB) -> None:
conn, _ = conn_db_readwrite
lst = [[]]
conn.execute("CREATE NODE TABLE tab(id SERIAL, lst INT64[][], PRIMARY KEY(id))")
result = conn.execute("CREATE (t:tab {lst: $1}) RETURN t.*", {"1": lst})
assert result.has_next()
assert result.get_next() == [0, lst]
assert not result.has_next()
result.close()
def test_issue_2874(conn_db_readwrite: ConnDB) -> None:
conn, _ = conn_db_readwrite
result = conn.execute(
"UNWIND $idList as tid MATCH (t:person {ID: tid}) RETURN t.fName;",
{"idList": [1, 2, 3]},
)
assert result.has_next()
assert result.get_next() == ["Bob"]
assert result.has_next()
assert result.get_next() == ["Carol"]
assert not result.has_next()
result.close()
def test_issue_2906(conn_db_readwrite: ConnDB) -> None:
conn, _ = conn_db_readwrite
result = conn.execute(
"MATCH (a:person) WHERE $1 > a.ID AND $1 < a.age / 5 RETURN a.fName;", {"1": 6}
)
assert result.has_next()
assert result.get_next() == ["Alice"]
assert result.has_next()
assert result.get_next() == ["Carol"]
assert not result.has_next()
result.close()
def test_issue_3135(conn_db_readwrite: ConnDB) -> None:
conn, _ = conn_db_readwrite
conn.execute("CREATE NODE TABLE t1(id SERIAL, number INT32, PRIMARY KEY(id));")
conn.execute("CREATE (:t1 {number: $1})", {"1": 2})
result = conn.execute("MATCH (n:t1) RETURN n.number;")
assert result.has_next()
assert result.get_next() == [2]
assert not result.has_next()
result.close()
def test_empty_list2(conn_db_readwrite: ConnDB) -> None:
conn, _ = conn_db_readwrite
conn.execute("""
CREATE NODE TABLE SnapArtifactScan (
artifact_name STRING,
scan_columns STRING[],
scan_filter STRING,
scan_limit INT64,
scan_id STRING,
PRIMARY KEY(scan_id)
)
""")
result = conn.execute(
"""
MERGE (n:SnapArtifactScan { scan_id: $scan_id })
SET n.artifact_name = $artifact_name, n.scan_columns = $scan_columns
RETURN n.scan_id
""",
{
"artifact_name": "taxi_zones",
"scan_columns": [],
"scan_id": "896de6b9c7b69fa2598def49e8c61de07949be374d229a82899c9c75994fad20",
},
)
assert result.has_next()
assert result.get_next() == [
"896de6b9c7b69fa2598def49e8c61de07949be374d229a82899c9c75994fad20"
]
assert not result.has_next()
result.close()
def test_empty_map(conn_db_readwrite: ConnDB) -> None:
conn, _ = conn_db_readwrite
conn.execute("""
CREATE NODE TABLE Test (
id SERIAL,
prop1 MAP(STRING, STRING),
prop2 MAP(STRING, STRING[]),
PRIMARY KEY(id)
)
""")
result = conn.execute(
"""
CREATE (n:Test {prop1: $prop1, prop2: $prop2})
RETURN n.id, n.prop1, n.prop2
""",
{
"prop1": {"key": [], "value": []},
"prop2": {"key": ["a"], "value": [[]]},
},
)
assert result.has_next()
assert result.get_next() == [0, {}, {"a": []}]
assert not result.has_next()
result.close()
def test_int8_type_sniffing(conn_db_readwrite: ConnDB) -> None:
conn, _ = conn_db_readwrite
conn.execute("CREATE NODE TABLE Chunk(id INT64, PRIMARY KEY(id))")
conn.execute("CREATE (c:Chunk {id:259})")
result = conn.execute(
"MATCH (node:Chunk) WHERE node.id IN $chunk_ids RETURN node.id",
{"chunk_ids": [1]},
)
assert result.get_num_tuples() == 0
result.close()
def test_issue_483_numpy_ndarray_parameter(conn_db_readwrite: ConnDB) -> None:
np = pytest.importorskip("numpy")
conn, _ = conn_db_readwrite
conn.execute("CREATE NODE TABLE T(id INT64, v FLOAT[3], PRIMARY KEY(id))")
conn.execute("CREATE (:T {id: 1})")
arr = np.array([0.1, 0.2, 0.3], dtype=np.float32)
result = conn.execute(
"MATCH (n:T {id: 1}) SET n.v = $v RETURN n.v",
{"v": arr},
)
assert result.has_next()
assert result.get_next() == [
[pytest.approx(0.1), pytest.approx(0.2), pytest.approx(0.3)]
]
assert not result.has_next()
result.close()
# TODO(Maxwell): check if we should change getCastCost() for the following test
# def test_issue_3248(conn_db_readwrite: ConnDB) -> None:
# conn, _ = conn_db_readwrite
# # Define schema
# conn.execute("CREATE NODE TABLE Item(id UINT64, item STRING, price DOUBLE, vector DOUBLE[2], PRIMARY KEY (id))")
#
# # Add data
# conn.execute("MERGE (a:Item {id: 1, item: 'apple', price: 2.0, vector: cast([3.1, 4.1], 'DOUBLE[2]')})")
# conn.execute("MERGE (b:Item {id: 2, item: 'banana', price: 1.0, vector: cast([5.9, 26.5], 'DOUBLE[2]')})")
#
# # Run similarity search
# result = conn.execute("MATCH (a:Item) RETURN a.item, a.price,
# array_cosine_similarity(a.vector, [6.0, 25.0]) AS sim ORDER BY sim DESC")
# assert result.has_next()
# assert result.get_next() == [2]
# assert result.has_next()
# assert result.get_next() == [2]
# assert not result.has_next()
# result.close()