matrixone-python-sdk 0.1.0__py3-none-any.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.
Files changed (122) hide show
  1. matrixone/__init__.py +155 -0
  2. matrixone/account.py +723 -0
  3. matrixone/async_client.py +3913 -0
  4. matrixone/async_metadata_manager.py +311 -0
  5. matrixone/async_orm.py +123 -0
  6. matrixone/async_vector_index_manager.py +633 -0
  7. matrixone/base_client.py +208 -0
  8. matrixone/client.py +4672 -0
  9. matrixone/config.py +452 -0
  10. matrixone/connection_hooks.py +286 -0
  11. matrixone/exceptions.py +89 -0
  12. matrixone/logger.py +782 -0
  13. matrixone/metadata.py +820 -0
  14. matrixone/moctl.py +219 -0
  15. matrixone/orm.py +2277 -0
  16. matrixone/pitr.py +646 -0
  17. matrixone/pubsub.py +771 -0
  18. matrixone/restore.py +411 -0
  19. matrixone/search_vector_index.py +1176 -0
  20. matrixone/snapshot.py +550 -0
  21. matrixone/sql_builder.py +844 -0
  22. matrixone/sqlalchemy_ext/__init__.py +161 -0
  23. matrixone/sqlalchemy_ext/adapters.py +163 -0
  24. matrixone/sqlalchemy_ext/dialect.py +534 -0
  25. matrixone/sqlalchemy_ext/fulltext_index.py +895 -0
  26. matrixone/sqlalchemy_ext/fulltext_search.py +1686 -0
  27. matrixone/sqlalchemy_ext/hnsw_config.py +194 -0
  28. matrixone/sqlalchemy_ext/ivf_config.py +252 -0
  29. matrixone/sqlalchemy_ext/table_builder.py +351 -0
  30. matrixone/sqlalchemy_ext/vector_index.py +1721 -0
  31. matrixone/sqlalchemy_ext/vector_type.py +948 -0
  32. matrixone/version.py +580 -0
  33. matrixone_python_sdk-0.1.0.dist-info/METADATA +706 -0
  34. matrixone_python_sdk-0.1.0.dist-info/RECORD +122 -0
  35. matrixone_python_sdk-0.1.0.dist-info/WHEEL +5 -0
  36. matrixone_python_sdk-0.1.0.dist-info/entry_points.txt +5 -0
  37. matrixone_python_sdk-0.1.0.dist-info/licenses/LICENSE +200 -0
  38. matrixone_python_sdk-0.1.0.dist-info/top_level.txt +2 -0
  39. tests/__init__.py +19 -0
  40. tests/offline/__init__.py +20 -0
  41. tests/offline/conftest.py +77 -0
  42. tests/offline/test_account.py +703 -0
  43. tests/offline/test_async_client_query_comprehensive.py +1218 -0
  44. tests/offline/test_basic.py +54 -0
  45. tests/offline/test_case_sensitivity.py +227 -0
  46. tests/offline/test_connection_hooks_offline.py +287 -0
  47. tests/offline/test_dialect_schema_handling.py +609 -0
  48. tests/offline/test_explain_methods.py +346 -0
  49. tests/offline/test_filter_logical_in.py +237 -0
  50. tests/offline/test_fulltext_search_comprehensive.py +795 -0
  51. tests/offline/test_ivf_config.py +249 -0
  52. tests/offline/test_join_methods.py +281 -0
  53. tests/offline/test_join_sqlalchemy_compatibility.py +276 -0
  54. tests/offline/test_logical_in_method.py +237 -0
  55. tests/offline/test_matrixone_version_parsing.py +264 -0
  56. tests/offline/test_metadata_offline.py +557 -0
  57. tests/offline/test_moctl.py +300 -0
  58. tests/offline/test_moctl_simple.py +251 -0
  59. tests/offline/test_model_support_offline.py +359 -0
  60. tests/offline/test_model_support_simple.py +225 -0
  61. tests/offline/test_pinecone_filter_offline.py +377 -0
  62. tests/offline/test_pitr.py +585 -0
  63. tests/offline/test_pubsub.py +712 -0
  64. tests/offline/test_query_update.py +283 -0
  65. tests/offline/test_restore.py +445 -0
  66. tests/offline/test_snapshot_comprehensive.py +384 -0
  67. tests/offline/test_sql_escaping_edge_cases.py +551 -0
  68. tests/offline/test_sqlalchemy_integration.py +382 -0
  69. tests/offline/test_sqlalchemy_vector_integration.py +434 -0
  70. tests/offline/test_table_builder.py +198 -0
  71. tests/offline/test_unified_filter.py +398 -0
  72. tests/offline/test_unified_transaction.py +495 -0
  73. tests/offline/test_vector_index.py +238 -0
  74. tests/offline/test_vector_operations.py +688 -0
  75. tests/offline/test_vector_type.py +174 -0
  76. tests/offline/test_version_core.py +328 -0
  77. tests/offline/test_version_management.py +372 -0
  78. tests/offline/test_version_standalone.py +652 -0
  79. tests/online/__init__.py +20 -0
  80. tests/online/conftest.py +216 -0
  81. tests/online/test_account_management.py +194 -0
  82. tests/online/test_advanced_features.py +344 -0
  83. tests/online/test_async_client_interfaces.py +330 -0
  84. tests/online/test_async_client_online.py +285 -0
  85. tests/online/test_async_model_insert_online.py +293 -0
  86. tests/online/test_async_orm_online.py +300 -0
  87. tests/online/test_async_simple_query_online.py +802 -0
  88. tests/online/test_async_transaction_simple_query.py +300 -0
  89. tests/online/test_basic_connection.py +130 -0
  90. tests/online/test_client_online.py +238 -0
  91. tests/online/test_config.py +90 -0
  92. tests/online/test_config_validation.py +123 -0
  93. tests/online/test_connection_hooks_new_online.py +217 -0
  94. tests/online/test_dialect_schema_handling_online.py +331 -0
  95. tests/online/test_filter_logical_in_online.py +374 -0
  96. tests/online/test_fulltext_comprehensive.py +1773 -0
  97. tests/online/test_fulltext_label_online.py +433 -0
  98. tests/online/test_fulltext_search_online.py +842 -0
  99. tests/online/test_ivf_stats_online.py +506 -0
  100. tests/online/test_logger_integration.py +311 -0
  101. tests/online/test_matrixone_query_orm.py +540 -0
  102. tests/online/test_metadata_online.py +579 -0
  103. tests/online/test_model_insert_online.py +255 -0
  104. tests/online/test_mysql_driver_validation.py +213 -0
  105. tests/online/test_orm_advanced_features.py +2022 -0
  106. tests/online/test_orm_cte_integration.py +269 -0
  107. tests/online/test_orm_online.py +270 -0
  108. tests/online/test_pinecone_filter.py +708 -0
  109. tests/online/test_pubsub_operations.py +352 -0
  110. tests/online/test_query_methods.py +225 -0
  111. tests/online/test_query_update_online.py +433 -0
  112. tests/online/test_search_vector_index.py +557 -0
  113. tests/online/test_simple_fulltext_online.py +915 -0
  114. tests/online/test_snapshot_comprehensive.py +998 -0
  115. tests/online/test_sqlalchemy_engine_integration.py +336 -0
  116. tests/online/test_sqlalchemy_integration.py +425 -0
  117. tests/online/test_transaction_contexts.py +1219 -0
  118. tests/online/test_transaction_insert_methods.py +356 -0
  119. tests/online/test_transaction_query_methods.py +288 -0
  120. tests/online/test_unified_filter_online.py +529 -0
  121. tests/online/test_vector_comprehensive.py +706 -0
  122. tests/online/test_version_management.py +291 -0
@@ -0,0 +1,372 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Copyright 2021 - 2022 Matrix Origin
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ """
18
+ MatrixOne Python SDK - Version Management Tests
19
+
20
+ Test suite for the version management framework.
21
+ """
22
+
23
+ import unittest
24
+ import sys
25
+ import os
26
+
27
+ # Add the matrixone package to the path
28
+ sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'matrixone'))
29
+
30
+ from matrixone.version import (
31
+ VersionManager,
32
+ VersionInfo,
33
+ FeatureRequirement,
34
+ VersionComparison,
35
+ requires_version,
36
+ VersionError,
37
+ )
38
+ from matrixone.exceptions import VersionError as MatrixOneVersionError
39
+
40
+
41
+ class TestVersionParsing(unittest.TestCase):
42
+ """Test version parsing functionality"""
43
+
44
+ def setUp(self):
45
+ self.version_manager = VersionManager()
46
+
47
+ def test_valid_version_parsing(self):
48
+ """Test parsing valid version strings"""
49
+ test_cases = [
50
+ ("3.0.1", VersionInfo(3, 0, 1)),
51
+ ("1.0.0", VersionInfo(1, 0, 0)),
52
+ ("10.25.100", VersionInfo(10, 25, 100)),
53
+ ("0.0.1", VersionInfo(0, 0, 1)),
54
+ ]
55
+
56
+ for version_str, expected in test_cases:
57
+ with self.subTest(version=version_str):
58
+ result = self.version_manager.parse_version(version_str)
59
+ self.assertEqual(result.major, expected.major)
60
+ self.assertEqual(result.minor, expected.minor)
61
+ self.assertEqual(result.patch, expected.patch)
62
+
63
+ def test_invalid_version_parsing(self):
64
+ """Test parsing invalid version strings"""
65
+ invalid_versions = [
66
+ "3.0", # Missing patch
67
+ "3.0.1.2", # Too many components
68
+ "3.0.a", # Non-numeric component
69
+ "3.0.1-beta", # Pre-release suffix
70
+ "", # Empty string
71
+ "invalid", # Completely invalid
72
+ ]
73
+
74
+ for invalid_version in invalid_versions:
75
+ with self.subTest(version=invalid_version):
76
+ with self.assertRaises(ValueError):
77
+ self.version_manager.parse_version(invalid_version)
78
+
79
+ def test_version_string_representation(self):
80
+ """Test version string representation"""
81
+ version = VersionInfo(3, 0, 1)
82
+ self.assertEqual(str(version), "3.0.1")
83
+
84
+
85
+ class TestVersionComparison(unittest.TestCase):
86
+ """Test version comparison functionality"""
87
+
88
+ def setUp(self):
89
+ self.version_manager = VersionManager()
90
+
91
+ def test_version_comparisons(self):
92
+ """Test various version comparisons"""
93
+ test_cases = [
94
+ # (version1, version2, expected_result)
95
+ ("3.0.2", "3.0.1", VersionComparison.GREATER),
96
+ ("3.0.1", "3.0.2", VersionComparison.LESS),
97
+ ("3.0.1", "3.0.1", VersionComparison.EQUAL),
98
+ ("2.1.19", "3.0.9", VersionComparison.LESS),
99
+ ("3.0.9", "2.1.19", VersionComparison.GREATER),
100
+ ("1.0.0", "2.0.0", VersionComparison.LESS),
101
+ ("2.0.0", "1.9.9", VersionComparison.GREATER),
102
+ ]
103
+
104
+ for v1, v2, expected in test_cases:
105
+ with self.subTest(v1=v1, v2=v2):
106
+ result = self.version_manager.compare_versions(v1, v2)
107
+ self.assertEqual(result, expected)
108
+
109
+ def test_version_compatibility_checks(self):
110
+ """Test version compatibility checking"""
111
+ self.version_manager.set_backend_version("3.0.1")
112
+
113
+ # Test >= operator
114
+ self.assertTrue(self.version_manager.is_version_compatible("3.0.0", operator=">="))
115
+ self.assertTrue(self.version_manager.is_version_compatible("3.0.1", operator=">="))
116
+ self.assertFalse(self.version_manager.is_version_compatible("3.0.2", operator=">="))
117
+
118
+ # Test > operator
119
+ self.assertTrue(self.version_manager.is_version_compatible("3.0.0", operator=">"))
120
+ self.assertFalse(self.version_manager.is_version_compatible("3.0.1", operator=">"))
121
+ self.assertFalse(self.version_manager.is_version_compatible("3.0.2", operator=">"))
122
+
123
+ # Test <= operator
124
+ self.assertFalse(self.version_manager.is_version_compatible("3.0.0", operator="<="))
125
+ self.assertTrue(self.version_manager.is_version_compatible("3.0.1", operator="<="))
126
+ self.assertTrue(self.version_manager.is_version_compatible("3.0.2", operator="<="))
127
+
128
+ # Test < operator
129
+ self.assertFalse(self.version_manager.is_version_compatible("3.0.0", operator="<"))
130
+ self.assertFalse(self.version_manager.is_version_compatible("3.0.1", operator="<"))
131
+ self.assertTrue(self.version_manager.is_version_compatible("3.0.2", operator="<"))
132
+
133
+ # Test == operator
134
+ self.assertFalse(self.version_manager.is_version_compatible("3.0.0", operator="=="))
135
+ self.assertTrue(self.version_manager.is_version_compatible("3.0.1", operator="=="))
136
+ self.assertFalse(self.version_manager.is_version_compatible("3.0.2", operator="=="))
137
+
138
+ # Test != operator
139
+ self.assertTrue(self.version_manager.is_version_compatible("3.0.0", operator="!="))
140
+ self.assertFalse(self.version_manager.is_version_compatible("3.0.1", operator="!="))
141
+ self.assertTrue(self.version_manager.is_version_compatible("3.0.2", operator="!="))
142
+
143
+
144
+ class TestFeatureRequirements(unittest.TestCase):
145
+ """Test feature requirement functionality"""
146
+
147
+ def setUp(self):
148
+ self.version_manager = VersionManager()
149
+
150
+ def test_feature_registration_and_availability(self):
151
+ """Test feature registration and availability checking"""
152
+ # Register a feature requirement
153
+ feature = FeatureRequirement(
154
+ feature_name="test_feature",
155
+ min_version=VersionInfo(3, 0, 0),
156
+ max_version=VersionInfo(3, 5, 0),
157
+ description="Test feature",
158
+ alternative="Use alternative_feature instead",
159
+ )
160
+ self.version_manager.register_feature_requirement(feature)
161
+
162
+ # Test with compatible version
163
+ self.version_manager.set_backend_version("3.1.0")
164
+ self.assertTrue(self.version_manager.is_feature_available("test_feature"))
165
+
166
+ # Test with version too low
167
+ self.version_manager.set_backend_version("2.9.0")
168
+ self.assertFalse(self.version_manager.is_feature_available("test_feature"))
169
+
170
+ # Test with version too high
171
+ self.version_manager.set_backend_version("3.6.0")
172
+ self.assertFalse(self.version_manager.is_feature_available("test_feature"))
173
+
174
+ def test_feature_info_retrieval(self):
175
+ """Test feature information retrieval"""
176
+ feature = FeatureRequirement(
177
+ feature_name="info_test",
178
+ min_version=VersionInfo(2, 0, 0),
179
+ description="Information test feature",
180
+ alternative="Alternative approach",
181
+ )
182
+ self.version_manager.register_feature_requirement(feature)
183
+
184
+ retrieved = self.version_manager.get_feature_info("info_test")
185
+ self.assertIsNotNone(retrieved)
186
+ self.assertEqual(retrieved.feature_name, "info_test")
187
+ self.assertEqual(retrieved.description, "Information test feature")
188
+ self.assertEqual(retrieved.alternative, "Alternative approach")
189
+
190
+ # Test non-existent feature
191
+ self.assertIsNone(self.version_manager.get_feature_info("non_existent"))
192
+
193
+ def test_version_hints(self):
194
+ """Test version hint generation"""
195
+ self.version_manager.register_feature_requirement(
196
+ FeatureRequirement(
197
+ feature_name="hint_test",
198
+ min_version=VersionInfo(3, 0, 0),
199
+ description="Hint test feature",
200
+ alternative="Use hint_alternative",
201
+ )
202
+ )
203
+
204
+ # Test with version too low
205
+ self.version_manager.set_backend_version("2.5.0")
206
+ hint = self.version_manager.get_version_hint("hint_test", "Test context")
207
+
208
+ self.assertIn("3.0.0", hint)
209
+ self.assertIn("2.5.0", hint)
210
+ self.assertIn("hint_alternative", hint)
211
+ self.assertIn("Test context", hint)
212
+
213
+
214
+ class TestVersionDecorator(unittest.TestCase):
215
+ """Test version checking decorator"""
216
+
217
+ def test_successful_version_check(self):
218
+ """Test successful version check"""
219
+ # Clear any existing feature requirements to avoid interference
220
+ from matrixone.version import _version_manager
221
+
222
+ _version_manager._feature_requirements.clear()
223
+
224
+ class TestClass:
225
+ def __init__(self):
226
+ # Set global version manager
227
+ _version_manager.set_backend_version("3.0.0")
228
+
229
+ @requires_version(min_version="2.0.0", feature_name="test_feature", description="Test feature")
230
+ def test_method(self):
231
+ return "success"
232
+
233
+ obj = TestClass()
234
+ result = obj.test_method()
235
+ self.assertEqual(result, "success")
236
+
237
+ def test_failed_version_check(self):
238
+ """Test failed version check"""
239
+
240
+ class TestClass:
241
+ def __init__(self):
242
+ # Set global version manager
243
+ from matrixone.version import _version_manager
244
+
245
+ _version_manager.set_backend_version("1.0.0")
246
+
247
+ @requires_version(
248
+ min_version="2.0.0",
249
+ feature_name="test_feature",
250
+ description="Test feature",
251
+ alternative="Use alternative method",
252
+ )
253
+ def test_method(self):
254
+ return "success"
255
+
256
+ obj = TestClass()
257
+ with self.assertRaises(VersionError):
258
+ obj.test_method()
259
+
260
+ def test_version_range_check(self):
261
+ """Test version range checking"""
262
+
263
+ class TestClass:
264
+ def __init__(self, version):
265
+ # Set global version manager
266
+ from matrixone.version import _version_manager
267
+
268
+ _version_manager.set_backend_version(version)
269
+
270
+ @requires_version(
271
+ min_version="2.0.0",
272
+ max_version="2.9.9",
273
+ feature_name="legacy_feature",
274
+ description="Legacy feature",
275
+ )
276
+ def legacy_method(self):
277
+ return "legacy success"
278
+
279
+ # Test within range
280
+ obj = TestClass("2.5.0")
281
+ result = obj.legacy_method()
282
+ self.assertEqual(result, "legacy success")
283
+
284
+ # Test below range
285
+ obj = TestClass("1.9.0")
286
+ with self.assertRaises(VersionError):
287
+ obj.legacy_method()
288
+
289
+ # Test above range
290
+ obj = TestClass("3.0.0")
291
+ with self.assertRaises(VersionError):
292
+ obj.legacy_method()
293
+
294
+
295
+ class TestIntegration(unittest.TestCase):
296
+ """Test integration with MatrixOne client"""
297
+
298
+ def test_client_version_management_api(self):
299
+ """Test client version management API"""
300
+ from matrixone import Client
301
+
302
+ # Create client (without connecting)
303
+ client = Client()
304
+
305
+ # Test manual version setting
306
+ client.set_backend_version("3.0.1")
307
+ self.assertEqual(client.get_backend_version(), "3.0.1")
308
+
309
+ # Test version compatibility check
310
+ self.assertTrue(client.check_version_compatibility("3.0.0", ">="))
311
+ self.assertFalse(client.check_version_compatibility("3.0.2", ">="))
312
+
313
+ # Test feature availability (should work since we have default features)
314
+ self.assertTrue(client.is_feature_available("snapshot_creation"))
315
+
316
+ # Test feature info retrieval (feature may not exist if not registered)
317
+ info = client.get_feature_info("snapshot_creation")
318
+ if info is not None:
319
+ self.assertEqual(info['feature_name'], "snapshot_creation")
320
+ else:
321
+ # Feature not registered, which is acceptable
322
+ self.assertIsNone(info)
323
+
324
+
325
+ class TestErrorHandling(unittest.TestCase):
326
+ """Test error handling"""
327
+
328
+ def test_version_error_inheritance(self):
329
+ """Test that VersionError inherits from MatrixOneError"""
330
+ from matrixone.exceptions import MatrixOneError
331
+
332
+ self.assertTrue(issubclass(VersionError, MatrixOneError))
333
+ self.assertTrue(issubclass(MatrixOneVersionError, MatrixOneError))
334
+
335
+
336
+ def run_tests():
337
+ """Run all tests"""
338
+ # Create test suite
339
+ test_suite = unittest.TestSuite()
340
+
341
+ # Add test classes
342
+ test_classes = [
343
+ TestVersionParsing,
344
+ TestVersionComparison,
345
+ TestFeatureRequirements,
346
+ TestVersionDecorator,
347
+ TestIntegration,
348
+ TestErrorHandling,
349
+ ]
350
+
351
+ for test_class in test_classes:
352
+ tests = unittest.TestLoader().loadTestsFromTestCase(test_class)
353
+ test_suite.addTests(tests)
354
+
355
+ # Run tests
356
+ runner = unittest.TextTestRunner(verbosity=2)
357
+ result = runner.run(test_suite)
358
+
359
+ return result.wasSuccessful()
360
+
361
+
362
+ if __name__ == "__main__":
363
+ print("MatrixOne Python SDK - Version Management Test Suite")
364
+ print("=" * 60)
365
+
366
+ success = run_tests()
367
+
368
+ if success:
369
+ print("\n✓ All tests passed!")
370
+ else:
371
+ print("\n✗ Some tests failed!")
372
+ sys.exit(1)