avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mas...@apache.org
Subject svn commit: r836133 - in /hadoop/avro/trunk: ./ src/c/ src/c/datatypes/
Date Sat, 14 Nov 2009 07:09:02 GMT
Author: massie
Date: Sat Nov 14 07:09:01 2009
New Revision: 836133

URL: http://svn.apache.org/viewvc?rev=836133&view=rev
Log:
AVRO-195. Complex type support for write streams

Added:
    hadoop/avro/trunk/src/c/datatypes/decorator.c
Modified:
    hadoop/avro/trunk/CHANGES.txt
    hadoop/avro/trunk/src/c/Makefile.am
    hadoop/avro/trunk/src/c/avro.h
    hadoop/avro/trunk/src/c/avro_private.h
    hadoop/avro/trunk/src/c/avro_value.c
    hadoop/avro/trunk/src/c/datatypes/array.c
    hadoop/avro/trunk/src/c/datatypes/boolean.c
    hadoop/avro/trunk/src/c/datatypes/bytes.c
    hadoop/avro/trunk/src/c/datatypes/double.c
    hadoop/avro/trunk/src/c/datatypes/enum.c
    hadoop/avro/trunk/src/c/datatypes/fixed.c
    hadoop/avro/trunk/src/c/datatypes/float.c
    hadoop/avro/trunk/src/c/datatypes/int.c
    hadoop/avro/trunk/src/c/datatypes/long.c
    hadoop/avro/trunk/src/c/datatypes/map.c
    hadoop/avro/trunk/src/c/datatypes/null.c
    hadoop/avro/trunk/src/c/datatypes/record.c
    hadoop/avro/trunk/src/c/datatypes/string.c
    hadoop/avro/trunk/src/c/datatypes/union.c
    hadoop/avro/trunk/src/c/version.sh

Modified: hadoop/avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Sat Nov 14 07:09:01 2009
@@ -62,6 +62,8 @@
 
     AVRO-192. Improved errors for Java schema parsing problems. (cutting)
 
+    AVRO-195. Complex type support for write streams (massie)
+
   OPTIMIZATIONS
 
     AVRO-172. More efficient schema processing (massie)

Modified: hadoop/avro/trunk/src/c/Makefile.am
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/Makefile.am?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/Makefile.am (original)
+++ hadoop/avro/trunk/src/c/Makefile.am Sat Nov 14 07:09:01 2009
@@ -18,6 +18,7 @@
 datatypes/array.c datatypes/boolean.c datatypes/bytes.c datatypes/double.c \
 datatypes/enum.c datatypes/fixed.c datatypes/float.c datatypes/int.c datatypes/long.c \
 datatypes/map.c datatypes/null.c datatypes/record.c datatypes/string.c datatypes/union.c
\
+datatypes/decorator.c \
 io/file.c io/socket.c io/memory.c io/file_container.c 
 libavro_la_LDFLAGS = \
         -version-info $(LIBAVRO_VERSION) \

Modified: hadoop/avro/trunk/src/c/avro.h
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro.h?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/avro.h (original)
+++ hadoop/avro/trunk/src/c/avro.h Sat Nov 14 07:09:01 2009
@@ -24,8 +24,8 @@
 extern "C" {
 #endif
 
-#include <stdint.h>
 #include <wchar.h>
+#include <stdint.h>
 
 /**
 @mainpage
@@ -89,15 +89,15 @@
    AVRO_MAP,    /**< complex map */
    AVRO_ARRAY,  /**< complex array */
    AVRO_UNION,  /**< complex union */
-
-   AVRO_FIELD,  /**< complex record field */
-   AVRO_DECORATOR, /**< resursive schema decorator */
-
    /* NOTE: AVRO_NUM_TYPES must always be last */
    AVRO_NUM_TYPES /**< number of avro types */
 };
 typedef enum avro_type avro_type_t;
 
+typedef struct avro_value * avro_value;
+
+avro_status_t avro_value_type(avro_value value, avro_type_t *type);
+
 #ifdef __cplusplus
 }
 #endif

Modified: hadoop/avro/trunk/src/c/avro_private.h
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro_private.h?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/avro_private.h (original)
+++ hadoop/avro/trunk/src/c/avro_private.h Sat Nov 14 07:09:01 2009
@@ -30,6 +30,13 @@
 #include "apr_file_io.h"
 #include "apr_network_io.h"
 
