avro_turf 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4973e043a05b5317719217586f8cee3b9f913d1a
4
- data.tar.gz: fb36f804b15c0bed61161d7b73242b7cb0a4cd83
3
+ metadata.gz: 0df3c290be95bcafd27a4473ba75df36a5275a6b
4
+ data.tar.gz: 17e1a0283f0479c60a691d3c52e33fb8eaf3f30c
5
5
  SHA512:
6
- metadata.gz: 234fa5e60fa5d41ead791b6f48c0db08b2ae02a53848b0fbd31dcf13ee07610800c8407a760e86b9329da3f0b0a2d96ea6c44768f7db9438e18aebe72a3f7ab6
7
- data.tar.gz: deaa4c2afa94cabe4d50070d17c3cd455623461d1fb91397e2ed0a2ff473df9892e409836efe7e4bc13d55658de6b340955c1342a8251bee1a52aef2b8d875cb
6
+ metadata.gz: 7df0d445557d08c28a9a6e0357dea7b76159846ab3f3e456b1200e4a28c84bb1853727d4259bcf94432567f8031cfb34e80b30963b5fb1e1f43fff5ce0a52e1e
7
+ data.tar.gz: 144873d0859cb6c937898b94ca3649dca34284b9fa16ebaa122244faef4c20d838c871ab51ecf91c9c69d803d84fd55215867544ac57d5283a86b18fbc8ffc9f
data/README.md CHANGED
@@ -99,7 +99,7 @@ By default, AvroTurf will encode data in the Avro data file format. This means t
99
99
 
100
100
  The Messaging API will automatically register schemas used for encoding data, and will fetch the corresponding schema when decoding. Instead of including the full schema in the output, only a schema id generated by the registry is included. Registering the same schema twice is idempotent, so no coordination is needed.
101
101
 
102
- **NOTE:** The Messaging format is _not_ compatible with the Avro data file API.
102
+ **NOTE:** [The Messaging format](https://github.com/confluentinc/schema-registry/blob/master/docs/serializer-formatter.rst#wire-format) is _not_ compatible with the Avro data file API.
103
103
 
104
104
  The Messaging API is not included by default, so you must require 'avro_turf/messaging' explicitly if you want to use it.
105
105
 
@@ -43,12 +43,12 @@ class AvroTurf
43
43
  # namespace - The namespace of the schema (optional).
44
44
  #
45
45
  # Returns the encoded data as a String.
46
- def encode(message, schema_name: nil, namespace: @namespace)
46
+ def encode(message, schema_name: nil, namespace: @namespace, subject: nil)
47
47
  schema = @schema_store.find(schema_name, namespace)
48
48
 
49
49
  # Schemas are registered under the full name of the top level Avro record
50
- # type.
51
- schema_id = @registry.register(schema.fullname, schema)
50
+ # type, or `subject` if it's provided.
51
+ schema_id = @registry.register(subject || schema.fullname, schema)
52
52
 
53
53
  stream = StringIO.new
54
54
  writer = Avro::IO::DatumWriter.new(schema)
@@ -34,8 +34,19 @@ class AvroTurf
34
34
  end
35
35
  end
36
36
  end
37
+
38
+ module DatumReader
39
+ def read_default_value(field_schema, default_value)
40
+ if default_value == :no_default
41
+ raise Avro::AvroError, "Missing data for #{field_schema} with no default"
42
+ end
43
+
44
+ super
45
+ end
46
+ end
37
47
  end
38
48
  end
39
49
 
40
50
  Avro::Schema::RecordSchema.send(:prepend, AvroTurf::AvroGemPatch::RecordSchema)
41
51
  Avro::Schema::Field.send(:prepend, AvroTurf::AvroGemPatch::Field)
52
+ Avro::IO::DatumReader.send(:prepend, AvroTurf::AvroGemPatch::DatumReader)
@@ -1,3 +1,3 @@
1
1
  class AvroTurf
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
@@ -79,7 +79,14 @@ describe AvroTurf::Messaging do
79
79
  allow(registry).to receive(:register).and_call_original
80
80
  message = { "full_name" => "John Doe" }
81
81
  avro.encode(message, schema_name: "person")
82
- expect(registry).to have_received(:register)
82
+ expect(registry).to have_received(:register).with("person", anything)
83
+ end
84
+
85
+ it "allows specifying a schema registry subject" do
86
+ allow(registry).to receive(:register).and_call_original
87
+ message = { "full_name" => "John Doe" }
88
+ avro.encode(message, schema_name: "person", subject: "people")
89
+ expect(registry).to have_received(:register).with("people", anything)
83
90
  end
84
91
  end
85
92
 
@@ -22,3 +22,45 @@ describe Avro::Schema do
22
22
  })
23
23
  end
24
24
  end
25
+
26
+
27
+ describe Avro::IO::DatumReader do
28
+ let(:writer_schema) do
29
+ Avro::Schema.parse <<-AVSC
30
+ {
31
+ "name": "no_default",
32
+ "type": "record",
33
+ "fields": [
34
+ { "type": "string", "name": "one" }
35
+ ]
36
+ }
37
+ AVSC
38
+ end
39
+ let(:reader_schema) do
40
+ Avro::Schema.parse <<-AVSC
41
+ {
42
+ "name": "no_default",
43
+ "type": "record",
44
+ "fields": [
45
+ { "type": "string", "name": "one" },
46
+ { "type": "string", "name": "two" }
47
+ ]
48
+ }
49
+ AVSC
50
+ end
51
+
52
+ it "raises an error for missing fields without a default" do
53
+ stream = StringIO.new
54
+ writer = Avro::IO::DatumWriter.new(writer_schema)
55
+ encoder = Avro::IO::BinaryEncoder.new(stream)
56
+ writer.write({ 'one' => 'first' }, encoder)
57
+ encoded = stream.string
58
+
59
+ stream = StringIO.new(encoded)
60
+ decoder = Avro::IO::BinaryDecoder.new(stream)
61
+ reader = Avro::IO::DatumReader.new(writer_schema, reader_schema)
62
+ expect do
63
+ reader.read(decoder)
64
+ end.to raise_error(Avro::AvroError, 'Missing data for "string" with no default')
65
+ end
66
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avro_turf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Schierbeck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-15 00:00:00.000000000 Z
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro