All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data Fields | Related Functions
as_record Struct Reference

Detailed Description

Records in Aerospike are collections of named bins.

The bins in a record are analogous to columns in relational databases. However, unlike columns, the bins themselves are not typed. Instead, bins contain values which are typed. So, it is possible to have multiple records with bins of the same name but different types for values.

The bin's value can only be of the types defined in as_bin_value.

Initialization

There are several ways to initialize an as_record.

You can create the as_record on the stack:

Then initialize it using either the as_record_init() function or as_record_inita() macro.

The as_record_init() function will initialize the variable, then allocate the specified number of bins using malloc(). The following initializes rec with 2 bins.

as_record_init(&rec, 2);

The as_record_inita() macro will initialize the variable, then allocate the specified number of bins using alloca(). The following initializes rec with 2 bins.

as_record_inita(&rec, 2);

The as_record_new() function will allocate an as_record on the heap using malloc() then allocate the specified number of bins using malloc(). The following creates a new as_record with 2 bins.

Destruction

When you no longer require an as_record, you should call as_record_destroy() to release the record and associated resources.

If the record has been ref-counted, then the ref-count will be decremented, until it reaches 0 (zero), at which point, the record will be released.

Setting Bin Values

The following are functions for setting values in bins of a record. Utilize the appropriate setter for the data you want to store in a bin.

Function Description
as_record_set_int64() Set the bin value to a 64-bit integer.
as_record_set_str() Set the bin value to a NULL-terminated string.
as_record_set_integer() Set the bin value to an as_integer.
as_record_set_double() Set the bin value to an as_double.
as_record_set_string() Set the bin value to an as_string.
as_record_set_geojson() Set the bin value to an as_geojson.
as_record_set_bytes() Set the bin value to an as_bytes.
as_record_set_list() Set the bin value to an as_list.
as_record_set_map() Set the bin value to an as_map.
as_record_set_nil() Set the bin value to an as_nil.
as_record_set() Set the bin value to an as_bin_value.

Getting Bin Values

The following are functions for getting values from bins of a record. Utilize the appropriate getter for the data you want to read from a bin.

Function Description
as_record_get_int64() Get the bin as a 64-bit integer.
as_record_get_str() Get the bin as a NULL-terminated string.
as_record_get_integer() Get the bin as an as_integer.
as_record_get_double() Get the bin as an as_double.
as_record_get_string() Get the bin as an as_string.
as_record_get_geojson() Get the bin as an as_geojson.
as_record_get_bytes() Get the bin as an as_bytes.
as_record_get_list() Get the bin as an as_list.
as_record_get_map() Get the bin as an as_map.
as_record_get() Get the bin as an as_bin_value.

If you are unsure of the type of data stored in the bin, then you should use as_record_get(). You can then check the type of the value using as_val_type().

as_bin_value* value = as_record_get(rec, "bin1");
switch ( as_val_type(value) ) {
case AS_NIL: break;
case AS_INTEGER: break;
case AS_DOUBLE: break;
case AS_STRING: break;
case AS_GEOJSON: break;
case AS_BYTES: break;
case AS_LIST: break;
case AS_MAP: break;
case AS_REC: break;
case AS_UNDEF: break;
}

Traversing Bins

If you want to traverse the bins of a record, then you have two options:

Definition at line 166 of file as_record.h.

#include "as_record.h"

+ Inheritance diagram for as_record:
+ Collaboration diagram for as_record:

Data Fields

as_bins bins
 
uint16_t gen
 
as_key key
 
uint32_t ttl
 
- Data Fields inherited from as_rec
void * data
 
const struct as_rec_hooks_s * hooks
 
- Data Fields inherited from as_val
uint32_t count
 
bool free
 
as_val_t type
 

Related Functions

(Note that these are not member functions.)

AS_EXTERN void as_record_destroy (as_record *rec)
 
AS_EXTERN bool as_record_foreach (const as_record *rec, as_rec_foreach_callback callback, void *udata)
 
static as_recordas_record_fromval (const as_val *v)
 
AS_EXTERN as_bin_valueas_record_get (const as_record *rec, const as_bin_name name)
 
AS_EXTERN as_doubleas_record_get_as_double (const as_record *rec, const as_bin_name name)
 
AS_EXTERN as_bytesas_record_get_bytes (const as_record *rec, const as_bin_name name)
 
AS_EXTERN double as_record_get_double (const as_record *rec, const as_bin_name name, double fallback)
 
AS_EXTERN as_geojsonas_record_get_geojson (const as_record *rec, const as_bin_name name)
 
AS_EXTERN char * as_record_get_geojson_str (const as_record *rec, const as_bin_name name)
 
AS_EXTERN int64_t as_record_get_int64 (const as_record *rec, const as_bin_name name, int64_t fallback)
 
AS_EXTERN as_integeras_record_get_integer (const as_record *rec, const as_bin_name name)
 
AS_EXTERN as_listas_record_get_list (const as_record *rec, const as_bin_name name)
 
AS_EXTERN as_mapas_record_get_map (const as_record *rec, const as_bin_name name)
 
AS_EXTERN char * as_record_get_str (const as_record *rec, const as_bin_name name)
 
AS_EXTERN as_stringas_record_get_string (const as_record *rec, const as_bin_name name)
 
AS_EXTERN as_recordas_record_init (as_record *rec, uint16_t nbins)
 
#define as_record_inita(__rec, __nbins)
 
AS_EXTERN as_recordas_record_new (uint16_t nbins)
 
AS_EXTERN uint16_t as_record_numbins (const as_record *rec)
 
AS_EXTERN bool as_record_set (as_record *rec, const as_bin_name name, as_bin_value *value)
 
AS_EXTERN bool as_record_set_as_double (as_record *rec, const as_bin_name name, as_double *value)
 
AS_EXTERN bool as_record_set_bytes (as_record *rec, const as_bin_name name, as_bytes *value)
 
AS_EXTERN bool as_record_set_double (as_record *rec, const as_bin_name name, double value)
 
AS_EXTERN bool as_record_set_geojson (as_record *rec, const as_bin_name name, as_geojson *value)
 
static bool as_record_set_geojson_str (as_record *rec, const as_bin_name name, const char *value)
 
AS_EXTERN bool as_record_set_geojson_strp (as_record *rec, const as_bin_name name, const char *value, bool free)
 
AS_EXTERN bool as_record_set_int64 (as_record *rec, const as_bin_name name, int64_t value)
 
AS_EXTERN bool as_record_set_integer (as_record *rec, const as_bin_name name, as_integer *value)
 
AS_EXTERN bool as_record_set_list (as_record *rec, const as_bin_name name, as_list *value)
 
AS_EXTERN bool as_record_set_map (as_record *rec, const as_bin_name name, as_map *value)
 
AS_EXTERN bool as_record_set_nil (as_record *rec, const as_bin_name name)
 
static bool as_record_set_raw (as_record *rec, const as_bin_name name, const uint8_t *value, uint32_t size)
 
AS_EXTERN bool as_record_set_raw_typep (as_record *rec, const as_bin_name name, const uint8_t *value, uint32_t size, as_bytes_type type, bool free)
 
AS_EXTERN bool as_record_set_rawp (as_record *rec, const as_bin_name name, const uint8_t *value, uint32_t size, bool free)
 
static bool as_record_set_str (as_record *rec, const as_bin_name name, const char *value)
 
AS_EXTERN bool as_record_set_string (as_record *rec, const as_bin_name name, as_string *value)
 
AS_EXTERN bool as_record_set_strp (as_record *rec, const as_bin_name name, const char *value, bool free)
 
static as_valas_record_toval (const as_record *rec)
 

Friends And Related Function Documentation

AS_EXTERN void as_record_destroy ( as_record rec)
related

Destroy the as_record and associated resources.

Parameters
recThe record to destroy.
AS_EXTERN bool as_record_foreach ( const as_record rec,
as_rec_foreach_callback  callback,
void *  udata 
)
related

Iterate over each bin in the record and invoke the callback function.

