Loading...
Searching...
No Matches
as_query.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2024 Aerospike, Inc.
3 *
4 * Portions may be licensed to Aerospike, Inc. under one or more contributor
5 * license agreements.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8 * use this file except in compliance with the License. You may obtain a copy of
9 * the License at http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17#pragma once
18
20#include <aerospike/as_bin.h>
21#include <aerospike/as_key.h>
22#include <aerospike/as_list.h>
24#include <aerospike/as_udf.h>
25
26#include <stdarg.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32//---------------------------------
33// Macros
34//---------------------------------
35
36/**
37 * Filter on string bins.
38 *
39 * ~~~~~~~~~~{.c}
40 * as_query_where(query, "bin1", as_string_equals("abc"));
41 * ~~~~~~~~~~
42 *
43 * @relates as_query
44 * @ingroup query_operations
45 */
46#define as_string_equals(__val) AS_PREDICATE_EQUAL, AS_INDEX_TYPE_DEFAULT, AS_INDEX_STRING, __val
47
48/**
49 * Filter on blob bins.
50 * Requires server version 7.0+.
51 *
52 * ~~~~~~~~~~{.c}
53 * // as_blob_equals(uint8_t* bytes, uint32_t size, bool free)
54 * as_query_where(query, "bin1", as_blob_equals(bytes, size, true));
55 * ~~~~~~~~~~
56 *
57 * @relates as_query
58 * @ingroup query_operations
59 */
60#define as_blob_equals(__val, __size, __free) AS_PREDICATE_EQUAL, AS_INDEX_TYPE_DEFAULT, AS_INDEX_BLOB, __val, __size, __free
61
62/**
63 * Filter on integer bins.
64 *
65 * ~~~~~~~~~~{.c}
66 * as_query_where(query, "bin1", as_integer_equals(123));
67 * ~~~~~~~~~~
68 *
69 * @relates as_query
70 * @ingroup query_operations
71 */
72#define as_integer_equals(__val) AS_PREDICATE_EQUAL, AS_INDEX_TYPE_DEFAULT, AS_INDEX_NUMERIC, (int64_t)__val
73
74/**
75 * Ranger filter on integer bins.
76 *
77 * ~~~~~~~~~~{.c}
78 * as_query_where(query, "bin1", as_integer_range(1,100));
79 * ~~~~~~~~~~
80 *
81 * @relates as_query
82 * @ingroup query_operations
83 */
84#define as_integer_range(__min, __max) AS_PREDICATE_RANGE, AS_INDEX_TYPE_DEFAULT, AS_INDEX_NUMERIC, (int64_t)__min, (int64_t)__max
85
86/**
87 * Range filter on list/map elements.
88 *
89 * ~~~~~~~~~~{.c}
90 * as_query_where(query, "bin1", as_range(LIST,NUMERIC,1,100));
91 * ~~~~~~~~~~
92 *
93 * @relates as_query
94 * @ingroup query_operations
95 */
96#define as_range(indextype, datatype, __min, __max) AS_PREDICATE_RANGE, AS_INDEX_TYPE_ ##indextype, AS_INDEX_ ##datatype, __min, __max
97
98/**
99 * Contains filter on list/map elements.
100 *
101 * ~~~~~~~~~~{.c}
102 * as_query_where(query, "bin1", as_contains(LIST,STRING,"val"));
103 * ~~~~~~~~~~
104 *
105 * @relates as_query
106 * @ingroup query_operations
107 */
108#define as_contains(indextype, datatype, __val) AS_PREDICATE_EQUAL, AS_INDEX_TYPE_ ##indextype, AS_INDEX_ ##datatype, __val
109
110/**
111 * Contains blob filter on list/map elements.
112 * Requires server version 7.0+.
113 *
114 * ~~~~~~~~~~{.c}
115 * // as_blob_contains(type, uint8_t* bytes, uint32_t size, bool free)
116 * as_query_where(query, "bin1", as_blob_equals(LIST, bytes, size, true));
117 * ~~~~~~~~~~
118 *
119 * @relates as_query
120 * @ingroup query_operations
121 */
122#define as_blob_contains(indextype, __val, __size, __free) AS_PREDICATE_EQUAL, AS_INDEX_TYPE_ ##indextype, AS_INDEX_BLOB, __val, __size, __free
123
124/**
125 * Filter specified type on bins.
126 *
127 * ~~~~~~~~~~{.c}
128 * as_query_where(query, "bin1", as_equals(NUMERIC,5));
129 * ~~~~~~~~~~
130 *
131 * @relates as_query
132 * @ingroup query_operations
133 */
134#define as_equals(datatype, __val) AS_PREDICATE_EQUAL, AS_INDEX_TYPE_DEFAULT, AS_INDEX_ ##datatype, __val
135
136/**
137 * Within filter on GEO bins.
138 *
139 * ~~~~~~~~~~{.c}
140 * as_query_where(query, "bin1", as_geo_within(region));
141 * ~~~~~~~~~~
142 *
143 * @relates as_query
144 * @ingroup query_operations
145 */
146#define as_geo_within(__val) AS_PREDICATE_RANGE, AS_INDEX_TYPE_DEFAULT, AS_INDEX_GEO2DSPHERE, __val
147
148/**
149 * Contains filter on GEO bins.
150 *
151 * ~~~~~~~~~~{.c}
152 * as_query_where(query, "bin1", as_geo_contains(region));
153 * ~~~~~~~~~~
154 *
155 * @relates as_query
156 * @ingroup query_operations
157 */
158#define as_geo_contains(__val) AS_PREDICATE_RANGE, AS_INDEX_TYPE_DEFAULT, AS_INDEX_GEO2DSPHERE, __val
159
160//---------------------------------
161// Types
162//---------------------------------
163
164struct as_operations_s;
165
166/**
167 * Union of supported predicates
168 */
169typedef union as_predicate_value_u {
170 int64_t integer;
171
172 struct {
173 char* string;
174 bool _free;
175 } string_val;
176
177 struct {
178 uint8_t* bytes;
179 uint32_t bytes_size;
180 bool _free;
181 } blob_val;
182
183 struct {
184 int64_t min;
185 int64_t max;
186 } integer_range;
188
189/**
190 * The types of predicates supported.
191 */
192typedef enum as_predicate_type_e {
193
194 /**
195 * String Equality Predicate.
196 * Requires as_predicate_value.string to be set.
197 */
199
202
203/**
204 * Defines a predicate, including the bin, type of predicate and the value
205 * for the predicate.
206 */
207typedef struct as_predicate_s {
208
209 /**
210 * Bin to apply the predicate to
211 */
213
214 /**
215 * The CDT context to query. Use as_query_where_with_ctx() to set.
216 */
218
219 /**
220 * The size of the CDT context. Use as_query_where_with_ctx() to set.
221 */
222 uint32_t ctx_size;
223
224 /**
225 * Should ctx be destroyed on as_query_destroy(). Default: false.
226 */
228
229 /**
230 * The predicate type, dictates which values to use from the union
231 */
233
234 /**
235 * The value for the predicate.
236 */
238
239 /*
240 * The type of data user wants to query
241 */
242
244
245 /*
246 * The type of index predicate is on
247 */
250
251/**
252 * Enumerations defining the direction of an ordering.
253 */
254typedef enum as_order_e {
255
256 /**
257 * Ascending order
258 */
260
261 /**
262 * bin should be in ascending order
263 */
265
267
268
269/**
270 * Defines the direction a bin should be ordered by.
271 */
272typedef struct as_ordering_s {
273
274 /**
275 * Name of the bin to sort by
276 */
278
279 /**
280 * Direction of the sort
281 */
283
285
286/**
287 * Sequence of bins which should be selected during a query.
288 *
289 * Entries can either be initialized on the stack or on the heap.
290 *
291 * Initialization should be performed via a query object, using:
292 * - as_query_select_init()
293 * - as_query_select_inita()
294 */
295typedef struct as_query_bins_s {
296
297 /**
298 * @private
299 * If true, then as_query_destroy() will free this instance.
300 */
301 bool _free;
302
303 /**
304 * Number of entries allocated
305 */
306 uint16_t capacity;
307
308 /**
309 * Number of entries used
310 */
311 uint16_t size;
312
313 /**
314 * Sequence of entries
315 */
317
319
320/**
321 * Sequence of predicates to be applied to a query.
322 *
323 * Entries can either be initialized on the stack or on the heap.
324 *
325 * Initialization should be performed via a query object, using:
326 * - as_query_where_init()
327 * - as_query_where_inita()
328 */
329typedef struct as_query_predicates_s {
330
331 /**
332 * @private
333 * If true, then as_query_destroy() will free this instance.
334 */
335 bool _free;
336
337 /**
338 * Number of entries allocated
339 */
340 uint16_t capacity;
341
342 /**
343 * Number of entries used
344 */
345 uint16_t size;
346
347 /**
348 * Sequence of entries
349 */
351
353
354/**
355 * The as_query object is used define a query to be executed in the database.
356 *
357 * ## Initialization
358 *
359 * Before using an as_query, it must be initialized via either:
360 * - as_query_init()
361 * - as_query_new()
362 *
363 * as_query_init() should be used on a stack allocated as_query. It will
364 * initialize the as_query with the given namespace and set. On success,
365 * it will return a pointer to the initialized as_query. Otherwise, NULL
366 * is returned.
367 *
368 * ~~~~~~~~~~{.c}
369 * as_query query;
370 * as_query_init(&query, "namespace", "set");
371 * ~~~~~~~~~~
372 *
373 * as_query_new() should be used to allocate and initialize a heap allocated
374 * as_query. It will allocate the as_query, then initialized it with the
375 * given namespace and set. On success, it will return a pointer to the
376 * initialized as_query. Otherwise, NULL is returned.
377 *
378 * ~~~~~~~~~~{.c}
379 * as_query* query = as_query_new("namespace", "set");
380 * ~~~~~~~~~~
381 *
382 * ## Destruction
383 *
384 * When you are finished with the as_query, you can destroy it and associated
385 * resources:
386 *
387 * ~~~~~~~~~~{.c}
388 * as_query_destroy(query);
389 * ~~~~~~~~~~
390 *
391 * ## Usage
392 *
393 * The following explains how to use an as_query to build a query.
394 *
395 * ### Selecting Bins
396 *
397 * as_query_select() is used to specify the bins to be selected by the query.
398 *
399 * ~~~~~~~~~~{.c}
400 * as_query_select(query, "bin1");
401 * as_query_select(query, "bin2");
402 * ~~~~~~~~~~
403 *
404 * Before adding bins to select, the select structure must be initialized via
405 * either:
406 * - as_query_select_inita() - Initializes the structure on the stack.
407 * - as_query_select_init() - Initializes the structure on the heap.
408 *
409 * Both functions are given the number of bins to be selected.
410 *
411 * A complete example using as_query_select_inita()
412 *
413 * ~~~~~~~~~~{.c}
414 * as_query_select_inita(query, 2);
415 * as_query_select(query, "bin1");
416 * as_query_select(query, "bin2");
417 * ~~~~~~~~~~
418 *
419 * ### Predicates on Bins
420 *
421 * as_query_where() is used to specify predicates to be added to the the query.
422 *
423 * **Note:** Currently, a single where predicate is supported. To do more advanced filtering,
424 * you will want to use a UDF to process the result set on the server.
425 *
426 * ~~~~~~~~~~{.c}
427 * as_query_where(query, "bin1", as_string_equals("abc"));
428 * ~~~~~~~~~~
429 *
430 * The predicates that you can apply to a bin include:
431 * - as_string_equals() - Test for string equality.
432 * - as_integer_equals() - Test for integer equality.
433 * - as_integer_range() - Test for integer within a range.
434 *
435 * Before adding predicates, the where structure must be initialized. To
436 * initialize the where structure, you can choose to use one of the following:
437 * - as_query_where_inita() - Initializes the structure on the stack.
438 * - as_query_where_init() - Initializes the structure on the heap.
439 *
440 * Both functions are given the number of predicates to be added.
441 *
442 * A complete example using as_query_where_inita():
443 *
444 * ~~~~~~~~~~{.c}
445 * as_query_where_inita(query, 1);
446 * as_query_where(query, "bin1", as_string_equals("abc"));
447 * ~~~~~~~~~~
448 *
449 * ### Applying a UDF to Query Results
450 *
451 * A UDF can be applied to the results of a query.
452 *
453 * To define the UDF for the query, use as_query_apply().
454 *
455 * ~~~~~~~~~~{.c}
456 * as_query_apply(query, "udf_module", "udf_function", arglist);
457 * ~~~~~~~~~~
458 *
459 * @ingroup query_operations
460 */
461typedef struct as_query_s {
462
463 /**
464 * @private
465 * If true, then as_query_destroy() will free this instance.
466 */
467 bool _free;
468
469 /**
470 * Namespace to be queried.
471 *
472 * Should be initialized via either:
473 * - as_query_init() - To initialize a stack allocated query.
474 * - as_query_new() - To heap allocate and initialize a query.
475 */
477
478 /**
479 * Set to be queried.
480 *
481 * Should be initialized via either:
482 * - as_query_init() - To initialize a stack allocated query.
483 * - as_query_new() - To heap allocate and initialize a query.
484 */
486
487 /**
488 * Name of bins to select.
489 *
490 * Use either of the following function to initialize:
491 * - as_query_select_init() - To initialize on the heap.
492 * - as_query_select_inita() - To initialize on the stack.
493 *
494 * Use as_query_select() to populate.
495 */
497
498 /**
499 * Predicates for filtering.
500 *
501 * Use either of the following function to initialize:
502 * - as_query_where_init() - To initialize on the heap.
503 * - as_query_where_inita() - To initialize on the stack.
504 *
505 * Use as_query_where() to populate.
506 */
508
509 /**
510 * UDF to apply to results of a background query or a foreground aggregation query.
511 *
512 * Should be set via `as_query_apply()`.
513 */
515
516 /**
517 * Perform write operations on a background query.
518 * If ops is set, ops will be destroyed when as_query_destroy() is called.
519 */
520 struct as_operations_s* ops;
521
522 /**
523 * Status of all partitions.
524 */
526
527 /**
528 * Approximate number of records to return to client. This number is divided by the
529 * number of nodes involved in the query. The actual number of records returned
530 * may be less than max_records if node record counts are small and unbalanced across
531 * nodes.
532 *
533 * Default: 0 (do not limit record count)
534 */
535 uint64_t max_records;
536
537 /**
538 * Limit returned records per second (rps) rate for each server.
539 * Do not apply rps limit if records_per_second is zero.
540 *
541 * Default: 0
542 */
544
545 /**
546 * The time-to-live (expiration) of the record in seconds. Note that ttl
547 * is only used on background query writes.
548 *
549 * There are also special values that can be set in the record ttl:
550 * <ul>
551 * <li>AS_RECORD_DEFAULT_TTL: Use the server default ttl from the namespace.</li>
552 * <li>AS_RECORD_NO_EXPIRE_TTL: Do not expire the record.</li>
553 * <li>AS_RECORD_NO_CHANGE_TTL: Keep the existing record ttl when the record is updated.</li>
554 * <li>AS_RECORD_CLIENT_DEFAULT_TTL: Use the default client ttl in as_policy_write.</li>
555 * </ul>
556 */
557 uint32_t ttl;
558
559 /**
560 * Should records be read in pages in conjunction with max_records policy.
561 *
562 * Default: false
563 */
565
566 /**
567 * Set to true if query should only return keys and no bin data.
568 *
569 * Default: false.
570 */
572
573} as_query;
574
575//---------------------------------
576// Instance Functions
577//---------------------------------
578
579/**
580 * Initialize a stack allocated as_query.
581 *
582 * ~~~~~~~~~~{.c}
583 * as_query query;
584 * as_query_init(&query, "test", "demo");
585 * ~~~~~~~~~~
586 *
587 * @param query The query to initialize.
588 * @param ns The namespace to query.
589 * @param set The set to query.
590 *
591 * @return On success, the initialized query. Otherwise NULL.
592 *
593 * @relates as_query
594 * @ingroup query_operations
595 */
597as_query_init(as_query* query, const char* ns, const char* set);
598
599/**
600 * Create and initialize a new heap allocated as_query.
601 *
602 * ~~~~~~~~~~{.c}
603 * as_query* query = as_query_new("test", "demo");
604 * ~~~~~~~~~~
605 *
606 * @param ns The namespace to query.
607 * @param set The set to query.
608 *
609 * @return On success, the new query. Otherwise NULL.
610 *
611 * @relates as_query
612 * @ingroup query_operations
613 */
615as_query_new(const char* ns, const char* set);
616
617/**
618 * Destroy the query and associated resources.
619 *
620 * @relates as_query
621 * @ingroup query_operations
622 */
623AS_EXTERN void
625
626//---------------------------------
627// Select Functions
628//---------------------------------
629
630/**
631 * Initializes `as_query.select` with a capacity of `n` using `alloca`
632 *
633 * For heap allocation, use `as_query_select_init()`.
634 *
635 * ~~~~~~~~~~{.c}
636 * as_query_select_inita(&query, 2);
637 * as_query_select(&query, "bin1");
638 * as_query_select(&query, "bin2");
639 * ~~~~~~~~~~
640 *
641 * @param __query The query to initialize.
642 * @param __n The number of bins to allocate.
643 *
644 * @relates as_query
645 * @ingroup query_operations
646 */
647#define as_query_select_inita(__query, __n) \
648 do { \
649 if ((__query)->select.entries == NULL) {\
650 (__query)->select.entries = (as_bin_name*) alloca(sizeof(as_bin_name) * (__n));\
651 if ( (__query)->select.entries ) { \
652 (__query)->select.capacity = (__n);\
653 (__query)->select.size = 0;\
654 (__query)->select._free = false;\
655 }\
656 } \
657 } while(0)
658
659/**
660 * Initializes `as_query.select` with a capacity of `n` using `malloc()`.
661 *
662 * For stack allocation, use `as_query_select_inita()`.
663 *
664 * ~~~~~~~~~~{.c}
665 * as_query_select_init(&query, 2);
666 * as_query_select(&query, "bin1");
667 * as_query_select(&query, "bin2");
668 * ~~~~~~~~~~
669 *
670 * @param query The query to initialize.
671 * @param n The number of bins to allocate.
672 *
673 * @return On success, the initialized. Otherwise an error occurred.
674 *
675 * @relates as_query
676 * @ingroup query_operations
677 */
678AS_EXTERN bool
679as_query_select_init(as_query* query, uint16_t n);
680
681/**
682 * Select bins to be projected from matching records.
683 *
684 * You have to ensure as_query.select has sufficient capacity, prior to
685 * adding a bin. If capacity is sufficient then false is returned.
686 *
687 * ~~~~~~~~~~{.c}
688 * as_query_select_init(&query, 2);
689 * as_query_select(&query, "bin1");
690 * as_query_select(&query, "bin2");
691 * ~~~~~~~~~~
692 *
693 * @param query The query to modify.
694 * @param bin The name of the bin to select.
695 *
696 * @return On success, true. Otherwise an error occurred.
697 * @relates as_query
698 * @ingroup query_operations
699 */
700AS_EXTERN bool
701as_query_select(as_query* query, const char * bin);
702
703//---------------------------------
704// Where Functions
705//---------------------------------
706
707/**
708 * Initializes `as_query.where` with a capacity of `n` using `alloca()`.
709 *
710 * For heap allocation, use `as_query_where_init()`.
711 *
712 * ~~~~~~~~~~{.c}
713 * as_query_where_inita(&query, 1);
714 * as_query_where(&query, "bin1", as_string_equals("abc"));
715 * ~~~~~~~~~~
716 *
717 * @param __query The query to initialize.
718 * @param __n The number of as_predicate to allocate.
719 *
720 * @return On success, true. Otherwise an error occurred.
721 *
722 * @relates as_query
723 * @ingroup query_operations
724 */
725#define as_query_where_inita(__query, __n) \
726 do { \
727 if ((__query)->where.entries == NULL) {\
728 (__query)->where.entries = (as_predicate*) alloca(sizeof(as_predicate) * (__n));\
729 if ( (__query)->where.entries ) {\
730 (__query)->where.capacity = (__n);\
731 (__query)->where.size = 0;\
732 (__query)->where._free = false;\
733 }\
734 } \
735 } while(0)
736
737/**
738 * Initializes `as_query.where` with a capacity of `n` using `malloc()`.
739 *
740 * For stack allocation, use `as_query_where_inita()`.
741 *
742 * ~~~~~~~~~~{.c}
743 * as_query_where_init(&query, 1);
744 * as_query_where(&query, "bin1", as_integer_equals(123));
745 * ~~~~~~~~~~
746 *
747 * @param query The query to initialize.
748 * @param n The number of as_predicate to allocate.
749 *
750 * @return On success, true. Otherwise an error occurred.
751 *
752 * @relates as_query
753 * @ingroup query_operations
754 */
755AS_EXTERN bool
756as_query_where_init(as_query* query, uint16_t n);
757
758/**
759 * Add a predicate to the query.
760 *
761 * You have to ensure as_query.where has sufficient capacity, prior to
762 * adding a predicate. If capacity is insufficient then false is returned.
763 *
764 * String predicates are not owned by as_query. If the string is allocated
765 * on the heap, the caller is responsible for freeing the string after the query
766 * has been executed. as_query_destroy() will not free this string predicate.
767 *
768 * ~~~~~~~~~~{.c}
769 * as_query_where_init(&query, 3);
770 * as_query_where(&query, "bin1", as_string_equals("abc"));
771 * as_query_where(&query, "bin1", as_integer_equals(123));
772 * as_query_where(&query, "bin1", as_integer_range(0,123));
773 * ~~~~~~~~~~
774 *
775 * @param query The query add the predicate to.
776 * @param bin The name of the bin the predicate will apply to.
777 * @param type The type of predicate.
778 * @param itype The type of index.
779 * @param dtype The underlying data type that the index is based on.
780 * @param ... The values for the predicate.
781 *
782 * @return On success, true. Otherwise an error occurred.
783 *
784 * @relates as_query
785 * @ingroup query_operations
786 */
787AS_EXTERN bool
789 as_query* query, const char * bin, as_predicate_type type, as_index_type itype,
790 as_index_datatype dtype, ...
791 );
792
793/**
794 * Add a predicate and context to the query.
795 *
796 * You have to ensure as_query.where has sufficient capacity, prior to
797 * adding a predicate. If capacity is insufficient then false is returned.
798 *
799 * String predicates are not owned by as_query. If the string is allocated
800 * on the heap, the caller is responsible for freeing the string after the query
801 * has been executed. as_query_destroy() will not free this string predicate.
802 *
803 * ~~~~~~~~~~{.c}
804 * as_cdt_ctx ctx;
805 * as_cdt_ctx_init(&ctx, 1);
806 * as_cdt_ctx_add_list_rank(&ctx, -1);
807 * as_query_where_init(&query, 3);
808 * as_query_where_with_ctx(&query, "bin1", &ctx, as_string_equals("abc"));
809 * as_query_where_with_ctx(&query, "bin1", &ctx, as_integer_equals(123));
810 * as_query_where_with_ctx(&query, "bin1", &ctx, as_integer_range(0,123));
811 * ~~~~~~~~~~
812 *
813 * @param query The query add the predicate to.
814 * @param bin The name of the bin the predicate will apply to.
815 * @param ctx The CDT context describing the path to locate the data to be indexed.
816 * @param type The type of predicate.
817 * @param itype The type of index.
818 * @param dtype The underlying data type that the index is based on.
819 * @param ... The values for the predicate.
820 *
821 * @return On success, true. Otherwise an error occurred.
822 *
823 * @relates as_query
824 * @ingroup query_operations
825 */
826AS_EXTERN bool
828 as_query* query, const char* bin, struct as_cdt_ctx* ctx, as_predicate_type type,
829 as_index_type itype, as_index_datatype dtype, ...
830 );
831
832//---------------------------------
833// Background Query Functions
834//---------------------------------
835
836/**
837 * Apply a function to the results of the query.
838 *
839 * ~~~~~~~~~~{.c}
840 * as_query_apply(&query, "my_module", "my_function", NULL);
841 * ~~~~~~~~~~
842 *
843 * @param query The query to apply the function to.
844 * @param module The module containing the function to invoke.
845 * @param function The function in the module to invoke.
846 * @param arglist The arguments to use when calling the function.
847 *
848 * @return On success, true. Otherwise an error occurred.
849 *
850 * @relates as_query
851 * @ingroup query_operations
852 */
853AS_EXTERN bool
854as_query_apply(as_query* query, const char* module, const char* function, const as_list* arglist);
855
856//---------------------------------
857// Paginate Functions
858//---------------------------------
859
860/**
861 * Set if records should be read in pages in conjunction with max_records policy.
862 *
863 * @relates as_query
864 * @ingroup query_operations
865 */
866static inline void
867as_query_set_paginate(as_query* query, bool paginate)
868{
869 query->paginate = paginate;
870}
871
872/**
873 * Set completion status of all partitions from a previous query that ended early.
874 * The query will resume from this point.
875 *
876 * @relates as_query
877 * @ingroup query_operations
878 */
879static inline void
884
885/**
886 * If using query pagination, did the previous paginated query with this query instance
887 * return all records?
888 *
889 * @relates as_query
890 * @ingroup query_operations
891 */
892static inline bool
894{
895 return query->parts_all && query->parts_all->done;
896}
897
898//---------------------------------
899// Serialization Functions
900//---------------------------------
901
902/**
903 * Serialize query definition to bytes.
904 *
905 * @relates as_query
906 * @ingroup query_operations
907 */
908AS_EXTERN bool
909as_query_to_bytes(const as_query* query, uint8_t** bytes, uint32_t* bytes_size);
910
911/**
912 * Deserialize bytes to query definition. Query definition is assumed to be on the stack.
913 * as_query_destroy() should be called when done with the query definition.
914 *
915 * @returns true on success and false on failure.
916 *
917 * @relates as_query
918 * @ingroup query_operations
919 */
920AS_EXTERN bool
921as_query_from_bytes(as_query* query, const uint8_t* bytes, uint32_t bytes_size);
922
923/**
924 * Create query definition on the heap and deserialize bytes to that query definition.
925 * as_query_destroy() should be called when done with the query definition.
926 *
927 * @returns query definition on success and NULL on failure.
928 *
929 * @relates as_query
930 * @ingroup query_operations
931 */
933as_query_from_bytes_new(const uint8_t* bytes, uint32_t bytes_size);
934
935/**
936 * Compare query objects.
937 * @private
938 * @relates as_query
939 * @ingroup query_operations
940 */
941AS_EXTERN bool
943
944#ifdef __cplusplus
945} // end extern "C"
946#endif
as_index_datatype
char as_bin_name[AS_BIN_NAME_MAX_SIZE]
Definition as_bin.h:53
char as_namespace[AS_NAMESPACE_MAX_SIZE]
Definition as_key.h:55
char as_set[AS_SET_MAX_SIZE]
Definition as_key.h:60
static as_partitions_status * as_partitions_status_reserve(as_partitions_status *parts_all)
uint8_t type
Definition as_proto.h:1
as_predicate_type
Definition as_query.h:192
@ AS_PREDICATE_RANGE
Definition as_query.h:200
@ AS_PREDICATE_EQUAL
Definition as_query.h:198
as_order
Definition as_query.h:254
@ AS_ORDER_DESCENDING
Definition as_query.h:264
@ AS_ORDER_ASCENDING
Definition as_query.h:259
#define AS_EXTERN
Definition as_std.h:25
as_index_type
AS_EXTERN as_query * as_query_init(as_query *query, const char *ns, const char *set)
AS_EXTERN as_query * as_query_from_bytes_new(const uint8_t *bytes, uint32_t bytes_size)
static bool as_query_is_done(as_query *query)
Definition as_query.h:893
static void as_query_set_paginate(as_query *query, bool paginate)
Definition as_query.h:867
AS_EXTERN bool as_query_compare(as_query *q1, as_query *q2)
AS_EXTERN bool as_query_where(as_query *query, const char *bin, as_predicate_type type, as_index_type itype, as_index_datatype dtype,...)
static void as_query_set_partitions(as_query *query, as_partitions_status *parts_all)
Definition as_query.h:880
AS_EXTERN bool as_query_select(as_query *query, const char *bin)
AS_EXTERN bool as_query_from_bytes(as_query *query, const uint8_t *bytes, uint32_t bytes_size)
AS_EXTERN void as_query_destroy(as_query *query)
AS_EXTERN as_query * as_query_new(const char *ns, const char *set)
AS_EXTERN bool as_query_apply(as_query *query, const char *module, const char *function, const as_list *arglist)
AS_EXTERN bool as_query_where_with_ctx(as_query *query, const char *bin, struct as_cdt_ctx *ctx, as_predicate_type type, as_index_type itype, as_index_datatype dtype,...)
AS_EXTERN bool as_query_select_init(as_query *query, uint16_t n)
AS_EXTERN bool as_query_to_bytes(const as_query *query, uint8_t **bytes, uint32_t *bytes_size)
AS_EXTERN bool as_query_where_init(as_query *query, uint16_t n)
as_bin_name bin
Definition as_query.h:277
as_order order
Definition as_query.h:282
uint32_t ctx_size
Definition as_query.h:222
bool ctx_free
Definition as_query.h:227
as_bin_name bin
Definition as_query.h:212
as_index_datatype dtype
Definition as_query.h:243
as_index_type itype
Definition as_query.h:248
as_predicate_value value
Definition as_query.h:237
as_predicate_type type
Definition as_query.h:232
struct as_cdt_ctx * ctx
Definition as_query.h:217
uint16_t size
Definition as_query.h:311
uint16_t capacity
Definition as_query.h:306
as_bin_name * entries
Definition as_query.h:316
as_predicate * entries
Definition as_query.h:350
uint32_t ttl
Definition as_query.h:557
as_set set
Definition as_query.h:485
as_namespace ns
Definition as_query.h:476
struct as_operations_s * ops
Definition as_query.h:520
bool no_bins
Definition as_query.h:571
as_query_predicates where
Definition as_query.h:507
as_query_bins select
Definition as_query.h:496
bool paginate
Definition as_query.h:564
uint32_t records_per_second
Definition as_query.h:543
as_udf_call apply
Definition as_query.h:514
as_partitions_status * parts_all
Definition as_query.h:525
uint64_t max_records
Definition as_query.h:535
uint8_t * bytes
Definition as_query.h:178
uint32_t bytes_size
Definition as_query.h:179