Jazz 1.25.+
Loading...
Searching...
No Matches
data_space.h
1/* Jazz (c) 2018-2026 kaalam.ai (The Authors of Jazz), using (under the same license):
2
3 1. Biomodelling - The AATBlockQueue class (c) Jacques BasaldĂșa, 2009-2012 licensed
4 exclusively for the use in the Jazz server software.
5
6 Copyright 2009-2012 Jacques BasaldĂșa
7
8 2. BBVA - Jazz: A lightweight analytical web server for data-driven applications.
9
10 Copyright 2016-2017 Banco Bilbao Vizcaya Argentaria, S.A.
11
12 This product includes software developed at
13
14 BBVA (https://www.bbva.com/)
15
16 3. LMDB, Copyright 2011-2017 Howard Chu, Symas Corp. All rights reserved.
17
18 Licensed under http://www.OpenLDAP.org/license.html
19
20
21 Licensed under the Apache License, Version 2.0 (the "License");
22 you may not use this file except in compliance with the License.
23 You may obtain a copy of the License at
24
25 http://www.apache.org/licenses/LICENSE-2.0
26
27 Unless required by applicable law or agreed to in writing, software
28 distributed under the License is distributed on an "AS IS" BASIS,
29 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 See the License for the specific language governing permissions and
31 limitations under the License.
32*/
33
34
35#include "src/include/jazz_bebop.h"
36
37#if defined CATCH_TEST
38#ifndef INCLUDED_JAZZ_CATCH2
39#define INCLUDED_JAZZ_CATCH2
40
41#include "src/catch2/catch.hpp"
42
43#endif
44#endif
45
46
47#ifndef INCLUDED_JAZZ_MODELS_DATA_SPACE
48#define INCLUDED_JAZZ_MODELS_DATA_SPACE
49
50
51//TODO: Make DataSpaces just an interface with the language and an internal container. A different one for each storage type.
52
53
60namespace jazz_models
61{
62
71// class RowSelection {
72
73// /** \brief The constructor for a RowSelection.
74
75// \param query A query string that is understood by the descendant. In Bop, this is the content of a WHERE clause with a syntax
76// that depends on how the Space is indexed (Time, categorical, Embedding storage, ...).
77// \param p_space The Space that created the object is required because the descendant may need to call .get_index_data() or other
78// methods.
79// */
80// RowSelection(pChar query, pSpace p_space) {}
81
82// /** \brief Restart the iterator.
83
84// \return True if the iterator was successfully restarted, false if it is not possible.
85// */
86// virtual bool restart() {
87// return false;
88// }
89
90// /** \brief Get the next row.
91
92// \return The next row number or SPACE_ROW_STOP_ITERATOR if the iteration is exhausted.
93// */
94// virtual RowNumber next() {
95// return SPACE_ROW_STOP_ITERATOR;
96// }
97
98// bool is_valid = false; ///< True if the iterator was created by a successful query.
99// };
100// typedef RowSelection *pRowSelection; ///< A pointer to a RowSelection
101
102
110// class ColSelection {
111
112// public:
113
114// /** \brief The constructor for a ColSelection.
115
116// The constructor will parse the query and create a list of column names and indices. These will not change during the lifetime
117// of the object.
118
119// \param query By default, a list of comma separated column names. A descendant may define a different interface.
120// In Bop, this is the content of a SELECT clause.
121// \param p_space The Space that created the object is required to call col_index().
122// */
123// ColSelection(pChar query, pSpace p_space);
124
125// virtual bool restart();
126
127// virtual int next_index();
128// virtual pName next_name();
129
130// bool is_valid = false; ///< True if the iterator was created by a successful query.
131
132// #ifndef CATCH_TEST
133// private:
134// #endif
135
136// int current_col = 0; ///< The index of the current column (the next to be retrieved).
137// stdNames name = {}; ///< The list of column names in the selection.
138// std::vector<int> index = {}; ///< The list of column indices in the selection.
139// };
140// typedef ColSelection *pColSelection; ///< A pointer to a ColSelection
141
142
143#define DATASPACE_INDEX_ROW_NUM 1
144#define DATASPACE_INDEX_KEY 2
145#define DATASPACE_INDEX_EMBEDDING 3
146
147// class Space : public Service {
148
149// public:
150
151// // Service interface
152
153// Space(pBaseAPI api, pName a_name);
154
155// virtual StatusCode start ();
156// virtual StatusCode shut_down();
157
158// // Persistence interface
159
160// /** \brief Load the metadata of the Space.
161
162// This method must be implemented by descendants. It will load a record of metadata from `//storage_base/storage_ent/name`.
163
164// \return SERVICE_NO_ERROR if successful, an error code otherwise.
165// */
166// virtual StatusCode load_meta() {
167// return SERVICE_NOT_IMPLEMENTED;
168// }
169
170// /** \brief Save the metadata of the Space.
171
172// This method must be implemented by descendants. It will store a record of metadata into `//storage_base/storage_ent/name`.
173
174// \return SERVICE_NO_ERROR if successful, an error code otherwise.
175// */
176// virtual StatusCode save_meta() {
177// return SERVICE_NOT_IMPLEMENTED;
178// }
179
180// // Internal interface for ColSelection to have access to data by rows.
181
182// /** \brief Return the number of rows in the Space.
183
184// \return The number of rows in the Space or SPACE_NOT_A_ROW if the Space is invalid.
185// */
186// virtual RowNumber num_rows() {
187// return SPACE_NOT_A_ROW;
188// }
189
190// /** \brief Get a pointer to the data of the index of a given row.
191
192// \param row The row number.
193
194// \return A pointer to the index or nullptr if there is no index. Examples include a vector for an embedding, of a string for
195// a key-based index and a TimePoint for a time-based index.
196// */
197// virtual void* get_index_data(RowNumber row) {
198// return nullptr;
199// }
200
201// // Space interface
202
203// /** \brief Get the number of columns in the Space.
204
205// \return The number of columns in the Space.
206// */
207// virtual int num_cols() {
208// return 0;
209// }
210
211// /** \brief Get the name of a column.
212
213// \param col The column index.
214
215// \return The name of the column or nullptr if the index is out of range.
216// */
217// virtual pName col_name(int col) {
218// return nullptr;
219// }
220
221// /** \brief Get the index of a column.
222
223// \param name The name of the column.
224
225// \return The index of the column or -1 if the column is not found.
226// */
227// virtual int col_index(pName name) {
228// return -1;
229// }
230
231// /** \brief Get the location of a cell as a Locator
232
233// \param row The row number.
234// \param col The column index.
235// \param index If the block contains multiple rows, which is the index of `row` in the block.
236
237// \return A pointer to a Locator object that can be used to access the cell or nullptr if the cell is not found.
238// */
239// virtual pLocator locator(RowNumber row, int col, int &index) {
240// return nullptr;
241// }
242
243// /** \brief Get a RowSelection from a query.
244
245// \param query A query string that is understood by the descendant. In Bop, this is the content of a WHERE clause with a syntax
246// that depends on how the Space is indexed (Time, categorical, Embedding storage, ...).
247
248// \return A RowSelection object that can be used to iterate over the rows that match the query.
249// */
250// virtual pRowSelection where(pChar query) {
251// return nullptr;
252// }
253
254// /** \brief Get a ColSelection from a query.
255
256// \param query By default, a list of comma separated column names. Spaces that use descendants of ColSelection may define a
257// different interface.
258// \return A ColSelection object that can be used to iterate over the selected columns. If the query is invalid, the object
259// will be invalid and return no columns. This is intentional since nullptr in a get_row() call means "all columns".
260// An invalid query produces a selection of "no columns".
261// */
262// virtual pColSelection select(pChar query) {
263// return new ColSelection(query, this);
264// }
265
266// /** \brief Get the appropriate Caster from the AS clause of a query.
267
268// \param query The name of the Caster to get.
269
270// \return A pointer to the Caster or nullptr if the Caster is not found.
271// */
272// virtual pCaster as(pChar query) {
273// stdName name(query);
274// Casters::iterator it = casters.find(name);
275// if (it == casters.end())
276// return nullptr;
277
278// return it->second;
279// }
280
281// /** \brief Register a Caster descendant to make it available in queries.
282
283// \param cast The Caster to register.
284
285// \return True if the Caster was successfully registered, false if a Caster with the same name is already registered.
286// */
287// virtual bool register_caster(pCaster cast) {
288// Casters::iterator it = casters.find(cast->name);
289// if (it != casters.end())
290// return false;
291
292// casters[cast->name] = cast;
293// return true;
294// }
295
296// /** \brief Get a row from the Space as a Tuple
297
298// \param p_txn A transaction that will be used to get the result. It must be destroyed with:
299// p_txn->p_owner->destroy_transaction(p_txn)
300// \param row The row number as obtained from a RowSelection.next() call.
301// \param cols Pointer to a ColSelection to specify columns to be retrieved. If nullptr, all columns are retrieved.
302// \param cast Pointer to a Caster to convert the result. If nullptr, no conversion is done.
303
304// \return SERVICE_NO_ERROR if successful, an error code otherwise.
305// */
306// virtual StatusCode get_row(pTransaction &p_txn, RowNumber row, pColSelection cols = nullptr, pCaster cast = nullptr) {
307// return SERVICE_NOT_IMPLEMENTED;
308// }
309
310// #ifndef CATCH_TEST
311// protected:
312// #endif
313
314// char storage_base [SHORT_NAME_SIZE]; ///< The base name of the storage container.
315// Name name; ///< The name of the Space.
316// pBaseAPI p_api; ///< A pointer to the BaseAPI that provides access to containers.
317// Casters casters; ///< A map of all the available Casters.
318// };
319
320
321// TODO: Take whatever is still valid from this old version.
322// /** \brief DataSpaces: The data space.
323
324// */
325// class DataSpaces : public Space {
326
327// public:
328
329// DataSpaces(pBaseAPI api);
330
331// virtual StatusCode start();
332// virtual pChar const id();
333
334// // Space interface
335
336// //TODO: This is similar but not quite identical, since it has a FROM predicate
337
338// // virtual StatusCode load_meta();
339// // virtual StatusCode save_meta();
340// // virtual RowNumber num_rows();
341// // virtual void* get_index_data(RowNumber row);
342// // virtual int num_cols();
343// // virtual pName col_name(int col);
344// // virtual int col_index(pName name);
345// // virtual pLocator locator(RowNumber row, int col, int &index);
346// // virtual pRowSelection where(pChar query);
347// // virtual StatusCode get_row(pTransaction &p_txn, RowNumber row, pColSelection cols = nullptr, pCaster cast = nullptr);
348
349// // DataSpaces-ETL interface
350
351// //TODO: Define the DataSpaces-ETL interface. This is understood by the Bop compiler and is used by ETL maintenance software that writes
352// // special Bop scripts to populate/update/destroy the DataSpaces.
353
354// private:
355
356// pBaseAPI p_api; ///< A pointer to the BaseAPI that provides access to containers.
357// Name storage_ent; ///< The name of the storage entity (Typically an lmdb database with the metadata of all DataSpaces).
358// };
359// typedef DataSpaces *pDataSpace; ///< A pointer to a DataSpaces
360
361} // namespace jazz_models
362
363#endif // ifndef INCLUDED_JAZZ_MODELS_DATA_SPACE
Concepts: A tree of Snippets with support fro blending that populates a semantic space.
Definition concept.cpp:39