Issue passing array to UDF function using "C" Client

udf

#1

hi there,

I am having issues accessing array values in UDF function, using C as client.

I have a UDF function to update bins using input array, which is working fine from AQL. The issue here is, i am unable to access array values in UDF function.

Below is the sample C code, please let me know if i missing something while passing the arguments. //C Code********** as_arraylist args; as_arraylist_inita(&args, 1);

   char *name_token[3] = {"email","rt@gmail.com","T"};
   as_arraylist_append_str(&args,*name_token);
   //as_arraylist_append_str(&args,name_token);
    
   as_val * p_return_val = NULL;
   if (aerospike_key_apply(as_ptr, &err, NULL, &key, "common_lua_functions", "mul_bin_update",(as_list*)&args, &p_return_val) != AEROSPIKE_OK) 
     {
      return("UDF Normal bin apply failed");
     }

//******************************************************************


#2

Hi guys,

I am still stuck with this issue. Any hint for this issue will be very much helpful.


#3

Hi Experts,

I have created a record UDF, using two dimensional array as input parameter.

I am able to successfully test the UDF using AQL + JSON combination.

However, when I am testing it using ‘C’ code, the UDF misbehaves. Tried with couple of approaches:

  1. Took 3 list of integer elements, ‘append’ it to the final list (having 3 elements) – works well
  2. When we try to make it generic using a list with N element (instead of fixed number of element, i.e. 3), it only stores the first appended value. Simply ignoring all subsequent list append requests.

Following code snippet describes the same.

My expected output is   :   [[2, 3, 4], [3, 4, 5], [4, 5, 6]]

Appreciate your expertise to pass two (and multi) dimensional array to a ‘LUA’ function using ‘C’

//======== LUA function

function mul_bin_update(rec, arr_values)   
local arr_val = {}  
arr_val = arr_values  
local listContent,result  
info("mylog %s", tostring(rec))  
info("mylog %s", tostring(arr_val))   
end

//======== C Code for Approach - 1

    as_arraylist args1;
    as_arraylist args2;
    as_arraylist args3;
    as_arraylist args_c;
    as_arraylist args;
   
    as_arraylist_inita(&args1,3);
    as_arraylist_inita(&args2,3);
    as_arraylist_inita(&args3,3);
    as_arraylist_inita(&args_c,3);
    as_arraylist_inita(&args,1);
    
	as_arraylist_append_int64(&args1,2);
    as_arraylist_append_int64(&args1,3);
    as_arraylist_append_int64(&args1,4);
   
    as_arraylist_append_int64(&args2,3);
    as_arraylist_append_int64(&args2,4);
    as_arraylist_append_int64(&args2,5);
    
    as_arraylist_append_int64(&args3,4);
    as_arraylist_append_int64(&args3,5);
    as_arraylist_append_int64(&args3,6);
    
    as_arraylist_append_list(&args_c,&args1);
    as_arraylist_append_list(&args_c,&args2);
    as_arraylist_append_list(&args_c,&args3);
    
    as_arraylist_append_list(&args,&args_c);
    
      as_val * p_return_val = NULL;
      if (aerospike_key_apply(&as, &err, NULL, &key, "common_lua_functions", "mul_bin_update",(as_list*)&args, &p_return_val) != AEROSPIKE_OK) 
       {
             LOG("aerospike_key_apply() returned %d - %s", err.code, err.message);
       }

//======== C Code for Approach - 2

	int size=3;
    as_arraylist args1;
    as_arraylist args_c;
    as_arraylist args;
    
    as_arraylist_inita(&args1,size);
    as_arraylist_inita(&args_c,size);
    as_arraylist_inita(&args,1);

    for (i = 1 ; i <= size ; i++)
    {       
         as_arraylist_append_int64(&args1,1+i);
         as_arraylist_append_int64(&args1,2+i);
         as_arraylist_append_int64(&args1,3+i);

         as_arraylist_append_list(&args_c,&args1);
    } 
    
     as_arraylist_append_list(&args,&args_c);

     as_val * p_return_val = NULL;
     if (aerospike_key_apply(&as, &err, NULL, &key, "common_lua_functions", "mul_bin_update",(as_list*)&args, &p_return_val) != AEROSPIKE_OK) 
      {
            LOG("aerospike_key_apply() returned %d - %s", err.code, err.message);
      }