bool print_bin(const char* name, const as_val * value, void* udata) {
char * sval = as_val_tostring(value);
printf("bin: name=%s, value=%s\n", name, sval);
free(sval);
return true;
}
as_record_foreach(rec, print_bin, NULL);

If the callback returns true, then iteration will continue to the next bin. Otherwise, the iteration will halt and as_record_foreach() will return false.

Parameters
recThe record containing the bins to iterate over.
callbackThe callback to invoke for each bin.
udataUser-data provided for the callback.
Returns
true if iteration completes fully. false if iteration was aborted.
static as_record * as_record_fromval ( const as_val v)
related

Convert from an as_val.

Definition at line 945 of file as_record.h.

References AS_REC, and as_util_fromval.

AS_EXTERN as_bin_value * as_record_get ( const as_record rec,
const as_bin_name  name 
)
related

Get specified bin's value.

as_val * value = as_record_get(rec, "bin");
Parameters
recThe record containing the bin.
nameThe name of the bin.
Returns
the value if it exists, otherwise NULL.
AS_EXTERN as_double * as_record_get_as_double ( const as_record rec,
const as_bin_name  name 
)
related

Get specified bin's value as an as_double.

as_double * value = as_record_get_as_double(rec, "bin");
Parameters
recThe record containing the bin.
nameThe name of the bin.
Returns
the value if it exists, otherwise NULL.
AS_EXTERN as_bytes * as_record_get_bytes ( const as_record rec,
const as_bin_name  name 
)
related

Get specified bin's value as an as_bytes.

as_bytes * value = as_record_get_bytes(rec, "bin");
Parameters
recThe record containing the bin.
nameThe name of the bin.
Returns
the value if it exists, otherwise NULL.
AS_EXTERN double as_record_get_double ( const as_record rec,
const as_bin_name  name,
double  fallback 
)
related

Get specified bin's value as a double.

double value = as_record_get_double(rec, "bin", -1.0);
Parameters
recThe record containing the bin.
nameThe name of the bin.
fallbackThe default value to use, if the bin doesn't exist or is not an integer.
Returns
the value if it exists, otherwise 0.
AS_EXTERN as_geojson * as_record_get_geojson ( const as_record rec,
const as_bin_name  name 
)
related

Get specified bin's value as an as_geojson.

as_geojson * value = as_record_get_geojson(rec, "bin");
Parameters
recThe record containing the bin.
nameThe name of the bin.
Returns
the value if it exists, otherwise NULL.
AS_EXTERN char * as_record_get_geojson_str ( const as_record rec,
const as_bin_name  name 
)
related

Get specified bin's value as an NULL terminated GeoJSON string.

char* value = as_record_get_geojson_str(rec, "bin");
Parameters
recThe record containing the bin.
nameThe name of the bin.
Returns
the value if it exists, otherwise NULL.
AS_EXTERN int64_t as_record_get_int64 ( const as_record rec,
const as_bin_name  name,
int64_t  fallback 
)
related

Get specified bin's value as an int64_t.

int64_t value = as_record_get_int64(rec, "bin", INT64_MAX);
Parameters
recThe record containing the bin.
nameThe name of the bin.
fallbackThe default value to use, if the bin doesn't exist or is not an integer.
Returns
the value if it exists, otherwise 0.
AS_EXTERN as_integer * as_record_get_integer ( const as_record rec,
const as_bin_name  name 
)
related

Get specified bin's value as an as_integer.

as_integer * value = as_record_get_integer(rec, "bin");
Parameters
recThe record containing the bin.
nameThe name of the bin.
Returns
the value if it exists, otherwise NULL.
AS_EXTERN as_list * as_record_get_list ( const as_record rec,
const as_bin_name  name 
)
related

Get specified bin's value as an as_list.

as_list * value = as_record_get_list(rec, "bin");
Parameters
recThe record containing the bin.
nameThe name of the bin.
Returns
the value if it exists, otherwise NULL.
AS_EXTERN as_map * as_record_get_map ( const as_record rec,
const as_bin_name  name 
)
related

Get specified bin's value as an as_map.

