red-arrow-format 25.0.0 → 26.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4113dbcda2378ab7d587d206bb50d89ebd6326b45155ca1ae84aa1db2c93c1f8
4
- data.tar.gz: de65113d15c44830aa40b6699b02c1844f162fb52139542947b31c5c4b034bc9
3
+ metadata.gz: a59d8373c7b6c127b088d1445d2ead7a7a47eb31d775a2fc015a269d28d60c1f
4
+ data.tar.gz: 353eabcf9bfdc8224b3668c97eed985190b09e489a70ec20f02ce8ef2945c69a
5
5
  SHA512:
6
- metadata.gz: 217422c5e7a43abe12826fea4ebfffdce96d7f97b4659f861c08924c059455be73d638e5b9bfae081b7110207524f2d5351fd4b3b03defe5077b907ff1eeae60
7
- data.tar.gz: 67801cd0f4a81027f832b3b6b68d045d5f2ec92632b456f0188a448fb706dd6468339753b563e69f71ee1ebd6cfea68a72d87cf5968a556a0c35d3647ba88da8
6
+ metadata.gz: 67b833d6630a7f411569a5a5cb62e21e6e6a570da7e99d7ec53ff780c20c84334ba5e93363e13edc38b17d405fe23123ef0608de4cbc4c18c7402461ebb6ad95
7
+ data.tar.gz: de2b184bcb715512acaf66ed6a5ce08d198cdcb8c923cef08a0de317d104dd1d7b5962b264f804a07fe071f18952787c38a3201c32ef8dd52ed59dcff96ca26a
data/Rakefile CHANGED
@@ -35,7 +35,9 @@ task default: :test
35
35
  desc "Run tests"
36
36
  task :test do
37
37
  cd(base_dir.to_s) do
38
- ruby("test/run.rb")
38
+ args = []
39
+ args << "-v" if ENV["RUNNER_DEBUG"]
40
+ ruby("test/run.rb", *args)
39
41
  end
40
42
  end
41
43
 
@@ -0,0 +1,140 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ module ArrowFormat
19
+ class ArrayBuilder
20
+ def initialize(values)
21
+ @values = values
22
+ end
23
+
24
+ def build
25
+ target = nil
26
+ @values.each do |value|
27
+ target = detect_target(value, target)
28
+ break if target and target[:detected]
29
+ end
30
+ if target
31
+ array_class = target[:array_class]
32
+ array_class ||= finalize_array_class(target)
33
+ type = target[:type]
34
+ if type
35
+ array_class.new(type, @values)
36
+ else
37
+ array_class.new(@values)
38
+ end
39
+ else
40
+ UTF8Array.new(@values)
41
+ end
42
+ end
43
+
44
+ private
45
+ def detect_target(value, target)
46
+ case value
47
+ when nil
48
+ target
49
+ when true, false
50
+ {
51
+ array_class: BooleanArray,
52
+ detected: true,
53
+ }
54
+ when String
55
+ {
56
+ array_class: UTF8Array,
57
+ detected: true,
58
+ }
59
+ when Float
60
+ {
61
+ array_class: Float64Array,
62
+ detected: true,
63
+ }
64
+ when Integer
65
+ target ||= {}
66
+ min = target[:min] || value
67
+ max = target[:max] || value
68
+ min = value if value < min
69
+ max = value if value > max
70
+
71
+ if target[:value_type] == :int or value < 0
72
+ {
73
+ value_type: :int,
74
+ min: min,
75
+ max: max,
76
+ }
77
+ else
78
+ {
79
+ value_type: :uint,
80
+ min: min,
81
+ max: max,
82
+ }
83
+ end
84
+ when Time
85
+ {
86
+ array_class: TimestampArray,
87
+ type: TimestampType.new(:nanosecond),
88
+ detected: true,
89
+ }
90
+ when Date
91
+ {
92
+ array_class: Date32Array,
93
+ detected: true,
94
+ }
95
+ else
96
+ {
97
+ array_class: UTF8Array,
98
+ detected: true,
99
+ }
100
+ end
101
+ end
102
+
103
+ def finalize_array_class(target)
104
+ value_type = target[:value_type]
105
+ case value_type
106
+ when :int
107
+ min = target[:min]
108
+ max = target[:max]
109
+
110
+ if Int8Type::MIN_VALUE <= min and max <= Int8Type::MAX_VALUE
111
+ Int8Array
112
+ elsif Int16Type::MIN_VALUE <= min and max <= Int16Type::MAX_VALUE
113
+ Int16Array
114
+ elsif Int32Type::MIN_VALUE <= min and max <= Int32Type::MAX_VALUE
115
+ Int32Array
116
+ elsif Int64Type::MIN_VALUE <= min and max <= Int64Type::MAX_VALUE
117
+ Int64Array
118
+ else
119
+ UTF8Array
120
+ end
121
+ when :uint
122
+ max = target[:max]
123
+
124
+ if max <= UInt8Type::MAX_VALUE
125
+ UInt8Array
126
+ elsif max <= UInt16Type::MAX_VALUE
127
+ UInt16Array
128
+ elsif max <= UInt32Type::MAX_VALUE
129
+ UInt32Array
130
+ elsif max <= UInt64Type::MAX_VALUE
131
+ UInt64Array
132
+ else
133
+ UTF8Array
134
+ end
135
+ else
136
+ UTF8Array
137
+ end
138
+ end
139
+ end
140
+ end