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/locators.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
230//TODO: Clarify why space is a Service. Spoiler: It is not!
231//TODO: Clarify how spaces build a tree.
232//TODO: Clarify why we need singular/plural like collections of, because we want to have just one service for all the spaces at a level.
233//TODO: Think that in Bop, a space is something that accepts then [] and the '.' the latter being just a property of what is on its left:
234 // (E.g.: this.is.just.a.hierarchy.defining.some.path.on.a.tree)
235//TODO: Is row the appropriate abstraction? Is a space somehow always tabular? A row is a key
236
256class Space : public Service {
257
258 public:
259
260 // Service interface
261
262 Space(pBaseAPI api, pName a_name);
263
264 virtual StatusCode start ();
265 virtual StatusCode shut_down();
266
267 // Persistence interface
268
276 return SERVICE_NOT_IMPLEMENTED;
277 }
278
286 return SERVICE_NOT_IMPLEMENTED;
287 }
288
289 // Internal interface for ColSelection to have access to data by rows.
290
295 virtual RowNumber num_rows() {
296 return SPACE_NOT_A_ROW;
297 }
298
306 virtual void* get_index_data(RowNumber row) {
307 return nullptr;
308 }
309
310 // Space interface
311
316 virtual int num_cols() {
317 return 0;
318 }
319
326 virtual pName col_name(int col) {
327 return nullptr;
328 }
329
336 virtual int col_index(pName name) {
337 return -1;
338 }
339
348 virtual pLocator locator(RowNumber row, int col, int &index) {
349 return nullptr;
350 }
351
359 virtual pRowSelection where(pChar query) {
360 return nullptr;
361 }
362
371 virtual pColSelection select(pChar query) {
372 return new ColSelection(query, this);
373 }
374
381 virtual pCaster as(pChar query) {
382 stdName name(query);
383 Casters::iterator it = casters.find(name);
384 if (it == casters.end())
385 return nullptr;
386
387 return it->second;
388 }
389
396 virtual bool register_caster(pCaster cast) {
397 Casters::iterator it = casters.find(cast->name);
398 if (it != casters.end())
399 return false;
400
401 casters[cast->name] = cast;
402 return true;
403 }
404
415 virtual StatusCode get_row(pTransaction &p_txn, RowNumber row, pColSelection cols = nullptr, pCaster cast = nullptr) {
416 return SERVICE_NOT_IMPLEMENTED;
417 }
418
419#ifndef CATCH_TEST
420 protected:
421#endif
422
423 char storage_base [SHORT_NAME_SIZE];
427};
428
429} // namespace jazz_bebop
430
431#endif // ifndef INCLUDED_JAZZ_BEBOP_SPACE
BaseAPI: The parent of API and Core.
Definition base_api.h:122
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:256
pBaseAPI p_api
A pointer to the BaseAPI that provides access to containers.
Definition space.h:425
virtual StatusCode load_meta()
Load the metadata of the Space.
Definition space.h:275
virtual pName col_name(int col)
Get the name of a column.
Definition space.h:326
virtual pRowSelection where(pChar query)
Get a RowSelection from a query.
Definition space.h:359
Casters casters
A map of all the available Casters.
Definition space.h:426
char storage_base[SHORT_NAME_SIZE]
The base name of the storage container.
Definition space.h:423
virtual StatusCode shut_down()
Definition space.cpp:195
virtual pColSelection select(pChar query)
Get a ColSelection from a query.
Definition space.h:371
virtual RowNumber num_rows()
Return the number of rows in the Space.
Definition space.h:295
Name name
The name of the Space.
Definition space.h:424
virtual bool register_caster(pCaster cast)
Register a Caster descendant to make it available in queries.
Definition space.h:396
virtual pCaster as(pChar query)
Get the appropriate Caster from the AS clause of a query.
Definition space.h:381
virtual int num_cols()
Get the number of columns in the Space.
Definition space.h:316
virtual int col_index(pName name)
Get the index of a column.
Definition space.h:336
virtual pLocator locator(RowNumber row, int col, int &index)
Get the location of a cell as a Locator.
Definition space.h:348
virtual void * get_index_data(RowNumber row)
Get a pointer to the data of the index of a given row.
Definition space.h:306
virtual StatusCode start()
Definition space.cpp:169
virtual StatusCode save_meta()
Save the metadata of the Space.
Definition space.h:285
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:415
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:186
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:184
Name * pName
A pointer to a Name.
Definition types.h:185
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