as_map * value = as_record_get_map(rec, "bin");
Parameters
recThe record containing the bin.
nameThe name of the bin.
Returns
the value if it exists, otherwise NULL.
AS_EXTERN char * as_record_get_str ( const as_record rec,
const as_bin_name  name 
)
related

Get specified bin's value as an NULL terminated string.

char* value = as_record_get_str(rec, "bin");
Parameters
recThe record containing the bin.
nameThe name of the bin.
Returns
the value if it exists, otherwise NULL.
AS_EXTERN as_string * as_record_get_string ( const as_record rec,
const as_bin_name  name 
)
related

Get specified bin's value as an as_string.

as_string * value = as_record_get_string(rec, "bin");
Parameters
recThe record containing the bin.
nameThe name of the bin.
Returns
the value if it exists, otherwise NULL.
AS_EXTERN as_record * as_record_init ( as_record rec,
uint16_t  nbins 
)
related

Initializes an as_record created on the stack.

as_record_set_int64(&r, "bin1", 123);
as_record_set_str(&r, "bin1", "abc");

When you are finished using the as_record instance, you should release the resources allocated to it by calling as_record_destroy().

Parameters
recThe record to initialize.
nbinsThe number of bins to initialize.
Returns
a pointer to the initialized as_record if successful, otherwise NULL.
#define as_record_inita (   __rec,
  __nbins 
)
related
Value:
as_record_init(__rec, 0);\
(__rec)->bins._free = false;\
(__rec)->bins.capacity = (__nbins);\
(__rec)->bins.size = 0;\
(__rec)->bins.entries = (as_bin*) alloca(sizeof(as_bin) * (__nbins));

Initialize a stack allocated as_record then allocate __nbins capacity for as_record.bins on the stack.

as_record record;
as_record_inita(&record, 2);
as_record_set_int64(&record, "bin1", 123);
as_record_set_int64(&record, "bin2", 456);

When you are finished using the as_record instance, you should release the resources allocated to it by calling as_record_destroy().

Parameters
__recThe as_record * to initialize.
__nbinsThe number of as_record.bins.entries to allocate on the stack.

Definition at line 253 of file as_record.h.

AS_EXTERN as_record * as_record_new ( uint16_t  nbins)
related

Create a new as_record on the heap.

as_record_set_int64(r, "bin1", 123);
as_record_set_str(r, "bin1", "abc");

When you are finished using the as_record instance, you should release the resources allocated to it by calling as_record_destroy().

Parameters
nbinsThe number of bins to initialize.
Returns
a pointer to the new as_record if successful, otherwise NULL.
AS_EXTERN uint16_t as_record_numbins ( const as_record rec)
related

Get the number of bins in the record.

Returns
the number of bins in the record.
AS_EXTERN bool as_record_set ( as_record rec,
const as_bin_name  name,
as_bin_value value 
)
related

Set specified bin's value to an as_bin_value.

Parameters
recThe record containing the bin.
nameThe name of the bin.
valueThe value of the bin.
Returns
true on success, false on failure.
AS_EXTERN bool as_record_set_as_double ( as_record rec,
const as_bin_name  name,
as_double value 
)
related

Set specified bin's value to an as_double.

as_record_set_as_double(rec, "bin", as_double_new(123.456));
Parameters
recThe record containing the bin.
nameThe name of the bin.
valueThe value of the bin. Must be in scope for the lifetime of the record.
Returns
true on success, false on failure.
AS_EXTERN bool as_record_set_bytes ( as_record rec,
const as_bin_name  name,
as_bytes value 
)
related

Set specified bin's value to an as_bytes.

as_record_set_integer(rec, "bin", bytes);
Parameters
recThe record containing the bin.
nameThe name of the bin.
valueThe value of the bin. Must be in scope for the lifetime of the record.
Returns
true on success, false on failure.
AS_EXTERN bool as_record_set_double ( as_record rec,
const as_bin_name  name,
double  value 
)
related

Set specified bin's value to a double.

as_record_set_double(rec, "bin", 123.456);
Parameters
recThe record containing the bin.
nameThe name of the bin.
valueThe value of the bin.
Returns
true on success, false on failure.
AS_EXTERN bool as_record_set_geojson ( as_record rec,
const as_bin_name  name,
as_geojson value 
)
related

