real-ladybug 0.0.1.dev1__cp312-cp312-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of real-ladybug might be problematic. Click here for more details.

Files changed (114) hide show
  1. real_ladybug/__init__.py +83 -0
  2. real_ladybug/_lbug.cp312-win_amd64.pyd +0 -0
  3. real_ladybug/_lbug.exp +0 -0
  4. real_ladybug/_lbug.lib +0 -0
  5. real_ladybug/async_connection.py +226 -0
  6. real_ladybug/connection.py +323 -0
  7. real_ladybug/constants.py +7 -0
  8. real_ladybug/database.py +307 -0
  9. real_ladybug/prepared_statement.py +51 -0
  10. real_ladybug/py.typed +0 -0
  11. real_ladybug/query_result.py +511 -0
  12. real_ladybug/torch_geometric_feature_store.py +185 -0
  13. real_ladybug/torch_geometric_graph_store.py +131 -0
  14. real_ladybug/torch_geometric_result_converter.py +282 -0
  15. real_ladybug/types.py +39 -0
  16. real_ladybug-0.0.1.dev1.dist-info/METADATA +88 -0
  17. real_ladybug-0.0.1.dev1.dist-info/RECORD +114 -0
  18. real_ladybug-0.0.1.dev1.dist-info/WHEEL +5 -0
  19. real_ladybug-0.0.1.dev1.dist-info/licenses/LICENSE +21 -0
  20. real_ladybug-0.0.1.dev1.dist-info/top_level.txt +3 -0
  21. real_ladybug-0.0.1.dev1.dist-info/zip-safe +1 -0
  22. real_ladybug-source/scripts/antlr4/hash.py +2 -0
  23. real_ladybug-source/scripts/antlr4/keywordhandler.py +47 -0
  24. real_ladybug-source/scripts/collect-extensions.py +68 -0
  25. real_ladybug-source/scripts/collect-single-file-header.py +126 -0
  26. real_ladybug-source/scripts/export-dbs.py +101 -0
  27. real_ladybug-source/scripts/export-import-test.py +345 -0
  28. real_ladybug-source/scripts/extension/purge-beta.py +34 -0
  29. real_ladybug-source/scripts/generate-cpp-docs/collect_files.py +122 -0
  30. real_ladybug-source/scripts/generate-tinysnb.py +34 -0
  31. real_ladybug-source/scripts/get-clangd-diagnostics.py +233 -0
  32. real_ladybug-source/scripts/migrate-lbug-db.py +308 -0
  33. real_ladybug-source/scripts/multiplatform-test-helper/collect-results.py +71 -0
  34. real_ladybug-source/scripts/multiplatform-test-helper/notify-discord.py +68 -0
  35. real_ladybug-source/scripts/pip-package/package_tar.py +90 -0
  36. real_ladybug-source/scripts/pip-package/setup.py +130 -0
  37. real_ladybug-source/scripts/run-clang-format.py +408 -0
  38. real_ladybug-source/scripts/setup-extension-repo.py +67 -0
  39. real_ladybug-source/scripts/test-simsimd-dispatch.py +45 -0
  40. real_ladybug-source/scripts/update-nightly-build-version.py +81 -0
  41. real_ladybug-source/third_party/brotli/scripts/dictionary/step-01-download-rfc.py +16 -0
  42. real_ladybug-source/third_party/brotli/scripts/dictionary/step-02-rfc-to-bin.py +34 -0
  43. real_ladybug-source/third_party/brotli/scripts/dictionary/step-03-validate-bin.py +35 -0
  44. real_ladybug-source/third_party/brotli/scripts/dictionary/step-04-generate-java-literals.py +85 -0
  45. real_ladybug-source/third_party/pybind11/tools/codespell_ignore_lines_from_errors.py +35 -0
  46. real_ladybug-source/third_party/pybind11/tools/libsize.py +36 -0
  47. real_ladybug-source/third_party/pybind11/tools/make_changelog.py +63 -0
  48. real_ladybug-source/tools/python_api/build/real_ladybug/__init__.py +83 -0
  49. real_ladybug-source/tools/python_api/build/real_ladybug/async_connection.py +226 -0
  50. real_ladybug-source/tools/python_api/build/real_ladybug/connection.py +323 -0
  51. real_ladybug-source/tools/python_api/build/real_ladybug/constants.py +7 -0
  52. real_ladybug-source/tools/python_api/build/real_ladybug/database.py +307 -0
  53. real_ladybug-source/tools/python_api/build/real_ladybug/prepared_statement.py +51 -0
  54. real_ladybug-source/tools/python_api/build/real_ladybug/py.typed +0 -0
  55. real_ladybug-source/tools/python_api/build/real_ladybug/query_result.py +511 -0
  56. real_ladybug-source/tools/python_api/build/real_ladybug/torch_geometric_feature_store.py +185 -0
  57. real_ladybug-source/tools/python_api/build/real_ladybug/torch_geometric_graph_store.py +131 -0
  58. real_ladybug-source/tools/python_api/build/real_ladybug/torch_geometric_result_converter.py +282 -0
  59. real_ladybug-source/tools/python_api/build/real_ladybug/types.py +39 -0
  60. real_ladybug-source/tools/python_api/src_py/__init__.py +83 -0
  61. real_ladybug-source/tools/python_api/src_py/async_connection.py +226 -0
  62. real_ladybug-source/tools/python_api/src_py/connection.py +323 -0
  63. real_ladybug-source/tools/python_api/src_py/constants.py +7 -0
  64. real_ladybug-source/tools/python_api/src_py/database.py +307 -0
  65. real_ladybug-source/tools/python_api/src_py/prepared_statement.py +51 -0
  66. real_ladybug-source/tools/python_api/src_py/py.typed +0 -0
  67. real_ladybug-source/tools/python_api/src_py/query_result.py +511 -0
  68. real_ladybug-source/tools/python_api/src_py/torch_geometric_feature_store.py +185 -0
  69. real_ladybug-source/tools/python_api/src_py/torch_geometric_graph_store.py +131 -0
  70. real_ladybug-source/tools/python_api/src_py/torch_geometric_result_converter.py +282 -0
  71. real_ladybug-source/tools/python_api/src_py/types.py +39 -0
  72. real_ladybug-source/tools/python_api/test/conftest.py +230 -0
  73. real_ladybug-source/tools/python_api/test/disabled_test_extension.py +73 -0
  74. real_ladybug-source/tools/python_api/test/ground_truth.py +430 -0
  75. real_ladybug-source/tools/python_api/test/test_arrow.py +694 -0
  76. real_ladybug-source/tools/python_api/test/test_async_connection.py +159 -0
  77. real_ladybug-source/tools/python_api/test/test_blob_parameter.py +145 -0
  78. real_ladybug-source/tools/python_api/test/test_connection.py +49 -0
  79. real_ladybug-source/tools/python_api/test/test_database.py +234 -0
  80. real_ladybug-source/tools/python_api/test/test_datatype.py +372 -0
  81. real_ladybug-source/tools/python_api/test/test_df.py +564 -0
  82. real_ladybug-source/tools/python_api/test/test_dict.py +112 -0
  83. real_ladybug-source/tools/python_api/test/test_exception.py +54 -0
  84. real_ladybug-source/tools/python_api/test/test_fsm.py +227 -0
  85. real_ladybug-source/tools/python_api/test/test_get_header.py +49 -0
  86. real_ladybug-source/tools/python_api/test/test_helper.py +8 -0
  87. real_ladybug-source/tools/python_api/test/test_issue.py +147 -0
  88. real_ladybug-source/tools/python_api/test/test_iteration.py +96 -0
  89. real_ladybug-source/tools/python_api/test/test_networkx.py +437 -0
  90. real_ladybug-source/tools/python_api/test/test_parameter.py +340 -0
  91. real_ladybug-source/tools/python_api/test/test_prepared_statement.py +117 -0
  92. real_ladybug-source/tools/python_api/test/test_query_result.py +54 -0
  93. real_ladybug-source/tools/python_api/test/test_query_result_close.py +44 -0
  94. real_ladybug-source/tools/python_api/test/test_scan_pandas.py +676 -0
  95. real_ladybug-source/tools/python_api/test/test_scan_pandas_pyarrow.py +714 -0
  96. real_ladybug-source/tools/python_api/test/test_scan_polars.py +165 -0
  97. real_ladybug-source/tools/python_api/test/test_scan_pyarrow.py +167 -0
  98. real_ladybug-source/tools/python_api/test/test_timeout.py +11 -0
  99. real_ladybug-source/tools/python_api/test/test_torch_geometric.py +640 -0
  100. real_ladybug-source/tools/python_api/test/test_torch_geometric_remote_backend.py +111 -0
  101. real_ladybug-source/tools/python_api/test/test_udf.py +207 -0
  102. real_ladybug-source/tools/python_api/test/test_version.py +6 -0
  103. real_ladybug-source/tools/python_api/test/test_wal.py +80 -0
  104. real_ladybug-source/tools/python_api/test/type_aliases.py +10 -0
  105. real_ladybug-source/tools/rust_api/update_version.py +47 -0
  106. real_ladybug-source/tools/shell/test/conftest.py +218 -0
  107. real_ladybug-source/tools/shell/test/test_helper.py +60 -0
  108. real_ladybug-source/tools/shell/test/test_shell_basics.py +325 -0
  109. real_ladybug-source/tools/shell/test/test_shell_commands.py +656 -0
  110. real_ladybug-source/tools/shell/test/test_shell_control_edit.py +438 -0
  111. real_ladybug-source/tools/shell/test/test_shell_control_search.py +468 -0
  112. real_ladybug-source/tools/shell/test/test_shell_esc_edit.py +232 -0
  113. real_ladybug-source/tools/shell/test/test_shell_esc_search.py +162 -0
  114. real_ladybug-source/tools/shell/test/test_shell_flags.py +645 -0
