red-arrow 0.8.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +14 -11
  3. data/{doc/text/apache-2.0.txt → LICENSE.txt} +0 -0
  4. data/NOTICE.txt +2 -0
  5. data/README.md +27 -30
  6. data/Rakefile +15 -21
  7. data/dependency-check/Rakefile +15 -12
  8. data/doc/text/development.md +19 -0
  9. data/lib/arrow.rb +14 -11
  10. data/lib/arrow/array-builder.rb +55 -55
  11. data/lib/arrow/array.rb +15 -11
  12. data/lib/arrow/block-closable.rb +14 -11
  13. data/lib/arrow/chunked-array.rb +15 -11
  14. data/lib/arrow/column.rb +14 -11
  15. data/lib/arrow/csv-loader.rb +49 -20
  16. data/lib/arrow/csv-reader.rb +14 -11
  17. data/lib/arrow/date32-array-builder.rb +14 -11
  18. data/lib/arrow/date32-array.rb +14 -11
  19. data/lib/arrow/date64-array-builder.rb +15 -12
  20. data/lib/arrow/date64-array.rb +14 -11
  21. data/lib/arrow/field.rb +14 -11
  22. data/lib/arrow/group.rb +55 -13
  23. data/lib/arrow/loader.rb +16 -15
  24. data/lib/arrow/record-batch-file-reader.rb +14 -11
  25. data/lib/arrow/record-batch-stream-reader.rb +14 -11
  26. data/lib/arrow/record-batch.rb +14 -11
  27. data/lib/arrow/record-containable.rb +14 -11
  28. data/lib/arrow/record.rb +14 -11
  29. data/lib/arrow/rolling-window.rb +48 -0
  30. data/lib/arrow/slicer.rb +20 -14
  31. data/lib/arrow/struct-array.rb +24 -0
  32. data/lib/arrow/table-formatter.rb +15 -11
  33. data/lib/arrow/table-list-formatter.rb +15 -11
  34. data/lib/arrow/table-loader.rb +24 -11
  35. data/lib/arrow/table-saver.rb +14 -11
  36. data/lib/arrow/table-table-formatter.rb +15 -11
  37. data/lib/arrow/table.rb +48 -17
  38. data/lib/arrow/tensor.rb +14 -11
  39. data/lib/arrow/timestamp-array-builder.rb +16 -29
  40. data/lib/arrow/timestamp-array.rb +15 -30
  41. data/lib/arrow/version.rb +23 -12
  42. data/red-arrow.gemspec +30 -30
  43. data/test/fixture/TestOrcFile.test1.orc +0 -0
  44. data/test/fixture/float-integer.csv +20 -0
  45. data/test/fixture/integer-float.csv +20 -0
  46. data/test/fixture/null-with-double-quote.csv +16 -0
  47. data/test/fixture/null-without-double-quote.csv +16 -0
  48. data/test/fixture/with-header-float.csv +20 -0
  49. data/test/fixture/with-header.csv +16 -0
  50. data/test/fixture/without-header-float.csv +19 -0
  51. data/test/fixture/without-header.csv +16 -0
  52. data/test/helper.rb +16 -11
  53. data/test/helper/fixture.rb +14 -11
  54. data/test/run-test.rb +17 -12
  55. data/test/test-array-builder.rb +14 -11
  56. data/test/test-array.rb +14 -11
  57. data/test/test-chunked-array.rb +14 -11
  58. data/test/test-column.rb +14 -11
  59. data/test/test-csv-loader.rb +68 -49
  60. data/test/test-csv-reader.rb +17 -12
  61. data/test/test-date32-array.rb +14 -11
  62. data/test/test-date64-array.rb +14 -11
  63. data/test/test-group.rb +56 -11
  64. data/test/test-orc.rb +177 -0
  65. data/test/test-record-batch-file-reader.rb +14 -11
  66. data/test/test-record-batch.rb +14 -11
  67. data/test/test-rolling-window.rb +40 -0
  68. data/test/test-slicer.rb +14 -11
  69. data/test/test-struct-array.rb +36 -0
  70. data/test/test-table.rb +50 -22
  71. data/test/test-timestamp-array.rb +14 -11
  72. metadata +42 -57
  73. data/.yardopts +0 -6
  74. data/doc/text/news.md +0 -176
  75. data/lib/arrow/buffer.rb +0 -24
  76. data/lib/arrow/compatibility.rb +0 -28
  77. data/lib/arrow/data-type.rb +0 -81
@@ -1,16 +1,19 @@
1
- # Copyright 2017 Kouhei Sutou <kou@clear-code.com>
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
2
8
  #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
9
+ # http://www.apache.org/licenses/LICENSE-2.0
6
10
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
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.
14
17
 
15
18
  module Arrow
16
19
  module BlockClosable
@@ -1,16 +1,19 @@
1
- # Copyright 2017-2018 Kouhei Sutou <kou@clear-code.com>
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
2
8
  #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
9
+ # http://www.apache.org/licenses/LICENSE-2.0
6
10
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
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.
14
17
 
15
18
  module Arrow
16
19
  class ChunkedArray
@@ -38,6 +41,7 @@ module Arrow
38
41
  end
39
42
 
40
43
  def [](i)
44
+ i += length if i < 0
41
45
  chunks.each do |array|
42
46
  return array[i] if i < array.length
43
47
  i -= array.length
@@ -1,16 +1,19 @@
1
- # Copyright 2017 Kouhei Sutou <kou@clear-code.com>
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
2
8
  #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
9
+ # http://www.apache.org/licenses/LICENSE-2.0
6
10
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
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.
14
17
 
15
18
  module Arrow
16
19
  class Column
@@ -1,16 +1,19 @@
1
- # Copyright 2017-2018 Kouhei Sutou <kou@clear-code.com>
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
2
8
  #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
9
+ # http://www.apache.org/licenses/LICENSE-2.0
6
10
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
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.
14
17
 
15
18
  require "csv"
16
19
  require "pathname"
@@ -117,20 +120,32 @@ module Arrow
117
120
  end
118
121
 
119
122
  def update_csv_parse_options(options, create_csv, *args)
120
- return options unless options.empty?
123
+ if options.key?(:converters)
124
+ new_options = options.dup
125
+ else
126
+ converters = [:all, BOOLEAN_CONVERTER, ISO8601_CONVERTER]
127
+ new_options = options.merge(converters: converters)
128
+ end
121
129
 
122
- converters = [:all, BOOLEAN_CONVERTER, ISO8601_CONVERTER]
123
- new_options = options.merge(converters: converters)
124
- __send__(create_csv, *args, **new_options) do |csv|
125
- new_options[:headers] = have_header?(csv)
130
+ unless options.key?(:headers)
131
+ __send__(create_csv, *args, **new_options) do |csv|
132
+ new_options[:headers] = have_header?(csv)
133
+ end
126
134
  end
127
- __send__(create_csv, *args, **new_options) do |csv|
128
- new_options[:converters] = detect_robust_converters(csv)
135
+ unless options.key?(:converters)
136
+ __send__(create_csv, *args, **new_options) do |csv|
137
+ new_options[:converters] = detect_robust_converters(csv)
138
+ end
129
139
  end
130
- return new_options
140
+
141
+ new_options
131
142
  end
132
143
 
133
144
  def have_header?(csv)
145
+ if @options.key?(:headers)
146
+ return @options[:headers]
147
+ end
148
+
134
149
  row1 = csv.shift
135
150
  return false if row1.nil?
136
151
  return false if row1.any?(&:nil?)
@@ -139,6 +154,8 @@ module Arrow
139
154
  return nil if row2.nil?
140
155
  return true if row2.any?(&:nil?)
141
156
 
157
+ return false if row1.any? {|value| not value.is_a?(String)}
158
+
142
159
  if row1.collect(&:class) != row2.collect(&:class)
143
160
  return true
144
161
  end
@@ -149,7 +166,16 @@ module Arrow
149
166
  def detect_robust_converters(csv)
150
167
  column_types = []
151
168
  csv.each do |row|
152
- row.each_with_index do |(_name, value), i|
169
+ if row.is_a?(CSV::Row)
170
+ each_value = Enumerator.new do |yielder|
171
+ row.each do |_name, value|
172
+ yielder << value
173
+ end
174
+ end
175
+ else
176
+ each_value = row.each
177
+ end
178
+ each_value.with_index do |value, i|
153
179
  current_column_type = column_types[i]
154
180
  next if current_column_type == :string
155
181
 
@@ -161,6 +187,9 @@ module Arrow
161
187
  candidate_type = :boolean
162
188
  when Integer
163
189
  candidate_type = :integer
190
+ if current_column_type == :float
191
+ candidate_type = :float
192
+ end
164
193
  when Float
165
194
  candidate_type = :float
166
195
  if current_column_type == :integer
@@ -1,16 +1,19 @@
1
- # Copyright 2017 Kouhei Sutou <kou@clear-code.com>
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
2
8
  #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
9
+ # http://www.apache.org/licenses/LICENSE-2.0
6
10
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
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.
14
17
 
15
18
  require "csv"
16
19
 
@@ -1,16 +1,19 @@
1
- # Copyright 2018 Kouhei Sutou <kou@clear-code.com>
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
2
8
  #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
9
+ # http://www.apache.org/licenses/LICENSE-2.0
6
10
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
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.
14
17
 
15
18
  module Arrow
16
19
  class Date32ArrayBuilder
@@ -1,16 +1,19 @@
1
- # Copyright 2017 Kouhei Sutou <kou@clear-code.com>
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
2
8
  #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
9
+ # http://www.apache.org/licenses/LICENSE-2.0
6
10
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
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.
14
17
 
15
18
  module Arrow
16
19
  class Date32Array
@@ -1,16 +1,19 @@
1
- # Copyright 2018 Kouhei Sutou <kou@clear-code.com>
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
2
8
  #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
9
+ # http://www.apache.org/licenses/LICENSE-2.0
6
10
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
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.
14
17
 
15
18
  module Arrow
16
19
  class Date64ArrayBuilder
@@ -21,7 +24,7 @@ module Arrow
21
24
  end
22
25
 
23
26
  if value.is_a?(Time)
24
- value.to_i * 1_000 + value.usec / 1000
27
+ value.to_i * 1_000 + value.usec / 1_000
25
28
  else
26
29
  value
27
30
  end
@@ -1,16 +1,19 @@
1
- # Copyright 2017 Kouhei Sutou <kou@clear-code.com>
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
2
8
  #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
9
+ # http://www.apache.org/licenses/LICENSE-2.0
6
10
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
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.
14
17
 
15
18
  module Arrow
16
19
  class Date64Array
@@ -1,16 +1,19 @@
1
- # Copyright 2017 Kouhei Sutou <kou@clear-code.com>
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
2
8
  #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
9
+ # http://www.apache.org/licenses/LICENSE-2.0
6
10
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
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.
14
17
 
15
18
  module Arrow
16
19
  class Field
@@ -1,18 +1,24 @@
1
- # Copyright 2018 Kouhei Sutou <kou@clear-code.com>
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
2
8
  #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
9
+ # http://www.apache.org/licenses/LICENSE-2.0
6
10
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
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.
14
17
 
15
18
  module Arrow
19
+ # Experimental
20
+ #
21
+ # TODO: Almost codes should be implemented in Apache Arrow C++.
16
22
  class Group
17
23
  def initialize(table, keys)
18
24
  @table = table
@@ -37,7 +43,7 @@ module Arrow
37
43
  key_names = @keys.collect(&:to_s)
38
44
  target_columns = @table.columns.reject do |column|
39
45
  key_names.include?(column.name) or
40
- not column.data_type.numeric?
46
+ not column.data_type.is_a?(NumericDataType)
41
47
  end
42
48
  aggregate(target_columns) do |column, indexes|
43
49
  n = 0
@@ -53,7 +59,7 @@ module Arrow
53
59
  key_names = @keys.collect(&:to_s)
54
60
  target_columns = @table.columns.reject do |column|
55
61
  key_names.include?(column.name) or
56
- not column.data_type.numeric?
62
+ not column.data_type.is_a?(NumericDataType)
57
63
  end
58
64
  aggregate(target_columns) do |column, indexes|
59
65
  average = 0.0
@@ -69,6 +75,42 @@ module Arrow
69
75
  end
70
76
  end
71
77
 
78
+ def min
79
+ key_names = @keys.collect(&:to_s)
80
+ target_columns = @table.columns.reject do |column|
81
+ key_names.include?(column.name) or
82
+ not column.data_type.is_a?(NumericDataType)
83
+ end
84
+ aggregate(target_columns) do |column, indexes|
85
+ n = nil
86
+ indexes.each do |index|
87
+ value = column[index]
88
+ next if value.nil?
89
+ n ||= value
90
+ n = value if value < n
91
+ end
92
+ n
93
+ end
94
+ end
95
+
96
+ def max
97
+ key_names = @keys.collect(&:to_s)
98
+ target_columns = @table.columns.reject do |column|
99
+ key_names.include?(column.name) or
100
+ not column.data_type.is_a?(NumericDataType)
101
+ end
102
+ aggregate(target_columns) do |column, indexes|
103
+ n = nil
104
+ indexes.each do |index|
105
+ value = column[index]
106
+ next if value.nil?
107
+ n ||= value
108
+ n = value if value > n
109
+ end
110
+ n
111
+ end
112
+ end
113
+
72
114
  private
73
115
  def aggregate(target_columns)
74
116
  sort_values = @table.n_rows.times.collect do |i|