avro-resolution_canonical_form 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/Appraisals +0 -4
- data/CHANGELOG.md +6 -0
- data/README.md +7 -5
- data/avro-resolution_canonical_form.gemspec +15 -0
- data/lib/avro-resolution_canonical_form/version.rb +1 -1
- data/lib/avro/resolution_canonical_form.rb +40 -12
- metadata +32 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92db806c8c64c020593f72c0915c506a6f644f732025e1b1188a6312999a1b7c
|
4
|
+
data.tar.gz: 352466440aa35ee0743aca9880b974c2a60db65e9b0326e985c42cdda3c47a35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d33a9ce1bb91751e437c15c379afc95bd0d7249b32f3d88be6a2c24ed9e5bb64de38927a90cdaab06fca39391c608a07a066222bc41e9dd424ad6c84432d1af9
|
7
|
+
data.tar.gz: 3597d4ebb038f45750aeb926b099bdb0f7cd07c6e7458f4f398507200090392f66cf026df28098c4daa914f7726a0066df4525b836c74cee369a803408f77c95
|
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# avro-resolution_canonical_form
|
2
2
|
|
3
|
+
## v0.3.0
|
4
|
+
- Require Avro v1.10.
|
5
|
+
- Include aliases, enum defaults, and decimal logical types in the resolution
|
6
|
+
canonical form. Schemas that use any of these parts of the Avro spec will
|
7
|
+
get a different fingerprint with this version.
|
8
|
+
|
3
9
|
## v0.2.1
|
4
10
|
- Restrict to `avro-patches` versions < 2.0.0.
|
5
11
|
|
data/README.md
CHANGED
@@ -23,12 +23,14 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
## Resolution Canonical Form
|
25
25
|
|
26
|
-
The Resolution Canonical Form extends the [Parsing Canonical Form](http://avro.apache.org/docs/1.
|
27
|
-
to include `default` and `aliases` attributes:
|
26
|
+
The Resolution Canonical Form extends the [Parsing Canonical Form](http://avro.apache.org/docs/1.10.0/spec.html#Parsing+Canonical+Form+for+Schemas)
|
27
|
+
to include `default` and `aliases` attributes and logical type for decimals:
|
28
28
|
|
29
|
+
* [STRIP] Keep only attributes that are relevant to resolution, which are:
|
30
|
+
`name, type, fields, symbols, items, values, size, default, aliases, logical_type(=decimal), precision, scale`
|
29
31
|
* [ORDER] Order the appearance of fields in JSON objects as follows:
|
30
32
|
`name, type, fields, symbols, items, values, size, default, aliases`
|
31
|
-
* [ALIASES] [Aliases](http://avro.apache.org/docs/1.
|
33
|
+
* [ALIASES] [Aliases](http://avro.apache.org/docs/1.10.0/spec.html#Aliases) for
|
32
34
|
named types and fields are converted to their fullname, using applicable
|
33
35
|
namespace, and sorted.
|
34
36
|
|
@@ -67,7 +69,7 @@ schema = Avro::Schema.parse(<<-JSON)
|
|
67
69
|
JSON
|
68
70
|
|
69
71
|
Avro::ResolutionCanonicalForm.to_resolution_form(schema)
|
70
|
-
#=> {"name"
|
72
|
+
#=> => "{\"name\":\"example.dimensions\",\"type\":\"record\",\"fields\":[{\"name\":\"height\",\"type\":\"int\",\"default\":1},{\"name\":\"width\",\"type\":\"int\",\"aliases\":[\"across\"]}],\"aliases\":[\"eg.sizing\",\"example.dims\"]}"
|
71
73
|
```
|
72
74
|
|
73
75
|
A new method, `#sha256_resolution_fingerprint`, is added to `Avro::Schema` to
|
@@ -77,7 +79,7 @@ the existing `#sha256_fingerprint` which is based on the Parsing Canonical Form.
|
|
77
79
|
```ruby
|
78
80
|
schema.sha256_resolution_fingerprint
|
79
81
|
|
80
|
-
#=>
|
82
|
+
#=> 71676413924523555041213790831440929350080614901361467355865523343334332562796
|
81
83
|
```
|
82
84
|
|
83
85
|
## Development
|
@@ -35,5 +35,20 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_development_dependency 'salsify_rubocop', '~> 0.46.0'
|
36
36
|
spec.add_development_dependency 'overcommit'
|
37
37
|
spec.add_development_dependency 'simplecov'
|
38
|
+
|
39
|
+
spec.add_runtime_dependency 'avro', '~> 1.10.0'
|
38
40
|
spec.add_runtime_dependency 'avro-patches', '< 2.0.0'
|
41
|
+
|
42
|
+
spec.post_install_message = %(
|
43
|
+
avro-resolution_canonical_form now requires Avro v1.10.
|
44
|
+
|
45
|
+
New features in Avro Ruby v1.10 are now included in the canonical form:
|
46
|
+
- aliases
|
47
|
+
- enum defaults
|
48
|
+
- decimal logical types
|
49
|
+
|
50
|
+
Schemas that use any of these features will get a different fingerprint with
|
51
|
+
this version. For projects that only use Ruby, use of these features is unlikely
|
52
|
+
as they were previously unsupported.
|
53
|
+
)
|
39
54
|
end
|
@@ -2,6 +2,8 @@ require 'avro-patches'
|
|
2
2
|
|
3
3
|
module Avro
|
4
4
|
class ResolutionCanonicalForm < SchemaNormalization
|
5
|
+
DECIMAL_LOGICAL_TYPE = 'decimal'.freeze
|
6
|
+
|
5
7
|
def self.to_resolution_form(schema)
|
6
8
|
new.to_resolution_form(schema)
|
7
9
|
end
|
@@ -12,20 +14,46 @@ module Avro
|
|
12
14
|
|
13
15
|
private
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def normalize_schema(schema)
|
18
|
+
if schema.type_sym == :bytes && schema.logical_type == DECIMAL_LOGICAL_TYPE
|
19
|
+
add_logical_type(schema, type: schema.type)
|
20
|
+
else
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
19
25
|
def normalize_field(field)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
extensions = {}
|
27
|
+
extensions[:default] = field.default if field.default?
|
28
|
+
if field.aliases && !field.aliases.empty?
|
29
|
+
extensions[:aliases] = field.aliases.sort
|
30
|
+
end
|
31
|
+
|
32
|
+
super.merge(extensions)
|
26
33
|
end
|
27
34
|
|
28
|
-
|
29
|
-
|
35
|
+
def add_logical_type(schema, serialized)
|
36
|
+
if schema.logical_type == DECIMAL_LOGICAL_TYPE
|
37
|
+
extensions = { logicalType: DECIMAL_LOGICAL_TYPE }
|
38
|
+
extensions[:precision] = schema.precision if schema.respond_to?(:precision) && schema.precision
|
39
|
+
extensions[:scale] = schema.scale if schema.respond_to?(:scale) && schema.scale
|
40
|
+
serialized.merge(extensions)
|
41
|
+
else
|
42
|
+
serialized
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def normalize_named_type(schema, attributes = {})
|
47
|
+
extensions = {}
|
48
|
+
if schema.respond_to?(:default)
|
49
|
+
# For enum defaults
|
50
|
+
extensions[:default] = schema.default unless schema.default.nil?
|
51
|
+
end
|
52
|
+
|
53
|
+
aliases = schema.fullname_aliases
|
54
|
+
extensions[:aliases] = aliases.sort unless aliases.empty?
|
55
|
+
extensions = add_logical_type(schema, extensions)
|
56
|
+
super.merge(extensions)
|
57
|
+
end
|
30
58
|
end
|
31
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avro-resolution_canonical_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Salsify, Inc
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: avro
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.10.0
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.10.0
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: avro-patches
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,7 +170,18 @@ licenses:
|
|
156
170
|
- MIT
|
157
171
|
metadata:
|
158
172
|
allowed_push_host: https://rubygems.org
|
159
|
-
post_install_message:
|
173
|
+
post_install_message: |2
|
174
|
+
|
175
|
+
avro-resolution_canonical_form now requires Avro v1.10.
|
176
|
+
|
177
|
+
New features in Avro Ruby v1.10 are now included in the canonical form:
|
178
|
+
- aliases
|
179
|
+
- enum defaults
|
180
|
+
- decimal logical types
|
181
|
+
|
182
|
+
Schemas that use any of these features will get a different fingerprint with
|
183
|
+
this version. For projects that only use Ruby, use of these features is unlikely
|
184
|
+
as they were previously unsupported.
|
160
185
|
rdoc_options: []
|
161
186
|
require_paths:
|
162
187
|
- lib
|
@@ -171,9 +196,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
196
|
- !ruby/object:Gem::Version
|
172
197
|
version: '0'
|
173
198
|
requirements: []
|
174
|
-
rubyforge_project:
|
175
|
-
rubygems_version: 2.7.
|
176
|
-
signing_key:
|
199
|
+
rubyforge_project:
|
200
|
+
rubygems_version: 2.7.6.2
|
201
|
+
signing_key:
|
177
202
|
specification_version: 4
|
178
203
|
summary: Unique identification of Avro schemas for schema resolution
|
179
204
|
test_files: []
|