@@ -0,0 +1,54 @@
1
+ from __future__ import annotations
2
+
3
+ import real_ladybug as lb
4
+ import pytest
5
+ from type_aliases import ConnDB
6
+
7
+
8
+ def test_exception(conn_db_readonly: ConnDB) -> None:
9
+ conn, _ = conn_db_readonly
10
+
11
+ with pytest.raises(RuntimeError, match=r"Parameter 1 not found."):
12
+ conn.execute("MATCH (a:person) WHERE a.registerTime = $1 RETURN COUNT(*);", {"asd": 1})
13
+
14
+ with pytest.raises(RuntimeError, match=r"Binder exception: Cannot find property dummy for a."):
15
+ conn.execute("MATCH (a:person) RETURN a.dummy;")
16
+
17
+
18
+ def test_db_path_exception() -> None:
19
+ path = ":memory:"
20
+ error_message = "Cannot open an in-memory database under READ ONLY mode."
21
+ with pytest.raises(RuntimeError, match=error_message):
22
+ lb.Database(path, read_only=True)
23
+
24
+
25
+ def test_read_only_exception(conn_db_readonly: ConnDB) -> None:
26
+ _, db = conn_db_readonly
27
+ path = db.database_path
28
+ read_only_db = lb.Database(path, read_only=True)
29
+ conn = lb.Connection(read_only_db)
30
+ with pytest.raises(RuntimeError, match=r"Cannot execute write operations in a read-only database!"):
31
+ conn.execute("CREATE NODE TABLE test (id INT64, PRIMARY KEY(id));")
32
+
33
+
34
+ def test_max_db_size_exception() -> None:
35
+ with pytest.raises(
36
+ RuntimeError, match=r"Buffer manager exception: The given max db size should be at least 8388608 bytes."
37
+ ):
38
+ lb.Database("test.db", max_db_size=1024)
39
+
40
+ with pytest.raises(RuntimeError, match=r"Buffer manager exception: The given max db size should be a power of 2."):
41
+ lb.Database("test.db", max_db_size=8388609)
42
+
43
+
44
+ def test_buffer_pool_size_exception() -> None:
45
+ with pytest.raises(
46
+ RuntimeError, match=r"Buffer manager exception: The given buffer pool size should be at least 4096 bytes."
47
+ ):
48
+ lb.Database("test.db", buffer_pool_size=1024)
49
+
50
+
51
+ def test_query_exception(conn_db_readonly: ConnDB) -> None:
52
+ conn, _ = conn_db_readonly
53
+ with pytest.raises(RuntimeError, match=r"Binder exception: Table nonexisting does not exist."):
54
+ conn.execute("MATCH (a:nonexisting) RETURN a;")
@@ -0,0 +1,227 @@
1
+ from pathlib import Path
2
+
3
+ import real_ladybug as lb
4
+ import pytest
5
+ from test_helper import LBUG_ROOT
6
+ from conftest import get_db_file_path
7
+
8
+
9
+ def get_used_page_ranges(conn, table, column=None):
10
+ used_pages = []
11
+ if column is None:
12
+ storage_info = conn.execute(f'call storage_info("{table}") return start_page_idx, num_pages')
13
+ else:
14
+ storage_info = conn.execute(
15
+ f'call storage_info("{table}") where prefix(column_name, "{column}") return start_page_idx, num_pages'
16
+ )
17
+ while storage_info.has_next():
18
+ cur_tuple = storage_info.get_next()
19
+ # don't add empty (e.g. constant-compressed) pages
20
+ if cur_tuple[1] > 0:
21
+ used_pages.append(cur_tuple)
22
+ return used_pages
23
+
24
+
25
+ def get_total_used_pages(conn):
26
+ return conn.execute("call file_info() return num_pages").get_next()[0]
27
+
28
+
29
+ def get_free_page_ranges(conn):
30
+ free_pages = []
31
+ result = conn.execute("call fsm_info() return *")
32
+ while result.has_next():
33
+ cur_tuple = result.get_next()
34
+ assert cur_tuple[1] > 0
35
+ free_pages.append(cur_tuple)
36
+ return free_pages
37
+
38
+
39
+ def combine_adjacent_page_ranges(page_ranges):
40
+ new_page_ranges = []
41
+ last_range = None
42
+ for page_range in page_ranges:
43
+ if last_range is not None and last_range[0] + last_range[1] == page_range[0]:
44
+ new_range = [last_range[0], last_range[1] + page_range[1]]
45
+ last_range = new_range
46
+ else:
47
+ if last_range is not None:
48
+ new_page_ranges.append(last_range)
49
+ last_range = page_range
50
+ if last_range:
51
+ new_page_ranges.append(last_range)
52
+ return new_page_ranges
53
+
54
+
55
+ def compare_page_range_lists(used_list, free_list):
56
+ used_list.sort()
57
+ free_list.sort()
58
+ # used pages should be subset of new free pages
59
+ for entry in combine_adjacent_page_ranges(used_list):
60
+ assert any(entry[0] >= i[0] and entry[0] + entry[1] <= i[0] + i[1] for i in free_list)
61
+
62
+
63
+ def prevent_data_file_truncation(conn):
64
+ conn.execute("CREATE NODE TABLE IF NOT EXISTS TMP(ID INT64, PRIMARY KEY(ID))")
65
+ conn.execute("CREATE (:TMP{id: 1})")
66
+ conn.execute("CREATE (:TMP{id: 2})")
67
+
68
+
69
+ @pytest.fixture
70
+ def fsm_node_table_setup(tmp_path: Path):
71
+ db = lb.Database(get_db_file_path(tmp_path))
72
+ conn = lb.Connection(db)
73
+ conn.execute("call threads=1")
74
+ conn.execute("call auto_checkpoint=false")
75
+ conn.execute(
76
+ "create node table person (ID INt64, fName StRING, gender INT64, isStudent BoOLEAN, isWorker BOOLEAN, age INT64, eyeSight DOUBLE, birthdate DATE, registerTime TIMESTAMP, lastJobDuration interval, workedHours INT64[], usedNames STRING[], courseScoresPerTerm INT64[][], grades INT64[4], height float, u UUID, PRIMARY KEY (ID));"
77
+ )
78
+ conn.execute(
79
+ f"COPY person FROM ['{LBUG_ROOT}/dataset/tinysnb/vPerson.csv', '{LBUG_ROOT}/dataset/tinysnb/vPerson2.csv'](ignore_errors=true, header=false)"
80
+ )
81
+ return db, conn
82
+
83
+
84
+ @pytest.fixture
85
+ def fsm_rel_table_setup(fsm_node_table_setup):
86
+ _, conn = fsm_node_table_setup
87
+ conn.execute(
88
+ "create rel table knows (FROM person TO person, date DATE, meetTime TIMESTAMP, validInterval INTERVAL, comments STRING[], summary STRUCT(locations STRING[], transfer STRUCT(day DATE, amount INT64[])), notes UNION(firstmet DATE, type INT16, comment STRING), someMap MAP(STRING, STRING), MANY_MAnY);"
89
+ )
90
+ conn.execute(
91
+ f"COPY knows FROM ['{LBUG_ROOT}/dataset/tinysnb/eKnows.csv', '{LBUG_ROOT}/dataset/tinysnb/eKnows_2.csv']"
92
+ )
93
+ return fsm_node_table_setup
94
+
95
+
96
+ @pytest.fixture
97
+ def fsm_rel_group_setup(tmp_path: Path):
98
+ db = lb.Database(get_db_file_path(tmp_path))
99
+ conn = lb.Connection(db)
100
+ conn.execute("call threads=1")
101
+ conn.execute("call auto_checkpoint=false")
102
+ conn.execute("create node table personA (ID INt64, fName StRING, PRIMARY KEY (ID));")
103
+ conn.execute("create node table personB (ID INt64, fName StRING, PRIMARY KEY (ID));")
104
+ conn.execute("create rel table likes (FROM personA TO personB, FROM personB To personA, date DATE);")
105
+ conn.execute(f'COPY personA FROM "{LBUG_ROOT}/dataset/rel-group/node.csv";')
106
+ conn.execute(f'COPY personB FROM "{LBUG_ROOT}/dataset/rel-group/node.csv";')
107
+ conn.execute(f'COPY likes FROM "{LBUG_ROOT}/dataset/rel-group/edge.csv" (FROM="personA", TO="personB");')
108
+ conn.execute(f'COPY likes FROM "{LBUG_ROOT}/dataset/rel-group/edge.csv" (FROM="personB", TO="personA");')
109
+ return db, conn
110
+
111
+
112
+ def test_fsm_reclaim_list_column(fsm_node_table_setup) -> None:
113
+ _, conn = fsm_node_table_setup
114
+ used_pages = get_used_page_ranges(conn, "person", "workedHours")
115
+ conn.execute("alter table person drop workedHours")
116
+ prevent_data_file_truncation(conn)
117
+ conn.execute("checkpoint")
118
+ free_pages = get_free_page_ranges(conn)
119
+ compare_page_range_lists(used_pages, free_pages)
120
+
121
+
122
+ def test_fsm_reclaim_string_column(fsm_node_table_setup) -> None:
123
+ _, conn = fsm_node_table_setup
124
+ used_pages = get_used_page_ranges(conn, "person", "fName")
125
+ conn.execute("alter table person drop fName")
126
+ prevent_data_file_truncation(conn)
127
+ conn.execute("checkpoint")
128
+ free_pages = get_free_page_ranges(conn)
129
+ compare_page_range_lists(used_pages, free_pages)
130
+
131
+
132
+ def test_fsm_reclaim_list_of_lists(fsm_node_table_setup) -> None:
133
+ _, conn = fsm_node_table_setup
134
+ used_pages = get_used_page_ranges(conn, "person", "courseScoresPerTerm")
135
+ conn.execute("alter table person drop courseScoresPerTerm")
136
+ prevent_data_file_truncation(conn)
137
+ conn.execute("checkpoint")
138
+ free_pages = get_free_page_ranges(conn)
139
+ compare_page_range_lists(used_pages, free_pages)
140
+
141
+
142
+ def test_fsm_reclaim_node_table(fsm_node_table_setup) -> None:
143
+ _, conn = fsm_node_table_setup
144
+ used_pages = get_used_page_ranges(conn, "person")
145
+ conn.execute("drop table person")
146
+ prevent_data_file_truncation(conn)
147
+ conn.execute("checkpoint")
148
+ free_pages = get_free_page_ranges(conn)
149
+ compare_page_range_lists(used_pages, free_pages)
150
+
151
+
152
+ def test_fsm_reclaim_node_table_recopy(fsm_node_table_setup) -> None:
153
+ _, conn = fsm_node_table_setup
154
+ prev_num_pages = get_total_used_pages(conn)
155
+ conn.execute("drop table person")
156
+ conn.execute("checkpoint")
157
+
158
+ conn.execute(
159
+ "create node table person (ID INt64, fName StRING, gender INT64, isStudent BoOLEAN, isWorker BOOLEAN, age INT64, eyeSight DOUBLE, birthdate DATE, registerTime TIMESTAMP, lastJobDuration interval, workedHours INT64[], usedNames STRING[], courseScoresPerTerm INT64[][], grades INT64[4], height float, u UUID, PRIMARY KEY (ID));"
160
+ )
161
+ conn.execute(
162
+ f"COPY person FROM ['{LBUG_ROOT}/dataset/tinysnb/vPerson.csv', '{LBUG_ROOT}/dataset/tinysnb/vPerson2.csv'](ignore_errors=true, header=false)"
163
+ )
164
+ new_num_pages = get_total_used_pages(conn)
165
+ assert prev_num_pages == new_num_pages
166
+
167
+
168
+ def test_fsm_reclaim_node_table_delete(fsm_node_table_setup) -> None:
169
+ _, conn = fsm_node_table_setup
170
+ used_pages = get_used_page_ranges(conn, "person")
171
+ conn.execute("match (p:person) delete p")
172
+ prevent_data_file_truncation(conn)
173
+ conn.execute("checkpoint")
174
+ free_pages = get_free_page_ranges(conn)
175
+ compare_page_range_lists(used_pages, free_pages)
176
+
177
+
178
+ def test_fsm_reclaim_rel_table(fsm_rel_table_setup) -> None:
179
+ _, conn = fsm_rel_table_setup
180
+ used_pages = get_used_page_ranges(conn, "knows")
181
+ conn.execute("drop table knows")
182
+ prevent_data_file_truncation(conn)
183
+ conn.execute("checkpoint")
184
+ free_pages = get_free_page_ranges(conn)
185
+ compare_page_range_lists(used_pages, free_pages)
186
+
187
+
188
+ def test_fsm_reclaim_rel_table_delete(fsm_node_table_setup) -> None:
189
+ _, conn = fsm_node_table_setup
190
+ used_pages = get_used_page_ranges(conn, "person")
191
+ conn.execute("match (p:person) delete p")
192
+ prevent_data_file_truncation(conn)
193
+ conn.execute("checkpoint")
194
+ free_pages = get_free_page_ranges(conn)
195
+ compare_page_range_lists(used_pages, free_pages)
196
+
197
+
198
+ def test_fsm_reclaim_struct(fsm_rel_table_setup) -> None:
199
+ _, conn = fsm_rel_table_setup
200
+ used_pages = get_used_page_ranges(conn, "knows", "fwd_summary") + get_used_page_ranges(
201
+ conn, "knows", "bwd_summary"
202
+ )
203
+ conn.execute("alter table knows drop summary")
204
+ prevent_data_file_truncation(conn)
205
+ conn.execute("checkpoint")
206
+ free_pages = get_free_page_ranges(conn)
207
+ compare_page_range_lists(used_pages, free_pages)
208
+
209
+
210
+ def test_fsm_reclaim_rel_group(fsm_rel_group_setup) -> None:
211
+ _, conn = fsm_rel_group_setup
212
+ used_pages = get_used_page_ranges(conn, "likes")
213
+ conn.execute("drop table likes")
214
+ prevent_data_file_truncation(conn)
215
+ conn.execute("checkpoint")
216
+ free_pages = get_free_page_ranges(conn)
217
+ compare_page_range_lists(used_pages, free_pages)
218
+
219
+
220
+ def test_fsm_reclaim_rel_group_column(fsm_rel_group_setup) -> None:
221
+ _, conn = fsm_rel_group_setup
222
+ used_pages = get_used_page_ranges(conn, "likes", "fwd_date") + get_used_page_ranges(conn, "likes", "bwd_date")
223
+ conn.execute("alter table likes drop date")
224
+ prevent_data_file_truncation(conn)
225
+ conn.execute("checkpoint")
226
+ free_pages = get_free_page_ranges(conn)
227
+ compare_page_range_lists(used_pages, free_pages)
@@ -0,0 +1,49 @@
1
+ from __future__ import annotations
2
+
3
+ from type_aliases import ConnDB
4
+
5
+
6
+ def test_get_column_names(conn_db_readonly: ConnDB) -> None:
7
+ conn, _ = conn_db_readonly
8
+ with conn.execute("MATCH (a:person)-[e:knows]->(b:person) RETURN a.fName, e.date, b.ID;") as result:
9
+ column_names = result.get_column_names()
10
+ assert column_names[0] == "a.fName"
11
+ assert column_names[1] == "e.date"
12
+ assert column_names[2] == "b.ID"
13
+
14
+
15
+ def test_get_column_data_types(conn_db_readonly: ConnDB) -> None:
16
+ conn, _ = conn_db_readonly
17
+ with conn.execute(
18
+ "MATCH (p:person) RETURN p.ID, p.fName, p.isStudent, p.eyeSight, p.birthdate, p.registerTime, "
19
+ "p.lastJobDuration, p.workedHours, p.courseScoresPerTerm;"
20
+ ) as result:
21
+ column_data_types = result.get_column_data_types()
22
+ assert column_data_types[0] == "INT64"
23
+ assert column_data_types[1] == "STRING"
24
+ assert column_data_types[2] == "BOOL"
25
+ assert column_data_types[3] == "DOUBLE"
26
+ assert column_data_types[4] == "DATE"
27
+ assert column_data_types[5] == "TIMESTAMP"
28
+ assert column_data_types[6] == "INTERVAL"
29
+ assert column_data_types[7] == "INT64[]"
30
+ assert column_data_types[8] == "INT64[][]"
31
+
32
+
33
+ def test_get_schema(conn_db_readonly: ConnDB) -> None:
34
+ conn, _ = conn_db_readonly
35
+ with conn.execute(
36
+ "MATCH (p:person) RETURN p.ID, p.fName, p.isStudent, p.eyeSight, p.birthdate, p.registerTime, "
37
+ "p.lastJobDuration, p.workedHours, p.courseScoresPerTerm;"
38
+ ) as result:
39
+ assert result.get_schema() == {
40
+ "p.ID": "INT64",
41
+ "p.fName": "STRING",
42
+ "p.isStudent": "BOOL",
43
+ "p.eyeSight": "DOUBLE",
44
+ "p.birthdate": "DATE",
45
+ "p.registerTime": "TIMESTAMP",
46
+ "p.lastJobDuration": "INTERVAL",
47
+ "p.workedHours": "INT64[]",
48
+ "p.courseScoresPerTerm": "INT64[][]",
49
+ }
@@ -0,0 +1,8 @@
1
+ import sys
2
+ from pathlib import Path
3
+
4
+ LBUG_ROOT = Path(__file__).parent.parent.parent.parent
5
+
6
+ if sys.platform == "win32":
7
+ # \ in paths is not supported by lbug's parser
8
+ LBUG_ROOT = str(LBUG_ROOT).replace("\\", "/")
@@ -0,0 +1,147 @@
1
+ from __future__ import annotations
2
+
3
+ try:
4
+ from tools.python_api.test.type_aliases import ConnDB
5
+ except ImportError:
6
+ from type_aliases import ConnDB
7
+
8
+ # required by python-lint
9
+
10
+
11
+ def test_param_empty(conn_db_readwrite: ConnDB) -> None:
12
+ conn, _ = conn_db_readwrite
13
+ lst = [[]]
14
+ conn.execute("CREATE NODE TABLE tab(id SERIAL, lst INT64[][], PRIMARY KEY(id))")
15
+ result = conn.execute("CREATE (t:tab {lst: $1}) RETURN t.*", {"1": lst})
16
+ assert result.has_next()
17
+ assert result.get_next() == [0, lst]
18
+ assert not result.has_next()
19
+ result.close()
20
+
21
+
22
+ def test_issue_2874(conn_db_readwrite: ConnDB) -> None:
23
+ conn, _ = conn_db_readwrite
24
+ result = conn.execute("UNWIND $idList as tid MATCH (t:person {ID: tid}) RETURN t.fName;", {"idList": [1, 2, 3]})
25
+ assert result.has_next()
26
+ assert result.get_next() == ["Bob"]
27
+ assert result.has_next()
28
+ assert result.get_next() == ["Carol"]
29
+ assert not result.has_next()
30
+ result.close()
31
+
32
+
33
+ def test_issue_2906(conn_db_readwrite: ConnDB) -> None:
34
+ conn, _ = conn_db_readwrite
35
+ result = conn.execute("MATCH (a:person) WHERE $1 > a.ID AND $1 < a.age / 5 RETURN a.fName;", {"1": 6})
36
+ assert result.has_next()
37
+ assert result.get_next() == ["Alice"]
38
+ assert result.has_next()
39
+ assert result.get_next() == ["Carol"]
40
+ assert not result.has_next()
41
+ result.close()
42
+
43
+
44
+ def test_issue_3135(conn_db_readwrite: ConnDB) -> None:
45
+ conn, _ = conn_db_readwrite
46
+ conn.execute("CREATE NODE TABLE t1(id SERIAL, number INT32, PRIMARY KEY(id));")
47
+ conn.execute("CREATE (:t1 {number: $1})", {"1": 2})
48
+ result = conn.execute("MATCH (n:t1) RETURN n.number;")
49
+ assert result.has_next()
50
+ assert result.get_next() == [2]
51
+ assert not result.has_next()
52
+ result.close()
53
+
54
+
55
+ def test_empty_list2(conn_db_readwrite: ConnDB) -> None:
56
+ conn, _ = conn_db_readwrite
57
+ conn.execute(
58
+ """
59
+ CREATE NODE TABLE SnapArtifactScan (
60
+ artifact_name STRING,
61
+ scan_columns STRING[],
62
+ scan_filter STRING,
63
+ scan_limit INT64,
64
+ scan_id STRING,
65
+ PRIMARY KEY(scan_id)
66
+ )
67
+ """
68
+ )
69
+ result = conn.execute(
70
+ """
71
+ MERGE (n:SnapArtifactScan { scan_id: $scan_id })
72
+ SET n.artifact_name = $artifact_name, n.scan_columns = $scan_columns
73
+ RETURN n.scan_id
74
+ """,
75
+ {
76
+ "artifact_name": "taxi_zones",
77
+ "scan_columns": [],
78
+ "scan_id": "896de6b9c7b69fa2598def49e8c61de07949be374d229a82899c9c75994fad20",
79
+ },
80
+ )
81
+ assert result.has_next()
82
+ assert result.get_next() == ["896de6b9c7b69fa2598def49e8c61de07949be374d229a82899c9c75994fad20"]
83
+ assert not result.has_next()
84
+ result.close()
85
+
86
+
87
+ def test_empty_map(conn_db_readwrite: ConnDB) -> None:
88
+ conn, _ = conn_db_readwrite
89
+ conn.execute(
90
+ """
91
+ CREATE NODE TABLE Test (
92
+ id SERIAL,
93
+ prop1 MAP(STRING, STRING),
94
+ prop2 MAP(STRING, STRING[]),
95
+ PRIMARY KEY(id)
96
+ )
97
+ """
98
+ )
99
+ result = conn.execute(
100
+ """
101
+ CREATE (n:Test {prop1: $prop1, prop2: $prop2})
102
+ RETURN n.id, n.prop1, n.prop2
103
+ """,
104
+ {
105
+ "prop1": {"key": [], "value": []},
106
+ "prop2": {"key": ["a"], "value": [[]]},
107
+ },
108
+ )
109
+ assert result.has_next()
110
+ assert result.get_next() == [0, {}, {"a": []}]
111
+ assert not result.has_next()
112
+ result.close()
113
+
114
+
115
+ def test_int8_type_sniffing(conn_db_readwrite: ConnDB) -> None:
116
+ conn, _ = conn_db_readwrite
117
+ conn.execute("CREATE NODE TABLE Chunk(id INT64, PRIMARY KEY(id))")
118
+
119
+ conn.execute("CREATE (c:Chunk {id:259})")
120
+
121
+ result = conn.execute(
122
+ "MATCH (node:Chunk) WHERE node.id IN $chunk_ids RETURN node.id",
123
+ {"chunk_ids": [1]},
124
+ )
125
+ assert result.get_num_tuples() == 0
126
+ result.close()
127
+
128
+
129
+ # TODO(Maxwell): check if we should change getCastCost() for the following test
130
+ # def test_issue_3248(conn_db_readwrite: ConnDB) -> None:
131
+ # conn, _ = conn_db_readwrite
132
+ # # Define schema
133
+ # conn.execute("CREATE NODE TABLE Item(id UINT64, item STRING, price DOUBLE, vector DOUBLE[2], PRIMARY KEY (id))")
134
+ #
135
+ # # Add data
136
+ # conn.execute("MERGE (a:Item {id: 1, item: 'apple', price: 2.0, vector: cast([3.1, 4.1], 'DOUBLE[2]')})")
137
+ # conn.execute("MERGE (b:Item {id: 2, item: 'banana', price: 1.0, vector: cast([5.9, 26.5], 'DOUBLE[2]')})")
138
+ #
139
+ # # Run similarity search
140
+ # result = conn.execute("MATCH (a:Item) RETURN a.item, a.price,
141
+ # array_cosine_similarity(a.vector, [6.0, 25.0]) AS sim ORDER BY sim DESC")
142
+ # assert result.has_next()
143
+ # assert result.get_next() == [2]
144
+ # assert result.has_next()
145
+ # assert result.get_next() == [2]
146
+ # assert not result.has_next()
147
+ # result.close()
@@ -0,0 +1,96 @@
1
+ from __future__ import annotations
2
+
3
+ import real_ladybug as lb
4
+
5
+ from type_aliases import ConnDB
6
+
7
+
8
+ def test_iteration_list(conn_db_in_mem: ConnDB) -> None:
9
+ conn, _ = conn_db_in_mem
10
+ conn.execute("CREATE NODE TABLE person(name STRING, age INT64, PRIMARY KEY(name));")
11
+ conn.execute("CREATE (:person {name: 'Alice', age: 30});")
12
+ conn.execute("CREATE (:person {name: 'Bob', age: 40});")
13
+ result = conn.execute("MATCH (p:person) RETURN p.*")
14
+ assert result.get_num_tuples() == 2
15
+
16
+ rows = list(result)
17
+ assert rows[0] == ["Alice", 30]
18
+ assert rows[1] == ["Bob", 40]
19
+
20
+
21
+ def test_iteration_loop(conn_db_in_mem: ConnDB) -> None:
22
+ conn, _ = conn_db_in_mem
23
+ conn.execute("CREATE NODE TABLE person(name STRING, age INT64, PRIMARY KEY(name));")
24
+ conn.execute("CREATE (:person {name: 'Alice', age: 30});")
25
+ conn.execute("CREATE (:person {name: 'Bob', age: 40});")
26
+ result = conn.execute("MATCH (p:person) RETURN p.*")
27
+ assert result.get_num_tuples() == 2
28
+
29
+ rows = []
30
+ for row in result:
31
+ rows.append(row)
32
+
33
+ assert rows[0] == ["Alice", 30]
34
+ assert rows[1] == ["Bob", 40]
35
+
36
+
37
+ def test_get_all(conn_db_in_mem: ConnDB) -> None:
38
+ conn, _ = conn_db_in_mem
39
+ db = lb.Database(database_path=":memory:")
40
+ assert not db.is_closed
41
+ assert db._database is not None
42
+
43
+ conn = lb.Connection(db)
44
+ conn.execute("CREATE NODE TABLE person(name STRING, age INT64, PRIMARY KEY(name));")
45
+ conn.execute("CREATE (:person {name: 'Alice', age: 30});")
46
+ conn.execute("CREATE (:person {name: 'Bob', age: 40});")
47
+ result = conn.execute("MATCH (p:person) RETURN p.*")
48
+ assert result.get_num_tuples() == 2
49
+
50
+ rows = result.get_all()
51
+
52
+ assert rows[0] == ["Alice", 30]
53
+ assert rows[1] == ["Bob", 40]
54
+
55
+
56
+ def test_get_n(conn_db_in_mem: ConnDB) -> None:
57
+ conn, _ = conn_db_in_mem
58
+ db = lb.Database(database_path=":memory:")
59
+ assert not db.is_closed
60
+ assert db._database is not None
61
+
62
+ conn = lb.Connection(db)
63
+ conn.execute("CREATE NODE TABLE person(name STRING, age INT64, PRIMARY KEY(name));")
64
+ conn.execute("CREATE (:person {name: 'Alice', age: 30});")
65
+ conn.execute("CREATE (:person {name: 'Bob', age: 40});")
66
+ conn.execute("CREATE (:person {name: 'Cole', age: 20});")
67
+
68
+ # Basic
69
+ result = conn.execute("MATCH (p:person) RETURN p.*")
70
+ assert result.get_num_tuples() == 3
71
+
72
+ rows = result.get_n(2)
73
+
74
+ assert len(rows) == 2
75
+ assert rows[0] == ["Alice", 30]
76
+ assert rows[1] == ["Bob", 40]
77
+
78
+ rows = result.get_n(1)
79
+
80
+ assert len(rows) == 1
81
+ assert rows[0] == ["Cole", 20]
82
+
83
+ rows = result.get_n(3)
84
+
85
+ assert len(rows) == 0
86
+
87
+ # Empty rows on excess count
88
+ result = conn.execute("MATCH (p:person) RETURN p.*")
89
+ assert result.get_num_tuples() == 3
90
+
91
+ rows = result.get_n(10)
92
+
93
+ assert len(rows) == 3
94
+ assert rows[0] == ["Alice", 30]
95
+ assert rows[1] == ["Bob", 40]
96
+ assert rows[2] == ["Cole", 20]