]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
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 DenseUnionDataType | |
20 | alias_method :initialize_raw, :initialize | |
21 | private :initialize_raw | |
22 | ||
23 | # Creates a new {Arrow::DenseUnionDataType}. | |
24 | # | |
25 | # @overload initialize(fields, type_codes) | |
26 | # | |
27 | # @param fields [::Array<Arrow::Field, Hash>] The fields of the | |
28 | # dense union data type. You can mix {Arrow::Field} and field | |
29 | # description in the fields. | |
30 | # | |
31 | # See {Arrow::Field.new} how to specify field description. | |
32 | # | |
33 | # @param type_codes [::Array<Integer>] The IDs that indicates | |
34 | # corresponding fields. | |
35 | # | |
36 | # @example Create a dense union data type for `{2: visible, 9: count}` | |
37 | # fields = [ | |
38 | # Arrow::Field.new("visible", :boolean), | |
39 | # { | |
40 | # name: "count", | |
41 | # type: :int32, | |
42 | # }, | |
43 | # ] | |
44 | # Arrow::DenseUnionDataType.new(fields, [2, 9]) | |
45 | # | |
46 | # @overload initialize(description) | |
47 | # | |
48 | # @param description [Hash] The description of the dense union | |
49 | # data type. It must have `:fields` and `:type_codes` values. | |
50 | # | |
51 | # @option description [::Array<Arrow::Field, Hash>] :fields The | |
52 | # fields of the dense union data type. You can mix | |
53 | # {Arrow::Field} and field description in the fields. | |
54 | # | |
55 | # See {Arrow::Field.new} how to specify field description. | |
56 | # | |
57 | # @option description [::Array<Integer>] :type_codes The IDs | |
58 | # that indicates corresponding fields. | |
59 | # | |
60 | # @example Create a dense union data type for `{2: visible, 9: count}` | |
61 | # fields = [ | |
62 | # Arrow::Field.new("visible", :boolean), | |
63 | # { | |
64 | # name: "count", | |
65 | # type: :int32, | |
66 | # }, | |
67 | # ] | |
68 | # Arrow::DenseUnionDataType.new(fields: fields, | |
69 | # type_codes: [2, 9]) | |
70 | def initialize(*args) | |
71 | n_args = args.size | |
72 | case n_args | |
73 | when 1 | |
74 | description = args[0] | |
75 | fields = description[:fields] | |
76 | type_codes = description[:type_codes] | |
77 | when 2 | |
78 | fields, type_codes = args | |
79 | else | |
80 | message = "wrong number of arguments (given, #{n_args}, expected 1..2)" | |
81 | raise ArgumentError, message | |
82 | end | |
83 | fields = fields.collect do |field| | |
84 | field = Field.new(field) unless field.is_a?(Field) | |
85 | field | |
86 | end | |
87 | initialize_raw(fields, type_codes) | |
88 | end | |
89 | end | |
90 | end |