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,161 @@
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
+ SQLAlchemy extensions for MatrixOne Python client.
17
+
18
+ This module provides SQLAlchemy-specific extensions and utilities
19
+ for working with MatrixOne database features.
20
+ """
21
+
22
+ from .dialect import MatrixOneDialect
23
+ from .fulltext_index import (
24
+ FulltextAlgorithmType,
25
+ FulltextIndex,
26
+ FulltextModeType,
27
+ FulltextParserType,
28
+ FulltextSearchBuilder,
29
+ create_fulltext_index,
30
+ fulltext_search_builder,
31
+ )
32
+ from .fulltext_search import (
33
+ FulltextFilter,
34
+ )
35
+ from .fulltext_search import FulltextIndexManager as FulltextSearchManager
36
+ from .fulltext_search import (
37
+ FulltextSearchAlgorithm,
38
+ )
39
+ from .fulltext_search import FulltextSearchBuilder as AdvancedFulltextSearchBuilder
40
+ from .fulltext_search import (
41
+ FulltextSearchMode,
42
+ boolean_match,
43
+ group,
44
+ natural_match,
45
+ )
46
+ from .hnsw_config import (
47
+ HNSWConfig,
48
+ create_hnsw_config,
49
+ disable_hnsw_indexing,
50
+ enable_hnsw_indexing,
51
+ get_hnsw_status,
52
+ )
53
+ from .ivf_config import (
54
+ IVFConfig,
55
+ create_ivf_config,
56
+ disable_ivf_indexing,
57
+ enable_ivf_indexing,
58
+ get_ivf_status,
59
+ set_probe_limit,
60
+ )
61
+ from .table_builder import (
62
+ VectorTableBuilder,
63
+ create_document_vector_table,
64
+ create_product_vector_table,
65
+ create_vector_index_table,
66
+ create_vector_table,
67
+ )
68
+ from .vector_index import (
69
+ CreateVectorIndex,
70
+ HnswVectorIndex,
71
+ IVFVectorIndex,
72
+ VectorIndex,
73
+ VectorIndexBuilder,
74
+ VectorIndexType,
75
+ VectorOpType,
76
+ create_hnsw_index,
77
+ create_ivfflat_index,
78
+ create_vector_index,
79
+ vector_index_builder,
80
+ )
81
+
82
+ # Import SQLAlchemy extensions
83
+ from .vector_type import (
84
+ VectorColumn,
85
+ Vectorf32,
86
+ Vectorf64,
87
+ VectorPrecision,
88
+ VectorType,
89
+ VectorTypeDecorator,
90
+ cosine_distance,
91
+ create_vector_column,
92
+ inner_product,
93
+ l2_distance,
94
+ l2_distance_sq,
95
+ most_similar,
96
+ negative_inner_product,
97
+ vector_distance_functions,
98
+ vector_similarity_search,
99
+ within_distance,
100
+ )
101
+
102
+ __all__ = [
103
+ "VectorType",
104
+ "Vectorf32",
105
+ "Vectorf64",
106
+ "VectorTypeDecorator",
107
+ "VectorColumn",
108
+ "VectorPrecision",
109
+ "create_vector_column",
110
+ "vector_distance_functions",
111
+ "l2_distance",
112
+ "l2_distance_sq",
113
+ "cosine_distance",
114
+ "inner_product",
115
+ "negative_inner_product",
116
+ "within_distance",
117
+ "most_similar",
118
+ "vector_similarity_search",
119
+ "MatrixOneDialect",
120
+ "VectorTableBuilder",
121
+ "create_vector_table",
122
+ "create_vector_index_table",
123
+ "create_document_vector_table",
124
+ "create_product_vector_table",
125
+ "VectorIndex",
126
+ "IVFVectorIndex",
127
+ "HnswVectorIndex",
128
+ "VectorIndexType",
129
+ "VectorOpType",
130
+ "CreateVectorIndex",
131
+ "create_vector_index",
132
+ "create_ivfflat_index",
133
+ "create_hnsw_index",
134
+ "VectorIndexBuilder",
135
+ "vector_index_builder",
136
+ "HNSWConfig",
137
+ "create_hnsw_config",
138
+ "enable_hnsw_indexing",
139
+ "disable_hnsw_indexing",
140
+ "get_hnsw_status",
141
+ "IVFConfig",
142
+ "create_ivf_config",
143
+ "enable_ivf_indexing",
144
+ "disable_ivf_indexing",
145
+ "set_probe_limit",
146
+ "get_ivf_status",
147
+ "FulltextIndex",
148
+ "FulltextAlgorithmType",
149
+ "FulltextModeType",
150
+ "FulltextSearchBuilder",
151
+ "create_fulltext_index",
152
+ "fulltext_search_builder",
153
+ "FulltextSearchMode",
154
+ "FulltextSearchAlgorithm",
155
+ "AdvancedFulltextSearchBuilder",
156
+ "FulltextSearchManager",
157
+ "FulltextFilter",
158
+ "boolean_match",
159
+ "natural_match",
160
+ "group",
161
+ ]
@@ -0,0 +1,163 @@
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
+ SQLAlchemy adapters for custom filter objects.
17
+
18
+ This module provides generic adapters for SQLAlchemy's logical operators (and_, or_, not_)
19
+ to work seamlessly with custom filter objects that have a compile() method.
20
+
21
+ These adapters allow mixing custom filter objects with regular SQLAlchemy expressions
22
+ in logical operations.
23
+ """
24
+
25
+ from typing import Any, Union
26
+
27
+ from sqlalchemy import and_, false, not_, or_, text, true
28
+ from sqlalchemy.sql.elements import ClauseElement
29
+
30
+ # SQLAlchemy boolean constants for handling empty conditions
31
+ _TRUE_CONDITION = true()
32
+ _FALSE_CONDITION = false()
33
+
34
+
35
+ class CustomFilterMixin:
36
+ """
37
+ Mixin interface for custom filter objects that can be used with logical adapters.
38
+
39
+ Any custom filter class that implements a compile() method can be used with
40
+ the logical adapters in this module.
41
+ """
42
+
43
+ def compile(self, **kwargs) -> str:
44
+ """
45
+ Compile the filter to a SQL string.
46
+
47
+ Returns:
48
+
49
+ SQL string representation of the filter
50
+ """
51
+ raise NotImplementedError("Subclasses must implement compile() method")
52
+
53
+
54
+ def logical_and(*conditions: Union[Any, CustomFilterMixin]) -> ClauseElement:
55
+ """
56
+ Create AND expressions that support custom filter objects.
57
+
58
+ This is a generic wrapper around SQLAlchemy's and_() that can handle any objects
59
+ with a compile() method alongside regular SQLAlchemy expressions.
60
+
61
+ Args:
62
+
63
+ *conditions: Mix of custom filter objects (with compile() method)
64
+ and regular SQLAlchemy expressions
65
+
66
+ Returns:
67
+
68
+ SQLAlchemy expression that can be used with filter()
69
+
70
+ Example:
71
+
72
+ query.filter(logical_and(
73
+ custom_filter.some_condition(),
74
+ Article.category == "Programming",
75
+ another_custom_filter.other_condition()
76
+ ))
77
+ """
78
+ processed_conditions = []
79
+ for condition in conditions:
80
+ if hasattr(condition, 'compile') and callable(getattr(condition, 'compile')):
81
+ # Wrap each custom filter condition in parentheses for proper grouping
82
+ processed_conditions.append(text(f"({condition.compile()})"))
83
+ else:
84
+ processed_conditions.append(condition)
85
+
86
+ # Handle empty conditions to avoid SQLAlchemy deprecation warning
87
+ if not processed_conditions:
88
+ return and_(_TRUE_CONDITION) # Use true() as a neutral condition
89
+
90
+ return and_(*processed_conditions)
91
+
92
+
93
+ def logical_or(*conditions: Union[Any, CustomFilterMixin]) -> ClauseElement:
94
+ """
95
+ Create OR expressions that support custom filter objects.
96
+
97
+ This is a generic wrapper around SQLAlchemy's or_() that can handle any objects
98
+ with a compile() method alongside regular SQLAlchemy expressions.
99
+
100
+ Args:
101
+
102
+ *conditions: Mix of custom filter objects (with compile() method)
103
+ and regular SQLAlchemy expressions
104
+
105
+ Returns:
106
+
107
+ SQLAlchemy expression that can be used with filter()
108
+
109
+ Example:
110
+
111
+ query.filter(logical_or(
112
+ custom_filter.condition_a(),
113
+ custom_filter.condition_b(),
114
+ Article.status == "published"
115
+ ))
116
+ """
117
+ processed_conditions = []
118
+ for condition in conditions:
119
+ if hasattr(condition, 'compile') and callable(getattr(condition, 'compile')):
120
+ # Wrap each custom filter condition in parentheses for proper grouping
121
+ processed_conditions.append(text(f"({condition.compile()})"))
122
+ else:
123
+ processed_conditions.append(condition)
124
+
125
+ # Handle empty conditions to avoid SQLAlchemy deprecation warning
126
+ if not processed_conditions:
127
+ return or_(_FALSE_CONDITION) # Use false() as a neutral condition for OR
128
+
129
+ return or_(*processed_conditions)
130
+
131
+
132
+ def logical_not(condition: Union[Any, CustomFilterMixin]) -> ClauseElement:
133
+ """
134
+ Create NOT expressions that support custom filter objects.
135
+
136
+ This is a generic wrapper around SQLAlchemy's not_() that can handle objects
137
+ with a compile() method alongside regular SQLAlchemy expressions.
138
+
139
+ Args:
140
+
141
+ condition: A custom filter object (with compile() method) or regular SQLAlchemy expression
142
+
143
+ Returns:
144
+
145
+ SQLAlchemy expression that can be used with filter()
146
+
147
+ Example:
148
+
149
+ query.filter(logical_not(
150
+ custom_filter.some_condition()
151
+ ))
152
+ """
153
+ if hasattr(condition, 'compile') and callable(getattr(condition, 'compile')):
154
+ # Wrap the custom filter condition in parentheses for proper grouping
155
+ return text(f"NOT ({condition.compile()})")
156
+ else:
157
+ return not_(condition)
158
+
159
+
160
+ # Convenience aliases for shorter usage
161
+ and_adapter = logical_and
162
+ or_adapter = logical_or
163
+ not_adapter = logical_not