Skip to content

Instantly share code, notes, and snippets.

@umdstu
Created April 10, 2017 13:44
Show Gist options
  • Save umdstu/ad49cba13bd79e1b856ea163554f588c to your computer and use it in GitHub Desktop.
Save umdstu/ad49cba13bd79e1b856ea163554f588c to your computer and use it in GitHub Desktop.
require "avro_turf"
avro = AvroTurf.new(schemas_path: ".")
=> #<AvroTurf:0x007fa44a9e72d0 @namespace=nil, @schema_store=#<AvroTurf::SchemaStore:0x007fa44a9e7258 @path=".", @schemas={}>, @codec=nil>
avro.encode({ "full_name" => "Jane", "age" => "28" }, schema_name: "person")
=> "Obj\u0001\u0004\u0014avro.codec\bnull\u0016avro.schema\xE0\u0001{\"type\":\"record\",\"name\":\"person\",\"fields\":[{\"name\":\"full_name\",\"type\":\"string\"},{\"name\":\"age\",\"type\":\"string\"}]}\u0000M\xAF\xB4\xF5%J\x83[\a\xFC{\u0013?)A\xB9\u0002\u0010\bJane\u000428M\xAF\xB4\xF5%J\x83[\a\xFC{\u0013?)A\xB9"
#
#after adding "namespace" value
#
avro.encode({ "full_name" => "Jane", "age" => "28" }, schema_name: "person")
AvroTurf::SchemaError: expected schema `./person.avsc' to define type `person'
from /Users/capollo/.rvm/gems/ruby-2.2.5@rails5/gems/avro_turf-0.8.0/lib/avro_turf/schema_store.rb:23:in `find'
from /Users/capollo/.rvm/gems/ruby-2.2.5@rails5/gems/avro_turf-0.8.0/lib/avro_turf.rb:51:in `encode_to_stream'
from /Users/capollo/.rvm/gems/ruby-2.2.5@rails5/gems/avro_turf-0.8.0/lib/avro_turf.rb:37:in `encode'
from (irb):4
from /Users/capollo/.rvm/rubies/ruby-2.2.5/bin/irb:11:in `<main>'
{
"name": "person",
"type": "record",
"namespace": "avro.person.tree",
"fields": [
{
"name": "full_name",
"type": "string"
},
{
"name": "age",
"type": "string"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment