[prev in list] [next in list] [prev in thread] [next in thread]
List: avro-commits
Subject: svn commit: r946466 - in /avro/trunk: CHANGES.txt lang/ruby/lib/avro/io.rb lang/ruby/lib/avro/protoc
From: jmhodges () apache ! org
Date: 2010-05-19 22:30:12
Message-ID: 20100519223012.1C341238897D () eris ! apache ! org
[Download RAW message or body]
Author: jmhodges
Date: Wed May 19 22:30:11 2010
New Revision: 946466
URL: http://svn.apache.org/viewvc?rev=946466&view=rev
Log:
AVRO-543. Schema comparison is hella slow on the Ruby side.
Modified:
avro/trunk/CHANGES.txt
avro/trunk/lang/ruby/lib/avro/io.rb
avro/trunk/lang/ruby/lib/avro/protocol.rb
avro/trunk/lang/ruby/lib/avro/schema.rb
Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=946466&r1=946465&r2=946466&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed May 19 22:30:11 2010
@@ -40,6 +40,8 @@ Avro 1.4.0 (unreleased)
AVRO-540. Java: Make GenericArray reversible. (Eric Evans via cutting)
+ 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/trunk/lang/ruby/lib/avro/io.rb
URL: http://svn.apache.org/viewvc/avro/trunk/lang/ruby/lib/avro/io.rb?rev=946466&r1=946465&r2=946466&view=diff
==============================================================================
--- avro/trunk/lang/ruby/lib/avro/io.rb (original)
+++ avro/trunk/lang/ruby/lib/avro/io.rb Wed May 19 22:30:11 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/trunk/lang/ruby/lib/avro/protocol.rb
URL: http://svn.apache.org/viewvc/avro/trunk/lang/ruby/lib/avro/protocol.rb?rev=946466&r1=946465&r2=946466&view=diff
==============================================================================
--- avro/trunk/lang/ruby/lib/avro/protocol.rb (original)
+++ avro/trunk/lang/ruby/lib/avro/protocol.rb Wed May 19 22:30:11 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/trunk/lang/ruby/lib/avro/schema.rb
URL: http://svn.apache.org/viewvc/avro/trunk/lang/ruby/lib/avro/schema.rb?rev=946466&r1=946465&r2=946466&view=diff
==============================================================================
--- avro/trunk/lang/ruby/lib/avro/schema.rb (original)
+++ avro/trunk/lang/ruby/lib/avro/schema.rb Wed May 19 22:30:11 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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic