Author: massie
Date: Tue Jan 26 23:58:49 2010
New Revision: 903505
URL: http://svn.apache.org/viewvc?rev=903505&view=rev
Log:
AVRO-379. Changed record getter/setter API to match other datatypes
Removed:
hadoop/avro/trunk/lang/c/tests/test_avro_interop.c
Modified:
hadoop/avro/trunk/CHANGES.txt
hadoop/avro/trunk/lang/c/examples/quickstop.c
hadoop/avro/trunk/lang/c/src/avro.h
hadoop/avro/trunk/lang/c/src/datum.c
hadoop/avro/trunk/lang/c/src/datum_read.c
hadoop/avro/trunk/lang/c/src/datum_validate.c
hadoop/avro/trunk/lang/c/src/datum_write.c
hadoop/avro/trunk/lang/c/src/io.c
hadoop/avro/trunk/lang/c/tests/test_avro_data.c
hadoop/avro/trunk/lang/c/version.sh
Modified: hadoop/avro/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=903505&r1=903504&r2=903505&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Tue Jan 26 23:58:49 2010
@@ -260,6 +260,8 @@
AVRO-378. Add example code to the C implementation and update
documentation (massie)
+ AVRO-379. Changed record getter/setter API to match other datatypes
(massie)
+
OPTIMIZATIONS
AVRO-172. More efficient schema processing (massie)
Modified: hadoop/avro/trunk/lang/c/examples/quickstop.c
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/examples/quickstop.c?rev=903505&r1=903504&r2=903505&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/examples/quickstop.c (original)
+++ hadoop/avro/trunk/lang/c/examples/quickstop.c Tue Jan 26 23:58:49 2010
@@ -58,11 +58,11 @@
avro_datum_t age_datum = avro_int32(age);
avro_datum_t phone_datum = avro_string(phone);
- if (avro_record_field_set(person, "ID", id_datum)
- || avro_record_field_set(person, "First", first_datum)
- || avro_record_field_set(person, "Last", last_datum)
- || avro_record_field_set(person, "Age", age_datum)
- || avro_record_field_set(person, "Phone", phone_datum)) {
+ if (avro_record_set(person, "ID", id_datum)
+ || avro_record_set(person, "First", first_datum)
+ || avro_record_set(person, "Last", last_datum)
+ || avro_record_set(person, "Age", age_datum)
+ || avro_record_set(person, "Phone", phone_datum)) {
fprintf(stderr, "Unable to create Person datum structure");
exit(EXIT_FAILURE);
}
@@ -97,11 +97,11 @@
avro_datum_t id_datum, first_datum, last_datum, phone_datum,
age_datum;
- id_datum = avro_record_field_get(person, "ID");
- first_datum = avro_record_field_get(person, "First");
- last_datum = avro_record_field_get(person, "Last");
- phone_datum = avro_record_field_get(person, "Phone");
- age_datum = avro_record_field_get(person, "Age");
+ avro_record_get(person, "ID", &id_datum);
+ avro_record_get(person, "First", &first_datum);
+ avro_record_get(person, "Last", &last_datum);
+ avro_record_get(person, "Phone", &phone_datum);
+ avro_record_get(person, "Age", &age_datum);
avro_int64_get(id_datum, &i64);
fprintf(stdout, "%ld | ", i64);
Modified: hadoop/avro/trunk/lang/c/src/avro.h
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/avro.h?rev=903505&r1=903504&r2=903505&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/avro.h (original)
+++ hadoop/avro/trunk/lang/c/src/avro.h Tue Jan 26 23:58:49 2010
@@ -203,8 +203,10 @@
int avro_boolean_get(avro_datum_t datum, int8_t * i);
int avro_fixed_get(avro_datum_t datum, char **bytes, int64_t * size);
-avro_datum_t avro_record_field_get(const avro_datum_t record,
- const char *field_name);
+int avro_record_get(const avro_datum_t record, const char *field_name,
+ avro_datum_t * value);
+int avro_map_get(const avro_datum_t datum, const char *key,
+ avro_datum_t * value);
/* setters */
int avro_string_set(avro_datum_t datum, const char *p);
@@ -229,8 +231,8 @@
int avro_wrapfixed_set(avro_datum_t datum, const char *bytes,
const int64_t size);
-int avro_record_field_set(const avro_datum_t record,
- const char *field_name, const avro_datum_t value);
+int avro_record_set(const avro_datum_t record, const char *field_name,
+ const avro_datum_t value);
int avro_map_set(const avro_datum_t map, const char *key,
const avro_datum_t value);
int avro_array_append_datum(const avro_datum_t array_datum,
Modified: hadoop/avro/trunk/lang/c/src/datum.c
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/datum.c?rev=903505&r1=903504&r2=903505&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/datum.c (original)
+++ hadoop/avro/trunk/lang/c/src/datum.c Tue Jan 26 23:58:49 2010
@@ -196,7 +196,7 @@
int avro_bytes_get(avro_datum_t datum, char **bytes, int64_t * size)
{
- if (!(is_avro_datum(datum) && is_avro_string(datum)) || !bytes ||
!size) {
+ if (!(is_avro_datum(datum) && is_avro_bytes(datum)) || !bytes || !size)
{
return EINVAL;
}
*bytes = avro_datum_to_bytes(datum)->bytes;
@@ -392,41 +392,36 @@
return &datum->obj;
}
-avro_datum_t
-avro_record_field_get(const avro_datum_t datum, const char *field_name)
+int
+avro_record_get(const avro_datum_t datum, const char *field_name,
+ avro_datum_t * field)
{
union {
avro_datum_t field;
st_data_t data;
} val;
- if (is_avro_datum(datum) && is_avro_record(datum)) {
- struct avro_record_datum_t *record =
- avro_datum_to_record(datum);
+ if (is_avro_datum(datum) && is_avro_record(datum) && field_name) {
if (st_lookup
- (record->fields, (st_data_t) field_name, &(val.data))) {
- return val.field;
+ (avro_datum_to_record(datum)->fields,
+ (st_data_t) field_name, &(val.data))) {
+ *field = val.field;
+ return 0;
}
}
- return NULL;
+ return EINVAL;
}
int
-avro_record_field_set(const avro_datum_t datum,
- const char *field_name, const avro_datum_t field_value)
+avro_record_set(const avro_datum_t datum, const char *field_name,
+ const avro_datum_t field_value)
{
char *key = (char *)field_name;
- union {
- avro_datum_t old_value;
- st_data_t data;
- } val;
+ avro_datum_t old_field;
- if (is_avro_datum(datum) && is_avro_record(datum)) {
- struct avro_record_datum_t *record =
- avro_datum_to_record(datum);
- if (st_lookup
- (record->fields, (st_data_t) field_name, &val.data)) {
+ if (is_avro_datum(datum) && is_avro_record(datum) && field_name) {
+ if (avro_record_get(datum, field_name, &old_field) == 0) {
/* Overriding old value */
- avro_datum_decref(val.old_value);
+ avro_datum_decref(old_field);
} else {
/* Inserting new value */
key = strdup(field_name);
@@ -435,7 +430,7 @@
}
}
avro_datum_incref(field_value);
- st_insert(record->fields, (st_data_t) key,
+ st_insert(avro_datum_to_record(datum)->fields, (st_data_t) key,
(st_data_t) field_value);
return 0;
}
@@ -545,7 +540,7 @@
int avro_fixed_get(avro_datum_t datum, char **bytes, int64_t * size)
{
- if (!(is_avro_datum(datum) && is_avro_string(datum)) || !bytes ||
!size) {
+ if (!(is_avro_datum(datum) && is_avro_fixed(datum)) || !bytes || !size)
{
return EINVAL;
}
*bytes = avro_datum_to_fixed(datum)->bytes;
@@ -566,24 +561,41 @@
}
int
-avro_map_set(const avro_datum_t datum, const char *key,
- const avro_datum_t value)
+avro_map_get(const avro_datum_t datum, const char *key, avro_datum_t * value)
{
- char *save_key = (char *)key;
struct avro_map_datum_t *map;
union {
+ avro_datum_t datum;
st_data_t data;
- avro_datum_t old_datum;
} val;
- if (!is_avro_datum(datum) || !is_avro_map(datum) || !key
- || !is_avro_datum(value)) {
+ if (!(is_avro_datum(datum) && is_avro_map(datum) && key && value)) {
return EINVAL;
}
+
map = avro_datum_to_map(datum);
if (st_lookup(map->map, (st_data_t) key, &(val.data))) {
+ *value = val.datum;
+ return 0;
+ }
+ return EINVAL;
+}
+
+int
+avro_map_set(const avro_datum_t datum, const char *key,
+ const avro_datum_t value)
+{
+ char *save_key = (char *)key;
+ avro_datum_t old_datum;
+
+ if (!is_avro_datum(datum) || !is_avro_map(datum) || !key
+ || !is_avro_datum(value)) {
+ return EINVAL;
+ }
+
+ if (avro_map_get(datum, key, &old_datum) == 0) {
/* Overwriting an old value */
- avro_datum_decref(val.old_datum);
+ avro_datum_decref(old_datum);
} else {
/* Inserting a new value */
save_key = strdup(key);
@@ -592,7 +604,8 @@
}
}
avro_datum_incref(value);
- st_insert(map->map, (st_data_t) save_key, (st_data_t) value);
+ st_insert(avro_datum_to_map(datum)->map, (st_data_t) save_key,
+ (st_data_t) value);
return 0;
}
Modified: hadoop/avro/trunk/lang/c/src/datum_read.c
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/datum_read.c?rev=903505&r1=903504&r2=903505&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/datum_read.c (original)
+++ hadoop/avro/trunk/lang/c/src/datum_read.c Tue Jan 26 23:58:49 2010
@@ -279,8 +279,7 @@
return rval;
}
rval =
- avro_record_field_set(record, field->name,
- field_datum);
+ avro_record_set(record, field->name, field_datum);
if (rval) {
return rval;
}
Modified: hadoop/avro/trunk/lang/c/src/datum_validate.c
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/datum_validate.c?rev=903505&r1=903504&r2=903505&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/datum_validate.c (original)
+++ hadoop/avro/trunk/lang/c/src/datum_validate.c Tue Jan 26 23:58:49 2010
@@ -156,13 +156,16 @@
for (field = STAILQ_FIRST(&record_schema->fields);
field != NULL;
field = STAILQ_NEXT(field, fields)) {
- avro_datum_t field_datum =
- avro_record_field_get(datum, field->name);
- if (!field_datum) {
+ int field_rval;
+ avro_datum_t field_datum;
+ field_rval =
+ avro_record_get(datum, field->name,
+ &field_datum);
+ if (field_rval) {
/*
* TODO: check for default values
*/
- return 0;
+ return field_rval;
}
if (!avro_schema_datum_validate
(field->type, field_datum)) {
Modified: hadoop/avro/trunk/lang/c/src/datum_write.c
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/datum_write.c?rev=903505&r1=903504&r2=903505&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/datum_write.c (original)
+++ hadoop/avro/trunk/lang/c/src/datum_write.c Tue Jan 26 23:58:49 2010
@@ -28,9 +28,13 @@
int rval;
struct avro_record_field_t *field = STAILQ_FIRST(&record->fields);
for (; field != NULL; field = STAILQ_NEXT(field, fields)) {
- rval = avro_write_data(writer, field->type,
- avro_record_field_get(datum,
- field->name));
+ int field_rval;
+ avro_datum_t field_datum;
+ field_rval = avro_record_get(datum, field->name, &field_datum);
+ if (field_rval) {
+ return field_rval;
+ }
+ rval = avro_write_data(writer, field->type, field_datum);
if (rval) {
return rval;
}
Modified: hadoop/avro/trunk/lang/c/src/io.c
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/src/io.c?rev=903505&r1=903504&r2=903505&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/src/io.c (original)
+++ hadoop/avro/trunk/lang/c/src/io.c Tue Jan 26 23:58:49 2010
@@ -152,10 +152,12 @@
static int
avro_read_file(struct avro_file_reader_t *reader, void *buf, int64_t len)
{
- /*
- * TODO
- */
- return -1;
+ int rval = fread(buf, len, 1, reader->fp);
+
+ if (rval == 0) {
+ return ferror(reader->fp) ? -1 : 0;
+ }
+ return 0;
}
int avro_read(avro_reader_t reader, void *buf, int64_t len)
@@ -188,10 +190,14 @@
static int
avro_write_file(struct avro_file_writer_t *writer, void *buf, int64_t len)
{
- /*
- * TODO
- */
- return -1;
+ int rval;
+ if (len > 0) {
+ rval = fwrite(buf, len, 1, writer->fp);
+ if (rval == 0) {
+ return feof(writer->fp) ? -1 : 0;
+ }
+ }
+ return 0;
}
int avro_write(avro_writer_t writer, void *buf, int64_t len)
Modified: hadoop/avro/trunk/lang/c/tests/test_avro_data.c
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/tests/test_avro_data.c?rev=903505&r1=903504&r2=903505&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/tests/test_avro_data.c (original)
+++ hadoop/avro/trunk/lang/c/tests/test_avro_data.c Tue Jan 26 23:58:49 2010
@@ -190,8 +190,8 @@
name_datum = avro_wrapstring("Joseph Campbell");
age_datum = avro_int32(83);
- avro_record_field_set(datum, "name", name_datum);
- avro_record_field_set(datum, "age", age_datum);
+ avro_record_set(datum, "name", name_datum);
+ avro_record_set(datum, "age", age_datum);
write_read_check(schema, NULL, datum, "record");
Modified: hadoop/avro/trunk/lang/c/version.sh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/c/version.sh?rev=903505&r1=903504&r2=903505&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/c/version.sh (original)
+++ hadoop/avro/trunk/lang/c/version.sh Tue Jan 26 23:58:49 2010
@@ -18,9 +18,9 @@
# libavro_binary_age = 0
# libavro_interface_age = 0
#
-libavro_micro_version=13
-libavro_interface_age=1
-libavro_binary_age=1
+libavro_micro_version=14
+libavro_interface_age=0
+libavro_binary_age=0
# IGNORE EVERYTHING ELSE FROM HERE DOWN.........
if test $# != 1; then