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,291 @@
1
+ # Copyright 2021 - 2022 Matrix Origin
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """
16
+ Online tests for version management
17
+
18
+ These tests are inspired by example_10_version_management.py
19
+ """
20
+
21
+ import pytest
22
+ from matrixone import Client, AsyncClient
23
+ from matrixone.version import VersionManager, VersionInfo, FeatureRequirement, requires_version
24
+ from matrixone.exceptions import VersionError, ConnectionError, QueryError
25
+ from matrixone.logger import create_default_logger
26
+
27
+
28
+ @pytest.mark.online
29
+ class TestVersionManagement:
30
+ """Test version management functionality"""
31
+
32
+ def test_version_parsing_and_comparison(self):
33
+ """Test version parsing and comparison"""
34
+ version_manager = VersionManager()
35
+
36
+ # Test version parsing
37
+ versions = ["3.0.1", "3.0.2", "2.1.19", "3.0.9", "1.5.0"]
38
+
39
+ for version_str in versions:
40
+ version = version_manager.parse_version(version_str)
41
+ assert isinstance(version, VersionInfo)
42
+ assert str(version) == version_str
43
+
44
+ # Test version comparisons
45
+ test_cases = [
46
+ ("3.0.2", "3.0.1", 1), # 3.0.2 > 3.0.1
47
+ ("2.1.19", "3.0.9", -1), # 2.1.19 < 3.0.9
48
+ ("3.0.1", "3.0.1", 0), # 3.0.1 == 3.0.1
49
+ ]
50
+
51
+ for v1_str, v2_str, expected in test_cases:
52
+ v1 = version_manager.parse_version(v1_str)
53
+ v2 = version_manager.parse_version(v2_str)
54
+
55
+ comparison = version_manager.compare_versions(v1, v2)
56
+ if expected > 0:
57
+ assert comparison.value == 1, f"{v1} should be greater than {v2}"
58
+ elif expected < 0:
59
+ assert comparison.value == -1, f"{v1} should be less than {v2}"
60
+ else:
61
+ assert comparison.value == 0, f"{v1} should be equal to {v2}"
62
+
63
+ def test_backend_version_detection(self, test_client):
64
+ """Test backend version detection"""
65
+ version_manager = VersionManager()
66
+
67
+ # Test version detection
68
+ version_str = test_client.get_backend_version()
69
+ assert version_str is not None
70
+ assert isinstance(version_str, str)
71
+ assert len(version_str) > 0
72
+
73
+ # Parse version string to get VersionInfo
74
+ version_info = version_manager.parse_version(version_str)
75
+ assert isinstance(version_info, VersionInfo)
76
+
77
+ # Test version components
78
+ assert version_info.major >= 0
79
+ assert version_info.minor >= 0
80
+ assert version_info.patch >= 0
81
+
82
+ def test_feature_availability_checking(self, test_client):
83
+ """Test feature availability checking"""
84
+ version_manager = VersionManager()
85
+ backend_version_str = test_client.get_backend_version()
86
+ backend_version = version_manager.parse_version(backend_version_str)
87
+
88
+ # Test feature requirements
89
+ feature_requirements = [
90
+ FeatureRequirement("basic_query", "1.0.0"),
91
+ FeatureRequirement("transactions", "2.0.0"),
92
+ FeatureRequirement("advanced_features", "3.0.0"),
93
+ ]
94
+
95
+ for feature_req in feature_requirements:
96
+ is_available = version_manager.is_feature_available(feature_req.feature_name)
97
+ assert isinstance(is_available, bool)
98
+
99
+ # Basic query should always be available
100
+ if feature_req.feature_name == "basic_query":
101
+ assert is_available, "Basic query should always be available"
102
+
103
+ def test_version_aware_error_messages(self, test_client):
104
+ """Test version-aware error messages"""
105
+ version_manager = VersionManager()
106
+ backend_version_str = test_client.get_backend_version()
107
+ backend_version = version_manager.parse_version(backend_version_str)
108
+
109
+ # Test version error creation
110
+ try:
111
+ # Try to use a feature that requires a very high version
112
+ feature_req = FeatureRequirement("nonexistent_feature", "999.0.0")
113
+ is_available = version_manager.is_feature_available(feature_req.feature_name)
114
+ # This should return True for unregistered features
115
+ assert isinstance(is_available, bool)
116
+ except Exception as e:
117
+ # If an error is raised, it should contain relevant information
118
+ assert "version" in str(e).lower() or "feature" in str(e).lower()
119
+
120
+ def test_version_checking_decorators(self):
121
+ """Test version checking decorators"""
122
+ version_manager = VersionManager()
123
+
124
+ # Test decorator with valid version
125
+ @requires_version("1.0.0")
126
+ def test_function():
127
+ return "success"
128
+
129
+ # This should work with any backend version >= 1.0.0
130
+ result = test_function()
131
+ assert result == "success"
132
+
133
+ # Test decorator with high version requirement
134
+ @requires_version("999.0.0")
135
+ def test_function_high_version():
136
+ return "success"
137
+
138
+ # This might fail depending on backend version
139
+ try:
140
+ result = test_function_high_version()
141
+ assert result == "success"
142
+ except VersionError:
143
+ # Expected to fail if backend version < 999.0.0
144
+ pass
145
+
146
+ def test_custom_feature_requirements(self, test_client):
147
+ """Test custom feature requirements"""
148
+ version_manager = VersionManager()
149
+ backend_version_str = test_client.get_backend_version()
150
+ backend_version = version_manager.parse_version(backend_version_str)
151
+
152
+ # Test custom feature requirement
153
+ custom_feature = FeatureRequirement("custom_feature", "2.5.0")
154
+
155
+ is_available = version_manager.is_feature_available(custom_feature.feature_name)
156
+ assert isinstance(is_available, bool)
157
+
158
+ # Test feature requirement with description
159
+ feature_with_desc = FeatureRequirement("feature_with_description", "1.0.0", description="This is a test feature")
160
+
161
+ assert feature_with_desc.description == "This is a test feature"
162
+
163
+ is_available = version_manager.is_feature_available(feature_with_desc.feature_name)
164
+ assert isinstance(is_available, bool)
165
+
166
+ def test_version_compatibility_matrix(self, test_client):
167
+ """Test version compatibility matrix"""
168
+ version_manager = VersionManager()
169
+ backend_version_str = test_client.get_backend_version()
170
+ backend_version = version_manager.parse_version(backend_version_str)
171
+
172
+ # Test compatibility with different SDK versions
173
+ sdk_versions = ["1.0.0", "2.0.0", "3.0.0"]
174
+
175
+ for sdk_version_str in sdk_versions:
176
+ sdk_version = version_manager.parse_version(sdk_version_str)
177
+
178
+ # Test basic compatibility by comparing versions
179
+ comparison = version_manager.compare_versions(backend_version, sdk_version)
180
+ # Backend should be >= SDK version for compatibility
181
+ is_compatible = comparison.value >= 0
182
+ assert isinstance(is_compatible, bool)
183
+
184
+ def test_version_info_properties(self, test_client):
185
+ """Test VersionInfo properties"""
186
+ version_manager = VersionManager()
187
+ backend_version_str = test_client.get_backend_version()
188
+ backend_version = version_manager.parse_version(backend_version_str)
189
+
190
+ # Test version properties
191
+ assert hasattr(backend_version, 'major')
192
+ assert hasattr(backend_version, 'minor')
193
+ assert hasattr(backend_version, 'patch')
194
+
195
+ assert isinstance(backend_version.major, int)
196
+ assert isinstance(backend_version.minor, int)
197
+ assert isinstance(backend_version.patch, int)
198
+
199
+ # Test version string representation
200
+ version_str = str(backend_version)
201
+ assert isinstance(version_str, str)
202
+ assert len(version_str) > 0
203
+
204
+ # Test version tuple
205
+ version_tuple = (backend_version.major, backend_version.minor, backend_version.patch)
206
+ assert isinstance(version_tuple, tuple)
207
+ assert len(version_tuple) == 3
208
+
209
+ def test_version_manager_methods(self):
210
+ """Test VersionManager methods"""
211
+ version_manager = VersionManager()
212
+
213
+ # Test parse_version method
214
+ version = version_manager.parse_version("1.2.3")
215
+ assert isinstance(version, VersionInfo)
216
+ assert version.major == 1
217
+ assert version.minor == 2
218
+ assert version.patch == 3
219
+
220
+ # Test compare_versions method
221
+ v1 = version_manager.parse_version("1.2.3")
222
+ v2 = version_manager.parse_version("1.2.4")
223
+
224
+ comparison = version_manager.compare_versions(v1, v2)
225
+ assert comparison.value < 0 # v1 < v2
226
+
227
+ # Test compatibility by comparing versions
228
+ backend_version = version_manager.parse_version("2.0.0")
229
+ sdk_version = version_manager.parse_version("1.0.0")
230
+
231
+ comparison = version_manager.compare_versions(backend_version, sdk_version)
232
+ is_compatible = comparison.value >= 0
233
+ assert isinstance(is_compatible, bool)
234
+
235
+ @pytest.mark.asyncio
236
+ async def test_async_version_management(self, test_async_client):
237
+ """Test async version management"""
238
+ # Test async version detection - AsyncClient doesn't have get_backend_version
239
+ # So we'll test basic async operations instead
240
+ result = await test_async_client.execute("SELECT VERSION()")
241
+ assert result is not None
242
+ assert len(result.rows) > 0
243
+
244
+ version_str = result.rows[0][0]
245
+ assert isinstance(version_str, str)
246
+ assert len(version_str) > 0
247
+
248
+ def test_version_with_logging(self, connection_params):
249
+ """Test version management with logging"""
250
+ host, port, user, password, database = connection_params
251
+
252
+ # Create logger
253
+ logger = create_default_logger()
254
+
255
+ # Create client with logging
256
+ client = Client(logger=logger)
257
+ client.connect(host=host, port=port, user=user, password=password, database=database)
258
+
259
+ try:
260
+ # Test version detection with logging
261
+ version_str = client.get_backend_version()
262
+ assert version_str is not None
263
+ assert isinstance(version_str, str)
264
+
265
+ finally:
266
+ client.disconnect()
267
+
268
+ def test_version_error_handling(self):
269
+ """Test version error handling"""
270
+ version_manager = VersionManager()
271
+
272
+ # Test invalid version string
273
+ try:
274
+ version_manager.parse_version("invalid_version")
275
+ assert False, "Should have failed with invalid version"
276
+ except Exception:
277
+ pass # Expected to fail
278
+
279
+ # Test empty version string
280
+ try:
281
+ version_manager.parse_version("")
282
+ assert False, "Should have failed with empty version"
283
+ except Exception:
284
+ pass # Expected to fail
285
+
286
+ # Test None version
287
+ try:
288
+ version_manager.parse_version(None)
289
+ assert False, "Should have failed with None version"
290
+ except Exception:
291
+ pass # Expected to fail