+enum avro_private_types
+{
+  AVRO_FIELD = AVRO_NUM_TYPES,
+  AVRO_DECORATOR,
+  AVRO_NUM_PRIVATE_TYPES
+};
+
 /* Util function */
 char *avro_util_file_read_full (apr_pool_t * pool, const char *fname,
 				apr_size_t * len);
@@ -91,7 +98,6 @@
   const JSON_value *schema;
   struct avro_value *parent;
 };
-typedef struct avro_value avro_value;
 
 struct avro_value_methods
 {
@@ -109,7 +115,7 @@
   apr_hash_t *named_objects;
 };
 
-struct avro_value_info
+struct avro_value_module
 {
   avro_string_t name;
   avro_type_t type;
@@ -121,7 +127,7 @@
   struct avro_value_methods formats[AVRO_NUM_DATA_FORMATS];
 };
 
-extern const struct avro_value_info *avro_value_registry[];
+extern const struct avro_value_module *avro_value_registry[];
 
 avro_status_t avro_value_read_data (struct avro_value *value,
 				    struct avro_reader *channel);

Modified: hadoop/avro/trunk/src/c/avro_value.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro_value.c?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/avro_value.c (original)
+++ hadoop/avro/trunk/src/c/avro_value.c Sat Nov 14 07:09:01 2009
@@ -18,40 +18,40 @@
 */
 #include "avro_private.h"
 
