red-arrow 8.0.0 → 9.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 +4 -4
 - data/ext/arrow/converters.hpp +3 -0
 - data/ext/arrow/extconf.rb +6 -4
 - data/lib/arrow/array-builder.rb +40 -6
 - data/lib/arrow/array-computable.rb +37 -0
 - data/lib/arrow/array.rb +16 -0
 - data/lib/arrow/chunked-array.rb +21 -0
 - data/lib/arrow/column.rb +28 -0
 - data/lib/arrow/data-type.rb +2 -1
 - data/lib/arrow/decimal128-array-builder.rb +16 -6
 - data/lib/arrow/decimal128.rb +14 -0
 - data/lib/arrow/decimal256-array-builder.rb +16 -6
 - data/lib/arrow/decimal256.rb +14 -0
 - data/lib/arrow/field.rb +44 -3
 - data/lib/arrow/list-data-type.rb +1 -6
 - data/lib/arrow/loader.rb +3 -0
 - data/lib/arrow/string-array-builder.rb +30 -0
 - data/lib/arrow/time-unit.rb +31 -0
 - data/lib/arrow/time32-array-builder.rb +2 -14
 - data/lib/arrow/time32-data-type.rb +9 -38
 - data/lib/arrow/time64-array-builder.rb +2 -14
 - data/lib/arrow/time64-data-type.rb +9 -38
 - data/lib/arrow/timestamp-array-builder.rb +2 -14
 - data/lib/arrow/timestamp-data-type.rb +9 -34
 - data/lib/arrow/version.rb +1 -1
 - data/red-arrow.gemspec +1 -1
 - data/test/raw-records/test-dictionary-array.rb +341 -0
 - data/test/test-array-builder.rb +62 -0
 - data/test/test-chunked-array.rb +6 -0
 - data/test/test-column.rb +31 -0
 - data/test/test-decimal128-array-builder.rb +14 -0
 - data/test/test-decimal128-array.rb +5 -2
 - data/test/test-decimal128.rb +26 -2
 - data/test/test-decimal256-array-builder.rb +14 -0
 - data/test/test-decimal256-array.rb +5 -2
 - data/test/test-decimal256.rb +26 -2
 - data/test/test-field.rb +26 -0
 - data/test/values/test-dictionary-array.rb +30 -0
 - metadata +11 -6
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 23d181c0c2d49f1479ddae27c02427d75b72f66a31c097e1f0ead363422170ed
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: e2c5e259b177bb136d7f492e46ec3411b5f05d190618cec6736494315fc64efb
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: a4d7673b6457b4f288d9fc1e0bcc8b9adad239f21dbe722cbb412e81e51d117e8661027731bd4918be19c9ed6c6978f21613ebdd31fbe21271d2175f3d416655
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: f300245a89afeb3c8d5e56db26fe866ae666a429429c26155591b430bc47f9d7abe987e35fd0507133b9e5011f78381b6e46797b1072556786fb8fb54e19e9fe
         
     | 
    
        data/ext/arrow/converters.hpp
    CHANGED
    
    
    
        data/ext/arrow/extconf.rb
    CHANGED
    
    | 
         @@ -45,9 +45,10 @@ unless required_pkg_config_package([ 
     | 
|
| 
       45 
45 
     | 
    
         
             
                                                 Arrow::Version::MICRO,
         
     | 
| 
       46 
46 
     | 
    
         
             
                                               ],
         
     | 
| 
       47 
47 
     | 
    
         
             
                                               debian: "libarrow-dev",
         
     | 
| 
       48 
     | 
    
         
            -
                                                
     | 
| 
      
 48 
     | 
    
         
            +
                                               fedora: "libarrow-devel",
         
     | 
| 
       49 
49 
     | 
    
         
             
                                               homebrew: "apache-arrow",
         
     | 
| 
       50 
     | 
    
         
            -
                                               msys2: "arrow" 
     | 
| 
      
 50 
     | 
    
         
            +
                                               msys2: "arrow",
         
     | 
| 
      
 51 
     | 
    
         
            +
                                               redhat: "arrow-devel")
         
     | 
| 
       51 
52 
     | 
    
         
             
              exit(false)
         
     | 
| 
       52 
53 
     | 
    
         
             
            end
         
     | 
| 
       53 
54 
     | 
    
         | 
| 
         @@ -58,9 +59,10 @@ unless required_pkg_config_package([ 
     | 
|
| 
       58 
59 
     | 
    
         
             
                                                 Arrow::Version::MICRO,
         
     | 
| 
       59 
60 
     | 
    
         
             
                                               ],
         
     | 
| 
       60 
61 
     | 
    
         
             
                                               debian: "libarrow-glib-dev",
         
     | 
| 
       61 
     | 
    
         
            -
                                                
     | 
| 
      
 62 
     | 
    
         
            +
                                               fedora: "libarrow-glib-devel",
         
     | 
| 
       62 
63 
     | 
    
         
             
                                               homebrew: "apache-arrow-glib",
         
     | 
| 
       63 
     | 
    
         
            -
                                               msys2: "arrow" 
     | 
| 
      
 64 
     | 
    
         
            +
                                               msys2: "arrow",
         
     | 
| 
      
 65 
     | 
    
         
            +
                                               redhat: "arrow-glib-devel")
         
     | 
| 
       64 
66 
     | 
    
         
             
              exit(false)
         
     | 
| 
       65 
67 
     | 
    
         
             
            end
         
     | 
| 
       66 
68 
     | 
    
         | 
    
        data/lib/arrow/array-builder.rb
    CHANGED
    
    | 
         @@ -33,6 +33,11 @@ module Arrow 
     | 
|
| 
       33 
33 
     | 
    
         
             
                    end
         
     | 
| 
       34 
34 
     | 
    
         
             
                    if builder_info
         
     | 
