1use async_trait::async_trait;
4use bytes::Bytes;
5use thiserror::Error;
6
7use lance_namespace_reqwest_client::models::{
8 AlterTransactionRequest, AlterTransactionResponse, CountTableRowsRequest,
9 CreateEmptyTableRequest, CreateEmptyTableResponse, CreateNamespaceRequest,
10 CreateNamespaceResponse, CreateTableIndexRequest, CreateTableIndexResponse, CreateTableRequest,
11 CreateTableResponse, DeleteFromTableRequest, DeleteFromTableResponse, DeregisterTableRequest,
12 DeregisterTableResponse, DescribeNamespaceRequest, DescribeNamespaceResponse,
13 DescribeTableIndexStatsRequest, DescribeTableIndexStatsResponse, DescribeTableRequest,
14 DescribeTableResponse, DescribeTransactionRequest, DescribeTransactionResponse,
15 DropNamespaceRequest, DropNamespaceResponse, DropTableRequest, DropTableResponse,
16 InsertIntoTableRequest, InsertIntoTableResponse, ListNamespacesRequest, ListNamespacesResponse,
17 ListTableIndicesRequest, ListTableIndicesResponse, ListTablesRequest, ListTablesResponse,
18 MergeInsertIntoTableRequest, MergeInsertIntoTableResponse, NamespaceExistsRequest,
19 QueryTableRequest, RegisterTableRequest, RegisterTableResponse, TableExistsRequest,
20 UpdateTableRequest, UpdateTableResponse,
21};
22
23#[derive(Debug, Error)]
25pub enum NamespaceError {
26 #[error("Operation not supported: {0}")]
27 NotSupported(String),
28
29 #[error("IO error: {0}")]
30 Io(#[from] std::io::Error),
31
32 #[error("Other error: {0}")]
33 Other(String),
34}
35
36pub type Result<T> = std::result::Result<T, NamespaceError>;
38
39#[async_trait]
45pub trait LanceNamespace: Send + Sync {
46 async fn list_namespaces(
48 &self,
49 _request: ListNamespacesRequest,
50 ) -> Result<ListNamespacesResponse> {
51 Err(NamespaceError::NotSupported("list_namespaces".to_string()))
52 }
53
54 async fn describe_namespace(
56 &self,
57 _request: DescribeNamespaceRequest,
58 ) -> Result<DescribeNamespaceResponse> {
59 Err(NamespaceError::NotSupported(
60 "describe_namespace".to_string(),
61 ))
62 }
63
64 async fn create_namespace(
66 &self,
67 _request: CreateNamespaceRequest,
68 ) -> Result<CreateNamespaceResponse> {
69 Err(NamespaceError::NotSupported("create_namespace".to_string()))
70 }
71
72 async fn drop_namespace(
74 &self,
75 _request: DropNamespaceRequest,
76 ) -> Result<DropNamespaceResponse> {
77 Err(NamespaceError::NotSupported("drop_namespace".to_string()))
78 }
79
80 async fn namespace_exists(&self, _request: NamespaceExistsRequest) -> Result<()> {
82 Err(NamespaceError::NotSupported("namespace_exists".to_string()))
83 }
84
85 async fn list_tables(&self, _request: ListTablesRequest) -> Result<ListTablesResponse> {
87 Err(NamespaceError::NotSupported("list_tables".to_string()))
88 }
89
90 async fn describe_table(
92 &self,
93 _request: DescribeTableRequest,
94 ) -> Result<DescribeTableResponse> {
95 Err(NamespaceError::NotSupported("describe_table".to_string()))
96 }
97
98 async fn register_table(
100 &self,
101 _request: RegisterTableRequest,
102 ) -> Result<RegisterTableResponse> {
103 Err(NamespaceError::NotSupported("register_table".to_string()))
104 }
105
106 async fn table_exists(&self, _request: TableExistsRequest) -> Result<()> {
108 Err(NamespaceError::NotSupported("table_exists".to_string()))
109 }
110
111 async fn drop_table(&self, _request: DropTableRequest) -> Result<DropTableResponse> {
113 Err(NamespaceError::NotSupported("drop_table".to_string()))
114 }
115
116 async fn deregister_table(
118 &self,
119 _request: DeregisterTableRequest,
120 ) -> Result<DeregisterTableResponse> {
121 Err(NamespaceError::NotSupported("deregister_table".to_string()))
122 }
123
124 async fn count_table_rows(&self, _request: CountTableRowsRequest) -> Result<i64> {
126 Err(NamespaceError::NotSupported("count_table_rows".to_string()))
127 }
128
129 async fn create_table(
131 &self,
132 _request: CreateTableRequest,
133 _request_data: Bytes,
134 ) -> Result<CreateTableResponse> {
135 Err(NamespaceError::NotSupported("create_table".to_string()))
136 }
137
138 async fn create_empty_table(
140 &self,
141 _request: CreateEmptyTableRequest,
142 ) -> Result<CreateEmptyTableResponse> {
143 Err(NamespaceError::NotSupported(
144 "create_empty_table".to_string(),
145 ))
146 }
147
148 async fn insert_into_table(
150 &self,
151 _request: InsertIntoTableRequest,
152 _request_data: Bytes,
153 ) -> Result<InsertIntoTableResponse> {
154 Err(NamespaceError::NotSupported(
155 "insert_into_table".to_string(),
156 ))
157 }
158
159 async fn merge_insert_into_table(
161 &self,
162 _request: MergeInsertIntoTableRequest,
163 _request_data: Bytes,
164 ) -> Result<MergeInsertIntoTableResponse> {
165 Err(NamespaceError::NotSupported(
166 "merge_insert_into_table".to_string(),
167 ))
168 }
169
170 async fn update_table(&self, _request: UpdateTableRequest) -> Result<UpdateTableResponse> {
172 Err(NamespaceError::NotSupported("update_table".to_string()))
173 }
174
175 async fn delete_from_table(
177 &self,
178 _request: DeleteFromTableRequest,
179 ) -> Result<DeleteFromTableResponse> {
180 Err(NamespaceError::NotSupported(
181 "delete_from_table".to_string(),
182 ))
183 }
184
185 async fn query_table(&self, _request: QueryTableRequest) -> Result<Bytes> {
187 Err(NamespaceError::NotSupported("query_table".to_string()))
188 }
189
190 async fn create_table_index(
192 &self,
193 _request: CreateTableIndexRequest,
194 ) -> Result<CreateTableIndexResponse> {
195 Err(NamespaceError::NotSupported(
196 "create_table_index".to_string(),
197 ))
198 }
199
200 async fn list_table_indices(
202 &self,
203 _request: ListTableIndicesRequest,
204 ) -> Result<ListTableIndicesResponse> {
205 Err(NamespaceError::NotSupported(
206 "list_table_indices".to_string(),
207 ))
208 }
209
210 async fn describe_table_index_stats(
212 &self,
213 _request: DescribeTableIndexStatsRequest,
214 ) -> Result<DescribeTableIndexStatsResponse> {
215 Err(NamespaceError::NotSupported(
216 "describe_table_index_stats".to_string(),
217 ))
218 }
219
220 async fn describe_transaction(
222 &self,
223 _request: DescribeTransactionRequest,
224 ) -> Result<DescribeTransactionResponse> {
225 Err(NamespaceError::NotSupported(
226 "describe_transaction".to_string(),
227 ))
228 }
229
230 async fn alter_transaction(
232 &self,
233 _request: AlterTransactionRequest,
234 ) -> Result<AlterTransactionResponse> {
235 Err(NamespaceError::NotSupported(
236 "alter_transaction".to_string(),
237 ))
238 }
239}