-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Labels
3.5c api[Area] Related to the Tarantool C API reference[Area] Related to the Tarantool C API reference
Description
Product: Tarantool EE
Since: 3.5
Now one can combine several ArrowStream filters with logical AND and OR
combinators:
/* Create arrow stream options. */
box_arrow_options_t *options = box_arrow_options_new();
/* [2] >= 42 */
box_filter_t filter1;
filter1->type = FILTER_TYPE_GE;
filter1->field_no = 1; /* 0-indexation. */
char buf1[16];
mp_encode_uint(buf1, 42);
filter1->value = buf1;
/* [3] == 1 */
box_filter_t filter2;
filter2->type = FILTER_TYPE_EQ;
filter2->field_no = 2; /* 0-indexation. */
char buf2[16];
mp_encode_uint(buf2, 1);
filter2->value = buf2;
/* [1] < 20 */
box_filter_t filter3;
filter3->type = FILTER_TYPE_LT;
filter3->field_no = 1; /* 0-indexation. */
char buf3[16];
mp_encode_uint(buf3, 20);
filter3->value = buf3;
/* [2] >= 42 AND [3] == 1 */
box_filter_t filter_and;
filter_and->type = FILTER_TYPE_AND;
box_filter_t *chidlren_and[] = {&filter1, &filter2};
filter_and->children = children_and;
filter_and->chidlren_count = 2;
/* ([2] >= 42 AND [3] == 1) OR [1] < 20 */
box_filter_t filter_or;
filter_or->type = FILTER_TYPE_OR;
box_filter_t *chidlren_or[] = {&filter_and, &filter3};
filter_and->children = children_or;
filter_and->chidlren_count = 2;
box_arrow_options_set_filter(options, &filter_or);
/* Create stream. */
struct ArrowArrayStream stream;
int rc = box_index_arrow_stream(space_id, index_id, field_count, fields,
key, key + key_size, options, &stream);Note that the expressions are not optimized at all - each expression is
checked from the first to the last child until we understand that the
filter is satisfied, so it makes sense to place the most rare conditions
first for AND combinators and to place them last for OR combinators.
Requested by @drewdzzz in https://github.com/tarantool/tarantool-ee/commit/297f88dfb4a257ee50d9e8ba1b5ec7629a662264.
Metadata
Metadata
Assignees
Labels
3.5c api[Area] Related to the Tarantool C API reference[Area] Related to the Tarantool C API reference