-extern const struct avro_value_info avro_string_info;
-extern const struct avro_value_info avro_bytes_info;
-extern const struct avro_value_info avro_int_info;
-extern const struct avro_value_info avro_long_info;
-extern const struct avro_value_info avro_float_info;
-extern const struct avro_value_info avro_double_info;
-extern const struct avro_value_info avro_boolean_info;
-extern const struct avro_value_info avro_null_info;
-extern const struct avro_value_info avro_record_info;
-extern const struct avro_value_info avro_field_info;
-extern const struct avro_value_info avro_enum_info;
-extern const struct avro_value_info avro_fixed_info;
-extern const struct avro_value_info avro_map_info;
-extern const struct avro_value_info avro_array_info;
-extern const struct avro_value_info avro_union_info;
-extern const struct avro_value_info avro_decorator_info;
-/* WARNING: This registry must match the avro_value_t enum! */
-const struct avro_value_info *avro_value_registry[AVRO_NUM_TYPES] = {
-  &avro_string_info,
-  &avro_bytes_info,
-  &avro_int_info,
-  &avro_long_info,
-  &avro_float_info,
-  &avro_double_info,
-  &avro_boolean_info,
-  &avro_null_info,
-  &avro_record_info,
-  &avro_enum_info,
-  &avro_fixed_info,
-  &avro_map_info,
-  &avro_array_info,
-  &avro_union_info,
-  &avro_field_info,
-  &avro_decorator_info
+extern const struct avro_value_module avro_string_module;
+extern const struct avro_value_module avro_bytes_module;
+extern const struct avro_value_module avro_int_module;
+extern const struct avro_value_module avro_long_module;
+extern const struct avro_value_module avro_float_module;
+extern const struct avro_value_module avro_double_module;
+extern const struct avro_value_module avro_boolean_module;
+extern const struct avro_value_module avro_null_module;
+extern const struct avro_value_module avro_record_module;
+extern const struct avro_value_module avro_field_module;
+extern const struct avro_value_module avro_enum_module;
+extern const struct avro_value_module avro_fixed_module;
+extern const struct avro_value_module avro_map_module;
+extern const struct avro_value_module avro_array_module;
+extern const struct avro_value_module avro_union_module;
+extern const struct avro_value_module avro_decorator_module;
+/* WARNING! This registry needs to match avro_type and avro_private_type enums! */
+const struct avro_value_module *avro_value_registry[AVRO_NUM_PRIVATE_TYPES] = {
+  &avro_string_module,
+  &avro_bytes_module,
+  &avro_int_module,
+  &avro_long_module,
+  &avro_float_module,
+  &avro_double_module,
+  &avro_boolean_module,
+  &avro_null_module,
+  &avro_record_module,
+  &avro_enum_module,
+  &avro_fixed_module,
+  &avro_map_module,
+  &avro_array_module,
+  &avro_union_module,
+  &avro_field_module,
+  &avro_decorator_module
 };
 
 /* TODO: gperf this? */
@@ -63,7 +63,7 @@
     {
       for (i = 0; i < AVRO_NUM_TYPES; i++)
 	{
-	  const struct avro_value_info *info = avro_value_registry[i];
+	  const struct avro_value_module *info = avro_value_registry[i];
 	  if (!info->private && wcscmp (info->name, name) == 0)
 	    {
 	      *type = info->type;
@@ -104,99 +104,6 @@
   return AVRO_FAILURE;
 }
 
-struct avro_decorator_value
-{
-  struct avro_value_ctx *ctx;
-  struct avro_value *decoratee;
-  struct avro_value base_value;
-};
-
-static void
-avro_decorator_print (struct avro_value *value, FILE * fp)
-{
-  struct avro_decorator_value *self =
-    container_of (value, struct avro_decorator_value, base_value);
-  avro_value_indent (value, fp);
-  fprintf (fp, "decorator(%p)\n", self);
-  avro_value_print_info (self->decoratee, fp);
-}
-
-static avro_status_t
-avro_decorator_read_skip (struct avro_value *value,
-			  struct avro_reader *reader, int skip)
-{
-  struct avro_decorator_value *self =
-    container_of (value, struct avro_decorator_value, base_value);
-  /* Create a new decoratee */
-  self->decoratee = avro_value_from_json (self->ctx, value, value->schema);
-  if (!self->decoratee)
-    {
-      return AVRO_FAILURE;
-    }
-  if (skip)
-    {
-      return avro_value_skip_data (self->decoratee, reader);
-    }
-  return avro_value_read_data (self->decoratee, reader);
-}
-
-static avro_status_t
-avro_decorator_read (struct avro_value *value, struct avro_reader *reader)
-{
-  return avro_decorator_read_skip (value, reader, 0);
-}
-
-static avro_status_t
-avro_decorator_skip (struct avro_value *value, struct avro_reader *reader)
-{
-  return avro_decorator_read_skip (value, reader, 1);
-}
-
-static avro_status_t
-avro_decorator_write (struct avro_value *value, struct avro_writer *writer)
-{
-  return AVRO_FAILURE;
-}
-
-/* Used for recursive schemas */
-struct avro_value *
-avro_decorator_create (struct avro_value_ctx *ctx, struct avro_value *parent,
-		       apr_pool_t * pool, const JSON_value * json)
-{
-  struct avro_decorator_value *self =
-    apr_palloc (pool, sizeof (struct avro_decorator_value));
-  DEBUG (fprintf (stderr, "Creating a decorator\n"));
-  if (!self)
-    {
-      return NULL;
-    }
-  /* Save away the context */
-  self->ctx = ctx;
-  self->base_value.type = AVRO_DECORATOR;
-  self->base_value.pool = pool;
-  self->base_value.parent = parent;
-  self->base_value.schema = json;
-  return &self->base_value;
-}
-
-const struct avro_value_info avro_decorator_info = {
-  .name = L"decorator",
-  .type = AVRO_DECORATOR,
-  .private = 1,
-  .create = avro_decorator_create,
-  .formats = {{
-	       .read_data = avro_decorator_read,
-	       .skip_data = avro_decorator_skip,
-	       .write_data = avro_decorator_write},
-	      {
-	       /* TODO: import/export */
-	       .read_data = avro_decorator_read,
-	       .skip_data = avro_decorator_skip,
-	       .write_data = avro_decorator_write}},
-  .print_info = avro_decorator_print
-};
-
-
 struct avro_value *
 avro_value_from_json (struct avro_value_ctx *ctx,
 		      struct avro_value *parent, const JSON_value * json)
@@ -304,3 +211,14 @@
     }
   avro_value_registry[value->type]->print_info (value, fp);
 }
+
+avro_status_t
+avro_value_type (avro_value value, avro_type_t * type)
+{
+  if (!value || !type)
+    {
+      return AVRO_FAILURE;
+    }
+  *type = value->type;
+  return AVRO_OK;
+}

Modified: hadoop/avro/trunk/src/c/datatypes/array.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/datatypes/array.c?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/datatypes/array.c (original)
+++ hadoop/avro/trunk/src/c/datatypes/array.c Sat Nov 14 07:09:01 2009
@@ -45,7 +45,8 @@
     {
       for (i = 0; i < self->values->nelts; i++)
 	{
-	  avro_value *item = ((avro_value **) self->values->elts)[i];
+	  struct avro_value *item =
+	    ((struct avro_value **) self->values->elts)[i];
 	  avro_value_print_info (item, fp);
 	}
     }
@@ -87,14 +88,15 @@
   apr_pool_clear (self->pool);
 
   self->values =
-    skip ? NULL : apr_array_make (self->pool, count, sizeof (avro_value *));
+    skip ? NULL : apr_array_make (self->pool, count,
+				  sizeof (struct avro_value *));
 
   while (count > 0)
     {
       /* Read in the count number of items */
       if (skip)
 	{
-	  avro_value *item =
+	  struct avro_value *item =
 	    avro_value_from_json (self->ctx, self->base_value.parent,
 				  self->item_schema);
 	  for (i = 0; i < count; i++)
@@ -110,7 +112,7 @@
 	{
 	  for (i = 0; i < count; i++)
 	    {
-	      avro_value *item =
+	      struct avro_value *item =
 		avro_value_from_json (self->ctx, self->base_value.parent,
 				      self->item_schema);
 	      if (!item)
@@ -123,7 +125,7 @@
 		  return status;
 		}
 	      /* Save the item */
-	      *(avro_value **) apr_array_push (self->values) = item;
+	      *(struct avro_value **) apr_array_push (self->values) = item;
 	    }
 	}
 
@@ -151,18 +153,54 @@
 static avro_status_t
 avro_array_write (struct avro_value *value, struct avro_writer *writer)
 {
-/* TODO
   struct avro_array_value *self =
     container_of (value, struct avro_array_value, base_value);
-*/
-  return AVRO_OK;
+  struct avro_io_writer *io;
+  avro_status_t status;
+  const avro_long_t zero = 0;
+
+  if (!writer)
+    {
+      return AVRO_FAILURE;
+    }
+  io = writer->io;
+  if (!io)
+    {
+      return AVRO_FAILURE;
+    }
+
+  if (self->values)
+    {
+      avro_long_t len = self->values->nelts;
+      if (len > 0)
+	{
+	  avro_long_t i;
+	  status = avro_write_long (io, &len);
+	  if (status != AVRO_OK)
+	    {
+	      return status;
+	    }
+	  for (i = 0; i < len; i++)
+	    {
+	      struct avro_value *value =
+		((struct avro_value **) self->values->elts)[i];
+	      status = avro_value_write_data (value, writer);
+	      if (status != AVRO_OK)
+		{
+		  return status;
+		}
+	    }
+	}
+    }
+  /* Zero terminate */
+  return avro_write_long (io, (avro_long_t *) & zero);
 }
 
 static struct avro_value *
 avro_array_create (struct avro_value_ctx *ctx, struct avro_value *parent,
 		   apr_pool_t * pool, const JSON_value * json)
 {
-  avro_value *value;
+  struct avro_value *value;
   struct avro_array_value *self;
   apr_pool_t *tmp_pool;
 
@@ -207,7 +245,7 @@
   return &self->base_value;
 }
 
-const struct avro_value_info avro_array_info = {
+const struct avro_value_module avro_array_module = {
   .name = L"array",
   .type = AVRO_ARRAY,
   .private = 0,

Modified: hadoop/avro/trunk/src/c/datatypes/boolean.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/datatypes/boolean.c?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/datatypes/boolean.c (original)
+++ hadoop/avro/trunk/src/c/datatypes/boolean.c Sat Nov 14 07:09:01 2009
@@ -128,7 +128,7 @@
   return &self->base_value;
 }
 
-const struct avro_value_info avro_boolean_info = {
+const struct avro_value_module avro_boolean_module = {
   .name = L"boolean",
   .type = AVRO_BOOLEAN,
   .private = 0,

Modified: hadoop/avro/trunk/src/c/datatypes/bytes.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/datatypes/bytes.c?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/datatypes/bytes.c (original)
+++ hadoop/avro/trunk/src/c/datatypes/bytes.c Sat Nov 14 07:09:01 2009
@@ -24,8 +24,8 @@
   void *value;
   int value_set;
   avro_long_t size;
-  avro_value base_value;
   apr_pool_t *pool;
+  struct avro_value base_value;
 };
 
 static void
@@ -38,7 +38,7 @@
   fprintf (fp, "bytes(%p)", self);
   if (self->value_set)
     {
-      fprintf (fp, " size=%ld ", self->size);
+      fprintf (fp, " size=%lld ", self->size);
       dump (fp, (char *) self->value, self->size);
     }
   fprintf (fp, "\n");
@@ -95,8 +95,28 @@
 static avro_status_t
 avro_bytes_write (struct avro_value *value, struct avro_writer *writer)
 {
-  /* TODO */
-  return AVRO_FAILURE;
+  struct avro_io_writer *io;
+  struct avro_bytes_value *self =
+    container_of (value, struct avro_bytes_value, base_value);
+  avro_status_t status;
+  avro_long_t size = self->size;
+
+  if (!writer)
+    {
+      return AVRO_FAILURE;
+    }
+  io = writer->io;
+  if (!io)
+    {
+      return AVRO_FAILURE;
+    }
+
+  status = avro_write_long (io, &size);
+  if (status != AVRO_OK)
+    {
+      return status;
+    }
+  return io->write (io, self->value, size);
 }
 
 static struct avro_value *
@@ -122,7 +142,7 @@
   return &self->base_value;
 }
 
-const struct avro_value_info avro_bytes_info = {
+const struct avro_value_module avro_bytes_module = {
   .name = L"bytes",
   .type = AVRO_BYTES,
   .private = 0,

Added: hadoop/avro/trunk/src/c/datatypes/decorator.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/datatypes/decorator.c?rev=836133&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/datatypes/decorator.c (added)
+++ hadoop/avro/trunk/src/c/datatypes/decorator.c Sat Nov 14 07:09:01 2009
@@ -0,0 +1,111 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+#include "avro_private.h"
+
+struct avro_decorator_value
+{
+  struct avro_value_ctx *ctx;
+  struct avro_value *decoratee;
+  struct avro_value base_value;
+};
+
+static void
+avro_decorator_print (struct avro_value *value, FILE * fp)
+{
+  struct avro_decorator_value *self =
+    container_of (value, struct avro_decorator_value, base_value);
+  avro_value_indent (value, fp);
+  fprintf (fp, "decorator(%p)\n", self);
+  avro_value_print_info (self->decoratee, fp);
+}
+
+static avro_status_t
+avro_decorator_read_skip (struct avro_value *value,
+			  struct avro_reader *reader, int skip)
+{
+  struct avro_decorator_value *self =
+    container_of (value, struct avro_decorator_value, base_value);
+  /* Create a new decoratee */
+  self->decoratee = avro_value_from_json (self->ctx, value, value->schema);
+  if (!self->decoratee)
+    {
+      return AVRO_FAILURE;
+    }
+  if (skip)
+    {
+      return avro_value_skip_data (self->decoratee, reader);
+    }
+  return avro_value_read_data (self->decoratee, reader);
+}
+
+static avro_status_t
+avro_decorator_read (struct avro_value *value, struct avro_reader *reader)
+{
+  return avro_decorator_read_skip (value, reader, 0);
+}
+
+static avro_status_t
+avro_decorator_skip (struct avro_value *value, struct avro_reader *reader)
+{
+  return avro_decorator_read_skip (value, reader, 1);
+}
+
+static avro_status_t
+avro_decorator_write (struct avro_value *value, struct avro_writer *writer)
+{
+  return AVRO_FAILURE;
+}
+
+/* Used for recursive schemas */
+struct avro_value *
+avro_decorator_create (struct avro_value_ctx *ctx, struct avro_value *parent,
+		       apr_pool_t * pool, const JSON_value * json)
+{
+  struct avro_decorator_value *self =
+    apr_palloc (pool, sizeof (struct avro_decorator_value));
+  DEBUG (fprintf (stderr, "Creating a decorator\n"));
+  if (!self)
+    {
+      return NULL;
+    }
+  /* Save away the context */
+  self->ctx = ctx;
+  self->base_value.type = AVRO_DECORATOR;
+  self->base_value.pool = pool;
+  self->base_value.parent = parent;
+  self->base_value.schema = json;
+  return &self->base_value;
+}
+
+const struct avro_value_module avro_decorator_module = {
+  .name = L"decorator",
+  .type = AVRO_DECORATOR,
+  .private = 1,
+  .create = avro_decorator_create,
+  .formats = {{
+	       .read_data = avro_decorator_read,
+	       .skip_data = avro_decorator_skip,
+	       .write_data = avro_decorator_write},
+	      {
+	       /* TODO: import/export */
+	       .read_data = avro_decorator_read,
+	       .skip_data = avro_decorator_skip,
+	       .write_data = avro_decorator_write}},
+  .print_info = avro_decorator_print
+};

Modified: hadoop/avro/trunk/src/c/datatypes/double.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/datatypes/double.c?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/datatypes/double.c (original)
+++ hadoop/avro/trunk/src/c/datatypes/double.c Sat Nov 14 07:09:01 2009
@@ -100,7 +100,7 @@
   return &self->base_value;
 }
 
-const struct avro_value_info avro_double_info = {
+const struct avro_value_module avro_double_module = {
   .name = L"double",
   .type = AVRO_DOUBLE,
   .private = 0,

Modified: hadoop/avro/trunk/src/c/datatypes/enum.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/datatypes/enum.c?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/datatypes/enum.c (original)
+++ hadoop/avro/trunk/src/c/datatypes/enum.c Sat Nov 14 07:09:01 2009
@@ -90,11 +90,25 @@
 static avro_status_t
 avro_enum_write (struct avro_value *value, struct avro_writer *writer)
 {
-/* TODO
+  struct avro_io_writer *io;
   struct avro_avro_enum *self =
     container_of (value, struct avro_avro_enum, base_value);
-*/
-  return AVRO_OK;
+
+  if (!writer)
+    {
+      return AVRO_FAILURE;
+    }
+  io = writer->io;
+  if (!io)
+    {
+      return AVRO_FAILURE;
+    }
+  if (!self->value_set)
+    {
+      return AVRO_FAILURE;
+    }
+  /* Write the offset */
+  return avro_write_long (io, &self->offset);
 }
 
 static struct avro_value *
@@ -150,7 +164,7 @@
   return &self->base_value;
 }
 
-const struct avro_value_info avro_enum_info = {
+const struct avro_value_module avro_enum_module = {
   .name = L"enum",
   .type = AVRO_ENUM,
   .private = 0,

Modified: hadoop/avro/trunk/src/c/datatypes/fixed.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/datatypes/fixed.c?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/datatypes/fixed.c (original)
+++ hadoop/avro/trunk/src/c/datatypes/fixed.c Sat Nov 14 07:09:01 2009
@@ -27,7 +27,7 @@
 
   int value_set;
 
-  avro_value base_value;
+  struct avro_value base_value;
 };
 
 static void
@@ -79,8 +79,20 @@
 static avro_status_t
 avro_fixed_write (struct avro_value *value, struct avro_writer *writer)
 {
-  /* TODO */
-  return AVRO_FAILURE;
+  struct avro_fixed_value *self =
+    container_of (value, struct avro_fixed_value, base_value);
+  struct avro_io_writer *io;
+
+  if (!writer)
+    {
+      return AVRO_FAILURE;
+    }
+  io = writer->io;
+  if (!io)
+    {
+      return AVRO_FAILURE;
+    }
+  return io->write (io, self->value, self->size);
 }
 
 static struct avro_value *
@@ -135,7 +147,7 @@
   return &self->base_value;
 }
 
-const struct avro_value_info avro_fixed_info = {
+const struct avro_value_module avro_fixed_module = {
   .name = L"fixed",
   .type = AVRO_FIXED,
   .private = 0,

Modified: hadoop/avro/trunk/src/c/datatypes/float.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/datatypes/float.c?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/datatypes/float.c (original)
+++ hadoop/avro/trunk/src/c/datatypes/float.c Sat Nov 14 07:09:01 2009
@@ -100,7 +100,7 @@
   return &self->base_value;
 }
 
-const struct avro_value_info avro_float_info = {
+const struct avro_value_module avro_float_module = {
   .name = L"float",
   .type = AVRO_FLOAT,
   .private = 0,

Modified: hadoop/avro/trunk/src/c/datatypes/int.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/datatypes/int.c?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/datatypes/int.c (original)
+++ hadoop/avro/trunk/src/c/datatypes/int.c Sat Nov 14 07:09:01 2009
@@ -108,7 +108,7 @@
   return &self->base_value;
 }
 
-const struct avro_value_info avro_int_info = {
+const struct avro_value_module avro_int_module = {
   .name = L"int",
   .type = AVRO_INT,
   .private = 0,

Modified: hadoop/avro/trunk/src/c/datatypes/long.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/datatypes/long.c?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/datatypes/long.c (original)
+++ hadoop/avro/trunk/src/c/datatypes/long.c Sat Nov 14 07:09:01 2009
@@ -108,7 +108,7 @@
   return &self->base_value;
 }
 
-const struct avro_value_info avro_long_info = {
+const struct avro_value_module avro_long_module = {
   .name = L"long",
   .type = AVRO_LONG,
   .private = 0,

Modified: hadoop/avro/trunk/src/c/datatypes/map.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/datatypes/map.c?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/datatypes/map.c (original)
+++ hadoop/avro/trunk/src/c/datatypes/map.c Sat Nov 14 07:09:01 2009
@@ -51,8 +51,8 @@
       for (i = 0, hi = apr_hash_first (subpool, self->map); hi;
 	   hi = apr_hash_next (hi), i++)
 	{
-	  avro_value *key;
-	  avro_value *value;
+	  struct avro_value *key;
+	  struct avro_value *value;
 	  apr_hash_this (hi, (void *) &key, &len, (void *) &value);
 	  avro_value_print_info (key, fp);
 	  avro_value_print_info (value, fp);
@@ -95,10 +95,10 @@
     {
       for (i = 0; i < count; i++)
 	{
-	  avro_value *key =
+	  struct avro_value *key =
 	    avro_value_from_json (self->ctx, self->base_value.parent,
 				  self->key_schema);
-	  avro_value *value =
+	  struct avro_value *value =
 	    avro_value_from_json (self->ctx, self->base_value.parent,
 				  self->value_schema);
 	  if (!key || !value)
@@ -143,8 +143,56 @@
 static avro_status_t
 avro_map_write (struct avro_value *value, struct avro_writer *writer)
 {
-  /* TODO */
-  return AVRO_FAILURE;
+  struct avro_map_value *self =
+    container_of (value, struct avro_map_value, base_value);
+  struct avro_io_writer *io;
+  const avro_long_t zero = 0;
+  avro_status_t status;
+  avro_long_t count;
+
+  if (!writer)
+    {
+      return AVRO_FAILURE;
+    }
+  io = writer->io;
+  if (!io)
+    {
+      return AVRO_FAILURE;
+    }
+
+  if (self->map)
+    {
+      apr_hash_index_t *hi;
+      count = apr_hash_count (self->map);
+      if (count)
+	{
+	  status = avro_write_long (io, (avro_long_t *) & count);
+	  if (status != AVRO_OK)
+	    {
+	      return status;
+	    }
+	  hi = apr_hash_first (value->pool, self->map);
+	  for (; hi; hi = apr_hash_next (hi))
+	    {
+	      apr_ssize_t len;
+	      struct avro_value *key;
+	      struct avro_value *val;
+	      apr_hash_this (hi, (void *) &key, &len, (void *) &val);
+	      status = avro_value_write_data (key, writer);
+	      if (status != AVRO_OK)
+		{
+		  return status;
+		}
+	      status = avro_value_write_data (val, writer);
+	      if (status != AVRO_OK)
+		{
+		  return status;
+		}
+	    }
+	}
+    }
+  /* Zero terminate */
+  return avro_write_long (io, (avro_long_t *) & zero);
 }
 
 static struct avro_value *
@@ -152,7 +200,7 @@
 		 apr_pool_t * pool, const JSON_value * json)
 {
   struct avro_map_value *self;
-  avro_value *value;
+  struct avro_value *value;
   apr_pool_t *tmp_pool;
 
   DEBUG (fprintf (stderr, "Creating map\n"));
@@ -199,7 +247,7 @@
   return &self->base_value;
 }
 
-const struct avro_value_info avro_map_info = {
+const struct avro_value_module avro_map_module = {
   .name = L"map",
   .type = AVRO_MAP,
   .private = 0,

Modified: hadoop/avro/trunk/src/c/datatypes/null.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/datatypes/null.c?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/datatypes/null.c (original)
+++ hadoop/avro/trunk/src/c/datatypes/null.c Sat Nov 14 07:09:01 2009
@@ -54,7 +54,7 @@
   return self;
 }
 
-const struct avro_value_info avro_null_info = {
+const struct avro_value_module avro_null_module = {
   .name = L"null",
   .type = AVRO_NULL,
   .private = 0,

Modified: hadoop/avro/trunk/src/c/datatypes/record.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/datatypes/record.c?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/datatypes/record.c (original)
+++ hadoop/avro/trunk/src/c/datatypes/record.c Sat Nov 14 07:09:01 2009
@@ -24,7 +24,7 @@
   struct avro_value *value;
   struct avro_value *default_value;
 
-  avro_value base_value;
+  struct avro_value base_value;
 };
 
 struct avro_record_value
@@ -33,7 +33,7 @@
   avro_string_t space;
   apr_array_header_t *fields;
 
-  avro_value base_value;
+  struct avro_value base_value;
 };
 
 static void
@@ -277,7 +277,7 @@
   return &self->base_value;
 }
 
-const struct avro_value_info avro_field_info = {
+const struct avro_value_module avro_field_module = {
   .name = L"field",
   .type = AVRO_FIELD,
   .private = 1,
@@ -294,7 +294,7 @@
   .print_info = avro_field_print
 };
 
-const struct avro_value_info avro_record_info = {
+const struct avro_value_module avro_record_module = {
   .name = L"record",
   .type = AVRO_RECORD,
   .private = 0,

Modified: hadoop/avro/trunk/src/c/datatypes/string.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/datatypes/string.c?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/datatypes/string.c (original)
+++ hadoop/avro/trunk/src/c/datatypes/string.c Sat Nov 14 07:09:01 2009
@@ -132,7 +132,7 @@
   return &self->base_value;
 }
 
-const struct avro_value_info avro_string_info = {
+const struct avro_value_module avro_string_module = {
   .name = L"string",
   .type = AVRO_STRING,
   .private = 0,

Modified: hadoop/avro/trunk/src/c/datatypes/union.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/datatypes/union.c?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/datatypes/union.c (original)
+++ hadoop/avro/trunk/src/c/datatypes/union.c Sat Nov 14 07:09:01 2009
@@ -43,7 +43,7 @@
   struct avro_union_value *self =
     container_of (value, struct avro_union_value, base_value);
   struct avro_io_reader *io;
-  avro_value *requested_value;
+  struct avro_value *requested_value;
 
   io = reader->io;
   if (!io)
@@ -62,7 +62,8 @@
       return AVRO_FAILURE;
     }
 
-  requested_value = ((avro_value **) self->schemas->elts)[self->value_index];
+  requested_value =
+    ((struct avro_value **) self->schemas->elts)[self->value_index];
   if (!requested_value)
     {
       return AVRO_FAILURE;
@@ -96,15 +97,44 @@
 static avro_status_t
 avro_union_write (struct avro_value *value, struct avro_writer *writer)
 {
-  /* TODO */
-  return AVRO_FAILURE;
+  avro_status_t status;
+  struct avro_union_value *self =
+    container_of (value, struct avro_union_value, base_value);
+  struct avro_io_writer *io;
+  struct avro_value *requested_value;
+
+  io = writer->io;
+  if (!io)
+    {
+      return AVRO_FAILURE;
+    }
+
+  if (!self->value_set)
+    {
+      return AVRO_FAILURE;
+    }
+
+  status = avro_write_long (io, &self->value_index);
+  if (status != AVRO_OK)
+    {
+      return status;
+    }
+
+  requested_value =
+    ((struct avro_value **) self->schemas->elts)[self->value_index];
+  if (!requested_value)
+    {
+      return AVRO_FAILURE;
+    }
+
+  return avro_value_write_data (requested_value, writer);
 }
 
 static struct avro_value *
 avro_union_create (struct avro_value_ctx *ctx, struct avro_value *parent,
 		   apr_pool_t * pool, const JSON_value * json)
 {
-  avro_value *value;
+  struct avro_value *value;
   struct avro_union_value *self;
   int i;
 
@@ -125,7 +155,8 @@
   self->base_value.schema = json;
 
   self->schemas =
-    apr_array_make (pool, json->json_array->nelts, sizeof (avro_value *));
+    apr_array_make (pool, json->json_array->nelts,
+		    sizeof (struct avro_value *));
   if (!self->schemas)
     {
       return NULL;
@@ -140,13 +171,13 @@
 	  /* Invalid union schema */
 	  return NULL;
 	}
-      *(avro_value **) apr_array_push (self->schemas) = value;
+      *(struct avro_value **) apr_array_push (self->schemas) = value;
     }
   self->value_set = 0;
   return &self->base_value;
 }
 
-const struct avro_value_info avro_union_info = {
+const struct avro_value_module avro_union_module = {
   .name = L"union",
   .type = AVRO_UNION,
   .private = 0,

Modified: hadoop/avro/trunk/src/c/version.sh
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/version.sh?rev=836133&r1=836132&r2=836133&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/version.sh (original)
+++ hadoop/avro/trunk/src/c/version.sh Sat Nov 14 07:09:01 2009
@@ -18,9 +18,9 @@
 #         libavro_binary_age = 0
 #         libavro_interface_age = 0
 #
-libavro_micro_version=1
-libavro_interface_age=1
-libavro_binary_age=1
+libavro_micro_version=2
+libavro_interface_age=0
+libavro_binary_age=2
 
 # IGNORE EVERYTHING ELSE FROM HERE DOWN.........
 if test $# != 1; then



Mime
View raw message