How to execute multiple as_query_where using c


#1

Hi,

Is there any possible way to execute multiple as_query_where queries in c, I tried this but did’t worked. * as_query query;

  • as_query_init(&query, NS, SET);
    
  • as_query_where_inita(query, 3);
    
  • as_query_where(query, bin, as_integer_equals(2));
  • as_query_where(query, bin, as_integer_equals(5));
    
  • as_query_where(query, bin, as_integer_equals(3));
    
  • if (aerospike_query_foreach(AS, &err, NULL, &query, queryCB, NULL) != AEROSPIKE_OK)
    
  • {
    
  • ......
    
  • }
    

Thanks.


#2

Hi @vinay_negi

At present, only one as_query_where() predicate is supported. You might want to try UDFs for more advanced filters.


#3

You provide additional predicates with predicate filters.


#4

I tried it but showing error:

as_query query;

as_query_init(query, cNS,SET);

as_query_where_inita(query, 1);

as_query_where(query,STATE,as_integer_equals(5));

as_query_predexp_inita(query, 2);

as_query_predexp_add(query,as_predexp_integer_value(3));

as_query_predexp_add(query,as_predexp_integer_value(8));

if (aerospike_query_foreach(pAS, &err, NULL, query, callback, NULL) != AEROSPIKE_OK){ … }

error : aerospike_query_foreach() returned 4 - AEROSPIKE_ERR_REQUEST_INVALID


#5

If you are trying to check whether the bin value is equal to 3, 5, or 8. You will need Something like:

// Assuming that STATE is the name of the bin
    as_query_predexp_inita(query, 10);

    as_query_predexp_add(query,as_predexp_integer_value(3));
    as_query_predexp_add(query,as_predexp_integer_bin(STATE));
    as_query_predexp_add(query,as_predexp_integer_equal());

    as_query_predexp_add(query,as_predexp_integer_value(5));
    as_query_predexp_add(query,as_predexp_integer_bin(STATE));
    as_query_predexp_add(query,as_predexp_integer_equal());

    as_query_predexp_add(query,as_predexp_integer_value(8));
    as_query_predexp_add(query,as_predexp_integer_bin(STATE));
    as_query_predexp_add(query,as_predexp_integer_equal());

    as_query_predexp_add(query,as_predexp_or(3));

And you will need to remove:

as_query_where_inita(query, 1);
as_query_where(query,STATE,as_integer_equals(5));

See C client predexp_or for more information.