| 
       35 
35 
     | 
    
         
             
                      builder = builder_info[:builder]
         
     | 
| 
      
 36 
     | 
    
         
            +
                      if builder.nil? and builder_info[:builder_type]
         
     | 
| 
      
 37 
     | 
    
         
            +
                        builder = create_builder(builder_info)
         
     | 
| 
      
 38 
     | 
    
         
            +
                      end
         
     | 
| 
      
 39 
     | 
    
         
            +
                    end
         
     | 
| 
      
 40 
     | 
    
         
            +
                    if builder
         
     | 
| 
       36 
41 
     | 
    
         
             
                      builder.build(values)
         
     | 
| 
       37 
42 
     | 
    
         
             
                    else
         
     | 
| 
       38 
43 
     | 
    
         
             
                      Arrow::StringArray.new(values)
         
     | 
| 
         @@ -121,15 +126,28 @@ module Arrow 
     | 
|
| 
       121 
126 
     | 
    
         
             
                        detected: true,
         
     | 
| 
       122 
127 
     | 
    
         
             
                      }
         
     | 
| 
       123 
128 
     | 
    
         
             
                    when BigDecimal
         
     | 
| 
       124 
     | 
    
         
            -
                       
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
                          builder: Decimal128ArrayBuilder.new,
         
     | 
| 
       127 
     | 
    
         
            -
                        }
         
     | 
| 
       128 
     | 
    
         
            -
                      else
         
     | 
| 
      
 129 
     | 
    
         
            +
                      builder_info ||= {}
         
     | 
| 
      
 130 
     | 
    
         
            +
                      if builder_info[:builder] or value.nan? or value.infinite?
         
     | 
| 
       129 
131 
     | 
    
         
             
                        {
         
     | 
| 
       130 
     | 
    
         
            -
                          builder:  
     | 
| 
      
 132 
     | 
    
         
            +
                          builder: StringArrayBuilder.new,
         
     | 
| 
       131 
133 
     | 
    
         
             
                          detected: true,
         
     | 
| 
       132 
134 
     | 
    
         
             
                        }
         
     | 
| 
      
 135 
     | 
    
         
            +
                      else
         
     | 
| 
      
 136 
     | 
    
         
            +
                        precision = [builder_info[:precision] || 0, value.precision].max
         
     | 
| 
      
 137 
     | 
    
         
            +
                        scale = [builder_info[:scale] || 0, value.scale].max
         
     | 
| 
      
 138 
     | 
    
         
            +
                        if precision <= Decimal128DataType::MAX_PRECISION
         
     | 
| 
      
 139 
     | 
    
         
            +
                          {
         
     | 
| 
      
 140 
     | 
    
         
            +
                            builder_type: :decimal128,
         
     | 
| 
      
 141 
     | 
    
         
            +
                            precision: precision,
         
     | 
| 
      
 142 
     | 
    
         
            +
                            scale: scale,
         
     | 
| 
      
 143 
     | 
    
         
            +
                          }
         
     | 
| 
      
 144 
     | 
    
         
            +
                        else
         
     | 
| 
      
 145 
     | 
    
         
            +
                          {
         
     | 
| 
      
 146 
     | 
    
         
            +
                            builder_type: :decimal256,
         
     | 
| 
      
 147 
     | 
    
         
            +
                            precision: precision,
         
     | 
| 
      
 148 
     | 
    
         
            +
                            scale: scale,
         
     | 
| 
      
 149 
     | 
    
         
            +
                          }
         
     | 
| 
      
 150 
     | 
    
         
            +
                        end
         
     | 
| 
       133 
151 
     | 
    
         
             
                      end
         
     | 
| 
       134 
152 
     | 
    
         
             
                    when ::Array
         
     | 
| 
       135 
153 
     | 
    
         
             
                      sub_builder_info = nil
         
     | 
| 
         @@ -154,6 +172,22 @@ module Arrow 
     | 
|
| 
       154 
172 
     | 
    
         
             
                      }
         
     | 
| 
       155 
173 
     | 
    
         
             
                    end
         
     | 
| 
       156 
174 
     | 
    
         
             
                  end
         
     | 
| 
      
 175 
     | 
    
         
            +
             
     | 
| 
      
 176 
     | 
    
         
            +
                  def create_builder(builder_info)
         
     | 
| 
      
 177 
     | 
    
         
            +
                    builder_type = builder_info[:builder_type]
         
     | 
| 
      
 178 
     | 
    
         
            +
                    case builder_type
         
     | 
| 
      
 179 
     | 
    
         
            +
                    when :decimal128
         
     | 
| 
      
 180 
     | 
    
         
            +
                      data_type = Decimal128DataType.new(builder_info[:precision],
         
     | 
| 
      
 181 
     | 
    
         
            +
                                                         builder_info[:scale])
         
     | 
| 
      
 182 
     | 
    
         
            +
                      Decimal128ArrayBuilder.new(data_type)
         
     | 
| 
      
 183 
     | 
    
         
            +
                    when :decimal256
         
     | 
| 
      
 184 
     | 
    
         
            +
                      data_type = Decimal256DataType.new(builder_info[:precision],
         
     | 
| 
      
 185 
     | 
    
         
            +
                                                         builder_info[:scale])
         
     | 
| 
      
 186 
     | 
    
         
            +
                      Decimal256ArrayBuilder.new(data_type)
         
     | 
| 
      
 187 
     | 
    
         
            +
                    else
         
     | 
| 
      
 188 
     | 
    
         
            +
                      nil
         
     | 
| 
      
 189 
     | 
    
         
            +
                    end
         
     | 
| 
      
 190 
     | 
    
         
            +
                  end
         
     | 
| 
       157 
191 
     | 
    
         
             
                end
         
     | 
| 
       158 
192 
     | 
    
         | 
| 
       159 
193 
     | 
    
         
             
                def build(values)
         
     | 
| 
         @@ -0,0 +1,37 @@ 
     | 
|
| 
      
 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 Arrow
         
     | 
| 
      
 19 
     | 
    
         
            +
              module ArrayComputable
         
     | 
| 
      
 20 
     | 
    
         
            +
                def min(options: nil)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  compute("min", options: options).value
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                def max(options: nil)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  compute("max", options: options).value
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                def uniq
         
     | 
| 
      
 29 
     | 
    
         
            +
                  unique.values
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                private
         
     | 
| 
      
 33 
     | 
    
         
            +
                def compute(name, options: nil)
         
     | 
| 
      
 34 
     | 
    
         
            +
                  Function.find(name).execute([self], options).value
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
              end
         
     | 
| 
      
 37 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/arrow/array.rb
    CHANGED
    
    | 
         @@ -18,6 +18,8 @@ 
     | 
|
| 
       18 
18 
     | 
    
         
             
            module Arrow
         
     | 
| 
       19 
19 
     | 
    
         
             
              class Array
         
     | 
| 
       20 
20 
     | 
    
         
             
                include Enumerable
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                include ArrayComputable
         
     | 
| 
       21 
23 
     | 
    
         
             
                include GenericFilterable
         
     | 
| 
       22 
24 
     | 
    
         
             
                include GenericTakeable
         
     | 
| 
       23 
25 
     | 
    
         | 
| 
         @@ -34,6 +36,20 @@ module Arrow 
     | 
|
| 
       34 
36 
     | 
    
         
             
                    return nil unless const_defined?(builder_class_name)
         
     | 
| 
       35 
37 
     | 
    
         
             
                    const_get(builder_class_name)
         
     | 
| 
       36 
38 
     | 
    
         
             
                  end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                  # @api private
         
     | 
| 
      
 41 
     | 
    
         
            +
                  def try_convert(value)
         
     | 
| 
      
 42 
     | 
    
         
            +
                    case value
         
     | 
| 
      
 43 
     | 
    
         
            +
                    when ::Array
         
     | 
| 
      
 44 
     | 
    
         
            +
                      begin
         
     | 
| 
      
 45 
     | 
    
         
            +
                        new(value)
         
     | 
| 
      
 46 
     | 
    
         
            +
                      rescue ArgumentError
         
     | 
| 
      
 47 
     | 
    
         
            +
                        nil
         
     | 
| 
      
 48 
     | 
    
         
            +
                      end
         
     | 
| 
      
 49 
     | 
    
         
            +
                    else
         
     | 
| 
      
 50 
     | 
    
         
            +
                      nil
         
     | 
| 
      
 51 
     | 
    
         
            +
                    end
         
     | 
| 
      
 52 
     | 
    
         
            +
                  end
         
     | 
| 
       37 
53 
     | 
    
         
             
                end
         
     | 
| 
       38 
54 
     | 
    
         | 
| 
       39 
55 
     | 
    
         
             
                # @param i [Integer]
         
     | 
    
        data/lib/arrow/chunked-array.rb
    CHANGED
    
    | 
         @@ -18,6 +18,8 @@ 
     | 
|
| 
       18 
18 
     | 
    
         
             
            module Arrow
         
     | 
| 
       19 
19 
     | 
    
         
             
              class ChunkedArray
         
     | 
| 
       20 
20 
     | 
    
         
             
                include Enumerable
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                include ArrayComputable
         
     | 
| 
       21 
23 
     | 
    
         
             
                include GenericFilterable
         
     | 
| 
       22 
24 
     | 
    
         
             
                include GenericTakeable
         
     | 
| 
       23 
25 
     | 
    
         | 
| 
         @@ -87,5 +89,24 @@ module Arrow 
     | 
|
| 
       87 
89 
     | 
    
         
             
                    first_chunk.class.new(to_a)
         
     | 
| 
       88 
90 
     | 
    
         
             
                  end
         
     | 
| 
       89 
91 
     | 
    
         
             
                end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                def count(options: nil)
         
     | 
| 
      
 94 
     | 
    
         
            +
                  compute("count", options: options).value
         
     | 
| 
      
 95 
     | 
    
         
            +
                end
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
                def sum(options: nil)
         
     | 
| 
      
 98 
     | 
    
         
            +
                  compute("sum", options: options).value
         
     | 
| 
      
 99 
     | 
    
         
            +
                end
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
                def unique
         
     | 
| 
      
 102 
     | 
    
         
            +
                  compute("unique")
         
     | 
| 
      
 103 
     | 
    
         
            +
                end
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
                def cast(target_data_type, options: nil)
         
     | 
| 
      
 106 
     | 
    
         
            +
                  casted_chunks = chunks.collect do |chunk|
         
     | 
| 
      
 107 
     | 
    
         
            +
                    chunk.cast(target_data_type, options)
         
     | 
| 
      
 108 
     | 
    
         
            +
                  end
         
     | 
| 
      
 109 
     | 
    
         
            +
                  self.class.new(casted_chunks)
         
     | 
| 
      
 110 
     | 
    
         
            +
                end
         
     | 
| 
       90 
111 
     | 
    
         
             
              end
         
     | 
| 
       91 
112 
     | 
    
         
             
            end
         
     | 
    
        data/lib/arrow/column.rb
    CHANGED
    
    | 
         @@ -72,5 +72,33 @@ module Arrow 
     | 
|
| 
       72 
72 
     | 
    
         
             
                    @field == other.field and
         
     | 
| 
       73 
73 
     | 
    
         
             
                    @data == other.data
         
     | 
| 
       74 
74 
     | 
    
         
             
                end
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                def count(options: nil)
         
     | 
| 
      
 77 
     | 
    
         
            +
                  @data.count(options: options)
         
     | 
| 
      
 78 
     | 
    
         
            +
                end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                def sum(options: nil)
         
     | 
| 
      
 81 
     | 
    
         
            +
                  @data.sum(options: options)
         
     | 
| 
      
 82 
     | 
    
         
            +
                end
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
                def min(options: nil)
         
     | 
| 
      
 85 
     | 
    
         
            +
                  @data.min(options: options)
         
     | 
| 
      
 86 
     | 
    
         
            +
                end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                def max(options: nil)
         
     | 
| 
      
 89 
     | 
    
         
            +
                  @data.max(options: options)
         
     | 
| 
      
 90 
     | 
    
         
            +
                end
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                def unique
         
     | 
| 
      
 93 
     | 
    
         
            +
                  @data.unique
         
     | 
| 
      
 94 
     | 
    
         
            +
                end
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
                def uniq
         
     | 
| 
      
 97 
     | 
    
         
            +
                  @data.uniq
         
     | 
| 
      
 98 
     | 
    
         
            +
                end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                def cast(target_data_type, options: nil)
         
     | 
| 
      
 101 
     | 
    
         
            +
                  @data.cast(target_data_type, options: options)
         
     | 
| 
      
 102 
     | 
    
         
            +
                end
         
     | 
| 
       75 
103 
     | 
    
         
             
              end
         
     | 
| 
       76 
104 
     | 
    
         
             
            end
         
     | 
    
        data/lib/arrow/data-type.rb
    CHANGED
    
    | 
         @@ -110,7 +110,7 @@ module Arrow 
     | 
|
| 
       110 
110 
     | 
    
         
             
                          description[key] = value
         
     | 
| 
       111 
111 
     | 
    
         
             
                        end
         
     | 
| 
       112 
112 
     | 
    
         
             
                      end
         
     | 
| 
       113 
     | 
    
         
            -
                      if type.nil?
         
     | 
| 
      
 113 
     | 
    
         
            +
                      if type.nil? and self == DataType
         
     | 
| 
       114 
114 
     | 
    
         
             
                        message =
         
     | 
| 
       115 
115 
     | 
    
         
             
                          "data type description must have :type value: #{data_type.inspect}"
         
     | 
| 
       116 
116 
     | 
    
         
             
                        raise ArgumentError, message
         
     | 
| 
         @@ -152,6 +152,7 @@ module Arrow 
     | 
|
| 
       152 
152 
     | 
    
         | 
| 
       153 
153 
     | 
    
         
             
                  private
         
     | 
| 
       154 
154 
     | 
    
         
             
                  def resolve_class(data_type)
         
     | 
| 
      
 155 
     | 
    
         
            +
                    return self if data_type.nil?
         
     | 
| 
       155 
156 
     | 
    
         
             
                    components = data_type.to_s.split("_").collect(&:capitalize)
         
     | 
| 
       156 
157 
     | 
    
         
             
                    data_type_name = components.join.gsub(/\AUint/, "UInt")
         
     | 
| 
       157 
158 
     | 
    
         
             
                    data_type_class_name = "#{data_type_name}DataType"
         
     | 
| 
         @@ -42,16 +42,26 @@ module Arrow 
     | 
|
| 
       42 
42 
     | 
    
         
             
                end
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
       44 
44 
     | 
    
         
             
                private
         
     | 
| 
      
 45 
     | 
    
         
            +
                def precision
         
     | 
| 
      
 46 
     | 
    
         
            +
                  @precision ||= value_data_type.precision
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                def scale
         
     | 
| 
      
 50 
     | 
    
         
            +
                  @scale ||= value_data_type.scale
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
       45 
53 
     | 
    
         
             
                def normalize_value(value)
         
     | 
| 
       46 
54 
     | 
    
         
             
                  case value
         
     | 
| 
       47 
     | 
    
         
            -
                  when String
         
     | 
| 
       48 
     | 
    
         
            -
                    Decimal128.new(value)
         
     | 
| 
       49 
     | 
    
         
            -
                  when Float
         
     | 
| 
       50 
     | 
    
         
            -
                    Decimal128.new(value.to_s)
         
     | 
| 
       51 
55 
     | 
    
         
             
                  when BigDecimal
         
     | 
| 
       52 
     | 
    
         
            -
                     
     | 
| 
      
 56 
     | 
    
         
            +
                    if value.nan? or value.infinite?
         
     | 
| 
      
 57 
     | 
    
         
            +
                      message = "can't use #{value} as an Arrow::Decimal128Array value"
         
     | 
| 
      
 58 
     | 
    
         
            +
                      raise FloatDomainError, message
         
     | 
| 
      
 59 
     | 
    
         
            +
                    end
         
     | 
| 
      
 60 
     | 
    
         
            +
                    integer, decimal = value.to_s("f").split(".", 2)
         
     | 
| 
      
 61 
     | 
    
         
            +
                    decimal = decimal[0, scale].ljust(scale, "0")
         
     | 
| 
      
 62 
     | 
    
         
            +
                    Decimal128.new("#{integer}.#{decimal}")
         
     | 
| 
       53 
63 
     | 
    
         
             
                  else
         
     | 
| 
       54 
     | 
    
         
            -
                    value
         
     | 
| 
      
 64 
     | 
    
         
            +
                    Decimal128.try_convert(value) || value
         
     | 
| 
       55 
65 
     | 
    
         
             
                  end
         
     | 
| 
       56 
66 
     | 
    
         
             
                end
         
     | 
| 
       57 
67 
     | 
    
         
             
              end
         
     | 
    
        data/lib/arrow/decimal128.rb
    CHANGED
    
    | 
         @@ -17,6 +17,20 @@ 
     | 
|
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
            module Arrow
         
     | 
| 
       19 
19 
     | 
    
         
             
              class Decimal128
         
     | 
| 
      
 20 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 21 
     | 
    
         
            +
                  # @api private
         
     | 
| 
      
 22 
     | 
    
         
            +
                  def try_convert(value)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    case value
         
     | 
| 
      
 24 
     | 
    
         
            +
                    when String
         
     | 
| 
      
 25 
     | 
    
         
            +
                      new(value)
         
     | 
| 
      
 26 
     | 
    
         
            +
                    when Float
         
     | 
| 
      
 27 
     | 
    
         
            +
                      new(value.to_s)
         
     | 
| 
      
 28 
     | 
    
         
            +
                    else
         
     | 
| 
      
 29 
     | 
    
         
            +
                      nil
         
     | 
| 
      
 30 
     | 
    
         
            +
                    end
         
     | 
| 
      
 31 
     | 
    
         
            +
                  end
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
       20 
34 
     | 
    
         
             
                alias_method :to_s_raw, :to_s
         
     | 
| 
       21 
35 
     | 
    
         | 
| 
       22 
36 
     | 
    
         
             
                # @overload to_s
         
     | 
| 
         @@ -45,16 +45,26 @@ module Arrow 
     | 
|
| 
       45 
45 
     | 
    
         
             
                end
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
                private
         
     | 
| 
      
 48 
     | 
    
         
            +
                def precision
         
     | 
| 
      
 49 
     | 
    
         
            +
                  @precision ||= value_data_type.precision
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                def scale
         
     | 
| 
      
 53 
     | 
    
         
            +
                  @scale ||= value_data_type.scale
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
       48 
56 
     | 
    
         
             
                def normalize_value(value)
         
     | 
| 
       49 
57 
     | 
    
         
             
                  case value
         
     | 
| 
       50 
     | 
    
         
            -
                  when String
         
     | 
| 
       51 
     | 
    
         
            -
                    Decimal256.new(value)
         
     | 
| 
       52 
     | 
    
         
            -
                  when Float
         
     | 
| 
       53 
     | 
    
         
            -
                    Decimal256.new(value.to_s)
         
     | 
| 
       54 
58 
     | 
    
         
             
                  when BigDecimal
         
     | 
| 
       55 
     | 
    
         
            -
                     
     | 
| 
      
 59 
     | 
    
         
            +
                    if value.nan? or value.infinite?
         
     | 
| 
      
 60 
     | 
    
         
            +
                      message = "can't use #{value} as an Arrow::Decimal256Array value"
         
     | 
| 
      
 61 
     | 
    
         
            +
                      raise FloatDomainError, message
         
     | 
| 
      
 62 
     | 
    
         
            +
                    end
         
     | 
| 
      
 63 
     | 
    
         
            +
                    integer, decimal = value.to_s("f").split(".", 2)
         
     | 
| 
      
 64 
     | 
    
         
            +
                    decimal = decimal[0, scale].ljust(scale, "0")
         
     | 
| 
      
 65 
     | 
    
         
            +
                    Decimal256.new("#{integer}.#{decimal}")
         
     | 
| 
       56 
66 
     | 
    
         
             
                  else
         
     | 
| 
       57 
     | 
    
         
            -
                    value
         
     | 
| 
      
 67 
     | 
    
         
            +
                    Decimal256.try_convert(value) || value
         
     | 
| 
       58 
68 
     | 
    
         
             
                  end
         
     | 
| 
       59 
69 
     | 
    
         
             
                end
         
     | 
| 
       60 
70 
     | 
    
         
             
              end
         
     | 
    
        data/lib/arrow/decimal256.rb
    CHANGED
    
    | 
         @@ -17,6 +17,20 @@ 
     | 
|
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
            module Arrow
         
     | 
| 
       19 
19 
     | 
    
         
             
              class Decimal256
         
     | 
| 
      
 20 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 21 
     | 
    
         
            +
                  # @api private
         
     | 
| 
      
 22 
     | 
    
         
            +
                  def try_convert(value)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    case value
         
     | 
| 
      
 24 
     | 
    
         
            +
                    when String
         
     | 
| 
      
 25 
     | 
    
         
            +
                      new(value)
         
     | 
| 
      
 26 
     | 
    
         
            +
                    when Float
         
     | 
| 
      
 27 
     | 
    
         
            +
                      new(value.to_s)
         
     | 
| 
      
 28 
     | 
    
         
            +
                    else
         
     | 
| 
      
 29 
     | 
    
         
            +
                      nil
         
     | 
| 
      
 30 
     | 
    
         
            +
                    end
         
     | 
| 
      
 31 
     | 
    
         
            +
                  end
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
       20 
34 
     | 
    
         
             
                alias_method :to_s_raw, :to_s
         
     | 
| 
       21 
35 
     | 
    
         | 
| 
       22 
36 
     | 
    
         
             
                # @overload to_s
         
     | 
    
        data/lib/arrow/field.rb
    CHANGED
    
    | 
         @@ -17,12 +17,28 @@ 
     | 
|
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
            module Arrow
         
     | 
| 
       19 
19 
     | 
    
         
             
              class Field
         
     | 
| 
      
 20 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 21 
     | 
    
         
            +
                  # @api private
         
     | 
| 
      
 22 
     | 
    
         
            +
                  def try_convert(value)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    case value
         
     | 
| 
      
 24 
     | 
    
         
            +
                    when Hash
         
     | 
| 
      
 25 
     | 
    
         
            +
                      begin
         
     | 
| 
      
 26 
     | 
    
         
            +
                        new(value)
         
     | 
| 
      
 27 
     | 
    
         
            +
                      rescue ArgumentError
         
     | 
| 
      
 28 
     | 
    
         
            +
                        nil
         
     | 
| 
      
 29 
     | 
    
         
            +
                      end
         
     | 
| 
      
 30 
     | 
    
         
            +
                    else
         
     | 
| 
      
 31 
     | 
    
         
            +
                      nil
         
     | 
| 
      
 32 
     | 
    
         
            +
                    end
         
     | 
| 
      
 33 
     | 
    
         
            +
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
       20 
36 
     | 
    
         
             
                alias_method :initialize_raw, :initialize
         
     | 
| 
       21 
37 
     | 
    
         
             
                private :initialize_raw
         
     | 
| 
       22 
38 
     | 
    
         | 
| 
       23 
39 
     | 
    
         
             
                # Creates a new {Arrow::Field}.
         
     | 
| 
       24 
40 
     | 
    
         
             
                #
         
     | 
| 
       25 
     | 
    
         
            -
                # @overload initialize(name, data_type)
         
     | 
| 
      
 41 
     | 
    
         
            +
                # @overload initialize(name, data_type, nullable=false)
         
     | 
| 
       26 
42 
     | 
    
         
             
                #
         
     | 
| 
       27 
43 
     | 
    
         
             
                #   @param name [String, Symbol] The name of the field.
         
     | 
| 
       28 
44 
     | 
    
         
             
                #
         
     | 
| 
         @@ -34,6 +50,11 @@ module Arrow 
     | 
|
| 
       34 
50 
     | 
    
         
             
                #     See {Arrow::DataType.resolve} how to specify data type
         
     | 
| 
       35 
51 
     | 
    
         
             
                #     description.
         
     | 
| 
       36 
52 
     | 
    
         
             
                #
         
     | 
| 
      
 53 
     | 
    
         
            +
                #   @param nullable [Boolean, nil] (false) Whether the field may contain
         
     | 
| 
      
 54 
     | 
    
         
            +
                #     zero or more nulls.
         
     | 
| 
      
 55 
     | 
    
         
            +
                #
         
     | 
| 
      
 56 
     | 
    
         
            +
                #     `nil` is processed as `true` (null may be contained).
         
     | 
| 
      
 57 
     | 
    
         
            +
                #
         
     | 
| 
       37 
58 
     | 
    
         
             
                #   @example Create a field with {Arrow::DataType}s
         
     | 
| 
       38 
59 
     | 
    
         
             
                #     Arrow::Field.new("visible", Arrow::BooleanDataType.new)
         
     | 
| 
       39 
60 
     | 
    
         
             
                #
         
     | 
| 
         @@ -75,6 +96,11 @@ module Arrow 
     | 
|
| 
       75 
96 
     | 
    
         
             
                #     See {Arrow::DataType.resolve} how to specify data type
         
     | 
| 
       76 
97 
     | 
    
         
             
                #     description.
         
     | 
| 
       77 
98 
     | 
    
         
             
                #
         
     | 
| 
      
 99 
     | 
    
         
            +
                #   @option description [Boolean, nil] :nullable Whether the field
         
     | 
| 
      
 100 
     | 
    
         
            +
                #     may contain zero or more nulls.
         
     | 
| 
      
 101 
     | 
    
         
            +
                #
         
     | 
| 
      
 102 
     | 
    
         
            +
                #     `nil` is processed as `true` (null may be contained).
         
     | 
| 
      
 103 
     | 
    
         
            +
                #
         
     | 
| 
       78 
104 
     | 
    
         
             
                #   @example Create a field with {Arrow::DataType}s
         
     | 
| 
       79 
105 
     | 
    
         
             
                #     Arrow::Field.new(name: "visible",
         
     | 
| 
       80 
106 
     | 
    
         
             
                #                      data_type: Arrow::BooleanDataType.new)
         
     | 
| 
         @@ -92,6 +118,7 @@ module Arrow 
     | 
|
| 
       92 
118 
     | 
    
         
             
                    name = nil
         
     | 
| 
       93 
119 
     | 
    
         
             
                    data_type = nil
         
     | 
| 
       94 
120 
     | 
    
         
             
                    data_type_description = {}
         
     | 
| 
      
 121 
     | 
    
         
            +
                    nullable = nil
         
     | 
| 
       95 
122 
     | 
    
         
             
                    description.each do |key, value|
         
     | 
| 
       96 
123 
     | 
    
         
             
                      key = key.to_sym
         
     | 
| 
       97 
124 
     | 
    
         
             
                      case key
         
     | 
| 
         @@ -99,20 +126,34 @@ module Arrow 
     | 
|
| 
       99 
126 
     | 
    
         
             
                        name = value
         
     | 
| 
       100 
127 
     | 
    
         
             
                      when :data_type
         
     | 
| 
       101 
128 
     | 
    
         
             
                        data_type = DataType.resolve(value)
         
     | 
| 
      
 129 
     | 
    
         
            +
                      when :nullable
         
     | 
| 
      
 130 
     | 
    
         
            +
                        nullable = value
         
     | 
| 
       102 
131 
     | 
    
         
             
                      else
         
     | 
| 
       103 
132 
     | 
    
         
             
                        data_type_description[key] = value
         
     | 
| 
       104 
133 
     | 
    
         
             
                      end
         
     | 
| 
       105 
134 
     | 
    
         
             
                    end
         
     | 
| 
       106 
135 
     | 
    
         
             
                    data_type ||= DataType.resolve(data_type_description)
         
     | 
| 
       107 
136 
     | 
    
         
             
                  when 2
         
     | 
| 
      
 137 
     | 
    
         
            +
                    name = args[0]
         
     | 
| 
      
 138 
     | 
    
         
            +
                    data_type = args[1]
         
     | 
| 
      
 139 
     | 
    
         
            +
                    if data_type.is_a?(Hash)
         
     | 
| 
      
 140 
     | 
    
         
            +
                      data_type = data_type.dup
         
     | 
| 
      
 141 
     | 
    
         
            +
                      nullable = data_type.delete(:nullable)
         
     | 
| 
      
 142 
     | 
    
         
            +
                    else
         
     | 
| 
      
 143 
     | 
    
         
            +
                      nullable = nil
         
     | 
| 
      
 144 
     | 
    
         
            +
                    end
         
     | 
| 
      
 145 
     | 
    
         
            +
                    data_type = DataType.resolve(data_type)
         
     | 
| 
      
 146 
     | 
    
         
            +
                  when 3
         
     | 
| 
       108 
147 
     | 
    
         
             
                    name = args[0]
         
     | 
| 
       109 
148 
     | 
    
         
             
                    data_type = DataType.resolve(args[1])
         
     | 
| 
      
 149 
     | 
    
         
            +
                    nullable = args[2]
         
     | 
| 
       110 
150 
     | 
    
         
             
                  else
         
     | 
| 
       111 
     | 
    
         
            -
                    message = "wrong number of arguments (given #{n_args}, expected 1.. 
     | 
| 
      
 151 
     | 
    
         
            +
                    message = "wrong number of arguments (given #{n_args}, expected 1..3)"
         
     | 
| 
       112 
152 
     | 
    
         
             
                    raise ArgumentError, message
         
     | 
| 
       113 
153 
     | 
    
         
             
                  end
         
     | 
| 
      
 154 
     | 
    
         
            +
                  nullable = true if nullable.nil?
         
     | 
| 
       114 
155 
     | 
    
         | 
| 
       115 
     | 
    
         
            -
                  initialize_raw(name, data_type)
         
     | 
| 
      
 156 
     | 
    
         
            +
                  initialize_raw(name, data_type, nullable)
         
     | 
| 
       116 
157 
     | 
    
         
             
                end
         
     | 
| 
       117 
158 
     | 
    
         
             
              end
         
     | 
| 
       118 
159 
     | 
    
         
             
            end
         
     | 
    
        data/lib/arrow/list-data-type.rb
    CHANGED
    
    
    
        data/lib/arrow/loader.rb
    CHANGED
    
    | 
         @@ -34,6 +34,7 @@ module Arrow 
     | 
|
| 
       34 
34 
     | 
    
         
             
                end
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
36 
     | 
    
         
             
                def require_libraries
         
     | 
| 
      
 37 
     | 
    
         
            +
                  require "arrow/array-computable"
         
     | 
| 
       37 
38 
     | 
    
         
             
                  require "arrow/column-containable"
         
     | 
| 
       38 
39 
     | 
    
         
             
                  require "arrow/field-containable"
         
     | 
| 
       39 
40 
     | 
    
         
             
                  require "arrow/generic-filterable"
         
     | 
| 
         @@ -106,6 +107,7 @@ module Arrow 
     | 
|
| 
       106 
107 
     | 
    
         
             
                  require "arrow/source-node-options"
         
     | 
| 
       107 
108 
     | 
    
         
             
                  require "arrow/sparse-union-data-type"
         
     | 
| 
       108 
109 
     | 
    
         
             
                  require "arrow/string-dictionary-array-builder"
         
     | 
| 
      
 110 
     | 
    
         
            +
                  require "arrow/string-array-builder"
         
     | 
| 
       109 
111 
     | 
    
         
             
                  require "arrow/struct-array"
         
     | 
| 
       110 
112 
     | 
    
         
             
                  require "arrow/struct-array-builder"
         
     | 
| 
       111 
113 
     | 
    
         
             
                  require "arrow/struct-data-type"
         
     | 
| 
         @@ -118,6 +120,7 @@ module Arrow 
     | 
|
| 
       118 
120 
     | 
    
         
             
                  require "arrow/table-saver"
         
     | 
| 
       119 
121 
     | 
    
         
             
                  require "arrow/tensor"
         
     | 
| 
       120 
122 
     | 
    
         
             
                  require "arrow/time"
         
     | 
| 
      
 123 
     | 
    
         
            +
                  require "arrow/time-unit"
         
     | 
| 
       121 
124 
     | 
    
         
             
                  require "arrow/time32-array"
         
     | 
| 
       122 
125 
     | 
    
         
             
                  require "arrow/time32-array-builder"
         
     | 
| 
       123 
126 
     | 
    
         
             
                  require "arrow/time32-data-type"
         
     | 
| 
         @@ -0,0 +1,30 @@ 
     | 
|
| 
      
 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 Arrow
         
     | 
| 
      
 19 
     | 
    
         
            +
              class StringArrayBuilder
         
     | 
| 
      
 20 
     | 
    
         
            +
                private
         
     | 
| 
      
 21 
     | 
    
         
            +
                def convert_to_arrow_value(value)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  case value
         
     | 
| 
      
 23 
     | 
    
         
            +
                  when GLib::Bytes, String
         
     | 
| 
      
 24 
     | 
    
         
            +
                    value
         
     | 
| 
      
 25 
     | 
    
         
            +
                  else
         
     | 
| 
      
 26 
     | 
    
         
            +
                    value.to_s
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,31 @@ 
     | 
|
| 
      
 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 Arrow
         
     | 
| 
      
 19 
     | 
    
         
            +
              class TimeUnit
         
     | 
| 
      
 20 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 21 
     | 
    
         
            +
                  # @api private
         
     | 
| 
      
 22 
     | 
    
         
            +
                  def try_convert(value)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    if value.is_a?(Hash) and value.size == 1 and value[:unit]
         
     | 
| 
      
 24 
     | 
    
         
            +
                      super(value[:unit])
         
     | 
| 
      
 25 
     | 
    
         
            +
                    else
         
     | 
| 
      
 26 
     | 
    
         
            +
                      super
         
     | 
| 
      
 27 
     | 
    
         
            +
                    end
         
     | 
| 
      
 28 
     | 
    
         
            +
                  end
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -18,24 +18,12 @@ 
     | 
|
| 
       18 
18 
     | 
    
         
             
            module Arrow
         
     | 