Set specified bin's value to an as_geojson.

as_record_set_geojson(rec, "bin", as_geojson_new("abc", false));
Parameters
recThe record containing the bin.
nameThe name of the bin.
valueThe value of the bin. Must be in scope for the lifetime of the record.
Returns
true on success, false on failure.
static bool as_record_set_geojson_str ( as_record rec,
const as_bin_name  name,
const char *  value 
)
related

Set specified bin's value to an NULL terminated GeoJSON string.

as_record_set_geojson_str(rec, "bin", "abc");
Parameters
recThe record containing the bin.
nameThe name of the bin.
valueThe value of the bin. Must be in scope for the lifetime of the record.
Returns
true on success, false on failure.

Definition at line 453 of file as_record.h.

References as_record_set_geojson_strp().

AS_EXTERN bool as_record_set_geojson_strp ( as_record rec,
const as_bin_name  name,
const char *  value,
bool  free 
)
related

Set specified bin's value to an NULL terminated GeoJSON string.

as_record_set_geojson_strp(rec, "bin", strdup("abc"), true);
Parameters
recThe record containing the bin.
nameThe name of the bin.
valueThe value of the bin. Must be in scope for the lifetime of the record.
freeIf true, then the value will be freed when the record is destroyed.
Returns
true on success, false on failure.
AS_EXTERN bool as_record_set_int64 ( as_record rec,
const as_bin_name  name,
int64_t  value 
)
related

Set specified bin's value to an int64_t.

as_record_set_int64(rec, "bin", 123);
Parameters
recThe record containing the bin.
nameThe name of the bin.
valueThe value of the bin.
Returns
true on success, false on failure.
AS_EXTERN bool as_record_set_integer ( as_record rec,
const as_bin_name  name,
as_integer value 
)
related

Set specified bin's value to an as_integer.

Parameters
recThe record containing the bin.
nameThe name of the bin.
valueThe value of the bin. Must be in scope for the lifetime of the record.
Returns
true on success, false on failure.
AS_EXTERN bool as_record_set_list ( as_record rec,
const as_bin_name  name,
as_list value 
)
related

Set specified bin's value to an as_list.

as_arraylist_add_int64(&list, 1);
as_arraylist_add_int64(&list, 2);
as_arraylist_add_int64(&list, 3);
as_record_set_list(rec, "bin", &list);
Parameters
recThe record containing the bin.
nameThe name of the bin.
valueThe value of the bin. Must be in scope for the lifetime of the record.
Returns
true on success, false on failure.
AS_EXTERN bool as_record_set_map ( as_record rec,
const as_bin_name  name,
as_map value 
)
related

Set specified bin's value to an as_map.

as_hashmap_init(&map, 32);
as_stringmap_set_int64(&map, "a", 1);
as_stringmap_set_int64(&map, "b", 2);
as_stringmap_set_int64(&map, "c", 3);
as_record_set_map(rec, "bin", &map);
Parameters
recThe record containing the bin.
nameThe name of the bin.
valueThe value of the bin. Must be in scope for the lifetime of the record.
Returns
true on success, false on failure.
AS_EXTERN bool as_record_set_nil ( as_record rec,
const as_bin_name  name 
)
related

Set specified bin's value to as_nil.

as_record_set_nil(rec, "bin");
Parameters
recThe record containing the bin.
nameThe name of the bin.
Returns
true on success, false on failure.
static bool as_record_set_raw ( as_record rec,
const as_bin_name  name,
const uint8_t *  value,
uint32_t  size 
)
related

Set specified bin's value to an NULL terminated string.

uint8_t bytes[3] = {1,2,3};
as_record_set_raw(rec, "bin", bytes, 3);
Parameters
recThe record containing the bin.
nameThe name of the bin.
valueThe value of the bin. Must be in scope for the lifetime of the record.
sizeThe size of the value.
Returns
true on success, false on failure.

Definition at line 527 of file as_record.h.

References as_record_set_rawp().

