This is an automated email from the ASF dual-hosted git repository.

shiro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new fa6e423  ARROW-4162: [Ruby] Add support for creating data types from 
description
fa6e423 is described below

commit fa6e4238fdce81a17c1957ffbc8cd7defdbc3831
Author: Kouhei Sutou <[email protected]>
AuthorDate: Sun Jan 6 21:21:15 2019 +0900

    ARROW-4162: [Ruby] Add support for creating data types from description
    
    Author: Kouhei Sutou <[email protected]>
    
    Closes #3318 from kou/ruby-data-type-new-by-description and squashes the 
following commits:
    
    e7231e69 <Kouhei Sutou>  Add support for creating data types from 
description
---
 ruby/red-arrow/lib/arrow/decimal128-data-type.rb   |  69 ++++++++++++++
 ruby/red-arrow/lib/arrow/dense-union-data-type.rb  |  90 +++++++++++++++++
 ruby/red-arrow/lib/arrow/dictionary-data-type.rb   | 106 +++++++++++++++++++++
 ruby/red-arrow/lib/arrow/loader.rb                 |   7 ++
 ruby/red-arrow/lib/arrow/sparse-union-data-type.rb |  90 +++++++++++++++++
 ruby/red-arrow/lib/arrow/time32-data-type.rb       |  61 ++++++++++++
 ruby/red-arrow/lib/arrow/time64-data-type.rb       |  61 ++++++++++++
 ruby/red-arrow/lib/arrow/timestamp-data-type.rb    |  57 +++++++++++
 ruby/red-arrow/test/test-decimal128-data-type.rb   |  31 ++++++
 ruby/red-arrow/test/test-dense-union-data-type.rb  |  41 ++++++++
 ruby/red-arrow/test/test-dictionary-data-type.rb   |  40 ++++++++
 ruby/red-arrow/test/test-sparse-union-data-type.rb |  41 ++++++++
 ruby/red-arrow/test/test-time32-data-type.rb       |  42 ++++++++
 ruby/red-arrow/test/test-time64-data-type.rb       |  42 ++++++++
 ruby/red-arrow/test/test-timestamp-data-type.rb    |  42 ++++++++
 15 files changed, 820 insertions(+)

diff --git a/ruby/red-arrow/lib/arrow/decimal128-data-type.rb 
b/ruby/red-arrow/lib/arrow/decimal128-data-type.rb
new file mode 100644
index 0000000..c97944b
--- /dev/null
+++ b/ruby/red-arrow/lib/arrow/decimal128-data-type.rb
@@ -0,0 +1,69 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+module Arrow
+  class Decimal128DataType
+    alias_method :initialize_raw, :initialize
+    private :initialize_raw
+
+    # Creates a new {Arrow::Decimal128DataType}.
+    #
+    # @overload initialize(precision, scale)
+    #
+    #   @param precision [Integer] The precision of the decimal data
+    #     type. It's the number of digits including the number of
+    #     digits after the decimal point.
+    #
+    #   @param scale [Integer] The scale of the decimal data
+    #     type. It's the number of digits after the decimal point.
+    #
+    #   @example Create a decimal data type for "XXXXXX.YY" decimal
+    #     Arrow::Decimal128DataType.new(8, 2)
+    #
+    # @overload initialize(description)
+    #
+    #   @param description [Hash] The description of the decimal data
+    #     type. It must have `:precision` and `:scale` values.
+    #
+    #   @option description [Integer] :precision The precision of the
+    #     decimal data type. It's the number of digits including the
+    #     number of digits after the decimal point.
+    #
+    #   @option description [Integer] :scale The scale of the decimal
+    #     data type. It's the number of digits after the decimal
+    #     point.
+    #
+    #   @example Create a decimal data type for "XXXXXX.YY" decimal
+    #     Arrow::Decimal128DataType.new(precision: 8,
+    #                                   scale: 2)
+    def initialize(*args)
+      n_args = args.size
+      case n_args
+      when 1
+        description = args[0]
+        precision = description[:precision]
+        scale = description[:scale]
+      when 2
+        precision, scale = args
+      else
+        message = "wrong number of arguments (given, #{n_args}, expected 1..2)"
+        raise ArgumentError, message
+      end
+      initialize_raw(precision, scale)
+    end
+  end
+end
diff --git a/ruby/red-arrow/lib/arrow/dense-union-data-type.rb 
b/ruby/red-arrow/lib/arrow/dense-union-data-type.rb
new file mode 100644
index 0000000..740b313
--- /dev/null
+++ b/ruby/red-arrow/lib/arrow/dense-union-data-type.rb
@@ -0,0 +1,90 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+module Arrow
+  class DenseUnionDataType
+    alias_method :initialize_raw, :initialize
+    private :initialize_raw
+
+    # Creates a new {Arrow::DenseUnionDataType}.
+    #
+    # @overload initialize(fields, type_codes)
+    #
+    #   @param fields [::Array<Arrow::Field, Hash>] The fields of the
+    #     dense union data type. You can mix {Arrow::Field} and field
+    #     description in the fields.
+    #
+    #     See {Arrow::Field.new} how to specify field description.
+    #
+    #   @param type_codes [::Array<Integer>] The IDs that indicates
+    #     corresponding fields.
+    #
+    #   @example Create a dense union data type for {2: visible, 9: count}
+    #     fields = [
+    #       Arrow::Field.new("visible", :boolean),
+    #       {
+    #         name: "count",
+    #         type: :int32,
+    #       },
+    #     ]
+    #     Arrow::DenseUnionDataType.new(fields, [2, 9])
+    #
+    # @overload initialize(description)
+    #
+    #   @param description [Hash] The description of the dense union
+    #     data type. It must have `:fields` and `:type_codes` values.
+    #
+    #   @option description [::Array<Arrow::Field, Hash>] :fields The
+    #     fields of the dense union data type. You can mix
+    #     {Arrow::Field} and field description in the fields.
+    #
+    #     See {Arrow::Field.new} how to specify field description.
+    #
+    #   @option description [::Array<Integer>] :type_codes The IDs
+    #     that indicates corresponding fields.
+    #
+    #   @example Create a dense union data type for {2: visible, 9: count}
+    #     fields = [
+    #       Arrow::Field.new("visible", :boolean),
+    #       {
+    #         name: "count",
+    #         type: :int32,
+    #       },
+    #     ]
+    #     Arrow::DenseUnionDataType.new(fields: fields,
+    #                                   type_codes: [2, 9])
+    def initialize(*args)
+      n_args = args.size
+      case n_args
+      when 1
+        description = args[0]
+        fields = description[:fields]
+        type_codes = description[:type_codes]
+      when 2
+        fields, type_codes = args
+      else
+        message = "wrong number of arguments (given, #{n_args}, expected 1..2)"
+        raise ArgumentError, message
+      end
+      fields = fields.collect do |field|
+        field = Field.new(field) unless field.is_a?(Field)
+        field
+      end
+      initialize_raw(fields, type_codes)
+    end
+  end
+end
diff --git a/ruby/red-arrow/lib/arrow/dictionary-data-type.rb 
b/ruby/red-arrow/lib/arrow/dictionary-data-type.rb
new file mode 100644
index 0000000..e799fdf
--- /dev/null
+++ b/ruby/red-arrow/lib/arrow/dictionary-data-type.rb
@@ -0,0 +1,106 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+module Arrow
+  class DictionaryDataType
+    alias_method :initialize_raw, :initialize
+    private :initialize_raw
+
+    # Creates a new {Arrow::DictionaryDataType}.
+    #
+    # @overload initialize(index_data_type, dictionary, ordered)
+    #
+    #   @param index_data_type [Arrow::DataType, Hash, String, Symbol]
+    #     The index data type of the dictionary data type. It must be
+    #     signed integer data types. Here are available signed integer
+    #     data types:
+    #
+    #       * Arrow::Int8DataType
+    #       * Arrow::Int16DataType
+    #       * Arrow::Int32DataType
+    #       * Arrow::Int64DataType
+    #
+    #     You can specify data type as a description by `Hash`.
+    #
+    #     See {Arrow::DataType.resolve} how to specify data type
+    #     description.
+    #
+    #   @param dictionary [Arrow::Array] The real values of the
+    #     dictionary data type.
+    #
+    #   @param ordered [Boolean] Whether dictionary contents are
+    #     ordered or not.
+    #
+    #   @example Create a dictionary data type for {0: "Hello", 1: "World"}
+    #     index_data_type = :int8
+    #     dictionary = Arrow::StringArray.new(["Hello", "World"])
+    #     ordered = true
+    #     Arrow::DictionaryDataType.new(index_data_type,
+    #                                   dictionary,
+    #                                   ordered)
+    #
+    # @overload initialize(description)
+    #
+    #   @param description [Hash] The description of the dictionary
+    #     data type. It must have `:index_data_type`, `:dictionary`
+    #     and `:ordered` values.
+    #
+    #   @option description [Arrow::DataType, Hash, String, Symbol]
+    #     :index_data_type The index data type of the dictionary data
+    #     type. It must be signed integer data types. Here are
+    #     available signed integer data types:
+    #
+    #       * Arrow::Int8DataType
+    #       * Arrow::Int16DataType
+    #       * Arrow::Int32DataType
+    #       * Arrow::Int64DataType
+    #
+    #     You can specify data type as a description by `Hash`.
+    #
+    #     See {Arrow::DataType.resolve} how to specify data type
+    #     description.
+    #
+    #   @option description [Arrow::Array] :dictionary The real values
+    #     of the dictionary data type.
+    #
+    #   @option description [Boolean] :ordered Whether dictionary
+    #     contents are ordered or not.
+    #
+    #   @example Create a dictionary data type for {0: "Hello", 1: "World"}
+    #     dictionary = Arrow::StringArray.new(["Hello", "World"])
+    #     Arrow::DictionaryDataType.new(index_data_type: :int8,
+    #                                   dictionary: dictionary,
+    #                                   ordered: true)
+    def initialize(*args)
+      n_args = args.size
+      case n_args
+      when 1
+        description = args[0]
+        index_data_type = description[:index_data_type]
+        dictionary = description[:dictionary]
+        ordered = description[:ordered]
+      when 3
+        index_data_type, dictionary, ordered = args
+      else
+        message = "wrong number of arguments (given, #{n_args}, expected 1 or 
3)"
+        raise ArgumentError, message
+      end
+      index_data_type = DataType.resolve(index_data_type)
+      initialize_raw(index_data_type, dictionary, ordered)
+    end
+  end
+end
diff --git a/ruby/red-arrow/lib/arrow/loader.rb 
b/ruby/red-arrow/lib/arrow/loader.rb
index cea98e9..8747476 100644
--- a/ruby/red-arrow/lib/arrow/loader.rb
+++ b/ruby/red-arrow/lib/arrow/loader.rb
@@ -43,6 +43,9 @@ module Arrow
       require "arrow/date32-array-builder"
       require "arrow/date64-array"
       require "arrow/date64-array-builder"
+      require "arrow/decimal128-data-type"
+      require "arrow/dense-union-data-type"
+      require "arrow/dictionary-data-type"
       require "arrow/field"
       require "arrow/file-output-stream"
       require "arrow/list-data-type"
@@ -54,6 +57,7 @@ module Arrow
       require "arrow/rolling-window"
       require "arrow/schema"
       require "arrow/slicer"
+      require "arrow/sparse-union-data-type"
       require "arrow/struct-array"
       require "arrow/struct-data-type"
       require "arrow/table"
@@ -63,8 +67,11 @@ module Arrow
       require "arrow/table-loader"
       require "arrow/table-saver"
       require "arrow/tensor"
+      require "arrow/time32-data-type"
+      require "arrow/time64-data-type"
       require "arrow/timestamp-array"
       require "arrow/timestamp-array-builder"
+      require "arrow/timestamp-data-type"
       require "arrow/writable"
     end
 
diff --git a/ruby/red-arrow/lib/arrow/sparse-union-data-type.rb 
b/ruby/red-arrow/lib/arrow/sparse-union-data-type.rb
new file mode 100644
index 0000000..fb0ddf0
--- /dev/null
+++ b/ruby/red-arrow/lib/arrow/sparse-union-data-type.rb
@@ -0,0 +1,90 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+module Arrow
+  class SparseUnionDataType
+    alias_method :initialize_raw, :initialize
+    private :initialize_raw
+
+    # Creates a new {Arrow::SparseUnionDataType}.
+    #
+    # @overload initialize(fields, type_codes)
+    #
+    #   @param fields [::Array<Arrow::Field, Hash>] The fields of the
+    #     sparse union data type. You can mix {Arrow::Field} and field
+    #     description in the fields.
+    #
+    #     See {Arrow::Field.new} how to specify field description.
+    #
+    #   @param type_codes [::Array<Integer>] The IDs that indicates
+    #     corresponding fields.
+    #
+    #   @example Create a sparse union data type for {2: visible, 9: count}
+    #     fields = [
+    #       Arrow::Field.new("visible", :boolean),
+    #       {
+    #         name: "count",
+    #         type: :int32,
+    #       },
+    #     ]
+    #     Arrow::SparseUnionDataType.new(fields, [2, 9])
+    #
+    # @overload initialize(description)
+    #
+    #   @param description [Hash] The description of the sparse union
+    #     data type. It must have `:fields` and `:type_codes` values.
+    #
+    #   @option description [::Array<Arrow::Field, Hash>] :fields The
+    #     fields of the sparse union data type. You can mix
+    #     {Arrow::Field} and field description in the fields.
+    #
+    #     See {Arrow::Field.new} how to specify field description.
+    #
+    #   @option description [::Array<Integer>] :type_codes The IDs
+    #     that indicates corresponding fields.
+    #
+    #   @example Create a sparse union data type for {2: visible, 9: count}
+    #     fields = [
+    #       Arrow::Field.new("visible", :boolean),
+    #       {
+    #         name: "count",
+    #         type: :int32,
+    #       },
+    #     ]
+    #     Arrow::SparseUnionDataType.new(fields: fields,
+    #                                    type_codes: [2, 9])
+    def initialize(*args)
+      n_args = args.size
+      case n_args
+      when 1
+        description = args[0]
+        fields = description[:fields]
+        type_codes = description[:type_codes]
+      when 2
+        fields, type_codes = args
+      else
+        message = "wrong number of arguments (given, #{n_args}, expected 1..2)"
+        raise ArgumentError, message
+      end
+      fields = fields.collect do |field|
+        field = Field.new(field) unless field.is_a?(Field)
+        field
+      end
+      initialize_raw(fields, type_codes)
+    end
+  end
+end
diff --git a/ruby/red-arrow/lib/arrow/time32-data-type.rb 
b/ruby/red-arrow/lib/arrow/time32-data-type.rb
new file mode 100644
index 0000000..9e8d955
--- /dev/null
+++ b/ruby/red-arrow/lib/arrow/time32-data-type.rb
@@ -0,0 +1,61 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+module Arrow
+  class Time32DataType
+    alias_method :initialize_raw, :initialize
+    private :initialize_raw
+
+    # Creates a new {Arrow::Time32DataType}.
+    #
+    # @overload initialize(unit)
+    #
+    #   @param unit [Arrow::TimeUnit, Symbol] The unit of the
+    #     time32 data type.
+    #
+    #     The unit must be second or millisecond.
+    #
+    #   @example Create a time32 data type with {Arrow::TimeUnit}
+    #     Arrow::Time32DataType.new(Arrow::TimeUnit::MILLI)
+    #
+    #   @example Create a time32 data type with Symbol
+    #     Arrow::Time32DataType.new(:milli)
+    #
+    # @overload initialize(description)
+    #
+    #   @param description [Hash] The description of the time32 data
+    #     type. It must have `:unit` value.
+    #
+    #   @option description [Arrow::TimeUnit, Symbol] :unit The unit of
+    #     the time32 data type.
+    #
+    #     The unit must be second or millisecond.
+    #
+    #   @example Create a time32 data type with {Arrow::TimeUnit}
+    #     Arrow::Time32DataType.new(unit: Arrow::TimeUnit::MILLI)
+    #
+    #   @example Create a time32 data type with Symbol
+    #     Arrow::Time32DataType.new(unit: :milli)
+    def initialize(unit)
+      if unit.is_a?(Hash)
+        description = unit
+        unit = description[:unit]
+      end
+      initialize_raw(unit)
+    end
+  end
+end
diff --git a/ruby/red-arrow/lib/arrow/time64-data-type.rb 
b/ruby/red-arrow/lib/arrow/time64-data-type.rb
new file mode 100644
index 0000000..ca31a56
--- /dev/null
+++ b/ruby/red-arrow/lib/arrow/time64-data-type.rb
@@ -0,0 +1,61 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+module Arrow
+  class Time64DataType
+    alias_method :initialize_raw, :initialize
+    private :initialize_raw
+
+    # Creates a new {Arrow::Time64DataType}.
+    #
+    # @overload initialize(unit)
+    #
+    #   @param unit [Arrow::TimeUnit, Symbol] The unit of the
+    #     time64 data type.
+    #
+    #     The unit must be microsecond or nanosecond.
+    #
+    #   @example Create a time64 data type with {Arrow::TimeUnit}
+    #     Arrow::Time64DataType.new(Arrow::TimeUnit::NANO)
+    #
+    #   @example Create a time64 data type with Symbol
+    #     Arrow::Time64DataType.new(:nano)
+    #
+    # @overload initialize(description)
+    #
+    #   @param description [Hash] The description of the time64 data
+    #     type. It must have `:unit` value.
+    #
+    #   @option description [Arrow::TimeUnit, Symbol] :unit The unit of
+    #     the time64 data type.
+    #
+    #     The unit must be microsecond or nanosecond.
+    #
+    #   @example Create a time64 data type with {Arrow::TimeUnit}
+    #     Arrow::Time64DataType.new(unit: Arrow::TimeUnit::NANO)
+    #
+    #   @example Create a time64 data type with Symbol
+    #     Arrow::Time64DataType.new(unit: :nano)
+    def initialize(unit)
+      if unit.is_a?(Hash)
+        description = unit
+        unit = description[:unit]
+      end
+      initialize_raw(unit)
+    end
+  end
+end
diff --git a/ruby/red-arrow/lib/arrow/timestamp-data-type.rb 
b/ruby/red-arrow/lib/arrow/timestamp-data-type.rb
new file mode 100644
index 0000000..86ed3e0
--- /dev/null
+++ b/ruby/red-arrow/lib/arrow/timestamp-data-type.rb
@@ -0,0 +1,57 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+module Arrow
+  class TimestampDataType
+    alias_method :initialize_raw, :initialize
+    private :initialize_raw
+
+    # Creates a new {Arrow::TimestampDataType}.
+    #
+    # @overload initialize(unit)
+    #
+    #   @param unit [Arrow::TimeUnit, Symbol] The unit of the
+    #     timestamp data type.
+    #
+    #   @example Create a timestamp data type with {Arrow::TimeUnit}
+    #     Arrow::TimestampDataType.new(Arrow::TimeUnit::MILLI)
+    #
+    #   @example Create a timestamp data type with Symbol
+    #     Arrow::TimestampDataType.new(:milli)
+    #
+    # @overload initialize(description)
+    #
+    #   @param description [Hash] The description of the timestamp data
+    #     type. It must have `:unit` value.
+    #
+    #   @option description [Arrow::TimeUnit, Symbol] :unit The unit of
+    #     the timestamp data type.
+    #
+    #   @example Create a timestamp data type with {Arrow::TimeUnit}
+    #     Arrow::TimestampDataType.new(unit: Arrow::TimeUnit::MILLI)
+    #
+    #   @example Create a timestamp data type with Symbol
+    #     Arrow::TimestampDataType.new(unit: :milli)
+    def initialize(unit)
+      if unit.is_a?(Hash)
+        description = unit
+        unit = description[:unit]
+      end
+      initialize_raw(unit)
+    end
+  end
+end
diff --git a/ruby/red-arrow/test/test-decimal128-data-type.rb 
b/ruby/red-arrow/test/test-decimal128-data-type.rb
new file mode 100644
index 0000000..6cdd22f
--- /dev/null
+++ b/ruby/red-arrow/test/test-decimal128-data-type.rb
@@ -0,0 +1,31 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class Decimal128DataTypeTest < Test::Unit::TestCase
+  sub_test_case(".new") do
+    test("ordered arguments") do
+      assert_equal("decimal(8, 2)",
+                   Arrow::Decimal128DataType.new(8, 2).to_s)
+    end
+
+    test("description") do
+      assert_equal("decimal(8, 2)",
+                   Arrow::Decimal128DataType.new(precision: 8,
+                                                 scale: 2).to_s)
+    end
+  end
+end
diff --git a/ruby/red-arrow/test/test-dense-union-data-type.rb 
b/ruby/red-arrow/test/test-dense-union-data-type.rb
new file mode 100644
index 0000000..96699e5
--- /dev/null
+++ b/ruby/red-arrow/test/test-dense-union-data-type.rb
@@ -0,0 +1,41 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class DenseUnionDataTypeTest < Test::Unit::TestCase
+  sub_test_case(".new") do
+    def setup
+      @fields = [
+        Arrow::Field.new("visible", :boolean),
+        {
+          name: "count",
+          type: :int32,
+        },
+      ]
+    end
+
+    test("ordered arguments") do
+      assert_equal("union[dense]<visible: bool=2, count: int32=9>",
+                   Arrow::DenseUnionDataType.new(@fields, [2, 9]).to_s)
+    end
+
+    test("description") do
+      assert_equal("union[dense]<visible: bool=2, count: int32=9>",
+                   Arrow::DenseUnionDataType.new(fields: @fields,
+                                                  type_codes: [2, 9]).to_s)
+    end
+  end
+end
diff --git a/ruby/red-arrow/test/test-dictionary-data-type.rb 
b/ruby/red-arrow/test/test-dictionary-data-type.rb
new file mode 100644
index 0000000..be9cd6f
--- /dev/null
+++ b/ruby/red-arrow/test/test-dictionary-data-type.rb
@@ -0,0 +1,40 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class DictionaryDataTypeTest < Test::Unit::TestCase
+  sub_test_case(".new") do
+    def setup
+      @index_data_type = :int8
+      @dictionary = Arrow::StringArray.new(["Hello", "World"])
+      @ordered = true
+    end
+
+    test("ordered arguments") do
+      assert_equal("dictionary<values=string, indices=int8, ordered=1>",
+                   Arrow::DictionaryDataType.new(@index_data_type,
+                                                 @dictionary,
+                                                 @ordered).to_s)
+    end
+
+    test("description") do
+      assert_equal("dictionary<values=string, indices=int8, ordered=1>",
+                   Arrow::DictionaryDataType.new(index_data_type: 
@index_data_type,
+                                                 dictionary: @dictionary,
+                                                 ordered: @ordered).to_s)
+    end
+  end
+end
diff --git a/ruby/red-arrow/test/test-sparse-union-data-type.rb 
b/ruby/red-arrow/test/test-sparse-union-data-type.rb
new file mode 100644
index 0000000..4159b42
--- /dev/null
+++ b/ruby/red-arrow/test/test-sparse-union-data-type.rb
@@ -0,0 +1,41 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class SparseUnionDataTypeTest < Test::Unit::TestCase
+  sub_test_case(".new") do
+    def setup
+      @fields = [
+        Arrow::Field.new("visible", :boolean),
+        {
+          name: "count",
+          type: :int32,
+        },
+      ]
+    end
+
+    test("ordered arguments") do
+      assert_equal("union[sparse]<visible: bool=2, count: int32=9>",
+                   Arrow::SparseUnionDataType.new(@fields, [2, 9]).to_s)
+    end
+
+    test("description") do
+      assert_equal("union[sparse]<visible: bool=2, count: int32=9>",
+                   Arrow::SparseUnionDataType.new(fields: @fields,
+                                                  type_codes: [2, 9]).to_s)
+    end
+  end
+end
diff --git a/ruby/red-arrow/test/test-time32-data-type.rb 
b/ruby/red-arrow/test/test-time32-data-type.rb
new file mode 100644
index 0000000..26f1735
--- /dev/null
+++ b/ruby/red-arrow/test/test-time32-data-type.rb
@@ -0,0 +1,42 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class Time32DataTypeTest < Test::Unit::TestCase
+  sub_test_case(".new") do
+    test("Arrow::TimeUnit") do
+      assert_equal("time32[ms]",
+                   Arrow::Time32DataType.new(Arrow::TimeUnit::MILLI).to_s)
+    end
+
+    test("Symbol") do
+      assert_equal("time32[ms]",
+                   Arrow::Time32DataType.new(:milli).to_s)
+    end
+
+    test("unit: Arrow::TimeUnit") do
+      data_type = Arrow::Time32DataType.new(unit: Arrow::TimeUnit::MILLI)
+      assert_equal("time32[ms]",
+                   data_type.to_s)
+    end
+
+    test("unit: Symbol") do
+      data_type = Arrow::Time32DataType.new(unit: :milli)
+      assert_equal("time32[ms]",
+                   data_type.to_s)
+    end
+  end
+end
diff --git a/ruby/red-arrow/test/test-time64-data-type.rb 
b/ruby/red-arrow/test/test-time64-data-type.rb
new file mode 100644
index 0000000..a5f3417
--- /dev/null
+++ b/ruby/red-arrow/test/test-time64-data-type.rb
@@ -0,0 +1,42 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class Time64DataTypeTest < Test::Unit::TestCase
+  sub_test_case(".new") do
+    test("Arrow::TimeUnit") do
+      assert_equal("time64[ns]",
+                   Arrow::Time64DataType.new(Arrow::TimeUnit::NANO).to_s)
+    end
+
+    test("Symbol") do
+      assert_equal("time64[ns]",
+                   Arrow::Time64DataType.new(:nano).to_s)
+    end
+
+    test("unit: Arrow::TimeUnit") do
+      data_type = Arrow::Time64DataType.new(unit: Arrow::TimeUnit::NANO)
+      assert_equal("time64[ns]",
+                   data_type.to_s)
+    end
+
+    test("unit: Symbol") do
+      data_type = Arrow::Time64DataType.new(unit: :nano)
+      assert_equal("time64[ns]",
+                   data_type.to_s)
+    end
+  end
+end
diff --git a/ruby/red-arrow/test/test-timestamp-data-type.rb 
b/ruby/red-arrow/test/test-timestamp-data-type.rb
new file mode 100644
index 0000000..f8ccd3d
--- /dev/null
+++ b/ruby/red-arrow/test/test-timestamp-data-type.rb
@@ -0,0 +1,42 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TimestampDataTypeTest < Test::Unit::TestCase
+  sub_test_case(".new") do
+    test("Arrow::TimeUnit") do
+      assert_equal("timestamp[ms]",
+                   Arrow::TimestampDataType.new(Arrow::TimeUnit::MILLI).to_s)
+    end
+
+    test("Symbol") do
+      assert_equal("timestamp[ms]",
+                   Arrow::TimestampDataType.new(:milli).to_s)
+    end
+
+    test("unit: Arrow::TimeUnit") do
+      data_type = Arrow::TimestampDataType.new(unit: Arrow::TimeUnit::MILLI)
+      assert_equal("timestamp[ms]",
+                   data_type.to_s)
+    end
+
+    test("unit: Symbol") do
+      data_type = Arrow::TimestampDataType.new(unit: :milli)
+      assert_equal("timestamp[ms]",
+                   data_type.to_s)
+    end
+  end
+end

Reply via email to