Description
This code contains definitions for iinq functions.
- Copyright
- Copyright 2017 The University of British Columbia, IonDB Project Contributors (see AUTHORS.md)
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- 1.Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- 2.Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- 3.Neither the name of the copyright holder nor the names of its contributors
- may be used to endorse or promote products derived from this software without specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Definition in file iinq.h.
Include dependency graph for iinq.h:
This graph shows which files directly or indirectly include this file:
Classes | |
struct | ion_iinq_result_t |
struct | ion_iinq_query_processor_t |
struct | iinq_cleanup |
struct | iinq_source |
Macros | |
#define | IINQ_NEW_PROCESSOR_FUNC(name) void name(ion_iinq_result_t *result, void* state) |
#define | IINQ_QUERY_PROCESSOR(execute, state) ((ion_iinq_query_processor_t){ execute, state }) |
#define | CREATE_DICTIONARY(schema_name, key_type, key_size, value_size) iinq_create_source(#schema_name ".inq", key_type, key_size, value_size) |
#define | INSERT(schema_name, key, value) iinq_insert(#schema_name ".inq", key, value) |
#define | UPDATE(schema_name, key, value) iinq_insert(#schema_name ".inq", key, value) |
#define | DELETE_FROM(schema_name, key) iinq_delete(#schema_name ".inq", key) |
#define | DROP(schema_name) iinq_drop(#schema_name ".inq") |
#define | SELECT_ALL |
#define | _FROM_SOURCE_SINGLE(source) |
#define | _FROM_CHECK_CURSOR_SINGLE(source) (cs_cursor_active == (source.cursor_status = source.cursor->next(source.cursor, &source.ion_record)) || cs_cursor_initialized == source.cursor_status) |
#define | _FROM_ADVANCE_CURSORS |
#define | _FROM_SOURCE_1(_1) _FROM_SOURCE_SINGLE(_1) |
#define | _FROM_SOURCE_2(_1, _2) _FROM_SOURCE_1(_1) _FROM_SOURCE_1(_2) |
#define | _FROM_SOURCE_3(_1, _2, _3) _FROM_SOURCE_2(_1, _2) _FROM_SOURCE_1(_3) |
#define | _FROM_SOURCE_4(_1, _2, _3, _4) _FROM_SOURCE_3(_1, _2, _3) _FROM_SOURCE_1(_4) |
#define | _FROM_SOURCE_5(_1, _2, _3, _4, _5) _FROM_SOURCE_4(_1, _2, _3, _4) _FROM_SOURCE_1(_5) |
#define | _FROM_SOURCE_6(_1, _2, _3, _4, _5, _6) _FROM_SOURCE_5(_1, _2, _3, _4, _5) _FROM_SOURCE_1(_6) |
#define | _FROM_SOURCE_7(_1, _2, _3, _4, _5, _6, _7) _FROM_SOURCE_6(_1, _2, _3, _4, _5, _6) _FROM_SOURCE_1(_7) |
#define | _FROM_SOURCE_8(_1, _2, _3, _4, _5, _6, _7, _8) _FROM_SOURCE_7(_1, _2, _3, _4, _5, _6, _7) _FROM_SOURCE_1(_8) |
#define | _FROM_SOURCE_GET_OVERRIDE(_1, _2, _3, _4, _5, _6, _7, _8, MACRO, ...) MACRO |
#define | _FROM_SOURCES(...) _FROM_SOURCE_GET_OVERRIDE(__VA_ARGS__, _FROM_SOURCE_8, _FROM_SOURCE_7, _FROM_SOURCE_6, _FROM_SOURCE_5, _FROM_SOURCE_4, _FROM_SOURCE_3, _FROM_SOURCE_2, _FROM_SOURCE_1, THEBLACKWHOLE)(__VA_ARGS__) |
#define | _FROM_CHECK_CURSOR(sources) _FROM_CHECK_CURSOR_SINGLE(sources) |
#define | FROM(...) |
#define | WHERE(condition) (condition) |
#define | QUERY(select, from, where, groupby, having, orderby, limit, when, p) |
Typedefs | |
typedef unsigned int | ion_iinq_result_size_t |
typedef void(* | ion_iinq_query_processor_func_t) (ion_iinq_result_t *, void *) |
Function pointer type for processing not data modifying IINQ queries. More... | |
typedef struct iinq_source | ion_iinq_source_t |
typedef struct iinq_cleanup | ion_iinq_cleanup_t |
Functions | |
ion_err_t | iinq_create_source (char *schema_file_name, ion_key_type_t key_type, ion_key_size_t key_size, ion_value_size_t value_size) |
ion_err_t | iinq_open_source (char *schema_file_name, ion_dictionary_t *dictionary, ion_dictionary_handler_t *handler) |
ion_status_t | iinq_insert (char *schema_file_name, ion_key_t key, ion_value_t value) |
ion_status_t | iinq_update (char *schema_file_name, ion_key_t key, ion_value_t value) |
ion_status_t | iinq_delete (char *schema_file_name, ion_key_t key) |
ion_err_t | iinq_drop (char *schema_file_name) |
Macro Definition Documentation
#define _FROM_ADVANCE_CURSORS |
Value:
if (NULL == ref_cursor) { \
break; \
} \
last_cursor = ref_cursor; \
/* Keep going backwards through sources until we find one we can advance. If we re-initialize any cursors, reset ref_cursor to last. */ \
while (NULL != ref_cursor && (cs_cursor_active != (ref_cursor->reference->cursor_status = ref_cursor->reference->cursor->next(ref_cursor->reference->cursor, &ref_cursor->reference->ion_record)) && cs_cursor_initialized != ref_cursor->reference->cursor_status)) { \
ref_cursor->reference->cursor->destroy(&ref_cursor->reference->cursor); \
dictionary_find(&ref_cursor->reference->dictionary, &ref_cursor->reference->predicate, &ref_cursor->reference->cursor); \
if ((cs_cursor_active != (ref_cursor->reference->cursor_status = ref_cursor->reference->cursor->next(ref_cursor->reference->cursor, &ref_cursor->reference->ion_record)) && cs_cursor_initialized != ref_cursor->reference->cursor_status)) { \
goto IINQ_QUERY_CLEANUP; \
} \
ref_cursor = ref_cursor->last; \
} \
if (NULL == ref_cursor) { \
break; \
} \
else if (last_cursor != ref_cursor) { \
ref_cursor = last; \
}
ion_err_t dictionary_find(ion_dictionary_t *dictionary, ion_predicate_t *predicate, ion_dict_cursor_t **cursor)
Uses the given predicate and cursor to search the dictionary.
Definition: dictionary.c:562
Definition: dictionary_types.h:143
Definition: dictionary_types.h:133
#define _FROM_CHECK_CURSOR | ( | sources | ) | _FROM_CHECK_CURSOR_SINGLE(sources) |
#define _FROM_CHECK_CURSOR_SINGLE | ( | source | ) | (cs_cursor_active == (source.cursor_status = source.cursor->next(source.cursor, &source.ion_record)) || cs_cursor_initialized == source.cursor_status) |
#define _FROM_SOURCE_1 | ( | _1 | ) | _FROM_SOURCE_SINGLE(_1) |
#define _FROM_SOURCE_2 | ( | _1, | |
_2 | |||
) | _FROM_SOURCE_1(_1) _FROM_SOURCE_1(_2) |
#define _FROM_SOURCE_3 | ( | _1, | |
_2, | |||
_3 | |||
) | _FROM_SOURCE_2(_1, _2) _FROM_SOURCE_1(_3) |
#define _FROM_SOURCE_4 | ( | _1, | |
_2, | |||
_3, | |||
_4 | |||
) | _FROM_SOURCE_3(_1, _2, _3) _FROM_SOURCE_1(_4) |
#define _FROM_SOURCE_5 | ( | _1, | |
_2, | |||
_3, | |||
_4, | |||
_5 | |||
) | _FROM_SOURCE_4(_1, _2, _3, _4) _FROM_SOURCE_1(_5) |
#define _FROM_SOURCE_6 | ( | _1, | |
_2, | |||
_3, | |||
_4, | |||
_5, | |||
_6 | |||
) | _FROM_SOURCE_5(_1, _2, _3, _4, _5) _FROM_SOURCE_1(_6) |
#define _FROM_SOURCE_7 | ( | _1, | |
_2, | |||
_3, | |||
_4, | |||
_5, | |||
_6, | |||
_7 | |||
) | _FROM_SOURCE_6(_1, _2, _3, _4, _5, _6) _FROM_SOURCE_1(_7) |
#define _FROM_SOURCE_8 | ( | _1, | |
_2, | |||
_3, | |||
_4, | |||
_5, | |||
_6, | |||
_7, | |||
_8 | |||
) | _FROM_SOURCE_7(_1, _2, _3, _4, _5, _6, _7) _FROM_SOURCE_1(_8) |
#define _FROM_SOURCE_GET_OVERRIDE | ( | _1, | |
_2, | |||
_3, | |||
_4, | |||
_5, | |||
_6, | |||
_7, | |||
_8, | |||
MACRO, | |||
... | |||
) | MACRO |
#define _FROM_SOURCE_SINGLE | ( | source | ) |
Value:
ion_iinq_source_t source; \
source.cleanup.last = last; \
source.cleanup.reference = &source; \
if (NULL == first) { \
first = &source.cleanup; \
} \
if (NULL != last) { \
} \
last = &source.cleanup; \
source.cleanup.next = NULL; \
break; \
} \
source.ion_record.key = source.key; \
source.ion_record.value = source.value; \
break; \
} \
Definition: kv_system.h:160
ion_err_t iinq_open_source(char *schema_file_name, ion_dictionary_t *dictionary, ion_dictionary_handler_t *handler)
Definition: iinq.c:106
Definition: iinq.h:80
Definition: dictionary_types.h:307
ion_err_t dictionary_find(ion_dictionary_t *dictionary, ion_predicate_t *predicate, ion_dict_cursor_t **cursor)
Uses the given predicate and cursor to search the dictionary.
Definition: dictionary.c:562
ion_err_t dictionary_build_predicate(ion_predicate_t *predicate, ion_predicate_type_t type,...)
Builds a predicate based on the type given.
Definition: dictionary.c:512
#define _FROM_SOURCES | ( | ... | ) | _FROM_SOURCE_GET_OVERRIDE(__VA_ARGS__, _FROM_SOURCE_8, _FROM_SOURCE_7, _FROM_SOURCE_6, _FROM_SOURCE_5, _FROM_SOURCE_4, _FROM_SOURCE_3, _FROM_SOURCE_2, _FROM_SOURCE_1, THEBLACKWHOLE)(__VA_ARGS__) |
#define CREATE_DICTIONARY | ( | schema_name, | |
key_type, | |||
key_size, | |||
value_size | |||
) | iinq_create_source(#schema_name ".inq", key_type, key_size, value_size) |
#define DELETE_FROM | ( | schema_name, | |
key | |||
) | iinq_delete(#schema_name ".inq", key) |
#define FROM | ( | ... | ) |
Value:
ion_iinq_cleanup_t *first; \
ion_iinq_cleanup_t *last; \
ion_iinq_cleanup_t *ref_cursor; \
ion_iinq_cleanup_t *last_cursor; \
first = NULL; \
last = NULL; \
ref_cursor = NULL; \
last_cursor = NULL; \
_FROM_SOURCES(__VA_ARGS__) \
result.data = alloca(result.num_bytes); \
ref_cursor = first; \
/* Initialize all cursors except the last one. */ \
while (ref_cursor != last) { \
if (NULL == ref_cursor || (cs_cursor_active != (ref_cursor->reference->cursor_status = ref_cursor->reference->cursor->next(ref_cursor->reference->cursor, &ref_cursor->reference->ion_record)) && cs_cursor_initialized != ref_cursor->reference->cursor_status)) { \
break; \
} \
ref_cursor = ref_cursor->next; \
} \
ref_cursor = last; \
while (1) { \
struct iinq_cleanup ion_iinq_cleanup_t
Definition: iinq.h:74
Definition: dictionary_types.h:143
Definition: dictionary_types.h:133
#define IINQ_NEW_PROCESSOR_FUNC | ( | name | ) | void name(ion_iinq_result_t *result, void* state) |
#define IINQ_QUERY_PROCESSOR | ( | execute, | |
state | |||
) | ((ion_iinq_query_processor_t){ execute, state }) |
#define INSERT | ( | schema_name, | |
key, | |||
value | |||
) | iinq_insert(#schema_name ".inq", key, value) |
#define QUERY | ( | select, | |
from, | |||
where, | |||
groupby, | |||
having, | |||
orderby, | |||
limit, | |||
when, | |||
p | |||
) |
Value:
do { \
ion_iinq_result_t result; \
result.num_bytes = 0; \
from/* This includes a loop declaration with some other stuff. */ \
if (!where) { \
continue; \
} \
select \
} \
IINQ_QUERY_CLEANUP: \
while (NULL != first) { \
first->reference->cursor->destroy(&first->reference->cursor); \
ion_close_dictionary(&first->reference->dictionary); \
first = first->next; \
}\
} while (0);
ion_err_t ion_close_dictionary(ion_dictionary_t *dictionary)
Closes a given dictionary.
Definition: ion_master_table.c:486
#define SELECT_ALL |
Value:
ion_iinq_result_size_t result_loc = 0; \
ion_iinq_cleanup_t *copyer = first; \
while (NULL != copyer) { \
memcpy(result.data+(result_loc), copyer->reference->key, copyer->reference->dictionary.instance->record.key_size); \
result_loc += copyer->reference->dictionary.instance->record.key_size; \
memcpy(result.data+(result_loc), copyer->reference->value, copyer->reference->dictionary.instance->record.value_size); \
result_loc += copyer->reference->dictionary.instance->record.value_size; \
copyer = copyer->next; \
}
struct iinq_cleanup ion_iinq_cleanup_t
#define UPDATE | ( | schema_name, | |
key, | |||
value | |||
) | iinq_insert(#schema_name ".inq", key, value) |
Typedef Documentation
typedef struct iinq_cleanup ion_iinq_cleanup_t |
typedef void(* ion_iinq_query_processor_func_t) (ion_iinq_result_t *, void *) |
typedef unsigned int ion_iinq_result_size_t |
typedef struct iinq_source ion_iinq_source_t |
Function Documentation
ion_err_t iinq_create_source | ( | char * | schema_file_name, |
ion_key_type_t | key_type, | ||
ion_key_size_t | key_size, | ||
ion_value_size_t | value_size | ||
) |
Definition at line 42 of file iinq.c.
78 error = ion_master_table_create_dictionary(&handler, &dictionary, key_type, key_size, value_size, -1);
Definition: kv_system.h:160
ion_err_t ion_master_table_create_dictionary(ion_dictionary_handler_t *handler, ion_dictionary_t *dictionary, ion_key_type_t key_type, ion_key_size_t key_size, ion_value_size_t value_size, ion_dictionary_size_t dictionary_size)
Creates a dictionary through use of the master table.
Definition: ion_master_table.c:350
Definition: kv_system.h:188
Definition: kv_system.h:209
A dictionary contains information regarding an instance of the storage element and the associated han...
Definition: dictionary_types.h:273
Definition: kv_system.h:185
ion_err_t ion_close_dictionary(ion_dictionary_t *dictionary)
Closes a given dictionary.
Definition: ion_master_table.c:486
void bpptree_init(ion_dictionary_handler_t *handler)
Registers a specific handler for a dictionary instance.
Definition: bpp_tree_handler.c:711
Definition: kv_system.h:197
Definition: kv_system.h:182
A dictionary_handler is responsible for dealing with the specific interface for an underlying diction...
Definition: dictionary_types.h:207
Here is the call graph for this function:
ion_status_t iinq_delete | ( | char * | schema_file_name, |
ion_key_t | key | ||
) |
Definition at line 216 of file iinq.c.
Definition: kv_system.h:160
ion_status_t dictionary_delete(ion_dictionary_t *dictionary, ion_key_t key)
Delete a value given a key.
Definition: dictionary.c:199
A dictionary contains information regarding an instance of the storage element and the associated han...
Definition: dictionary_types.h:273
ion_err_t ion_close_dictionary(ion_dictionary_t *dictionary)
Closes a given dictionary.
Definition: ion_master_table.c:486
ion_err_t iinq_open_source(char *schema_file_name, ion_dictionary_t *dictionary, ion_dictionary_handler_t *handler)
Definition: iinq.c:106
A dictionary_handler is responsible for dealing with the specific interface for an underlying diction...
Definition: dictionary_types.h:207
A status object that describes the result of a dictionary operation.
Definition: kv_system.h:290
Here is the call graph for this function:
ion_err_t iinq_drop | ( | char * | schema_file_name | ) |
Definition at line 245 of file iinq.c.
Definition: kv_system.h:160
A dictionary contains information regarding an instance of the storage element and the associated han...
Definition: dictionary_types.h:273
ion_err_t dictionary_delete_dictionary(ion_dictionary_t *dictionary)
Destroys dictionary.
Definition: dictionary.c:178
ion_err_t iinq_open_source(char *schema_file_name, ion_dictionary_t *dictionary, ion_dictionary_handler_t *handler)
Definition: iinq.c:106
A dictionary_handler is responsible for dealing with the specific interface for an underlying diction...
Definition: dictionary_types.h:207
Here is the call graph for this function:
ion_status_t iinq_insert | ( | char * | schema_file_name, |
ion_key_t | key, | ||
ion_value_t | value | ||
) |
Definition at line 156 of file iinq.c.
Definition: kv_system.h:160
ion_status_t dictionary_insert(ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
Insert a value into a dictionary.
Definition: dictionary.c:151
A dictionary contains information regarding an instance of the storage element and the associated han...
Definition: dictionary_types.h:273
ion_err_t ion_close_dictionary(ion_dictionary_t *dictionary)
Closes a given dictionary.
Definition: ion_master_table.c:486
ion_err_t iinq_open_source(char *schema_file_name, ion_dictionary_t *dictionary, ion_dictionary_handler_t *handler)
Definition: iinq.c:106
A dictionary_handler is responsible for dealing with the specific interface for an underlying diction...
Definition: dictionary_types.h:207
A status object that describes the result of a dictionary operation.
Definition: kv_system.h:290
Here is the call graph for this function:
ion_err_t iinq_open_source | ( | char * | schema_file_name, |
ion_dictionary_t * | dictionary, | ||
ion_dictionary_handler_t * | handler | ||
) |
Definition at line 106 of file iinq.c.
Definition: kv_system.h:160
unsigned int ion_dictionary_id_t
A type used to identify dictionaries, specifically in the master table.
Definition: dictionary_types.h:51
Definition: kv_system.h:188
Definition: kv_system.h:185
void bpptree_init(ion_dictionary_handler_t *handler)
Registers a specific handler for a dictionary instance.
Definition: bpp_tree_handler.c:711
Definition: kv_system.h:197
ion_err_t ion_open_dictionary(ion_dictionary_handler_t *handler, ion_dictionary_t *dictionary, ion_dictionary_id_t id)
Finds the target dictionary and opens it.
Definition: ion_master_table.c:463
Definition: kv_system.h:182
Here is the call graph for this function:
Here is the caller graph for this function:
ion_status_t iinq_update | ( | char * | schema_file_name, |
ion_key_t | key, | ||
ion_value_t | value | ||
) |
Definition at line 186 of file iinq.c.
Definition: kv_system.h:160
ion_status_t dictionary_update(ion_dictionary_t *dictionary, ion_key_t key, ion_value_t value)
Update all records with a given key.
Definition: dictionary.c:169
A dictionary contains information regarding an instance of the storage element and the associated han...
Definition: dictionary_types.h:273
ion_err_t ion_close_dictionary(ion_dictionary_t *dictionary)
Closes a given dictionary.
Definition: ion_master_table.c:486
ion_err_t iinq_open_source(char *schema_file_name, ion_dictionary_t *dictionary, ion_dictionary_handler_t *handler)
Definition: iinq.c:106
A dictionary_handler is responsible for dealing with the specific interface for an underlying diction...
Definition: dictionary_types.h:207
A status object that describes the result of a dictionary operation.
Definition: kv_system.h:290
Here is the call graph for this function: