]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/ruby/red-arrow/lib/arrow/dictionary-data-type.rb
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / ruby / red-arrow / lib / arrow / dictionary-data-type.rb
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 DictionaryDataType
20 alias_method :initialize_raw, :initialize
21 private :initialize_raw
22
23 # Creates a new {Arrow::DictionaryDataType}.
24 #
25 # @overload initialize(index_data_type, value_data_type, ordered)
26 #
27 # @param index_data_type [Arrow::DataType, Hash, String, Symbol]
28 # The index data type of the dictionary data type. It must be
29 # signed integer data types. Here are available signed integer
30 # data types:
31 #
32 # * Arrow::Int8DataType
33 # * Arrow::Int16DataType
34 # * Arrow::Int32DataType
35 # * Arrow::Int64DataType
36 #
37 # You can specify data type as a description by `Hash`.
38 #
39 # See {Arrow::DataType.resolve} how to specify data type
40 # description.
41 #
42 # @param value_data_type [Arrow::DataType, Hash, String, Symbol]
43 # The value data type of the dictionary data type.
44 #
45 # You can specify data type as a description by `Hash`.
46 #
47 # See {Arrow::DataType.resolve} how to specify data type
48 # description.
49 #
50 # @param ordered [Boolean] Whether dictionary contents are
51 # ordered or not.
52 #
53 # @example Create a dictionary data type for `{0: "Hello", 1: "World"}`
54 # index_data_type = :int8
55 # value_data_type = :string
56 # ordered = true
57 # Arrow::DictionaryDataType.new(index_data_type,
58 # value_data_type,
59 # ordered)
60 #
61 # @overload initialize(description)
62 #
63 # @param description [Hash] The description of the dictionary
64 # data type. It must have `:index_data_type`, `:dictionary`
65 # and `:ordered` values.
66 #
67 # @option description [Arrow::DataType, Hash, String, Symbol]
68 # :index_data_type The index data type of the dictionary data
69 # type. It must be signed integer data types. Here are
70 # available signed integer data types:
71 #
72 # * Arrow::Int8DataType
73 # * Arrow::Int16DataType
74 # * Arrow::Int32DataType
75 # * Arrow::Int64DataType
76 #
77 # You can specify data type as a description by `Hash`.
78 #
79 # See {Arrow::DataType.resolve} how to specify data type
80 # description.
81 #
82 # @option description [Arrow::DataType, Hash, String, Symbol]
83 # :value_data_type
84 # The value data type of the dictionary data type.
85 #
86 # You can specify data type as a description by `Hash`.
87 #
88 # See {Arrow::DataType.resolve} how to specify data type
89 # description.
90 #
91 # @option description [Boolean] :ordered Whether dictionary
92 # contents are ordered or not.
93 #
94 # @example Create a dictionary data type for `{0: "Hello", 1: "World"}`
95 # Arrow::DictionaryDataType.new(index_data_type: :int8,
96 # value_data_type: :string,
97 # ordered: true)
98 def initialize(*args)
99 n_args = args.size
100 case n_args
101 when 1
102 description = args[0]
103 index_data_type = description[:index_data_type]
104 value_data_type = description[:value_data_type]
105 ordered = description[:ordered]
106 when 3
107 index_data_type, value_data_type, ordered = args
108 else
109 message = "wrong number of arguments (given, #{n_args}, expected 1 or 3)"
110 raise ArgumentError, message
111 end
112 index_data_type = DataType.resolve(index_data_type)
113 value_data_type = DataType.resolve(value_data_type)
114 initialize_raw(index_data_type, value_data_type, ordered)
115 end
116 end
117 end