avro 1.11.2 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/avro.gemspec +1 -1
- data/lib/avro/VERSION.txt +1 -1
- data/lib/avro/io.rb +4 -4
- data/lib/avro/logical_types.rb +28 -7
- data/lib/avro/schema.rb +4 -2
- data/test/random_data.rb +2 -0
- data/test/test_io.rb +4 -1
- data/test/test_logical_types.rb +25 -5
- data/test/test_schema.rb +2 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 494daaa5f42901a0ae52f6fe0b723c3c0f0ec2d951e425c76cdc3998c7f7d2af
|
4
|
+
data.tar.gz: 04d5c0c5eba948dfde59ea0c5d328de0926df053e9d9d04a8dd61bc6f1982a1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f52c72d63ce36d92ac83625b951422be2aea73889f8de13e4d40cc87af8c56a717484d6d55f71979d2acd1680f967c4d65b908e9f68bc25f850aa0ebac204db
|
7
|
+
data.tar.gz: a839620ed610140111c47de1ad050f75c35ed036221165cb3b1fae30556b8e41be86db073fd59fe788f4b346ed41efbff21c81cc4ad2a8caa136a40b9a04cec7
|
data/avro.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.description = "Avro is a data serialization and RPC format"
|
26
26
|
s.homepage = "https://avro.apache.org/"
|
27
27
|
s.license = "Apache-2.0"
|
28
|
-
s.required_ruby_version = ">= 2.
|
28
|
+
s.required_ruby_version = ">= 2.7"
|
29
29
|
|
30
30
|
s.metadata["homepage_uri"] = s.homepage
|
31
31
|
s.metadata["bug_tracker_uri"] = "https://issues.apache.org/jira/browse/AVRO"
|
data/lib/avro/VERSION.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.12.0
|
data/lib/avro/io.rb
CHANGED
@@ -75,7 +75,7 @@ module Avro
|
|
75
75
|
def read_float
|
76
76
|
# A float is written as 4 bytes.
|
77
77
|
# The float is converted into a 32-bit integer using a method
|
78
|
-
# equivalent to Java's
|
78
|
+
# equivalent to Java's floatToRawIntBits and then encoded in
|
79
79
|
# little-endian format.
|
80
80
|
read_and_unpack(4, 'e')
|
81
81
|
end
|
@@ -83,7 +83,7 @@ module Avro
|
|
83
83
|
def read_double
|
84
84
|
# A double is written as 8 bytes.
|
85
85
|
# The double is converted into a 64-bit integer using a method
|
86
|
-
# equivalent to Java's
|
86
|
+
# equivalent to Java's doubleToRawLongBits and then encoded in
|
87
87
|
# little-endian format.
|
88
88
|
read_and_unpack(8, 'E')
|
89
89
|
end
|
@@ -203,7 +203,7 @@ module Avro
|
|
203
203
|
|
204
204
|
# A float is written as 4 bytes.
|
205
205
|
# The float is converted into a 32-bit integer using a method
|
206
|
-
# equivalent to Java's
|
206
|
+
# equivalent to Java's floatToRawIntBits and then encoded in
|
207
207
|
# little-endian format.
|
208
208
|
def write_float(datum)
|
209
209
|
@writer.write([datum].pack('e'))
|
@@ -211,7 +211,7 @@ module Avro
|
|
211
211
|
|
212
212
|
# A double is written as 8 bytes.
|
213
213
|
# The double is converted into a 64-bit integer using a method
|
214
|
-
# equivalent to Java's
|
214
|
+
# equivalent to Java's doubleToRawLongBits and then encoded in
|
215
215
|
# little-endian format.
|
216
216
|
def write_double(datum)
|
217
217
|
@writer.write([datum].pack('E'))
|
data/lib/avro/logical_types.rb
CHANGED
@@ -214,30 +214,50 @@ module Avro
|
|
214
214
|
end
|
215
215
|
|
216
216
|
module TimestampMillis
|
217
|
+
SUBUNITS_PER_SECOND = 1000
|
218
|
+
|
217
219
|
def self.encode(value)
|
218
220
|
return value.to_i if value.is_a?(Numeric)
|
219
221
|
|
220
222
|
time = value.to_time
|
221
|
-
time.to_i *
|
223
|
+
time.to_i * SUBUNITS_PER_SECOND + time.usec / SUBUNITS_PER_SECOND
|
222
224
|
end
|
223
225
|
|
224
226
|
def self.decode(int)
|
225
|
-
s, ms = int
|
226
|
-
Time.at(s, ms
|
227
|
+
s, ms = int.divmod(SUBUNITS_PER_SECOND)
|
228
|
+
Time.at(s, ms, :millisecond).utc
|
227
229
|
end
|
228
230
|
end
|
229
231
|
|
230
232
|
module TimestampMicros
|
233
|
+
SUBUNITS_PER_SECOND = 1000_000
|
234
|
+
|
235
|
+
def self.encode(value)
|
236
|
+
return value.to_i if value.is_a?(Numeric)
|
237
|
+
|
238
|
+
time = value.to_time
|
239
|
+
time.to_i * SUBUNITS_PER_SECOND + time.usec
|
240
|
+
end
|
241
|
+
|
242
|
+
def self.decode(int)
|
243
|
+
s, us = int.divmod(SUBUNITS_PER_SECOND)
|
244
|
+
Time.at(s, us, :microsecond).utc
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
module TimestampNanos
|
249
|
+
SUBUNITS_PER_SECOND = 1000_000_000
|
250
|
+
|
231
251
|
def self.encode(value)
|
232
252
|
return value.to_i if value.is_a?(Numeric)
|
233
253
|
|
234
254
|
time = value.to_time
|
235
|
-
time.to_i *
|
255
|
+
time.to_i * SUBUNITS_PER_SECOND + time.nsec
|
236
256
|
end
|
237
257
|
|
238
258
|
def self.decode(int)
|
239
|
-
s,
|
240
|
-
Time.at(s,
|
259
|
+
s, ns = int.divmod(SUBUNITS_PER_SECOND)
|
260
|
+
Time.at(s, ns, :nanosecond).utc
|
241
261
|
end
|
242
262
|
end
|
243
263
|
|
@@ -260,7 +280,8 @@ module Avro
|
|
260
280
|
},
|
261
281
|
"long" => {
|
262
282
|
"timestamp-millis" => TimestampMillis,
|
263
|
-
"timestamp-micros" => TimestampMicros
|
283
|
+
"timestamp-micros" => TimestampMicros,
|
284
|
+
"timestamp-nanos" => TimestampNanos
|
264
285
|
},
|
265
286
|
}.freeze
|
266
287
|
|
data/lib/avro/schema.rb
CHANGED
@@ -111,7 +111,7 @@ module Avro
|
|
111
111
|
elsif PRIMITIVE_TYPES.include? json_obj
|
112
112
|
return PrimitiveSchema.new(json_obj)
|
113
113
|
else
|
114
|
-
raise UnknownSchemaError.new(json_obj)
|
114
|
+
raise UnknownSchemaError.new(json_obj, default_namespace)
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
@@ -621,9 +621,11 @@ module Avro
|
|
621
621
|
|
622
622
|
class UnknownSchemaError < SchemaParseError
|
623
623
|
attr_reader :type_name
|
624
|
+
attr_reader :default_namespace
|
624
625
|
|
625
|
-
def initialize(type)
|
626
|
+
def initialize(type, default_namespace)
|
626
627
|
@type_name = type
|
628
|
+
@default_namespace = default_namespace
|
627
629
|
super("#{type.inspect} is not a schema we know about.")
|
628
630
|
end
|
629
631
|
end
|
data/test/random_data.rb
CHANGED
data/test/test_io.rb
CHANGED
@@ -94,7 +94,10 @@ EOS
|
|
94
94
|
"logicalType": "timestamp-micros"}},
|
95
95
|
{"name": "ts2",
|
96
96
|
"type": {"type": "long",
|
97
|
-
"logicalType": "timestamp-millis"}}
|
97
|
+
"logicalType": "timestamp-millis"}},
|
98
|
+
{"name": "ts3",
|
99
|
+
"type": {"type": "long",
|
100
|
+
"logicalType": "timestamp-nanos"}}]}
|
98
101
|
EOS
|
99
102
|
check(record_schema)
|
100
103
|
end
|
data/test/test_logical_types.rb
CHANGED
@@ -92,6 +92,28 @@ class TestLogicalTypes < Test::Unit::TestCase
|
|
92
92
|
assert_equal Time.utc(2015, 5, 28, 21, 46, 53, 221843), type.decode(1432849613221843)
|
93
93
|
end
|
94
94
|
|
95
|
+
def test_timestamp_nanos_long
|
96
|
+
schema = Avro::Schema.parse <<-SCHEMA
|
97
|
+
{ "type": "long", "logicalType": "timestamp-nanos" }
|
98
|
+
SCHEMA
|
99
|
+
|
100
|
+
time = Time.at(628232400, 123456789, :nanosecond)
|
101
|
+
assert_equal 'timestamp-nanos', schema.logical_type
|
102
|
+
assert_encode_and_decode time, schema
|
103
|
+
assert_preencoded Avro::LogicalTypes::TimestampNanos.encode(time), schema, time.utc
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_timestamp_nanos_long_conversion
|
107
|
+
type = Avro::LogicalTypes::TimestampNanos
|
108
|
+
|
109
|
+
now = Time.now.utc
|
110
|
+
|
111
|
+
assert_equal Time.at(now.to_i, now.nsec, :nanosecond).utc, type.decode(type.encode(now))
|
112
|
+
assert_equal 1432849613221843789, type.encode(Time.at(1432849613, 221843789, :nanosecond).utc)
|
113
|
+
assert_equal 1432849613221843789, type.encode(DateTime.new(2015, 5, 28, 21, 46, 53.221843789))
|
114
|
+
assert_equal Time.at(1432849613, 221843789, :nanosecond).utc, type.decode(1432849613221843789)
|
115
|
+
end
|
116
|
+
|
95
117
|
def test_parse_fixed_duration
|
96
118
|
schema = Avro::Schema.parse <<-SCHEMA
|
97
119
|
{ "type": "fixed", "size": 12, "name": "fixed_dur", "logicalType": "duration" }
|
@@ -141,7 +163,7 @@ class TestLogicalTypes < Test::Unit::TestCase
|
|
141
163
|
"null"
|
142
164
|
],
|
143
165
|
"default": "\u0000"
|
144
|
-
}
|
166
|
+
}
|
145
167
|
]
|
146
168
|
}')
|
147
169
|
|
@@ -215,7 +237,7 @@ class TestLogicalTypes < Test::Unit::TestCase
|
|
215
237
|
sales_tax_record = {
|
216
238
|
"sales" => BigDecimal("12.34"),
|
217
239
|
"tax" => BigDecimal("0.000"),
|
218
|
-
"invoice_date" =>
|
240
|
+
"invoice_date" => Date.new(1970, 1, 1),
|
219
241
|
# time-millis is not supported
|
220
242
|
"invoice_time" => 0,
|
221
243
|
"created_at" => Time.at(0).utc,
|
@@ -316,7 +338,6 @@ class TestLogicalTypes < Test::Unit::TestCase
|
|
316
338
|
end
|
317
339
|
|
318
340
|
assert_equal 5, report.total_allocated
|
319
|
-
# Ruby 2.7 does not retain anything. Ruby 2.6 retains 1
|
320
341
|
assert_operator 1, :>=, report.total_retained
|
321
342
|
end
|
322
343
|
end
|
@@ -337,8 +358,7 @@ class TestLogicalTypes < Test::Unit::TestCase
|
|
337
358
|
end
|
338
359
|
|
339
360
|
assert_equal 5, report.total_allocated
|
340
|
-
|
341
|
-
assert_operator 2, :>=, report.total_retained
|
361
|
+
assert_equal 0, report.total_retained
|
342
362
|
end
|
343
363
|
end
|
344
364
|
|
data/test/test_schema.rb
CHANGED
@@ -176,6 +176,8 @@ class TestSchema < Test::Unit::TestCase
|
|
176
176
|
end
|
177
177
|
|
178
178
|
assert_equal '"MissingType" is not a schema we know about.', error.message
|
179
|
+
assert_equal "MissingType", error.type_name
|
180
|
+
assert_equal "my.name.space", error.default_namespace
|
179
181
|
end
|
180
182
|
|
181
183
|
def test_invalid_name
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Apache Software Foundation
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -72,7 +72,7 @@ metadata:
|
|
72
72
|
homepage_uri: https://avro.apache.org/
|
73
73
|
bug_tracker_uri: https://issues.apache.org/jira/browse/AVRO
|
74
74
|
source_code_uri: https://github.com/apache/avro
|
75
|
-
documentation_uri: https://avro.apache.org/docs/1.
|
75
|
+
documentation_uri: https://avro.apache.org/docs/1.12.0/
|
76
76
|
rubygems_mfa_required: 'true'
|
77
77
|
post_install_message:
|
78
78
|
rdoc_options:
|
@@ -85,14 +85,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
85
|
requirements:
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: '2.
|
88
|
+
version: '2.7'
|
89
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
90
|
requirements:
|
91
91
|
- - ">="
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
|
-
rubygems_version: 3.
|
95
|
+
rubygems_version: 3.3.5
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: Apache Avro for Ruby
|