red-arrow 0.11.0 → 0.12.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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/Rakefile +4 -0
  4. data/lib/arrow/array-builder.rb +6 -2
  5. data/lib/arrow/array.rb +6 -2
  6. data/{test/test-csv-reader.rb → lib/arrow/compression-type.rb} +16 -13
  7. data/lib/arrow/csv-loader.rb +102 -2
  8. data/lib/arrow/csv-read-options.rb +25 -0
  9. data/lib/arrow/data-type.rb +135 -0
  10. data/lib/arrow/decimal128-array-builder.rb +64 -0
  11. data/lib/arrow/decimal128-data-type.rb +69 -0
  12. data/lib/arrow/dense-union-data-type.rb +90 -0
  13. data/lib/arrow/dictionary-data-type.rb +106 -0
  14. data/lib/arrow/field-containable.rb +35 -0
  15. data/lib/arrow/field.rb +92 -8
  16. data/lib/arrow/file-output-stream.rb +34 -0
  17. data/lib/arrow/list-array-builder.rb +96 -0
  18. data/lib/arrow/list-data-type.rb +68 -0
  19. data/lib/arrow/loader.rb +30 -5
  20. data/lib/arrow/{csv-reader.rb → path-extension.rb} +19 -28
  21. data/lib/arrow/record-batch-builder.rb +115 -0
  22. data/lib/arrow/record-batch.rb +25 -0
  23. data/lib/arrow/schema.rb +97 -0
  24. data/lib/arrow/sparse-union-data-type.rb +90 -0
  25. data/lib/arrow/struct-array-builder.rb +146 -0
  26. data/lib/arrow/struct-array.rb +34 -0
  27. data/lib/arrow/struct-data-type.rb +130 -0
  28. data/lib/arrow/struct.rb +68 -0
  29. data/lib/arrow/table-loader.rb +65 -25
  30. data/lib/arrow/table-saver.rb +73 -24
  31. data/lib/arrow/table.rb +11 -2
  32. data/lib/arrow/time32-data-type.rb +61 -0
  33. data/lib/arrow/time64-data-type.rb +61 -0
  34. data/lib/arrow/timestamp-data-type.rb +57 -0
  35. data/lib/arrow/version.rb +5 -7
  36. data/lib/arrow/writable.rb +22 -0
  37. data/red-arrow.gemspec +8 -4
  38. data/test/helper.rb +1 -2
  39. data/test/test-csv-loader.rb +27 -0
  40. data/test/test-data-type.rb +47 -0
  41. data/test/test-decimal128-array-builder.rb +95 -0
  42. data/test/test-decimal128-array.rb +38 -0
  43. data/test/test-decimal128-data-type.rb +31 -0
  44. data/test/test-dense-union-data-type.rb +41 -0
  45. data/test/test-dictionary-data-type.rb +40 -0
  46. data/test/test-feather.rb +34 -0
  47. data/test/test-field.rb +71 -0
  48. data/test/test-file-output-stream.rb +54 -0
  49. data/test/test-list-array-builder.rb +79 -0
  50. data/test/test-list-array.rb +32 -0
  51. data/test/test-list-data-type.rb +43 -0
  52. data/test/test-record-batch-builder.rb +116 -0
  53. data/test/test-record-batch.rb +82 -27
  54. data/test/test-schema.rb +104 -0
  55. data/test/test-sparse-union-data-type.rb +41 -0
  56. data/test/test-struct-array-builder.rb +180 -0
  57. data/test/test-struct-array.rb +60 -15
  58. data/test/test-struct-data-type.rb +112 -0
  59. data/test/test-struct.rb +81 -0
  60. data/test/test-table.rb +165 -29
  61. data/test/test-time32-data-type.rb +42 -0
  62. data/test/test-time64-data-type.rb +42 -0
  63. data/test/test-timestamp-data-type.rb +42 -0
  64. metadata +99 -10
