All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cl_query.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2008-2013 by Aerospike.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  *****************************************************************************/
22 #pragma once
23 
24 #include <citrusleaf/cl_types.h>
25 #include <citrusleaf/cl_sindex.h>
26 
27 #include <aerospike/as_rec.h>
28 #include <aerospike/as_map.h>
29 #include <aerospike/as_list.h>
30 #include <aerospike/as_result.h>
31 #include <aerospike/as_stream.h>
32 
33 /******************************************************************************
34  * TYPES
35  *******************************************************************************/
36 
39 
40 // These are the types of UDF calls that go over the wire from the client to
41 // the server.
42 typedef enum cl_query_udf_type_s {
43  AS_UDF_CALLTYPE_NONE, // Regular UDF call, no query involved.
47 
48 
49 typedef struct cl_query_udf_s {
51  char * filename;
52  char * function;
54 } cl_query_udf;
55 
56 typedef struct cl_query {
57  char * ns;
58  char * indexname;
59  char * setname;
60  cf_vector * binnames; // Select
61  cf_vector * ranges; // Where
62  cf_vector * filters;
63  cf_vector * orderbys;
65  void * res_streamq;
66  int limit;
67  uint64_t job_id;
68 } cl_query;
69 
70 typedef struct cl_query_response_record_t {
71  char * ns;
72  cf_digest keyd;
73  char * set;
74  uint32_t generation;
75  uint32_t record_ttl;
77  int n_bins;
79  bool ismalloc;
80  bool free_bins;
82 
83 typedef bool (* cl_query_cb) (as_val * val, void * udata);
84 
85 
86 /******************************************************************************
87  * FUNCTIONS
88  ******************************************************************************/
89 #define cl_integer_equals(val) CL_EQ, CL_INT, val
90 #define cl_integer_range(start, end) CL_RANGE, CL_INT, start, end
91 #define cl_string_equals(val) CL_EQ, CL_STR, val
92 
93 
94 /**
95  * Allocates and initializes a new cl_query
96  */
97 cl_query * cl_query_new(const char * ns, const char * setname);
98 
99 /**
100  * Initializes an cl_query
101  */
102 cl_query * cl_query_init(cl_query * query, const char * ns, const char * setname);
103 
104 /**
105  * Destroy and free an cl_query
106  */
107 void cl_query_destroy(cl_query * query);
108 
109 /**
110  * Query Builders
111  */
112 
113 int cl_query_select (cl_query * query, const char * binname);
114 int cl_query_where(cl_query * query, const char * binname, cl_query_op, ...);
115 int cl_query_where_function(cl_query * query, const char * finame, cl_query_op, ...);
116 int cl_query_filter(cl_query * query, const char * binname, cl_query_op op, ...);
117 int cl_query_orderby(cl_query * query, const char * binname, cl_query_orderby_op order);
118 cl_rv cl_query_aggregate(cl_query * query, const char * filename, const char * function, as_list * arglist);
119 cl_rv cl_query_foreach(cl_query * query, const char * filename, const char * function, as_list * arglist);
120 int cl_query_limit(cl_query * query, uint64_t limit);
121 
122 
123 cl_rv citrusleaf_query_foreach(cl_cluster * cluster, const cl_query * query, void * udata, bool (*foreach)(as_val *, void *));
124 
125 
126 /*
127  * Init and destroy for client query environment. Should be called for once per cluster
128  * instance before performing citrusleaf query
129  */
130 int cl_cluster_query_init(cl_cluster* asc);
131 void cl_cluster_query_shutdown(cl_cluster* asc);
char * indexname
Definition: cl_query.h:58
void cl_query_destroy(cl_query *query)
cl_rv cl_query_aggregate(cl_query *query, const char *filename, const char *function, as_list *arglist)
int limit
Definition: cl_query.h:66
char * setname
Definition: cl_query.h:59
cl_rv
Definition: cl_types.h:64
cf_vector * orderbys
Definition: cl_query.h:63
uint32_t generation
Definition: cl_query.h:74
cl_query_udf_type type
Definition: cl_query.h:50
cl_query * cl_query_new(const char *ns, const char *setname)
char * ns
Definition: cl_query.h:57
int cl_query_orderby(cl_query *query, const char *binname, cl_query_orderby_op order)
cf_vector * ranges
Definition: cl_query.h:61
int cl_query_where(cl_query *query, const char *binname, cl_query_op,...)
int cl_cluster_query_init(cl_cluster *asc)
cl_query_udf udf
Definition: cl_query.h:64
cl_rv citrusleaf_query_foreach(cl_cluster *cluster, const cl_query *query, void *udata, bool(*foreach)(as_val *, void *))
Definition: cl_query.h:37
as_list * arglist
Definition: cl_query.h:53
cl_rv cl_query_foreach(cl_query *query, const char *filename, const char *function, as_list *arglist)
uint32_t record_ttl
Definition: cl_query.h:75
cl_query_orderby_op
Definition: cl_query.h:38
Definition: cl_query.h:37
Definition: cl_query.h:37
uint64_t job_id
Definition: cl_query.h:67
cf_vector * filters
Definition: cl_query.h:62
int cl_query_limit(cl_query *query, uint64_t limit)
char * filename
Definition: cl_query.h:51
cl_query * cl_query_init(cl_query *query, const char *ns, const char *setname)
cl_query_udf_type
Definition: cl_query.h:42
void cl_cluster_query_shutdown(cl_cluster *asc)
Definition: cl_query.h:37
void * res_streamq
Definition: cl_query.h:65
bool(* cl_query_cb)(as_val *val, void *udata)
Definition: cl_query.h:83
int cl_query_select(cl_query *query, const char *binname)
cf_vector * binnames
Definition: cl_query.h:60
int cl_query_where_function(cl_query *query, const char *finame, cl_query_op,...)
Definition: cl_query.h:37
cl_query_op
Definition: cl_query.h:37
int cl_query_filter(cl_query *query, const char *binname, cl_query_op op,...)