avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmhod...@apache.org
Subject svn commit: r946459 - in /avro/branches/branch-1.3: CHANGES.txt lang/ruby/lib/avro/io.rb lang/ruby/lib/avro/protocol.rb lang/ruby/lib/avro/schema.rb
Date Wed, 19 May 2010 22:13:20 GMT
Author: jmhodges
Date: Wed May 19 22:13:20 2010
New Revision: 946459

URL: http://svn.apache.org/viewvc?rev=946459&view=rev
Log:
Revert "AVRO-543. Schema comparison is hella slow on the Ruby side."

This reverts commit 17f96d9aa9175813ef051207befef5d2c1e5f17b.

Modified:
    avro/branches/branch-1.3/CHANGES.txt
    avro/branches/branch-1.3/lang/ruby/lib/avro/io.rb
    avro/branches/branch-1.3/lang/ruby/lib/avro/protocol.rb
    avro/branches/branch-1.3/lang/ruby/lib/avro/schema.rb

Modified: avro/branches/branch-1.3/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.3/CHANGES.txt?rev=946459&r1=946458&r2=946459&view=diff
==============================================================================
--- avro/branches/branch-1.3/CHANGES.txt (original)
+++ avro/branches/branch-1.3/CHANGES.txt Wed May 19 22:13:20 2010
@@ -22,8 +22,6 @@ Avro 1.3.2 (31 March 2010)
 
     AVRO-490. Add Ant task to deploy Java artifacts to Maven repo. (cutting)
 
-    AVRO-543. Schema comparison is hella slow on the Ruby side. (jmhodges)
-
   BUG FIXES
 
     AVRO-479. Fix 'sign' target in top-level build.sh to generate md5

Modified: avro/branches/branch-1.3/lang/ruby/lib/avro/io.rb
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.3/lang/ruby/lib/avro/io.rb?rev=946459&r1=946458&r2=946459&view=diff
==============================================================================
--- avro/branches/branch-1.3/lang/ruby/lib/avro/io.rb (original)
+++ avro/branches/branch-1.3/lang/ruby/lib/avro/io.rb Wed May 19 22:13:20 2010
@@ -247,7 +247,7 @@ module Avro
     class DatumReader
       def self.check_props(schema_one, schema_two, prop_list)
         prop_list.all? do |prop|
-          schema_one.send(prop) == schema_two.send(prop)
+          schema_one.to_hash[prop] == schema_two.to_hash[prop]
         end
       end
 
@@ -256,32 +256,31 @@ module Avro
         r_type = readers_schema.type
 
         # This conditional is begging for some OO love.
-        if w_type == 'union' || r_type == 'union'
+        if [w_type, r_type].include? 'union'
+          return true
+        elsif Schema::PRIMITIVE_TYPES.include?(w_type) &&
+              Schema::PRIMITIVE_TYPES.include?(r_type) &&
+            w_type == r_type
+          return true
+        elsif (w_type == r_type) && (r_type == 'record') &&
+            check_props(writers_schema, readers_schema, ['fullname'])
+          return true
+        elsif w_type == r_type && r_type == 'error' && check_props(writers_scheam,
readers_schema, ['fullname'])
+          return true
+        elsif w_type == r_type && r_type == 'request'
+          return true
+        elsif (w_type == r_type) && (r_type == 'fixed') &&
+            check_props(writers_schema, readers_schema, ['fullname', 'size'])
+          return true
+        elsif (w_type == r_type) && (r_type == 'enum') &&
+            check_props(writers_schema, readers_schema, ['fullname'])
+          return true
+        elsif (w_type == r_type) && (r_type == 'map') &&
+            check_props(writers_schema.values, readers_schema.values, ['type'])
+          return true
+        elsif (w_type == r_type) && (r_type == 'array') &&
+            check_props(writers_schema.items, readers_schema.items, ['type'])
           return true
-        end
-
-        if w_type == r_type
-          if Schema::PRIMITIVE_TYPES.include?(w_type) &&
-              Schema::PRIMITIVE_TYPES.include?(r_type)
-            return true
-          end
-
-          case r_type
-          when 'record'
-            return check_props(writers_schema, readers_schema, [:fullname])
-          when 'error'
-            return check_props(writers_scheam, readers_schema, [:fullname])
-          when 'request'
-            return true
-          when 'fixed'
-            return check_props(writers_schema, readers_schema, [:fullname, :size])
-          when 'enum'
-            return check_props(writers_schema, readers_schema, [:fullname])
-          when 'map'
-            return check_props(writers_schema.values, readers_schema.values, [:type])
-          when 'array'
-            return check_props(writers_schema.items, readers_schema.items, [:type])
-          end
         end
 
         # Handle schema promotion

Modified: avro/branches/branch-1.3/lang/ruby/lib/avro/protocol.rb
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.3/lang/ruby/lib/avro/protocol.rb?rev=946459&r1=946458&r2=946459&view=diff
==============================================================================
--- avro/branches/branch-1.3/lang/ruby/lib/avro/protocol.rb (original)
+++ avro/branches/branch-1.3/lang/ruby/lib/avro/protocol.rb Wed May 19 22:13:20 2010
@@ -57,11 +57,11 @@ module Avro
     end
 
     def to_s
-      Yajl.dump to_avro
+      Yajl.dump to_hash
     end
 
     def ==(other)
-      to_avro == other.to_avro
+      to_hash == Yajl.load(other.to_s)
     end
 
     private
@@ -96,14 +96,13 @@ module Avro
       message_objects
     end
 
-    protected
-    def to_avro
+    def to_hash
       hsh = {'protocol' => name}
       hsh['namespace'] = namespace if namespace
-      hsh['types'] = types.map{|t| t.to_avro } if types
+      hsh['types'] = types.map{|t| Yajl.load(t.to_s) } if types
 
       if messages
-        hsh['messages'] = messages.collect_hash{|k,t| [k, t.to_avro] }
+        hsh['messages'] = messages.collect_hash{|k,t| [k, Yajl.load(t.to_s)] }
       end
 
       hsh
@@ -120,22 +119,18 @@ module Avro
         @errors = parse_errors(errors, names) if errors
       end
 
-      def to_avro
-        hsh = {'request' => request.to_avro}
+      def to_s
+        hsh = {'request' => Yajl.load(request.to_s)}
         if response_from_names
           hsh['response'] = response.fullname
         else
-          hsh['response'] = response.to_avro
+          hsh['response'] = Yajl.load(response.to_s)
         end
 
         if errors
-          hsh['errors'] = errors.to_avro
+          hsh['errors'] = Yajl.load(errors.to_s)
         end
-        hsh
-      end
-
-      def to_s
-        Yajl.dump to_avro
+        Yajl.dump hsh
       end
 
       def parse_request(request, names)

Modified: avro/branches/branch-1.3/lang/ruby/lib/avro/schema.rb
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.3/lang/ruby/lib/avro/schema.rb?rev=946459&r1=946458&r2=946459&view=diff
==============================================================================
--- avro/branches/branch-1.3/lang/ruby/lib/avro/schema.rb (original)
+++ avro/branches/branch-1.3/lang/ruby/lib/avro/schema.rb Wed May 19 22:13:20 2010
@@ -129,12 +129,12 @@ module Avro
       @type.hash
     end
 
-    def to_avro
+    def to_hash
       {'type' => @type}
     end
 
     def to_s
-      Yajl.dump to_avro
+      Yajl.dump to_hash
     end
 
     class NamedSchema < Schema
@@ -145,7 +145,7 @@ module Avro
         names = Name.add_name(names, self)
       end
 
-      def to_avro
+      def to_hash
         props = {'name' => @name}
         props.merge!('namespace' => @namespace) if @namespace
         super.merge props
@@ -194,8 +194,8 @@ module Avro
         fields.inject({}){|hsh, field| hsh[field.name] = field; hsh }
       end
 
-      def to_avro
-        hsh = super.merge('fields' => @fields.map {|f| f.to_avro } )
+      def to_hash
+        hsh = super.merge('fields' => @fields.map {|f|Yajl.load(f.to_s)} )
         if type == 'request'
           hsh['fields']
         else
@@ -224,11 +224,11 @@ module Avro
         end
       end
 
-      def to_avro
+      def to_hash
         name_or_json = if items_schema_from_names
                          items.fullname
                        else
-                         items.to_avro
+                         Yajl.load(items.to_s)
                        end
         super.merge('items' => name_or_json)
       end
@@ -253,12 +253,12 @@ module Avro
         @values = values_schema
       end
 
-      def to_avro
+      def to_hash
         to_dump = super
         if values_schema_from_names
           to_dump['values'] = values
         else
-          to_dump['values'] = values.to_avro
+          to_dump['values'] = Yajl.load(values.to_s)
         end
         to_dump
       end
@@ -299,7 +299,7 @@ module Avro
         end
       end
 
-      def to_avro
+      def to_s
         # FIXME(jmhodges) this from_name pattern is really weird and
         # seems code-smelly.
         to_dump = []
@@ -307,10 +307,10 @@ module Avro
           if schema_from_names_indices.include?(i)
             to_dump << schema.fullname
           else
-            to_dump << schema.to_avro
+            to_dump << Yajl.load(schema.to_s)
           end
         end
-        to_dump
+        Yajl.dump(to_dump)
       end
     end
 
@@ -325,7 +325,7 @@ module Avro
         @symbols = symbols
       end
 
-      def to_avro
+      def to_hash
         super.merge('symbols' => symbols)
       end
     end
@@ -340,9 +340,8 @@ module Avro
         super(type)
       end
 
-      def to_avro
-        hsh = super
-        hsh.size == 1 ? type : hsh
+      def to_s
+        to_hash.size == 1 ? type.inspect : Yajl.dump(to_hash)
       end
     end
 
@@ -357,7 +356,7 @@ module Avro
         @size = size
       end
 
-      def to_avro
+      def to_hash
         super.merge('size' => @size)
       end
     end
@@ -378,8 +377,8 @@ module Avro
         @order = order
       end
 
-      def to_avro
-        sigh_type = type_from_names ? type.fullname : type.to_avro
+      def to_hash
+        sigh_type = type_from_names ? type.fullname : Yajl.load(type.to_s)
         hsh = {
           'name' => name,
           'type' => sigh_type
@@ -388,6 +387,10 @@ module Avro
         hsh['order'] = order if order
         hsh
       end
+
+      def to_s
+        Yajl.dump(to_hash)
+      end
     end
   end
 



Mime
View raw message