diff --git a/src/include/aerospike/as_query.h b/src/include/aerospike/as_query.h index cdd3d0ba0..6e4436c24 100644 --- a/src/include/aerospike/as_query.h +++ b/src/include/aerospike/as_query.h @@ -34,18 +34,19 @@ extern "C" { *****************************************************************************/ /** - * Macro for setting setting the STRING_EQUAL predicate. + * Filter on string bins. * * ~~~~~~~~~~{.c} * as_query_where(query, "bin1", as_string_equals("abc")); * ~~~~~~~~~~ * * @relates as_query + * @ingroup query_object */ #define as_string_equals(__val) AS_PREDICATE_EQUAL, AS_INDEX_TYPE_DEFAULT, AS_INDEX_STRING, __val /** - * Macro for setting setting the BLOB_EQUAL predicate. + * Filter on blob bins. * Requires server version 7.0+. * * ~~~~~~~~~~{.c} @@ -54,22 +55,24 @@ extern "C" { * ~~~~~~~~~~ * * @relates as_query + * @ingroup query_object */ #define as_blob_equals(__val, __size, __free) AS_PREDICATE_EQUAL, AS_INDEX_TYPE_DEFAULT, AS_INDEX_BLOB, __val, __size, __free /** - * Macro for setting setting the INTEGER_EQUAL predicate. + * Filter on integer bins. * * ~~~~~~~~~~{.c} * as_query_where(query, "bin1", as_integer_equals(123)); * ~~~~~~~~~~ * * @relates as_query + * @ingroup query_object */ #define as_integer_equals(__val) AS_PREDICATE_EQUAL, AS_INDEX_TYPE_DEFAULT, AS_INDEX_NUMERIC, (int64_t)__val /** - * Macro for setting setting the INTEGER_RANGE predicate. + * Ranger filter on integer bins. * * ~~~~~~~~~~{.c} * as_query_where(query, "bin1", as_integer_range(1,100)); @@ -81,7 +84,7 @@ extern "C" { #define as_integer_range(__min, __max) AS_PREDICATE_RANGE, AS_INDEX_TYPE_DEFAULT, AS_INDEX_NUMERIC, (int64_t)__min, (int64_t)__max /** - * Macro for setting setting the RANGE predicate. + * Range filter on list/map elements. * * ~~~~~~~~~~{.c} * as_query_where(query, "bin1", as_range(LIST,NUMERIC,1,100)); @@ -93,7 +96,7 @@ extern "C" { #define as_range(indextype, datatype, __min, __max) AS_PREDICATE_RANGE, AS_INDEX_TYPE_ ##indextype, AS_INDEX_ ##datatype, __min, __max /** - * Macro for setting setting the CONTAINS predicate. + * Contains filter on list/map elements. * * ~~~~~~~~~~{.c} * as_query_where(query, "bin1", as_contains(LIST,STRING,"val")); @@ -105,7 +108,21 @@ extern "C" { #define as_contains(indextype, datatype, __val) AS_PREDICATE_EQUAL, AS_INDEX_TYPE_ ##indextype, AS_INDEX_ ##datatype, __val /** - * Macro for setting setting the EQUALS predicate. + * Contains blob filter on list/map elements. + * Requires server version 7.0+. + * + * ~~~~~~~~~~{.c} + * // as_blob_contains(type, uint8_t* bytes, uint32_t size, bool free) + * as_query_where(query, "bin1", as_blob_equals(LIST, bytes, size, true)); + * ~~~~~~~~~~ + * + * @relates as_query + * @ingroup query_object + */ +#define as_blob_contains(indextype, __val, __size, __free) AS_PREDICATE_EQUAL, AS_INDEX_TYPE_ ##indextype, AS_INDEX_BLOB, __val, __size, __free + +/** + * Filter specified type on bins. * * ~~~~~~~~~~{.c} * as_query_where(query, "bin1", as_equals(NUMERIC,5)); @@ -116,8 +133,28 @@ extern "C" { */ #define as_equals(datatype, __val) AS_PREDICATE_EQUAL, AS_INDEX_TYPE_DEFAULT, AS_INDEX_ ##datatype, __val +/** + * Within filter on GEO bins. + * + * ~~~~~~~~~~{.c} + * as_query_where(query, "bin1", as_geo_within(region)); + * ~~~~~~~~~~ + * + * @relates as_query + * @ingroup query_object + */ #define as_geo_within(__val) AS_PREDICATE_RANGE, AS_INDEX_TYPE_DEFAULT, AS_INDEX_GEO2DSPHERE, __val +/** + * Contains filter on GEO bins. + * + * ~~~~~~~~~~{.c} + * as_query_where(query, "bin1", as_geo_contains(region)); + * ~~~~~~~~~~ + * + * @relates as_query + * @ingroup query_object + */ #define as_geo_contains(__val) AS_PREDICATE_RANGE, AS_INDEX_TYPE_DEFAULT, AS_INDEX_GEO2DSPHERE, __val diff --git a/src/test/aerospike_query/query_foreach.c b/src/test/aerospike_query/query_foreach.c index 978e91dc2..2fc9173f4 100644 --- a/src/test/aerospike_query/query_foreach.c +++ b/src/test/aerospike_query/query_foreach.c @@ -165,6 +165,9 @@ query_foreach_create(void) status = aerospike_index_create_complex(as, &err, &task, NULL, NAMESPACE, SET, "blob", "idx_blob_test", AS_INDEX_TYPE_DEFAULT, AS_INDEX_BLOB); index_process_return_code(status, &err, &task); + status = aerospike_index_create_complex(as, &err, &task, NULL, NAMESPACE, SET, "blob_list", "idx_list_blob_test", AS_INDEX_TYPE_LIST, AS_INDEX_BLOB); + index_process_return_code(status, &err, &task); + char* buffer = alloca(n_recs * 1024 + 1); uint32_t the_ttl = AS_RECORD_NO_EXPIRE_TTL; @@ -247,6 +250,13 @@ query_foreach_create(void) uint8_t* blob_ptr = blob; *(uint32_t*)blob_ptr = 50000 + i; + // Make list of blobs + as_arraylist list3; + as_arraylist_init(&list3, 1, 0); + as_bytes bytes; + as_bytes_init_wrap(&bytes, blob_ptr, 4, false); + as_arraylist_append_bytes(&list3, &bytes); + // We only create the g bin for odd records. bool create_g_bin = i % 2 == 1; @@ -264,6 +274,7 @@ query_foreach_create(void) as_record_set_list(&r, "x", (as_list *) &list); as_record_set_map(&r, "y", (as_map *) &map); as_record_set_list(&r, "z", (as_list *) &list2); + as_record_set_list(&r, "blob_list", (as_list *) &list3); as_record_set_str(&r, "bigstr", buffer); as_record_set_rawp(&r, "blob", blob_ptr, sizeof(uint32_t), false); @@ -369,6 +380,11 @@ query_foreach_destroy(void) info("error(%d): %s", err.code, err.message); } + aerospike_index_remove(as, &err, NULL, NAMESPACE, "idx_list_blob_test"); + if (err.code != AEROSPIKE_OK) { + info("error(%d): %s", err.code, err.message); + } + return true; } @@ -1766,6 +1782,33 @@ TEST(query_blob_index, "query blob index") as_query_destroy(&q); } +TEST(query_blob_list_index, "query blob list index") +{ + as_error err; + as_error_reset(&err); + + uint32_t count = 0; + + uint8_t blob[4]; + *((uint32_t*)blob) = 50003; + + as_query q; + as_query_init(&q, NAMESPACE, SET); + + as_query_select_inita(&q, 1); + as_query_select(&q, "blob_list"); + + as_query_where_inita(&q, 1); + as_query_where(&q, "blob_list", as_blob_contains(LIST, &blob, 4, false)); + + aerospike_query_foreach(as, &err, NULL, &q, query_foreach_count_callback, &count); + + assert_int_eq(err.code, 0); + assert_int_eq(count, 1); + + as_query_destroy(&q); +} + /****************************************************************************** * TEST SUITE *****************************************************************************/ @@ -1851,4 +1894,5 @@ SUITE(query_foreach, "aerospike_query_foreach tests") suite_add(query_list_ctx_is_string); suite_add(query_map_ctx_is_string); suite_add(query_blob_index); + suite_add(query_blob_list_index); }