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.
- matrixone/__init__.py +155 -0
- matrixone/account.py +723 -0
- matrixone/async_client.py +3913 -0
- matrixone/async_metadata_manager.py +311 -0
- matrixone/async_orm.py +123 -0
- matrixone/async_vector_index_manager.py +633 -0
- matrixone/base_client.py +208 -0
- matrixone/client.py +4672 -0
- matrixone/config.py +452 -0
- matrixone/connection_hooks.py +286 -0
- matrixone/exceptions.py +89 -0
- matrixone/logger.py +782 -0
- matrixone/metadata.py +820 -0
- matrixone/moctl.py +219 -0
- matrixone/orm.py +2277 -0
- matrixone/pitr.py +646 -0
- matrixone/pubsub.py +771 -0
- matrixone/restore.py +411 -0
- matrixone/search_vector_index.py +1176 -0
- matrixone/snapshot.py +550 -0
- matrixone/sql_builder.py +844 -0
- matrixone/sqlalchemy_ext/__init__.py +161 -0
- matrixone/sqlalchemy_ext/adapters.py +163 -0
- matrixone/sqlalchemy_ext/dialect.py +534 -0
- matrixone/sqlalchemy_ext/fulltext_index.py +895 -0
- matrixone/sqlalchemy_ext/fulltext_search.py +1686 -0
- matrixone/sqlalchemy_ext/hnsw_config.py +194 -0
- matrixone/sqlalchemy_ext/ivf_config.py +252 -0
- matrixone/sqlalchemy_ext/table_builder.py +351 -0
- matrixone/sqlalchemy_ext/vector_index.py +1721 -0
- matrixone/sqlalchemy_ext/vector_type.py +948 -0
- matrixone/version.py +580 -0
- matrixone_python_sdk-0.1.0.dist-info/METADATA +706 -0
- matrixone_python_sdk-0.1.0.dist-info/RECORD +122 -0
- matrixone_python_sdk-0.1.0.dist-info/WHEEL +5 -0
- matrixone_python_sdk-0.1.0.dist-info/entry_points.txt +5 -0
- matrixone_python_sdk-0.1.0.dist-info/licenses/LICENSE +200 -0
- matrixone_python_sdk-0.1.0.dist-info/top_level.txt +2 -0
- tests/__init__.py +19 -0
- tests/offline/__init__.py +20 -0
- tests/offline/conftest.py +77 -0
- tests/offline/test_account.py +703 -0
- tests/offline/test_async_client_query_comprehensive.py +1218 -0
- tests/offline/test_basic.py +54 -0
- tests/offline/test_case_sensitivity.py +227 -0
- tests/offline/test_connection_hooks_offline.py +287 -0
- tests/offline/test_dialect_schema_handling.py +609 -0
- tests/offline/test_explain_methods.py +346 -0
- tests/offline/test_filter_logical_in.py +237 -0
- tests/offline/test_fulltext_search_comprehensive.py +795 -0
- tests/offline/test_ivf_config.py +249 -0
- tests/offline/test_join_methods.py +281 -0
- tests/offline/test_join_sqlalchemy_compatibility.py +276 -0
- tests/offline/test_logical_in_method.py +237 -0
- tests/offline/test_matrixone_version_parsing.py +264 -0
- tests/offline/test_metadata_offline.py +557 -0
- tests/offline/test_moctl.py +300 -0
- tests/offline/test_moctl_simple.py +251 -0
- tests/offline/test_model_support_offline.py +359 -0
- tests/offline/test_model_support_simple.py +225 -0
- tests/offline/test_pinecone_filter_offline.py +377 -0
- tests/offline/test_pitr.py +585 -0
- tests/offline/test_pubsub.py +712 -0
- tests/offline/test_query_update.py +283 -0
- tests/offline/test_restore.py +445 -0
- tests/offline/test_snapshot_comprehensive.py +384 -0
- tests/offline/test_sql_escaping_edge_cases.py +551 -0
- tests/offline/test_sqlalchemy_integration.py +382 -0
- tests/offline/test_sqlalchemy_vector_integration.py +434 -0
- tests/offline/test_table_builder.py +198 -0
- tests/offline/test_unified_filter.py +398 -0
- tests/offline/test_unified_transaction.py +495 -0
- tests/offline/test_vector_index.py +238 -0
- tests/offline/test_vector_operations.py +688 -0
- tests/offline/test_vector_type.py +174 -0
- tests/offline/test_version_core.py +328 -0
- tests/offline/test_version_management.py +372 -0
- tests/offline/test_version_standalone.py +652 -0
- tests/online/__init__.py +20 -0
- tests/online/conftest.py +216 -0
- tests/online/test_account_management.py +194 -0
- tests/online/test_advanced_features.py +344 -0
- tests/online/test_async_client_interfaces.py +330 -0
- tests/online/test_async_client_online.py +285 -0
- tests/online/test_async_model_insert_online.py +293 -0
- tests/online/test_async_orm_online.py +300 -0
- tests/online/test_async_simple_query_online.py +802 -0
- tests/online/test_async_transaction_simple_query.py +300 -0
- tests/online/test_basic_connection.py +130 -0
- tests/online/test_client_online.py +238 -0
- tests/online/test_config.py +90 -0
- tests/online/test_config_validation.py +123 -0
- tests/online/test_connection_hooks_new_online.py +217 -0
- tests/online/test_dialect_schema_handling_online.py +331 -0
- tests/online/test_filter_logical_in_online.py +374 -0
- tests/online/test_fulltext_comprehensive.py +1773 -0
- tests/online/test_fulltext_label_online.py +433 -0
- tests/online/test_fulltext_search_online.py +842 -0
- tests/online/test_ivf_stats_online.py +506 -0
- tests/online/test_logger_integration.py +311 -0
- tests/online/test_matrixone_query_orm.py +540 -0
- tests/online/test_metadata_online.py +579 -0
- tests/online/test_model_insert_online.py +255 -0
- tests/online/test_mysql_driver_validation.py +213 -0
- tests/online/test_orm_advanced_features.py +2022 -0
- tests/online/test_orm_cte_integration.py +269 -0
- tests/online/test_orm_online.py +270 -0
- tests/online/test_pinecone_filter.py +708 -0
- tests/online/test_pubsub_operations.py +352 -0
- tests/online/test_query_methods.py +225 -0
- tests/online/test_query_update_online.py +433 -0
- tests/online/test_search_vector_index.py +557 -0
- tests/online/test_simple_fulltext_online.py +915 -0
- tests/online/test_snapshot_comprehensive.py +998 -0
- tests/online/test_sqlalchemy_engine_integration.py +336 -0
- tests/online/test_sqlalchemy_integration.py +425 -0
- tests/online/test_transaction_contexts.py +1219 -0
- tests/online/test_transaction_insert_methods.py +356 -0
- tests/online/test_transaction_query_methods.py +288 -0
- tests/online/test_unified_filter_online.py +529 -0
- tests/online/test_vector_comprehensive.py +706 -0
- tests/online/test_version_management.py +291 -0
matrixone/base_client.py
ADDED
@@ -0,0 +1,208 @@
|
|
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
|
+
Base client functionality for MatrixOne clients
|
17
|
+
"""
|
18
|
+
|
19
|
+
# No imports needed for this module
|
20
|
+
|
21
|
+
|
22
|
+
class BaseMatrixOneClient:
|
23
|
+
"""
|
24
|
+
Base class for MatrixOne clients with common SQL building logic.
|
25
|
+
|
26
|
+
This abstract base class provides common functionality and SQL building
|
27
|
+
logic that is shared between synchronous and asynchronous MatrixOne
|
28
|
+
clients. It includes methods for constructing SQL statements, handling
|
29
|
+
parameters, and managing common database operations.
|
30
|
+
|
31
|
+
Key Features:
|
32
|
+
|
33
|
+
- Common SQL building logic for INSERT, UPDATE, DELETE operations
|
34
|
+
- Parameter substitution and SQL injection prevention
|
35
|
+
- Batch operation support
|
36
|
+
- Error handling and validation
|
37
|
+
- Integration with MatrixOne's SQL syntax
|
38
|
+
|
39
|
+
Supported Operations:
|
40
|
+
|
41
|
+
- INSERT statement generation with parameter binding
|
42
|
+
- UPDATE statement generation with WHERE conditions
|
43
|
+
- DELETE statement generation with WHERE conditions
|
44
|
+
- Batch INSERT operations for multiple rows
|
45
|
+
- Parameter substitution and escaping
|
46
|
+
|
47
|
+
Usage:
|
48
|
+
|
49
|
+
This class is not intended to be used directly. It serves as a base
|
50
|
+
class for Client and AsyncClient implementations, providing common
|
51
|
+
functionality and reducing code duplication.
|
52
|
+
|
53
|
+
Note: This is an internal base class. Use Client or AsyncClient for
|
54
|
+
actual database operations.
|
55
|
+
"""
|
56
|
+
|
57
|
+
def _build_insert_sql(self, table_name: str, data: dict) -> str:
|
58
|
+
"""
|
59
|
+
Build INSERT SQL statement from data dictionary.
|
60
|
+
|
61
|
+
Args:
|
62
|
+
|
63
|
+
table_name: Name of the table
|
64
|
+
data: Data to insert (dict with column names as keys)
|
65
|
+
|
66
|
+
Returns:
|
67
|
+
|
68
|
+
SQL INSERT statement string
|
69
|
+
"""
|
70
|
+
columns = list(data.keys())
|
71
|
+
values = list(data.values())
|
72
|
+
|
73
|
+
# Convert vectors to string format
|
74
|
+
formatted_values = []
|
75
|
+
for value in values:
|
76
|
+
if value is None:
|
77
|
+
formatted_values.append("NULL")
|
78
|
+
elif isinstance(value, list):
|
79
|
+
formatted_values.append("'" + "[" + ",".join(map(str, value)) + "]" + "'")
|
80
|
+
else:
|
81
|
+
formatted_values.append(f"'{str(value)}'")
|
82
|
+
|
83
|
+
columns_str = ", ".join(columns)
|
84
|
+
values_str = ", ".join(formatted_values)
|
85
|
+
|
86
|
+
return f"INSERT INTO {table_name} ({columns_str}) VALUES ({values_str})"
|
87
|
+
|
88
|
+
def _build_batch_insert_sql(self, table_name: str, data_list: list) -> str:
|
89
|
+
"""
|
90
|
+
Build batch INSERT SQL statement from list of data dictionaries.
|
91
|
+
|
92
|
+
Args:
|
93
|
+
|
94
|
+
table_name: Name of the table
|
95
|
+
data_list: List of data dictionaries to insert
|
96
|
+
|
97
|
+
Returns:
|
98
|
+
|
99
|
+
SQL batch INSERT statement string
|
100
|
+
"""
|
101
|
+
if not data_list:
|
102
|
+
return ""
|
103
|
+
|
104
|
+
# Get columns from first record
|
105
|
+
columns = list(data_list[0].keys())
|
106
|
+
columns_str = ", ".join(columns)
|
107
|
+
|
108
|
+
# Build VALUES clause
|
109
|
+
values_list = []
|
110
|
+
for data in data_list:
|
111
|
+
formatted_values = []
|
112
|
+
for col in columns:
|
113
|
+
value = data[col]
|
114
|
+
if value is None:
|
115
|
+
formatted_values.append("NULL")
|
116
|
+
elif isinstance(value, list):
|
117
|
+
formatted_values.append("'" + "[" + ",".join(map(str, value)) + "]" + "'")
|
118
|
+
else:
|
119
|
+
# Escape single quotes in string values to prevent SQL injection
|
120
|
+
escaped_value = str(value).replace("'", "''")
|
121
|
+
formatted_values.append(f"'{escaped_value}'")
|
122
|
+
values_str = "(" + ", ".join(formatted_values) + ")"
|
123
|
+
values_list.append(values_str)
|
124
|
+
|
125
|
+
values_clause = ", ".join(values_list)
|
126
|
+
return f"INSERT INTO {table_name} ({columns_str}) VALUES {values_clause}"
|
127
|
+
|
128
|
+
|
129
|
+
class BaseMatrixOneExecutor:
|
130
|
+
"""
|
131
|
+
Base class for MatrixOne executors with common insert/batch_insert logic.
|
132
|
+
|
133
|
+
This abstract base class provides common execution logic for database
|
134
|
+
operations that is shared between different executor implementations.
|
135
|
+
It includes methods for data insertion, batch operations, and result
|
136
|
+
handling that are common across synchronous and asynchronous executors.
|
137
|
+
|
138
|
+
Key Features:
|
139
|
+
|
140
|
+
- Common data insertion logic
|
141
|
+
- Batch operation support
|
142
|
+
- Result set handling
|
143
|
+
- Error handling and validation
|
144
|
+
- Integration with MatrixOne's data operations
|
145
|
+
|
146
|
+
Supported Operations:
|
147
|
+
|
148
|
+
- Single row insertion with parameter binding
|
149
|
+
- Batch insertion for multiple rows
|
150
|
+
- Result set creation and management
|
151
|
+
- Error handling and exception management
|
152
|
+
|
153
|
+
Usage:
|
154
|
+
|
155
|
+
This class is not intended to be used directly. It serves as a base
|
156
|
+
class for ClientExecutor and AsyncClientExecutor implementations,
|
157
|
+
providing common functionality and reducing code duplication.
|
158
|
+
|
159
|
+
Note: This is an internal base class. Use Client or AsyncClient for
|
160
|
+
actual database operations.
|
161
|
+
"""
|
162
|
+
|
163
|
+
def __init__(self, base_client: BaseMatrixOneClient):
|
164
|
+
self.base_client = base_client
|
165
|
+
|
166
|
+
def insert(self, table_name: str, data: dict):
|
167
|
+
"""
|
168
|
+
Insert data into a table.
|
169
|
+
|
170
|
+
Args:
|
171
|
+
|
172
|
+
table_name: Name of the table
|
173
|
+
data: Data to insert (dict with column names as keys)
|
174
|
+
|
175
|
+
Returns:
|
176
|
+
|
177
|
+
Result from execute method (implementation specific)
|
178
|
+
"""
|
179
|
+
sql = self.base_client._build_insert_sql(table_name, data)
|
180
|
+
return self._execute(sql)
|
181
|
+
|
182
|
+
def batch_insert(self, table_name: str, data_list: list):
|
183
|
+
"""
|
184
|
+
Batch insert data into a table.
|
185
|
+
|
186
|
+
Args:
|
187
|
+
|
188
|
+
table_name: Name of the table
|
189
|
+
data_list: List of data dictionaries to insert
|
190
|
+
|
191
|
+
Returns:
|
192
|
+
|
193
|
+
Result from execute method (implementation specific)
|
194
|
+
"""
|
195
|
+
if not data_list:
|
196
|
+
# Return empty result based on the executor type
|
197
|
+
return self._get_empty_result()
|
198
|
+
|
199
|
+
sql = self.base_client._build_batch_insert_sql(table_name, data_list)
|
200
|
+
return self._execute(sql)
|
201
|
+
|
202
|
+
def _execute(self, sql: str):
|
203
|
+
"""Execute SQL - to be implemented by subclasses"""
|
204
|
+
raise NotImplementedError("Subclasses must implement _execute method")
|
205
|
+
|
206
|
+
def _get_empty_result(self):
|
207
|
+
"""Get empty result - to be implemented by subclasses"""
|
208
|
+
raise NotImplementedError("Subclasses must implement _get_empty_result method")
|