avro 1.11.3 → 1.12.0

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
  SHA256:
3
- metadata.gz: 124c809b0bcf3463852b754fb01cf2b75e4d90547a934d8932a27f52a3264b69
4
- data.tar.gz: e293185ed5b05dd1aaf6837dc9a64748cd0d26fbba8ab5fc0a4b608cca7ab244
3
+ metadata.gz: 494daaa5f42901a0ae52f6fe0b723c3c0f0ec2d951e425c76cdc3998c7f7d2af
4
+ data.tar.gz: 04d5c0c5eba948dfde59ea0c5d328de0926df053e9d9d04a8dd61bc6f1982a1f
5
5
  SHA512:
6
- metadata.gz: 677e4fc7525cea9ac5309b891bb88b60c2421ee58add86d90efa3fa0731199b6cbb2f0bb2b7db42c9237f54a36fb5dda49de649fb5d40810d73f1c7084d9e290
7
- data.tar.gz: e0bcfcd4f139ad961ae0af5ecac5eba24d6cfaab866487bd8c06918158d7e0f8307b33fc550cd35c2a75cc93fa75851c038a85a2f27f8eed123bf16219d07105
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.6"
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.11.3
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 floatToIntBits and then encoded in
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 doubleToLongBits and then encoded in
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 floatToIntBits and then encoded in
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 doubleToLongBits and then encoded in
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'))
@@ -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 * 1000 + time.usec / 1000
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 / 1000, int % 1000
226
- Time.at(s, ms * 1000).utc
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 * 1000_000 + time.usec
255
+ time.to_i * SUBUNITS_PER_SECOND + time.nsec
236
256
  end
237
257
 
238
258
  def self.decode(int)
239
- s, us = int / 1000_000, int % 1000_000
240
- Time.at(s, us).utc
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/test/random_data.rb CHANGED
@@ -89,6 +89,8 @@ class RandomData
89
89
  Avro::LogicalTypes::TimestampMicros.decode(rand_long)
90
90
  when 'timestamp-millis'
91
91
  Avro::LogicalTypes::TimestampMillis.decode(rand_long)
92
+ when 'timestamp-nanos'
93
+ Avro::LogicalTypes::TimestampNanos.decode(rand_long)
92
94
  end
93
95
  end
94
96
 
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
@@ -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" => Time.at(0).to_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
- # Ruby 2.7 does not retain anything. Ruby 2.6 retains 1 or 2
341
- assert_operator 2, :>=, report.total_retained
361
+ assert_equal 0, report.total_retained
342
362
  end
343
363
  end
344
364
 
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.11.3
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: 2023-09-15 00:00:00.000000000 Z
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.11.3/
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.6'
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.1.2
95
+ rubygems_version: 3.3.5
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: Apache Avro for Ruby