All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
as_query.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2023 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
29 extern "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_object
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_object
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_object
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_object
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_object
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_object
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_object
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_object
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_object
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_object
157  */
158 #define as_geo_contains(__val) AS_PREDICATE_RANGE, AS_INDEX_TYPE_DEFAULT, AS_INDEX_GEO2DSPHERE, __val
159 
160 
161 /******************************************************************************
162  * TYPES
163  *****************************************************************************/
164 
165 struct as_operations_s;
166 
167 /**
168  * Union of supported predicates
169  */
170 typedef union as_predicate_value_u {
171  int64_t integer;
172 
173  struct {
174  char* string;
175  bool _free;
176  } string_val;
177 
178  struct {
179  uint8_t* bytes;
180  uint32_t bytes_size;
181  bool _free;
182  } blob_val;
183 
184  struct {
185  int64_t min;
186  int64_t max;
187  } integer_range;
189 
190 /**
191  * The types of predicates supported.
192  */
193 typedef enum as_predicate_type_e {
194 
195  /**
196  * String Equality Predicate.
197  * Requires as_predicate_value.string to be set.
198  */
200 
203 
204 /**
205  * Defines a predicate, including the bin, type of predicate and the value
206  * for the predicate.
207  */
208 typedef struct as_predicate_s {
209 
210  /**
211  * Bin to apply the predicate to
212  */
214 
215  /**
216  * The CDT context to query. Use as_query_where_with_ctx() to set.
217  */
218  struct as_cdt_ctx* ctx;
219 
220  /**
221  * The size of the CDT context. Use as_query_where_with_ctx() to set.
222  */
223  uint32_t ctx_size;
224 
225  /**
226  * Should ctx be destroyed on as_query_destroy(). Default: false.
227  */
228  bool ctx_free;
229 
230  /**
231  * The predicate type, dictates which values to use from the union
232  */
234 
235  /**
236  * The value for the predicate.
237  */
239 
240  /*
241  * The type of data user wants to query
242  */
243 
245 
246  /*
247  * The type of index predicate is on
248  */
250 } as_predicate;
251 
252 /**
253  * Enumerations defining the direction of an ordering.
254  */
255 typedef enum as_order_e {
256 
257  /**
258  * Ascending order
259  */
261 
262  /**
263  * bin should be in ascending order
264  */
266 
267 } as_order;
268 
269 
270 /**
271  * Defines the direction a bin should be ordered by.
272  */
273 typedef struct as_ordering_s {
274 
275  /**
276  * Name of the bin to sort by
277  */
279 
280  /**
281  * Direction of the sort
282  */
284 
285 } as_ordering;
286 
287 /**
288  * Sequence of bins which should be selected during a query.
289  *
290  * Entries can either be initialized on the stack or on the heap.
291  *
292  * Initialization should be performed via a query object, using:
293  * - as_query_select_init()
294  * - as_query_select_inita()
295  */
296 typedef struct as_query_bins_s {
297 
298  /**
299  * @private
300  * If true, then as_query_destroy() will free this instance.
301  */
302  bool _free;
303 
304  /**
305  * Number of entries allocated
306  */
307  uint16_t capacity;
308 
309  /**
310  * Number of entries used
311  */
312  uint16_t size;
313 
314  /**
315  * Sequence of entries
316  */
318 
319 } as_query_bins;
320 
321 /**
322  * Sequence of predicates to be applied to a query.
323  *
324  * Entries can either be initialized on the stack or on the heap.
325  *
326  * Initialization should be performed via a query object, using:
327  * - as_query_where_init()
328  * - as_query_where_inita()
329  */
330 typedef struct as_query_predicates_s {
331 
332  /**
333  * @private
334  * If true, then as_query_destroy() will free this instance.
335  */
336  bool _free;
337 
338  /**
339  * Number of entries allocated
340  */
341  uint16_t capacity;
342 
343  /**
344  * Number of entries used
345  */
346  uint16_t size;
347 
348  /**
349  * Sequence of entries
350  */
352 
354 
355 /**
356  * The as_query object is used define a query to be executed in the database.
357  *
358  * ## Initialization
359  *
360  * Before using an as_query, it must be initialized via either:
361  * - as_query_init()
362  * - as_query_new()
363  *
364  * as_query_init() should be used on a stack allocated as_query. It will
365  * initialize the as_query with the given namespace and set. On success,
366  * it will return a pointer to the initialized as_query. Otherwise, NULL
367  * is returned.
368  *
369  * ~~~~~~~~~~{.c}
370  * as_query query;
371  * as_query_init(&query, "namespace", "set");
372  * ~~~~~~~~~~
373  *
374  * as_query_new() should be used to allocate and initialize a heap allocated
375  * as_query. It will allocate the as_query, then initialized it with the
376  * given namespace and set. On success, it will return a pointer to the
377  * initialized as_query. Otherwise, NULL is returned.
378  *
379  * ~~~~~~~~~~{.c}
380  * as_query* query = as_query_new("namespace", "set");
381  * ~~~~~~~~~~
382  *
383  * ## Destruction
384  *
385  * When you are finished with the as_query, you can destroy it and associated
386  * resources:
387  *
388  * ~~~~~~~~~~{.c}
389  * as_query_destroy(query);
390  * ~~~~~~~~~~
391  *
392  * ## Usage
393  *
394  * The following explains how to use an as_query to build a query.
395  *
396  * ### Selecting Bins
397  *
398  * as_query_select() is used to specify the bins to be selected by the query.
399  *
400  * ~~~~~~~~~~{.c}
401  * as_query_select(query, "bin1");
402  * as_query_select(query, "bin2");
403  * ~~~~~~~~~~
404  *
405  * Before adding bins to select, the select structure must be initialized via
406  * either:
407  * - as_query_select_inita() - Initializes the structure on the stack.
408  * - as_query_select_init() - Initializes the structure on the heap.
409  *
410  * Both functions are given the number of bins to be selected.
411  *
412  * A complete example using as_query_select_inita()
413  *
414  * ~~~~~~~~~~{.c}
415  * as_query_select_inita(query, 2);
416  * as_query_select(query, "bin1");
417  * as_query_select(query, "bin2");
418  * ~~~~~~~~~~
419  *
420  * ### Predicates on Bins
421  *
422  * as_query_where() is used to specify predicates to be added to the the query.
423  *
424  * **Note:** Currently, a single where predicate is supported. To do more advanced filtering,
425  * you will want to use a UDF to process the result set on the server.
426  *
427  * ~~~~~~~~~~{.c}
428  * as_query_where(query, "bin1", as_string_equals("abc"));
429  * ~~~~~~~~~~
430  *
431  * The predicates that you can apply to a bin include:
432  * - as_string_equals() - Test for string equality.
433  * - as_integer_equals() - Test for integer equality.
434  * - as_integer_range() - Test for integer within a range.
435  *
436  * Before adding predicates, the where structure must be initialized. To
437  * initialize the where structure, you can choose to use one of the following:
438  * - as_query_where_inita() - Initializes the structure on the stack.
439  * - as_query_where_init() - Initializes the structure on the heap.
440  *
441  * Both functions are given the number of predicates to be added.
442  *
443  * A complete example using as_query_where_inita():
444  *
445  * ~~~~~~~~~~{.c}
446  * as_query_where_inita(query, 1);
447  * as_query_where(query, "bin1", as_string_equals("abc"));
448  * ~~~~~~~~~~
449  *
450  * ### Applying a UDF to Query Results
451  *
452  * A UDF can be applied to the results of a query.
453  *
454  * To define the UDF for the query, use as_query_apply().
455  *
456  * ~~~~~~~~~~{.c}
457  * as_query_apply(query, "udf_module", "udf_function", arglist);
458  * ~~~~~~~~~~
459  *
460  * @ingroup client_objects
461  */
462 typedef struct as_query_s {
463 
464  /**
465  * @private
466  * If true, then as_query_destroy() will free this instance.
467  */
468  bool _free;
469 
470  /**
471  * Namespace to be queried.
472  *
473  * Should be initialized via either:
474  * - as_query_init() - To initialize a stack allocated query.
475  * - as_query_new() - To heap allocate and initialize a query.
476  */
478 
479  /**
480  * Set to be queried.
481  *
482  * Should be initialized via either:
483  * - as_query_init() - To initialize a stack allocated query.
484  * - as_query_new() - To heap allocate and initialize a query.
485  */
487 
488  /**
489  * Name of bins to select.
490  *
491  * Use either of the following function to initialize:
492  * - as_query_select_init() - To initialize on the heap.
493  * - as_query_select_inita() - To initialize on the stack.
494  *
495  * Use as_query_select() to populate.
496  */
498 
499  /**
500  * Predicates for filtering.
501  *
502  * Use either of the following function to initialize:
503  * - as_query_where_init() - To initialize on the heap.
504  * - as_query_where_inita() - To initialize on the stack.
505  *
506  * Use as_query_where() to populate.
507  */
509 
510  /**
511  * UDF to apply to results of a background query or a foreground aggregation query.
512  *
513  * Should be set via `as_query_apply()`.
514  */
516 
517  /**
518  * Perform write operations on a background query.
519  * If ops is set, ops will be destroyed when as_query_destroy() is called.
520  */
521  struct as_operations_s* ops;
522 
523  /**
524  * Status of all partitions.
525  */
527 
528  /**
529  * Approximate number of records to return to client. This number is divided by the
530  * number of nodes involved in the query. The actual number of records returned
531  * may be less than max_records if node record counts are small and unbalanced across
532  * nodes.
533  *
534  * Default: 0 (do not limit record count)
535  */
536  uint64_t max_records;
537 
538  /**
539  * Limit returned records per second (rps) rate for each server.
540  * Do not apply rps limit if records_per_second is zero.
541  *
542  * Default: 0
543  */
545 
546  /**
547  * The time-to-live (expiration) of the record in seconds. Note that ttl
548  * is only used on background query writes.
549  *
550  * There are also special values that can be set in the record ttl:
551  * <ul>
552  * <li>AS_RECORD_DEFAULT_TTL: Use the server default ttl from the namespace.</li>
553  * <li>AS_RECORD_NO_EXPIRE_TTL: Do not expire the record.</li>
554  * <li>AS_RECORD_NO_CHANGE_TTL: Keep the existing record ttl when the record is updated.</li>
555  * <li>AS_RECORD_CLIENT_DEFAULT_TTL: Use the default client ttl in as_policy_write.</li>
556  * </ul>
557  */
558  uint32_t ttl;
559 
560  /**
561  * Should records be read in pages in conjunction with max_records policy.
562  *
563  * Default: false
564  */
565  bool paginate;
566 
567  /**
568  * Set to true if query should only return keys and no bin data.
569  *
570  * Default: false.
571  */
572  bool no_bins;
573 
574 } as_query;
575 
576 /******************************************************************************
577  * INSTANCE FUNCTIONS
578  *****************************************************************************/
579 
580 /**
581  * Initialize a stack allocated as_query.
582  *
583  * ~~~~~~~~~~{.c}
584  * as_query query;
585  * as_query_init(&query, "test", "demo");
586  * ~~~~~~~~~~
587  *
588  * @param query The query to initialize.
589  * @param ns The namespace to query.
590  * @param set The set to query.
591  *
592  * @return On success, the initialized query. Otherwise NULL.
593  *
594  * @relates as_query
595  */
597 as_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_object
613  */
615 as_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_object
622  */
623 AS_EXTERN void
624 as_query_destroy(as_query* query);
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_object
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_object
677  */
678 AS_EXTERN bool
679 as_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  *
698  * @relates as_query
699  * @ingroup query_object
700  */
701 AS_EXTERN bool
702 as_query_select(as_query* query, const char * bin);
703 
704 /******************************************************************************
705  * WHERE FUNCTIONS
706  *****************************************************************************/
707 
708 /**
709  * Initializes `as_query.where` with a capacity of `n` using `alloca()`.
710  *
711  * For heap allocation, use `as_query_where_init()`.
712  *
713  * ~~~~~~~~~~{.c}
714  * as_query_where_inita(&query, 1);
715  * as_query_where(&query, "bin1", as_string_equals("abc"));
716  * ~~~~~~~~~~
717  *
718  * @param __query The query to initialize.
719  * @param __n The number of as_predicate to allocate.
720  *
721  * @return On success, true. Otherwise an error occurred.
722  *
723  * @relates as_query
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  */
754 AS_EXTERN bool
755 as_query_where_init(as_query* query, uint16_t n);
756 
757 /**
758  * Add a predicate to the query.
759  *
760  * You have to ensure as_query.where has sufficient capacity, prior to
761  * adding a predicate. If capacity is insufficient then false is returned.
762  *
763  * String predicates are not owned by as_query. If the string is allocated
764  * on the heap, the caller is responsible for freeing the string after the query
765  * has been executed. as_query_destroy() will not free this string predicate.
766  *
767  * ~~~~~~~~~~{.c}
768  * as_query_where_init(&query, 3);
769  * as_query_where(&query, "bin1", as_string_equals("abc"));
770  * as_query_where(&query, "bin1", as_integer_equals(123));
771  * as_query_where(&query, "bin1", as_integer_range(0,123));
772  * ~~~~~~~~~~
773  *
774  * @param query The query add the predicate to.
775  * @param bin The name of the bin the predicate will apply to.
776  * @param type The type of predicate.
777  * @param itype The type of index.
778  * @param dtype The underlying data type that the index is based on.
779  * @param ... The values for the predicate.
780  *
781  * @return On success, true. Otherwise an error occurred.
782  *
783  * @relates as_query
784  */
785 AS_EXTERN bool
787  as_query* query, const char * bin, as_predicate_type type, as_index_type itype,
788  as_index_datatype dtype, ...
789  );
790 
791 /**
792  * Add a predicate and context to the query.
793  *
794  * You have to ensure as_query.where has sufficient capacity, prior to
795  * adding a predicate. If capacity is insufficient then false is returned.
796  *
797  * String predicates are not owned by as_query. If the string is allocated
798  * on the heap, the caller is responsible for freeing the string after the query
799  * has been executed. as_query_destroy() will not free this string predicate.
800  *
801  * ~~~~~~~~~~{.c}
802  * as_cdt_ctx ctx;
803  * as_cdt_ctx_init(&ctx, 1);
804  * as_cdt_ctx_add_list_rank(&ctx, -1);
805  * as_query_where_init(&query, 3);
806  * as_query_where_with_ctx(&query, "bin1", &ctx, as_string_equals("abc"));
807  * as_query_where_with_ctx(&query, "bin1", &ctx, as_integer_equals(123));
808  * as_query_where_with_ctx(&query, "bin1", &ctx, as_integer_range(0,123));
809  * ~~~~~~~~~~
810  *
811  * @param query The query add the predicate to.
812  * @param bin The name of the bin the predicate will apply to.
813  * @param ctx The CDT context describing the path to locate the data to be indexed.
814  * @param type The type of predicate.
815  * @param itype The type of index.
816  * @param dtype The underlying data type that the index is based on.
817  * @param ... The values for the predicate.
818  *
819  * @return On success, true. Otherwise an error occurred.
820  *
821  * @relates as_query
822  */
823 AS_EXTERN bool
825  as_query* query, const char* bin, struct as_cdt_ctx* ctx, as_predicate_type type,
826  as_index_type itype, as_index_datatype dtype, ...
827  );
828 
829 /******************************************************************************
830  * QUERY MODIFIER FUNCTIONS
831  *****************************************************************************/
832 
833 /**
834  * Apply a function to the results of the query.
835  *
836  * ~~~~~~~~~~{.c}
837  * as_query_apply(&query, "my_module", "my_function", NULL);
838  * ~~~~~~~~~~
839  *
840  * @param query The query to apply the function to.
841  * @param module The module containing the function to invoke.
842  * @param function The function in the module to invoke.
843  * @param arglist The arguments to use when calling the function.
844  *
845  * @return On success, true. Otherwise an error occurred.
846  *
847  * @relates as_query
848  */
849 AS_EXTERN bool
850 as_query_apply(as_query* query, const char* module, const char* function, const as_list* arglist);
851 
852 /******************************************************************************
853  * QUERY PAGINATE
854  *****************************************************************************/
855 
856 /**
857  * Set if records should be read in pages in conjunction with max_records policy.
858  *
859  * @relates as_query
860  * @ingroup as_query_object
861  */
862 static inline void
863 as_query_set_paginate(as_query* query, bool paginate)
864 {
865  query->paginate = paginate;
866 }
867 
868 /**
869  * Set completion status of all partitions from a previous query that ended early.
870  * The query will resume from this point.
871  *
872  * @relates as_query
873  * @ingroup as_query_object
874  */
875 static inline void
877 {
878  query->parts_all = as_partitions_status_reserve(parts_all);
879 }
880 
881 /**
882  * If using query pagination, did the previous paginated query with this query instance
883  * return all records?
884  *
885  * @relates as_query
886  * @ingroup as_query_object
887  */
888 static inline bool
890 {
891  return query->parts_all && query->parts_all->done;
892 }
893 
894 /**
895  * Serialize query definition to bytes.
896  *
897  * @relates as_query
898  * @ingroup as_query_object
899  */
900 AS_EXTERN bool
901 as_query_to_bytes(const as_query* query, uint8_t** bytes, uint32_t* bytes_size);
902 
903 /**
904  * Deserialize bytes to query definition. Query definition is assumed to be on the stack.
905  * as_query_destroy() should be called when done with the query definition.
906  *
907  * @returns true on success and false on failure.
908  * @relates as_query
909  * @ingroup as_query_object
910  */
911 AS_EXTERN bool
912 as_query_from_bytes(as_query* query, const uint8_t* bytes, uint32_t bytes_size);
913 
914 /**
915  * Create query definition on the heap and deserialize bytes to that query definition.
916  * as_query_destroy() should be called when done with the query definition.
917  *
918  * @returns query definition on success and NULL on failure.
919  * @relates as_query
920  * @ingroup as_query_object
921  */
923 as_query_from_bytes_new(const uint8_t* bytes, uint32_t bytes_size);
924 
925 /**
926  * Compare query objects.
927  * @private
928  * @relates as_query
929  * @ingroup as_query_object
930  */
931 AS_EXTERN bool
933 
934 #ifdef __cplusplus
935 } // end extern "C"
936 #endif
uint32_t ttl
Definition: as_query.h:558
AS_EXTERN as_query * as_query_init(as_query *query, const char *ns, const char *set)
uint8_t type
Definition: as_proto.h:36
as_namespace ns
Definition: as_scan.h:267
AS_EXTERN as_query * as_query_new(const char *ns, const char *set)
bool ctx_free
Definition: as_query.h:228
struct as_operations_s * ops
Definition: as_query.h:521
bool paginate
Definition: as_query.h:565
as_predicate_type type
Definition: as_query.h:233
uint32_t bytes_size
Definition: as_query.h:180
as_index_datatype dtype
Definition: as_query.h:244
as_index_type itype
Definition: as_query.h:249
AS_EXTERN bool as_query_from_bytes(as_query *query, const uint8_t *bytes, uint32_t bytes_size)
struct as_cdt_ctx * ctx
Definition: as_query.h:218
as_udf_call apply
Definition: as_query.h:515
AS_EXTERN void as_query_destroy(as_query *query)
char as_namespace[AS_NAMESPACE_MAX_SIZE]
Definition: as_key.h:63
AS_EXTERN bool as_query_select(as_query *query, const char *bin)
uint32_t ctx_size
Definition: as_query.h:223
uint64_t max_records
Definition: as_query.h:536
bool no_bins
Definition: as_query.h:572
AS_EXTERN bool as_query_where(as_query *query, const char *bin, as_predicate_type type, as_index_type itype, as_index_datatype dtype,...)
as_predicate * entries
Definition: as_query.h:351
static void as_query_set_paginate(as_query *query, bool paginate)
Definition: as_query.h:863
uint16_t size
Definition: as_query.h:312
#define AS_EXTERN
Definition: as_std.h:25
as_bin_name bin
Definition: as_query.h:278
as_order order
Definition: as_query.h:283
AS_EXTERN bool as_query_where_init(as_query *query, uint16_t n)
as_query_bins select
Definition: as_query.h:497
as_bin_name bin
Definition: as_query.h:213
uint16_t capacity
Definition: as_query.h:341
as_namespace ns
Definition: as_query.h:477
AS_EXTERN bool as_query_compare(as_query *q1, as_query *q2)
uint8_t * bytes
Definition: as_query.h:179
uint32_t records_per_second
Definition: as_query.h:544
static as_partitions_status * as_partitions_status_reserve(as_partitions_status *parts_all)
AS_EXTERN bool as_query_select_init(as_query *query, uint16_t n)
as_bin_name * entries
Definition: as_query.h:317
as_index_type
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_order
Definition: as_query.h:255
static void as_query_set_partitions(as_query *query, as_partitions_status *parts_all)
Definition: as_query.h:876
as_partitions_status * parts_all
Definition: as_query.h:526
as_index_datatype
AS_EXTERN as_query * as_query_from_bytes_new(const uint8_t *bytes, uint32_t bytes_size)
as_set set
Definition: as_query.h:486
uint16_t capacity
Definition: as_query.h:307
char as_bin_name[AS_BIN_NAME_MAX_SIZE]
Definition: as_bin.h:53
as_predicate_value value
Definition: as_query.h:238
as_query_predicates where
Definition: as_query.h:508
static bool as_query_is_done(as_query *query)
Definition: as_query.h:889
as_predicate_type
Definition: as_query.h:193
AS_EXTERN bool as_query_apply(as_query *query, const char *module, const char *function, const as_list *arglist)
char as_set[AS_SET_MAX_SIZE]
Definition: as_key.h:70
AS_EXTERN bool as_query_to_bytes(const as_query *query, uint8_t **bytes, uint32_t *bytes_size)