Jazz 1.25.+
Loading...
Searching...
No Matches
space.h
1/* Jazz (c) 2018-2025 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/jazz_bebop/base_api.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_BEBOP_SPACE
48#define INCLUDED_JAZZ_BEBOP_SPACE
49
50
51namespace jazz_bebop
52{
53
54typedef uint64_t RowNumber;
56
57#define SPACE_NOT_A_ROW 0xffffFFFFffffFFFE
58#define SPACE_ROW_STOP_ITERATOR 0xffffFFFFffffFFFF
59
60
61class Space;
62typedef Space *pSpace;
63
64
67class stdName {
68
69 public:
70 stdName() {}
71
76 stdName(const pChar &name) {
77 strncpy(this->name, name, NAME_SIZE);
78 this->name[NAME_LENGTH] = 0;
79 }
80
86 memcpy(&this->name, &name, sizeof(stdName));
87 }
88
95 bool operator==(const stdName &o) const {
96 return strcmp(name, o.name) == 0;
97 }
98
105 bool operator<(const stdName &o) const {
106 return strcmp(name, o.name) < 0;
107 }
108
110};
111
112typedef std::vector<stdName> stdNames;
113
114
124
132 RowSelection(pChar query, pSpace p_space) {}
133
138 virtual bool restart() {
139 return false;
140 }
141
146 virtual RowNumber next() {
147 return SPACE_ROW_STOP_ITERATOR;
148 }
149
150 bool is_valid = false;
151};
153
154
163
164 public:
165
175 ColSelection(pChar query, pSpace p_space);
176
177 virtual bool restart();
178
179 virtual int next_index();
180 virtual pName next_name();
181
182 bool is_valid = false;
183
184#ifndef CATCH_TEST
185 private:
186#endif
187
188 int current_col = 0;
190 std::vector<int> index = {};
191};
193
194
203class Caster {
204 public:
205
211
219 virtual StatusCode get(pTransaction &p_txn, pBlock p_block) {
220 return SERVICE_NOT_IMPLEMENTED;
221 }
222
224};
225typedef Caster *pCaster;
226typedef std::map<stdName, pCaster> Casters;
228
229
248class Space : public Service {
249
250 public:
251
252 // Service interface
253
254 Space(pBaseAPI api, pName a_name);
255
256 virtual StatusCode start ();
257 virtual StatusCode shut_down();
258
259 // Persistence interface
260
268 return SERVICE_NOT_IMPLEMENTED;
269 }
270
278 return SERVICE_NOT_IMPLEMENTED;
279 }
280
281 // Internal interface for ColSelection to have access to data by rows.
282
287 virtual RowNumber num_rows() {
288 return SPACE_NOT_A_ROW;
289 }
290
298 virtual void* get_index_data(RowNumber row) {
299 return nullptr;
300 }
301
302 // Space interface
303
308 virtual int num_cols() {
309 return 0;
310 }
311
318 virtual pName col_name(int col) {
319 return nullptr;
320 }
321
328 virtual int col_index(pName name) {
329 return -1;
330 }
331
340 virtual pLocator locator(RowNumber row, int col, int &index) {
341 return nullptr;
342 }
343
351 virtual pRowSelection where(pChar query) {
352 return nullptr;
353 }
354
363 virtual pColSelection select(pChar query) {
364 return new ColSelection(query, this);
365 }
366
373 virtual pCaster as(pChar query) {
374 stdName name(query);
375 Casters::iterator it = casters.find(name);
376 if (it == casters.end())
377 return nullptr;
378
379 return it->second;
380 }
381
388 virtual bool register_caster(pCaster cast) {
389 Casters::iterator it = casters.find(cast->name);
390 if (it != casters.end())
391 return false;
392
393 casters[cast->name] = cast;
394 return true;
395 }
396
407 virtual StatusCode get_row(pTransaction &p_txn, RowNumber row, pColSelection cols = nullptr, pCaster cast = nullptr) {
408 return SERVICE_NOT_IMPLEMENTED;
409 }
410
411#ifndef CATCH_TEST
412 protected:
413#endif
414
415 char storage_base [SHORT_NAME_SIZE];
419};
420
421} // namespace jazz_bebop
422
423#endif // ifndef INCLUDED_JAZZ_BEBOP_SPACE
BaseAPI: The parent of API and Core.
Definition base_api.h:121
Caster: An optional converter of the output.
Definition space.h:203
virtual StatusCode get(pTransaction &p_txn, pBlock p_block)
Convert a block doing whatever the caster does.
Definition space.h:219
Caster(pBaseAPI api)
The constructor for a Caster.
Definition space.h:210
stdName name
The name of the Caster.
Definition space.h:223
ColSelection: A selection of columns from a Space.
Definition space.h:162
virtual pName next_name()
ColSelection: Get the next column name.
Definition space.cpp:140
virtual bool restart()
ColSelection: Restart the iterator.
Definition space.cpp:113
stdNames name
The list of column names in the selection.
Definition space.h:189
virtual int next_index()
ColSelection: Get the next column index.
Definition space.cpp:127
std::vector< int > index
The list of column indices in the selection.
Definition space.h:190
int current_col
The index of the current column (the next to be retrieved).
Definition space.h:188
bool is_valid
True if the iterator was created by a successful query.
Definition space.h:182
RowSelection: An iterator over the rows of a Space.
Definition space.h:123
virtual RowNumber next()
Get the next row.
Definition space.h:146
RowSelection(pChar query, pSpace p_space)
The constructor for a RowSelection.
Definition space.h:132
virtual bool restart()
Restart the iterator.
Definition space.h:138
bool is_valid
True if the iterator was created by a successful query.
Definition space.h:150
Space: The abstract space.
Definition space.h:248
pBaseAPI p_api
A pointer to the BaseAPI that provides access to containers.
Definition space.h:417
virtual StatusCode load_meta()
Load the metadata of the Space.
Definition space.h:267
virtual pName col_name(int col)
Get the name of a column.
Definition space.h:318
virtual pRowSelection where(pChar query)
Get a RowSelection from a query.
Definition space.h:351
Casters casters
A map of all the available Casters.
Definition space.h:418
char storage_base[SHORT_NAME_SIZE]
The base name of the storage container.
Definition space.h:415
virtual StatusCode shut_down()
Definition space.cpp:195
virtual pColSelection select(pChar query)
Get a ColSelection from a query.
Definition space.h:363
virtual RowNumber num_rows()
Return the number of rows in the Space.
Definition space.h:287
Name name
The name of the Space.
Definition space.h:416
virtual bool register_caster(pCaster cast)
Register a Caster descendant to make it available in queries.
Definition space.h:388
virtual pCaster as(pChar query)
Get the appropriate Caster from the AS clause of a query.
Definition space.h:373
virtual int num_cols()
Get the number of columns in the Space.
Definition space.h:308
virtual int col_index(pName name)
Get the index of a column.
Definition space.h:328
virtual pLocator locator(RowNumber row, int col, int &index)
Get the location of a cell as a Locator.
Definition space.h:340
virtual void * get_index_data(RowNumber row)
Get a pointer to the data of the index of a given row.
Definition space.h:298
virtual StatusCode start()
Definition space.cpp:169
virtual StatusCode save_meta()
Save the metadata of the Space.
Definition space.h:277
virtual StatusCode get_row(pTransaction &p_txn, RowNumber row, pColSelection cols=nullptr, pCaster cast=nullptr)
Get a row from the Space as a Tuple.
Definition space.h:407
A wrapped Name that supports being stacked in an std::vector and used as a key in an std::map.
Definition space.h:67
bool operator==(const stdName &o) const
Operator name == o.name.
Definition space.h:95
Name name
The name.
Definition space.h:109
bool operator<(const stdName &o) const
Operator name < o.name.
Definition space.h:105
stdName(const stdName &name)
Copy constructor for stdName.
Definition space.h:85
stdName(const pChar &name)
Constructor from cChar.
Definition space.h:76
A Jazz Service is a globally instanced configurable object that may allocate RAM.
Definition utils.h:285
A language to access any container by base using locators.
Definition base_api.cpp:39
Casters * pCasters
A pointer to a Casters.
Definition space.h:227
std::map< stdName, pCaster > Casters
A map of Caster pointers.
Definition space.h:226
std::vector< stdName > stdNames
A vector of stdName.
Definition space.h:112
Caster * pCaster
A pointer to a Caster.
Definition space.h:225
RowSelection * pRowSelection
A pointer to a RowSelection.
Definition space.h:152
Space * pSpace
Forward definition of Space.
Definition space.h:62
ColSelection * pColSelection
A pointer to a ColSelection.
Definition space.h:192
uint64_t RowNumber
A row number in a Space.
Definition space.h:54
Name ColumnName
A column name in a Space.
Definition space.h:55
char * pChar
A pointer to a char buffer.
Definition types.h:185
class Block * pBlock
A (forward defined) pointer to a Block.
Definition block.h:66
char Name[NAME_SIZE]
A short identifier used in Blocks, Containers and API.
Definition types.h:183
Name * pName
A pointer to a Name.
Definition types.h:184
int StatusCode
Type returned by the Service API.
Definition utils.h:141
Locator: A minimal structure to define the location of resources inside a Container.
Definition container.h:184
Transaction: A wrapper over a Block that defines the communication of a block with a Container.
Definition container.h:162