예제 #1
0
static bool check_bin3(as_record * rec, scan_check * check)
{
	as_val * bin = (as_val *) as_record_get(rec, "bin3");
	if ( !bin ) {
		error("Expected a value in bin('%s'), but got null", "bin3");
		return !(check->failed = true);
	}

	as_map * map = as_map_fromval(bin);
	if ( !map ) {
		error("Expected a map in bin('%s'), but got type %d", "bin3", as_val_type(bin));
		return !(check->failed = true);
	}

	int sz = as_map_size(map);
	if ( sz != 3 ) {
		error("Expected map size of %d, but got %d", 3, sz);
		return !(check->failed = true);
	} 

	int64_t bin1 = as_record_get_int64(rec, "bin1", INT64_MIN);
	int64_t ival = 0;

	ival = as_stringmap_get_int64(map, "x");
	if ( ival != bin1 ) {
		error("Expected map value '%s'=%ld, but got %ld", "x", bin1, ival);
		return !(check->failed = true);
	}
	
	ival = as_stringmap_get_int64(map, "y");
	if ( ival != bin1+1 ) {
		error("Expected map value '%s'=%ld, but got %ld", "y", bin1+1, ival);
		return !(check->failed = true);
	}

	ival = as_stringmap_get_int64(map, "z");
	if ( ival != bin1+2 ) {
		error("Expected map value '%s'=%ld, but got %ld", "z", bin1+2, ival);
		return !(check->failed = true);
	}

	return !(check->failed = false);
}
예제 #2
0
bool
query_cb_map(const as_val* p_val, void* udata)
{
	if (! p_val) {
		LOG("query callback returned null - query is complete");
		return true;
	}

	// Because of the UDF used, we expect an as_map to be returned.
	if (! as_map_fromval(p_val)) {
		LOG("query callback returned non-as_map object");
		return true;
	}

	// The map keys are number tokens ("1" to "10") and each value is the total
	// number of occurrences of the token in the records aggregated.
	char* val_as_str = as_val_tostring(p_val);

	LOG("query callback returned %s", val_as_str);
	free(val_as_str);

	return true;
}
예제 #3
0
/**
 *	Get specified bin's value as an as_map.
 *	as_map * value = as_record_get_map(rec, "bin");
 *	@param rec 	- the record containing the bin
 *	@param name 	- the name of the bin
 *	@return the value if it exists, otherwise NULL.
 */
as_map * as_record_get_map(const as_record * rec, const as_bin_name name) 
{
	return as_map_fromval((as_val *) as_record_get(rec, name));
}