@@ -0,0 +1,61 @@
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 Time64DataType
20
+ alias_method :initialize_raw, :initialize
21
+ private :initialize_raw
22
+
23
+ # Creates a new {Arrow::Time64DataType}.
24
+ #
25
+ # @overload initialize(unit)
26
+ #
27
+ # @param unit [Arrow::TimeUnit, Symbol] The unit of the
28
+ # time64 data type.
29
+ #
30
+ # The unit must be microsecond or nanosecond.
31
+ #
32
+ # @example Create a time64 data type with {Arrow::TimeUnit}
33
+ # Arrow::Time64DataType.new(Arrow::TimeUnit::NANO)
34
+ #
35
+ # @example Create a time64 data type with Symbol
36
+ # Arrow::Time64DataType.new(:nano)
37
+ #
38
+ # @overload initialize(description)
39
+ #
40
+ # @param description [Hash] The description of the time64 data
41
+ # type. It must have `:unit` value.
42
+ #
43
+ # @option description [Arrow::TimeUnit, Symbol] :unit The unit of
44
+ # the time64 data type.
45
+ #
46
+ # The unit must be microsecond or nanosecond.
47
+ #
48
+ # @example Create a time64 data type with {Arrow::TimeUnit}
49
+ # Arrow::Time64DataType.new(unit: Arrow::TimeUnit::NANO)
50
+ #
51
+ # @example Create a time64 data type with Symbol
52
+ # Arrow::Time64DataType.new(unit: :nano)
53
+ def initialize(unit)
54
+ if unit.is_a?(Hash)
55
+ description = unit
56
+ unit = description[:unit]
57
+ end
58
+ initialize_raw(unit)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,57 @@
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 TimestampDataType
20
+ alias_method :initialize_raw, :initialize
21
+ private :initialize_raw
22
+
23
+ # Creates a new {Arrow::TimestampDataType}.
24
+ #
25
+ # @overload initialize(unit)
26
+ #
27
+ # @param unit [Arrow::TimeUnit, Symbol] The unit of the
28
+ # timestamp data type.
29
+ #
30
+ # @example Create a timestamp data type with {Arrow::TimeUnit}
31
+ # Arrow::TimestampDataType.new(Arrow::TimeUnit::MILLI)
32
+ #
33
+ # @example Create a timestamp data type with Symbol
34
+ # Arrow::TimestampDataType.new(:milli)
35
+ #
36
+ # @overload initialize(description)
37
+ #
38
+ # @param description [Hash] The description of the timestamp data
39
+ # type. It must have `:unit` value.
40
+ #
41
+ # @option description [Arrow::TimeUnit, Symbol] :unit The unit of
42
+ # the timestamp data type.
43
+ #
44
+ # @example Create a timestamp data type with {Arrow::TimeUnit}
45
+ # Arrow::TimestampDataType.new(unit: Arrow::TimeUnit::MILLI)
46
+ #
47
+ # @example Create a timestamp data type with Symbol
48
+ # Arrow::TimestampDataType.new(unit: :milli)
49
+ def initialize(unit)
50
+ if unit.is_a?(Hash)
51
+ description = unit
52
+ unit = description[:unit]
53
+ end
54
+ initialize_raw(unit)
55
+ end
56
+ end
57
+ end
@@ -16,13 +16,11 @@
16
16
  # under the License.
17
17
 
18
18
  module Arrow
19
+ VERSION = "0.12.0"
20
+
19
21
  module Version
20
- MAJOR = 0
21
- MINOR = 11
22
- MICRO = 0
23
- TAG =
24
- STRING = "0.11.0"
22
+ numbers, TAG = VERSION.split("-")
23
+ MAJOR, MINOR, MICRO = numbers.split(".").collect(&:to_i)
24
+ STRING = VERSION
25
25
  end
26
-
27
- VERSION = Version::STRING
28
26
  end
@@ -0,0 +1,22 @@
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 Writable
20
+ alias_method :<<, :write
21
+ end
22
+ end
@@ -17,7 +17,7 @@
17
17
  # specific language governing permissions and limitations
18
18
  # under the License.
19
19
 
20
- require_relative "version"
20
+ require_relative "lib/arrow/version"
21
21
 
22
22
  Gem::Specification.new do |spec|