| 
       19 
19 
     | 
    
         
             
              class Time32ArrayBuilder
         
     | 
| 
       20 
20 
     | 
    
         
             
                class << self
         
     | 
| 
       21 
     | 
    
         
            -
                  def build( 
     | 
| 
       22 
     | 
    
         
            -
                    builder = new( 
     | 
| 
      
 21 
     | 
    
         
            +
                  def build(data_type, values)
         
     | 
| 
      
 22 
     | 
    
         
            +
                    builder = new(data_type)
         
     | 
| 
       23 
23 
     | 
    
         
             
                    builder.build(values)
         
     | 
| 
       24 
24 
     | 
    
         
             
                  end
         
     | 
| 
       25 
25 
     | 
    
         
             
                end
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
                alias_method :initialize_raw, :initialize
         
     | 
| 
       28 
     | 
    
         
            -
                def initialize(unit_or_data_type)
         
     | 
| 
       29 
     | 
    
         
            -
                  case unit_or_data_type
         
     | 
| 
       30 
     | 
    
         
            -
                  when DataType
         
     | 
| 
       31 
     | 
    
         
            -
                    data_type = unit_or_data_type
         
     | 
| 
       32 
     | 
    
         
            -
                  else
         
     | 
| 
       33 
     | 
    
         
            -
                    unit = unit_or_data_type
         
     | 
| 
       34 
     | 
    
         
            -
                    data_type = Time32DataType.new(unit)
         
     | 
| 
       35 
     | 
    
         
            -
                  end
         
     | 
| 
       36 
     | 
    
         
            -
                  initialize_raw(data_type)
         
     | 
| 
       37 
     | 
    
         
            -
                end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
27 
     | 
    
         
             
                def unit
         
     | 
| 
       40 
28 
     | 
    
         
             
                  @unit ||= value_data_type.unit
         
     | 
| 
       41 
29 
     | 
    
         
             
                end
         
     | 
| 
         @@ -17,45 +17,16 @@ 
     | 
|
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
            module Arrow
         
     | 
| 
       19 
19 
     | 
    
         
             
              class Time32DataType
         
     | 
| 
       20 
     | 
    
         
            -
                 
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                #
         
     | 
| 
       30 
     | 
    
         
            -
                #     The unit must be second or millisecond.
         
     | 
| 
       31 
     | 
    
         
            -
                #
         
     | 
| 
       32 
     | 
    
         
            -
                #   @example Create a time32 data type with Arrow::TimeUnit
         
     | 
| 
       33 
     | 
    
         
            -
                #     Arrow::Time32DataType.new(Arrow::TimeUnit::MILLI)
         
     | 
| 
       34 
     | 
    
         
            -
                #
         
     | 
| 
       35 
     | 
    
         
            -
                #   @example Create a time32 data type with Symbol
         
     | 
| 
       36 
     | 
    
         
            -
                #     Arrow::Time32DataType.new(:milli)
         
     | 
| 
       37 
     | 
    
         
            -
                #
         
     | 
| 
       38 
     | 
    
         
            -
                # @overload initialize(description)
         
     | 
| 
       39 
     | 
    
         
            -
                #
         
     | 
| 
       40 
     | 
    
         
            -
                #   @param description [Hash] The description of the time32 data
         
     | 
| 
       41 
     | 
    
         
            -
                #     type. It must have `:unit` value.
         
     | 
| 
       42 
     | 
    
         
            -
                #
         
     | 
| 
       43 
     | 
    
         
            -
                #   @option description [Arrow::TimeUnit, Symbol] :unit The unit of
         
     | 
| 
       44 
     | 
    
         
            -
                #     the time32 data type.
         
     | 
| 
       45 
     | 
    
         
            -
                #
         
     | 
| 
       46 
     | 
    
         
            -
                #     The unit must be second or millisecond.
         
     | 
| 
       47 
     | 
    
         
            -
                #
         
     | 
| 
       48 
     | 
    
         
            -
                #   @example Create a time32 data type with Arrow::TimeUnit
         
     | 
| 
       49 
     | 
    
         
            -
                #     Arrow::Time32DataType.new(unit: Arrow::TimeUnit::MILLI)
         
     | 
| 
       50 
     | 
    
         
            -
                #
         
     | 
| 
       51 
     | 
    
         
            -
                #   @example Create a time32 data type with Symbol
         
     | 
| 
       52 
     | 
    
         
            -
                #     Arrow::Time32DataType.new(unit: :milli)
         
     | 
| 
       53 
     | 
    
         
            -
                def initialize(unit)
         
     | 
| 
       54 
     | 
    
         
            -
                  if unit.is_a?(Hash)
         
     | 
| 
       55 
     | 
    
         
            -
                    description = unit
         
     | 
| 
       56 
     | 
    
         
            -
                    unit = description[:unit]
         
     | 
| 
      
 20 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 21 
     | 
    
         
            +
                  # @api private
         
     | 
| 
      
 22 
     | 
    
         
            +
                  def try_convert(value)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    case value
         
     | 
| 
      
 24 
     | 
    
         
            +
                    when Symbol, Arrow::TimeUnit
         
     | 
| 
      
 25 
     | 
    
         
            +
                      new(value)
         
     | 
| 
      
 26 
     | 
    
         
            +
                    else
         
     | 
| 
      
 27 
     | 
    
         
            +
                      super
         
     | 
| 
      
 28 
     | 
    
         
            +
                    end
         
     | 
| 
       57 
29 
     | 
    
         
             
                  end
         
     | 
| 
       58 
     | 
    
         
            -
                  initialize_raw(unit)
         
     | 
| 
       59 
30 
     | 
    
         
             
                end
         
     | 
| 
       60 
31 
     | 
    
         
             
              end
         
     | 
| 
       61 
32 
     | 
    
         
             
            end
         
     |