AS_EXTERN bool as_record_set_raw_typep ( as_record rec,
const as_bin_name  name,
const uint8_t *  value,
uint32_t  size,
as_bytes_type  type,
bool  free 
)
related

Set specified bin's value to an as_bytes value of a specified type.

uint8_t * bytes = (uint8_t *) malloc(3);
bytes[0] = 1;
bytes[1] = 2;
bytes[3] = 3;
as_record_set_raw(rec, "bin", bytes, 3, true);
Parameters
recThe record containing the bin.
nameThe name of the bin.
valueThe value of the bin. Must be in scope for the lifetime of the record.
sizeThe size of the value.
typeThe as_bytes_type designation (AS_BYTES_*)
freeIf true, then the value will be freed when the record is destroyed.
Returns
true on success, false on failure.
AS_EXTERN bool as_record_set_rawp ( as_record rec,
const as_bin_name  name,
const uint8_t *  value,
uint32_t  size,
bool  free 
)
related

Set specified bin's value to an NULL terminated string.

uint8_t * bytes = (uint8_t *) malloc(3);
bytes[0] = 1;
bytes[1] = 2;
bytes[3] = 3;
as_record_set_raw(rec, "bin", bytes, 3, true);
Parameters
recThe record containing the bin.
nameThe name of the bin.
valueThe value of the bin. Must be in scope for the lifetime of the record.
sizeThe size of the value.
freeIf true, then the value will be freed when the record is destroyed.
Returns
true on success, false on failure.
static bool as_record_set_str ( as_record rec,
const as_bin_name  name,
const char *  value 
)
related

Set specified bin's value to an NULL terminated string.

as_record_set_str(rec, "bin", "abc");
Parameters
recThe record containing the bin.
nameThe name of the bin.
valueThe value of the bin. Must be in scope for the lifetime of the record.
Returns
true on success, false on failure.

Definition at line 413 of file as_record.h.

References as_record_set_strp().

AS_EXTERN bool as_record_set_string ( as_record rec,
const as_bin_name  name,
as_string value 
)
related

Set specified bin's value to an as_string.

as_record_set_string(rec, "bin", as_string_new("abc", false));
Parameters
recThe record containing the bin.
nameThe name of the bin.
valueThe value of the bin. Must be in scope for the lifetime of the record.
Returns
true on success, false on failure.
AS_EXTERN bool as_record_set_strp ( as_record rec,
const as_bin_name  name,
const char *  value,
bool  free 
)
related

Set specified bin's value to an NULL terminated string.

as_record_set_strp(rec, "bin", strdup("abc"), true);
Parameters
recThe record containing the bin.
nameThe name of the bin.
valueThe value of the bin. Must be in scope for the lifetime of the record.
freeIf true, then the value will be freed when the record is destroyed.
Returns
true on success, false on failure.
static as_val * as_record_toval ( const as_record rec)
related

Convert to an as_val.

Definition at line 935 of file as_record.h.

Field Documentation

as_bins as_record::bins

The bins of the record.

Definition at line 206 of file as_record.h.

uint16_t as_record::gen

The generation of the record.

Definition at line 185 of file as_record.h.

as_key as_record::key

The key of the record. This is only populated on records returned from a scan or secondary index query. This should not be set by the user.

Definition at line 180 of file as_record.h.

uint32_t as_record::ttl

The time-to-live (expiration) of the record in seconds. There are also special values that can be set in the record TTL: (*) ZERO (defined as AS_RECORD_DEFAULT_TTL), which means that the record will adopt the default TTL value from the namespace. (*) 0xFFFFFFFF (also, -1 in a signed 32 bit int) (defined as AS_RECORD_NO_EXPIRE_TTL), which means that the record will get an internal "void_time" of zero, and thus will never expire. (*) 0xFFFFFFFE (also, -2 in a signed 32 bit int) (defined as AS_RECORD_NO_CHANGE_TTL), which means that the record ttl will not change when the record is updated.

Note that the TTL value will be employed ONLY on write/update calls.

Definition at line 201 of file as_record.h.


The documentation for this struct was generated from the following file: