avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmhod...@apache.org
Subject svn commit: r946457 - 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:12:30 GMT
Author: jmhodges
Date: Wed May 19 22:12:30 2010
New Revision: 946457

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

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=946457&r1=946456&r2=946457&view=diff
==============================================================================
--- avro/branches/branch-1.3/CHANGES.txt (original)
+++ avro/branches/branch-1.3/CHANGES.txt Wed May 19 22:12:30 2010
@@ -22,6 +22,8 @@ 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=946457&r1=946456&r2=946457&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:12:30 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.to_hash[prop] == schema_two.to_hash[prop]
+          schema_one.send(prop) == schema_two.send(prop)
         end
       end
 
@@ -256,33 +256,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=946457&r1=946456&r2=946457&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:12:30 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=946457&r1=946456&r2=946457&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:12:30 2010
@@ -129,12 +129,12 @@ module Avro
       @type.hash
     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
@@ -145,7 +145,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
@@ -194,8 +194,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
@@ -224,11 +224,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
@@ -299,7 +299,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 = []
@@ -307,10 +307,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
 
@@ -325,7 +325,7 @@ module Avro
         @symbols = symbols
       end
 
-      def to_hash
+      def to_avro
         super.merge('symbols' => symbols)
       end
     end
@@ -340,8 +340,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
 
@@ -356,7 +357,7 @@ module Avro
         @size = size
       end
 
-      def to_hash
+      def to_avro
         super.merge('size' => @size)
       end
     end
@@ -377,8 +378,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
@@ -387,10 +388,6 @@ module Avro
         hsh['order'] = order if order
         hsh
       end
-
-      def to_s
-        Yajl.dump(to_hash)
-      end
     end
   end
 



Mime
View raw message