23
23
  spec.name = "red-arrow"
@@ -25,9 +25,9 @@ Gem::Specification.new do |spec|
25
25
  Arrow::Version::MAJOR.to_s,
26
26
  Arrow::Version::MINOR.to_s,
27
27
  Arrow::Version::MICRO.to_s,
28
- # "beta1",
28
+ Arrow::Version::TAG,
29
29
  ]
30
- spec.version = version_components.join(".")
30
+ spec.version = version_components.compact.join(".")
31
31
  spec.homepage = "https://arrow.apache.org/"
32
32
  spec.authors = ["Apache Arrow Developers"]
33
33
  spec.email = ["dev@arrow.apache.org"]
@@ -45,11 +45,15 @@ Gem::Specification.new do |spec|
45
45
  spec.test_files += Dir.glob("test/**/*")
46
46
  spec.extensions = ["dependency-check/Rakefile"]
47
47
 
48
- spec.add_runtime_dependency("gobject-introspection", ">= 3.1.1")
48
+ spec.add_runtime_dependency("gobject-introspection", ">= 3.3.1")
49
49
  spec.add_runtime_dependency("pkg-config")
50
50
  spec.add_runtime_dependency("native-package-installer")
51
51
 
52
52
  spec.add_development_dependency("bundler")
53
53
  spec.add_development_dependency("rake")
54
+ spec.add_development_dependency("redcarpet")
54
55
  spec.add_development_dependency("test-unit")
56
+ spec.add_development_dependency("yard")
57
+
58
+ spec.metadata["msys2_mingw_dependencies"] = "apache-arrow"
55
59
  end
@@ -15,12 +15,11 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- require_relative "../version"
19
-
20
18
  require "arrow"
21
19
 
22
20
  require "pathname"
23
21
  require "tempfile"
22
+ require "zlib"
24
23
 
25
24
  require "test-unit"
26
25
 
@@ -115,4 +115,31 @@ class CSVLoaderTest < Test::Unit::TestCase
115
115
  load_csv(path)[:score].to_a)
116
116
  end
117
117
  end
118
+
119
+ sub_test_case("CSVReader") do
120
+ def load_csv(data, options)
121
+ Arrow::CSVLoader.load(data, options)
122
+ end
123
+
124
+ test(":column_types") do
125
+ assert_equal(Arrow::Table.new(:count => Arrow::UInt16Array.new([1, 2, 4])),
126
+ load_csv(<<-CSV, column_types: {count: :uint16}))
127
+ count
128
+ 1
129
+ 2
130
+ 4
131
+ CSV
132
+ end
133
+
134
+ test(":schema") do
135
+ table = Arrow::Table.new(:count => Arrow::UInt16Array.new([1, 2, 4]))
136
+ assert_equal(table,
137
+ load_csv(<<-CSV, schema: table.schema))
138
+ count
139
+ 1
140
+ 2
141
+ 4
142
+ CSV
143
+ end
144
+ end
118
145
  end
