You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by jm...@apache.org on 2010/06/04 07:38:06 UTC

svn commit: r951282 - 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

Author: jmhodges
Date: Fri Jun  4 05:38:06 2010
New Revision: 951282

URL: http://svn.apache.org/viewvc?rev=951282&view=rev
Log:
AVRO-543. Schema comparison is hella slow on the Ruby side. merge from trunk

Modified:
    avro/branches/branch-1.3/   (props changed)
    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

Propchange: avro/branches/branch-1.3/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jun  4 05:38:06 2010
@@ -1,2 +1,2 @@
-/avro/trunk:944035,944049
+/avro/trunk:944035,944049,946466
 /hadoop/avro/trunk:930458-930459,930461-930462,930599,931026-931027,931437,933158,933180-933181,933184,935526,938347,938577,941168

Modified: avro/branches/branch-1.3/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.3/CHANGES.txt?rev=951282&r1=951281&r2=951282&view=diff
==============================================================================
--- avro/branches/branch-1.3/CHANGES.txt (original)
+++ avro/branches/branch-1.3/CHANGES.txt Fri Jun  4 05:38:06 2010
@@ -27,6 +27,8 @@ Avro 1.3.3 (Unreleased)
 
     AVRO-511. Ruby implementation passes the rpc interop tests.
 
+    AVRO-543. Schema comparison is hella slow on the Ruby side. (jmhodges)
+
   BUG FIXES
     AVRO-461. Skipping primitives in the ruby side (jmhodges)
 

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=951282&r1=951281&r2=951282&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 Fri Jun  4 05:38:06 2010
@@ -221,7 +221,7 @@ module Avro
     class DatumReader
       def self.check_props(schema_one, schema_two, prop_list)
         prop_list.all? do |prop|
-          schema_one.to_hash[prop] == schema_two.to_hash[prop]
+          schema_one.send(prop) == schema_two.send(prop)
         end
       end
 
@@ -230,33 +230,34 @@ module Avro
         r_type = readers_schema.type
 
         # This conditional is begging for some OO love.
-        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'])
+        if w_type == 'union' || r_type == 'union'
           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
         if w_type == 'int' && ['long', 'float', 'double'].include?(r_type)
           return true

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=951282&r1=951281&r2=951282&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 Fri Jun  4 05:38:06 2010
@@ -57,11 +57,11 @@ module Avro
     end
 
     def to_s
-      Yajl.dump to_hash
+      Yajl.dump to_avro
     end
 
     def ==(other)
-      to_hash == Yajl.load(other.to_s)
+      to_avro == other.to_avro
     end
 
     private
@@ -96,13 +96,14 @@ module Avro
       message_objects
     end
 
-    def to_hash
+    protected
+    def to_avro
       hsh = {'protocol' => name}
       hsh['namespace'] = namespace if namespace
-      hsh['types'] = types.map{|t| Yajl.load(t.to_s) } if types
+      hsh['types'] = types.map{|t| t.to_avro } if types
 
       if messages
-        hsh['messages'] = messages.collect_hash{|k,t| [k, Yajl.load(t.to_s)] }
+        hsh['messages'] = messages.collect_hash{|k,t| [k, t.to_avro] }
       end
 
       hsh
@@ -119,18 +120,22 @@ module Avro
         @errors = parse_errors(errors, names) if errors
       end
 
-      def to_s
-        hsh = {'request' => Yajl.load(request.to_s)}
+      def to_avro
+        hsh = {'request' => request.to_avro}
         if response_from_names
           hsh['response'] = response.fullname
         else
-          hsh['response'] = Yajl.load(response.to_s)
+          hsh['response'] = response.to_avro
         end
 
         if errors
-          hsh['errors'] = Yajl.load(errors.to_s)
+          hsh['errors'] = errors.to_avro
         end
-        Yajl.dump hsh
+        hsh
+      end
+
+      def to_s
+        Yajl.dump to_avro
       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=951282&r1=951281&r2=951282&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 Fri Jun  4 05:38:06 2010
@@ -138,12 +138,12 @@ module Avro
       end
     end
 
-    def to_hash
+    def to_avro
       {'type' => @type}
     end
 
     def to_s
-      Yajl.dump to_hash
+      Yajl.dump to_avro
     end
 
     class NamedSchema < Schema
@@ -154,7 +154,7 @@ module Avro
         names = Name.add_name(names, self)
       end
 
-      def to_hash
+      def to_avro
         props = {'name' => @name}
         props.merge!('namespace' => @namespace) if @namespace
         super.merge props
@@ -203,8 +203,8 @@ module Avro
         fields.inject({}){|hsh, field| hsh[field.name] = field; hsh }
       end
 
-      def to_hash
-        hsh = super.merge('fields' => @fields.map {|f|Yajl.load(f.to_s)} )
+      def to_avro
+        hsh = super.merge('fields' => @fields.map {|f| f.to_avro } )
         if type == 'request'
           hsh['fields']
         else
@@ -228,11 +228,11 @@ module Avro
         end
       end
 
-      def to_hash
+      def to_avro
         name_or_json = if items_schema_from_names
                          items.fullname
                        else
-                         Yajl.load(items.to_s)
+                         items.to_avro
                        end
         super.merge('items' => name_or_json)
       end
@@ -253,12 +253,12 @@ module Avro
         @values = values_schema
       end
 
-      def to_hash
+      def to_avro
         to_dump = super
         if values_schema_from_names
           to_dump['values'] = values
         else
-          to_dump['values'] = Yajl.load(values.to_s)
+          to_dump['values'] = values.to_avro
         end
         to_dump
       end
@@ -295,7 +295,7 @@ module Avro
         end
       end
 
-      def to_s
+      def to_avro
         # FIXME(jmhodges) this from_name pattern is really weird and
         # seems code-smelly.
         to_dump = []
@@ -303,10 +303,10 @@ module Avro
           if schema_from_names_indices.include?(i)
             to_dump << schema.fullname
           else
-            to_dump << Yajl.load(schema.to_s)
+            to_dump << schema.to_avro
           end
         end
-        Yajl.dump(to_dump)
+        to_dump
       end
     end
 
@@ -321,7 +321,7 @@ module Avro
         @symbols = symbols
       end
 
-      def to_hash
+      def to_avro
         super.merge('symbols' => symbols)
       end
     end
@@ -336,8 +336,9 @@ module Avro
         super(type)
       end
 
-      def to_s
-        to_hash.size == 1 ? type.inspect : Yajl.dump(to_hash)
+      def to_avro
+        hsh = super
+        hsh.size == 1 ? type : hsh
       end
     end
 
@@ -352,7 +353,7 @@ module Avro
         @size = size
       end
 
-      def to_hash
+      def to_avro
         super.merge('size' => @size)
       end
     end
@@ -373,8 +374,8 @@ module Avro
         @order = order
       end
 
-      def to_hash
-        sigh_type = type_from_names ? type.fullname : Yajl.load(type.to_s)
+      def to_avro
+        sigh_type = type_from_names ? type.fullname : type.to_avro
         hsh = {
           'name' => name,
           'type' => sigh_type
@@ -383,10 +384,6 @@ module Avro
         hsh['order'] = order if order
         hsh
       end
-
-      def to_s
-        Yajl.dump(to_hash)
-      end
     end
   end