@@ -0,0 +1,47 @@
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
+ class DataTypeTest < Test::Unit::TestCase
19
+ sub_test_case(".resolve") do
20
+ test("DataType") do
21
+ assert_equal(Arrow::BooleanDataType.new,
22
+ Arrow::DataType.resolve(Arrow::BooleanDataType.new))
23
+ end
24
+
25
+ test("String") do
26
+ assert_equal(Arrow::BooleanDataType.new,
27
+ Arrow::DataType.resolve("boolean"))
28
+ end
29
+
30
+ test("Symbol") do
31
+ assert_equal(Arrow::BooleanDataType.new,
32
+ Arrow::DataType.resolve(:boolean))
33
+ end
34
+
35
+ test("Array") do
36
+ field = Arrow::Field.new(:visible, :boolean)
37
+ assert_equal(Arrow::ListDataType.new(field),
38
+ Arrow::DataType.resolve([:list, field]))
39
+ end
40
+
41
+ test("Hash") do
42
+ field = Arrow::Field.new(:visible, :boolean)
43
+ assert_equal(Arrow::ListDataType.new(field),
44
+ Arrow::DataType.resolve(type: :list, field: field))
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,95 @@
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
+ class Decimal128ArrayBuilderTest < Test::Unit::TestCase
19
+ def setup
20
+ @data_type = Arrow::Decimal128DataType.new(8, 2)
21
+ @builder = Arrow::Decimal128ArrayBuilder.new(@data_type)
22
+ end
23
+
24
+ sub_test_case("#append_value") do
25
+ test("nil") do
26
+ @builder.append_value(nil)
27
+ array = @builder.finish
28
+ assert_equal(nil, array[0])
29
+ end
30
+
31
+ test("Arrow::Decimal128") do
32
+ @builder.append_value(Arrow::Decimal128.new("10.1"))
33
+ array = @builder.finish
34
+ assert_equal(Arrow::Decimal128.new("10.1"),
35
+ array[0])
36
+ end
37
+
38
+ test("String") do
39
+ @builder.append_value("10.1")
40
+ array = @builder.finish
41
+ assert_equal(Arrow::Decimal128.new("10.1"),
42
+ array[0])
43
+ end
44
+
45
+ test("Float") do
46
+ @builder.append_value(10.1)
47
+ array = @builder.finish
48
+ assert_equal(Arrow::Decimal128.new("10.1"),
49
+ array[0])
50
+ end
51
+
52
+ test("BigDecimal") do
53
+ @builder.append_value(BigDecimal("10.1"))
54
+ array = @builder.finish
55
+ assert_equal(Arrow::Decimal128.new("10.1"),
56
+ array[0])
57
+ end
58
+ end
59
+
60
+ sub_test_case("#append_values") do
61
+ test("mixed") do
62
+ @builder.append_values([
63
+ Arrow::Decimal128.new("10.1"),
64
+ nil,
65
+ "10.1",
66
+ 10.1,
67
+ BigDecimal("10.1"),
68
+ ])
69
+ array = @builder.finish
70
+ assert_equal([
71
+ Arrow::Decimal128.new("10.1"),
72
+ nil,
73
+ Arrow::Decimal128.new("10.1"),
74
+ Arrow::Decimal128.new("10.1"),
75
+ Arrow::Decimal128.new("10.1"),
76
+ ],
77
+ array.to_a)
78
+ end
79
+
80
+ test("is_valids") do
81
+ @builder.append_values([
82
+ Arrow::Decimal128.new("10.1"),
83
+ nil,
84
+ Arrow::Decimal128.new("10.1"),
85
+ ])
86
+ array = @builder.finish
87
+ assert_equal([
88
+ Arrow::Decimal128.new("10.1"),
89
+ nil,
90
+ Arrow::Decimal128.new("10.1"),
91
+ ],
92
+ array.to_a)
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,38 @@
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
+ class Decimal128ArrayTest < Test::Unit::TestCase
19
+ sub_test_case(".new") do
20
+ test("build") do
21
+ data_type = Arrow::Decimal128DataType.new(8, 2)
22
+ values = [
23
+ 10.1,
24
+ nil,
25
+ "10.1",
26
+ BigDecimal("10.1"),
27
+ ]
28
+ array = Arrow::Decimal128Array.new(data_type, values)
29
+ assert_equal([
30
+ Arrow::Decimal128.new("10.1"),
31
+ nil,
32
+ Arrow::Decimal128.new("10.1"),
33
+ Arrow::Decimal128.new("10.1"),
34
+ ],
35
+ array.to_a)
36
+ end
37
+ end
38
+ 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
+ class Decimal128DataTypeTest < Test::Unit::TestCase
19
+ sub_test_case(".new") do
20
+ test("ordered arguments") do
21
+ assert_equal("decimal(8, 2)",
22
+ Arrow::Decimal128DataType.new(8, 2).to_s)
23
+ end
24
+
25
+ test("description") do
26
+ assert_equal("decimal(8, 2)",
27
+ Arrow::Decimal128DataType.new(precision: 8,
28
+ scale: 2).to_s)
29
+ end
30
+ end
31
+ end